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->GetNumberOfThreads(); 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->GetNumberOfThreads());
93 m_PolygonThread.resize(this->GetNumberOfThreads());
94 m_NbPixelsThread.resize(this->GetNumberOfThreads());
95 m_CurrentClass.resize(this->GetNumberOfThreads());
96 m_CurrentFID.resize(this->GetNumberOfThreads());
99 template <
class TInputImage,
class TMaskImage>
103 if (this->GetNumberOfOutputs() < 2)
110 template <
class TInputImage,
class TMaskImage>
114 if (this->GetNumberOfOutputs() < 2)
118 return static_cast<ClassCountObjectType*
>(this->itk::ProcessObject::GetOutput(1));
121 template <
class TInputImage,
class TMaskImage>
125 if (this->GetNumberOfOutputs() < 3)
132 template <
class TInputImage,
class TMaskImage>
136 if (this->GetNumberOfOutputs() < 3)
140 return static_cast<PolygonSizeObjectType*
>(this->itk::ProcessObject::GetOutput(2));
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();