21 #ifndef otbOGRDataToClassStatisticsFilter_hxx
22 #define otbOGRDataToClassStatisticsFilter_hxx
30 template <
class TInputImage,
class TMaskImage>
33 this->SetNumberOfRequiredOutputs(3);
34 this->SetNthOutput(0, TInputImage::New());
35 this->SetNthOutput(1, ClassCountObjectType::New());
36 this->SetNthOutput(2, PolygonSizeObjectType::New());
39 template <
class TInputImage,
class TMaskImage>
43 vectors->
GetLayer(this->GetLayerIndex()).SetSpatialFilter(
nullptr);
52 for (
unsigned int k = 0; k < this->GetNumberOfWorkUnits(); k++)
54 ClassCountMapType::iterator itClass = m_ElmtsInClassThread[k].
begin();
55 for (; itClass != m_ElmtsInClassThread[k].end(); ++itClass)
57 if (classCount.count(itClass->first))
59 classCount[itClass->first] += itClass->second;
63 classCount[itClass->first] = itClass->second;
66 PolygonSizeMapType::iterator itPoly = m_PolygonThread[k].begin();
67 for (; itPoly != m_PolygonThread[k].end(); ++itPoly)
69 if (polygonSize.count(itPoly->first))
71 polygonSize[itPoly->first] += itPoly->second;
75 polygonSize[itPoly->first] = itPoly->second;
80 m_ElmtsInClassThread.clear();
81 m_PolygonThread.clear();
82 m_NbPixelsThread.clear();
85 template <
class TInputImage,
class TMaskImage>
88 m_ElmtsInClassThread.clear();
89 m_PolygonThread.clear();
90 m_NbPixelsThread.clear();
92 m_ElmtsInClassThread.resize(this->GetNumberOfWorkUnits());
93 m_PolygonThread.resize(this->GetNumberOfWorkUnits());
94 m_NbPixelsThread.resize(this->GetNumberOfWorkUnits());
95 m_CurrentClass.resize(this->GetNumberOfWorkUnits());
96 m_CurrentFID.resize(this->GetNumberOfWorkUnits());
99 template <
class TInputImage,
class TMaskImage>
103 if (this->GetNumberOfOutputs() < 2)
110 template <
class TInputImage,
class TMaskImage>
114 if (this->GetNumberOfOutputs() < 2)
121 template <
class TInputImage,
class TMaskImage>
125 if (this->GetNumberOfOutputs() < 3)
132 template <
class TInputImage,
class TMaskImage>
136 if (this->GetNumberOfOutputs() < 3)
143 template <
class TInputImage,
class TMaskImage>
149 return static_cast<itk::DataObject*
>(TInputImage::New().GetPointer());
152 return static_cast<itk::DataObject*
>(ClassCountObjectType::New().GetPointer());
155 return static_cast<itk::DataObject*
>(PolygonSizeObjectType::New().GetPointer());
159 return static_cast<itk::DataObject*
>(TInputImage::New().GetPointer());
164 template <
class TInputImage,
class TMaskImage>
166 typename TInputImage::PointType&, itk::ThreadIdType& threadid)
168 std::string& className = m_CurrentClass[threadid];
169 unsigned long& fId = m_CurrentFID[threadid];
171 m_ElmtsInClassThread[threadid][className]++;
172 m_PolygonThread[threadid][fId]++;
173 m_NbPixelsThread[threadid]++;
176 template <
class TInputImage,
class TMaskImage>
179 std::string className(feature.
ogr().GetFieldAsString(this->GetFieldIndex()));
180 unsigned long fId = feature.
ogr().GetFID();
181 if (!m_ElmtsInClassThread[threadid].count(className))
183 m_ElmtsInClassThread[threadid][className] = 0;
185 if (!m_PolygonThread[threadid].count(fId))
187 m_PolygonThread[threadid][fId] = 0;
189 m_CurrentClass[threadid] = className;
190 m_CurrentFID[threadid] = fId;
195 template <
class TInputImage,
class TMaskImage>
198 this->GetFilter()->SetInput(image);
201 template <
class TInputImage,
class TMaskImage>
204 return this->GetFilter()->GetInput();
207 template <
class TInputImage,
class TMaskImage>
210 this->GetFilter()->SetOGRData(data);
213 template <
class TInputImage,
class TMaskImage>
216 return this->GetFilter()->GetOGRData();
219 template <
class TInputImage,
class TMaskImage>
222 this->GetFilter()->SetMask(mask);
225 template <
class TInputImage,
class TMaskImage>
228 return this->GetFilter()->GetMask();
231 template <
class TInputImage,
class TMaskImage>
234 this->GetFilter()->SetFieldName(key);
237 template <
class TInputImage,
class TMaskImage>
240 return this->GetFilter()->GetFieldName();
243 template <
class TInputImage,
class TMaskImage>
246 this->GetFilter()->SetLayerIndex(index);
249 template <
class TInputImage,
class TMaskImage>
252 return this->GetFilter()->GetLayerIndex();
255 template <
class TInputImage,
class TMaskImage>
259 return this->GetFilter()->GetClassCountOutput();
262 template <
class TInputImage,
class TMaskImage>
266 return this->GetFilter()->GetClassCountOutput();
269 template <
class TInputImage,
class TMaskImage>
273 return this->GetFilter()->GetPolygonSizeOutput();
276 template <
class TInputImage,
class TMaskImage>
280 return this->GetFilter()->GetPolygonSizeOutput();
const otb::ogr::DataSource * GetOGRData()
void SetLayerIndex(int index)
std::string GetFieldName()
void SetFieldName(std::string &key)
const ClassCountObjectType * GetClassCountOutput() const
void SetMask(const TMaskImage *mask)
const TInputImage * GetInput()
FilterType::ClassCountObjectType ClassCountObjectType
const TMaskImage * GetMask()
const PolygonSizeObjectType * GetPolygonSizeOutput() const
virtual void SetInput(const TInputImage *image)
FilterType::PolygonSizeObjectType PolygonSizeObjectType
void SetOGRData(const otb::ogr::DataSource *data)
void PrepareFeature(const ogr::Feature &feature, itk::ThreadIdType &threadid) override
std::map< std::string, unsigned long > ClassCountMapType
itk::DataObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
itk::SimpleDataObjectDecorator< ClassCountMapType > ClassCountObjectType
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
void ProcessSample(const ogr::Feature &feature, typename TInputImage::IndexType &imgIndex, typename TInputImage::PointType &imgPoint, itk::ThreadIdType &threadid) override
void Reset(void) override
itk::SimpleDataObjectDecorator< PolygonSizeMapType > PolygonSizeObjectType
const PolygonSizeObjectType * GetPolygonSizeOutput() const
PersistentOGRDataToClassStatisticsFilter()
const ClassCountObjectType * GetClassCountOutput() const
void Synthetize(void) override
std::map< unsigned long, unsigned long > PolygonSizeMapType
Collection of geometric objects.
Layer GetLayer(vcl_size_t i)
Geometric object with descriptive fields.
const_iterator begin() const
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.