OTB  10.0.0
Orfeo Toolbox
otbOGRDataToClassStatisticsFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbOGRDataToClassStatisticsFilter_h
22 #define otbOGRDataToClassStatisticsFilter_h
23 
26 #include "itkSimpleDataObjectDecorator.h"
27 #include <string>
28 
29 namespace otb
30 {
31 
39 template <class TInputImage, class TMaskImage>
40 class ITK_EXPORT PersistentOGRDataToClassStatisticsFilter : public PersistentSamplingFilterBase<TInputImage, TMaskImage>
41 {
42 public:
43 
47  typedef itk::SmartPointer<Self> Pointer;
48  typedef itk::SmartPointer<const Self> ConstPointer;
49 
50  typedef TInputImage InputImageType;
51  typedef typename InputImageType::Pointer InputImagePointer;
52  typedef typename InputImageType::RegionType RegionType;
53  typedef typename InputImageType::PointType PointType;
54 
56  typedef std::map<std::string, unsigned long> ClassCountMapType;
57  typedef std::map<unsigned long, unsigned long> PolygonSizeMapType;
58  typedef itk::SimpleDataObjectDecorator<ClassCountMapType> ClassCountObjectType;
59  typedef itk::SimpleDataObjectDecorator<PolygonSizeMapType> PolygonSizeObjectType;
60 
61  typedef itk::DataObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
62 
64  itkNewMacro(Self);
65 
68 
69  void Synthetize(void) override;
70 
72  void Reset(void) override;
73 
75  const ClassCountObjectType* GetClassCountOutput() const;
76  ClassCountObjectType* GetClassCountOutput();
78 
80  const PolygonSizeObjectType* GetPolygonSizeOutput() const;
81  PolygonSizeObjectType* GetPolygonSizeOutput();
83 
86  itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override;
87  using Superclass::MakeOutput;
88 
89 protected:
92 
95  {
96  }
97 
99  void ProcessSample(const ogr::Feature& feature, typename TInputImage::IndexType& imgIndex, typename TInputImage::PointType& imgPoint,
100  itk::ThreadIdType& threadid) override;
101 
103  void PrepareFeature(const ogr::Feature& feature, itk::ThreadIdType& threadid) override;
104 
105 private:
107  void operator=(const Self&) = delete;
108 
110  std::vector<unsigned long> m_NbPixelsThread;
111 
113  std::vector<ClassCountMapType> m_ElmtsInClassThread;
114 
116  std::vector<PolygonSizeMapType> m_PolygonThread;
117 
119  std::vector<std::string> m_CurrentClass;
120 
122  std::vector<unsigned long> m_CurrentFID;
123 };
124 
134 template <class TInputImage, class TMaskImage>
135 class ITK_EXPORT OGRDataToClassStatisticsFilter : public PersistentFilterStreamingDecorator<PersistentOGRDataToClassStatisticsFilter<TInputImage, TMaskImage>>
136 {
137 public:
138 
142  typedef itk::SmartPointer<Self> Pointer;
143  typedef itk::SmartPointer<const Self> ConstPointer;
144 
145  typedef TInputImage InputImageType;
146  typedef TMaskImage MaskImageType;
148 
154 
156  itkNewMacro(Self);
157 
160 
161  using Superclass::SetInput;
162  virtual void SetInput(const TInputImage* image);
163 
164  const TInputImage* GetInput();
165 
166  void SetOGRData(const otb::ogr::DataSource* data);
167  const otb::ogr::DataSource* GetOGRData();
168 
169  void SetMask(const TMaskImage* mask);
170  const TMaskImage* GetMask();
171 
172  void SetFieldName(std::string& key);
173  std::string GetFieldName();
174 
175  void SetLayerIndex(int index);
176  int GetLayerIndex();
177 
178  const ClassCountObjectType* GetClassCountOutput() const;
179  ClassCountObjectType* GetClassCountOutput();
180 
181  const PolygonSizeObjectType* GetPolygonSizeOutput() const;
182  PolygonSizeObjectType* GetPolygonSizeOutput();
183 
184 protected:
187  {
188  }
189 
192  {
193  }
194 
195 private:
197  void operator=(const Self&) = delete;
198 };
199 
200 } // end of namespace otb
201 
202 #ifndef OTB_MANUAL_INSTANTIATION
204 #endif
205 
206 #endif
Computes class statistics based on vectors using a persistent filter.
void operator=(const Self &)=delete
FilterType::ClassCountObjectType ClassCountObjectType
OGRDataToClassStatisticsFilter(const Self &)=delete
PersistentFilterStreamingDecorator< PersistentOGRDataToClassStatisticsFilter< TInputImage, TMaskImage > > Superclass
FilterType::PolygonSizeObjectType PolygonSizeObjectType
This filter link a persistent filter with a StreamingImageVirtualWriter.
Persistent filter to compute class statistics based on vectors.
std::map< std::string, unsigned long > ClassCountMapType
itk::DataObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
itk::SimpleDataObjectDecorator< ClassCountMapType > ClassCountObjectType
itk::SimpleDataObjectDecorator< PolygonSizeMapType > PolygonSizeObjectType
PersistentOGRDataToClassStatisticsFilter(const Self &)=delete
PersistentSamplingFilterBase< TInputImage, TMaskImage > Superclass
std::map< unsigned long, unsigned long > PolygonSizeMapType
Base class for persistent filter doing sampling tasks.
Collection of geometric objects.
Geometric object with descriptive fields.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.