OTB  9.0.0
Orfeo Toolbox
otbOGRDataToClassStatisticsFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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:
106  PersistentOGRDataToClassStatisticsFilter(const Self&) = delete;
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:
196  OGRDataToClassStatisticsFilter(const Self&) = delete;
197  void operator=(const Self&) = delete;
198 };
199 
200 } // end of namespace otb
201 
202 #ifndef OTB_MANUAL_INSTANTIATION
204 #endif
205 
206 #endif
otb::PersistentOGRDataToClassStatisticsFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbOGRDataToClassStatisticsFilter.h:48
otb::OGRDataToClassStatisticsFilter::Superclass
PersistentFilterStreamingDecorator< PersistentOGRDataToClassStatisticsFilter< TInputImage, TMaskImage > > Superclass
Definition: otbOGRDataToClassStatisticsFilter.h:141
otb::OGRDataToClassStatisticsFilter::FilterType
Superclass::FilterType FilterType
Definition: otbOGRDataToClassStatisticsFilter.h:149
otb::PersistentOGRDataToClassStatisticsFilter::m_CurrentFID
std::vector< unsigned long > m_CurrentFID
Definition: otbOGRDataToClassStatisticsFilter.h:122
otb::PersistentOGRDataToClassStatisticsFilter::m_CurrentClass
std::vector< std::string > m_CurrentClass
Definition: otbOGRDataToClassStatisticsFilter.h:119
otb::PersistentOGRDataToClassStatisticsFilter::DataObjectPointerArraySizeType
itk::DataObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbOGRDataToClassStatisticsFilter.h:61
otb::PersistentOGRDataToClassStatisticsFilter::InputImagePointer
InputImageType::Pointer InputImagePointer
Definition: otbOGRDataToClassStatisticsFilter.h:51
otb::PersistentOGRDataToClassStatisticsFilter::PointType
InputImageType::PointType PointType
Definition: otbOGRDataToClassStatisticsFilter.h:53
otb::OGRDataToClassStatisticsFilter::MaskImageType
TMaskImage MaskImageType
Definition: otbOGRDataToClassStatisticsFilter.h:146
otbPersistentFilterStreamingDecorator.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PersistentOGRDataToClassStatisticsFilter::ClassCountObjectType
itk::SimpleDataObjectDecorator< ClassCountMapType > ClassCountObjectType
Definition: otbOGRDataToClassStatisticsFilter.h:58
otb::ogr::DataSource
Collection of geometric objects.
Definition: otbOGRDataSourceWrapper.h:83
otb::PersistentOGRDataToClassStatisticsFilter
Persistent filter to compute class statistics based on vectors.
Definition: otbOGRDataToClassStatisticsFilter.h:40
otb::PersistentOGRDataToClassStatisticsFilter::m_PolygonThread
std::vector< PolygonSizeMapType > m_PolygonThread
Definition: otbOGRDataToClassStatisticsFilter.h:116
otbPersistentSamplingFilterBase.h
otb::OGRDataToClassStatisticsFilter
Computes class statistics based on vectors using a persistent filter.
Definition: otbOGRDataToClassStatisticsFilter.h:135
otb::OGRDataToClassStatisticsFilter::ClassCountObjectType
FilterType::ClassCountObjectType ClassCountObjectType
Definition: otbOGRDataToClassStatisticsFilter.h:152
otb::PersistentOGRDataToClassStatisticsFilter::ClassCountMapType
std::map< std::string, unsigned long > ClassCountMapType
Definition: otbOGRDataToClassStatisticsFilter.h:56
otb::OGRDataToClassStatisticsFilter::PolygonSizeObjectType
FilterType::PolygonSizeObjectType PolygonSizeObjectType
Definition: otbOGRDataToClassStatisticsFilter.h:153
otb::PersistentSamplingFilterBase
Base class for persistent filter doing sampling tasks.
Definition: otbPersistentSamplingFilterBase.h:42
otb::OGRDataToClassStatisticsFilter::OGRDataToClassStatisticsFilter
OGRDataToClassStatisticsFilter()
Definition: otbOGRDataToClassStatisticsFilter.h:186
otb::PersistentOGRDataToClassStatisticsFilter::Self
PersistentOGRDataToClassStatisticsFilter Self
Definition: otbOGRDataToClassStatisticsFilter.h:45
otb::PersistentOGRDataToClassStatisticsFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOGRDataToClassStatisticsFilter.h:47
otb::PersistentOGRDataToClassStatisticsFilter::m_ElmtsInClassThread
std::vector< ClassCountMapType > m_ElmtsInClassThread
Definition: otbOGRDataToClassStatisticsFilter.h:113
otb::OGRDataToClassStatisticsFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOGRDataToClassStatisticsFilter.h:142
otb::OGRDataToClassStatisticsFilter::~OGRDataToClassStatisticsFilter
~OGRDataToClassStatisticsFilter() override
Definition: otbOGRDataToClassStatisticsFilter.h:191
otb::OGRDataToClassStatisticsFilter::InputImageType
TInputImage InputImageType
Definition: otbOGRDataToClassStatisticsFilter.h:145
otb::PersistentOGRDataToClassStatisticsFilter::~PersistentOGRDataToClassStatisticsFilter
~PersistentOGRDataToClassStatisticsFilter() override
Definition: otbOGRDataToClassStatisticsFilter.h:94
otb::PersistentFilterStreamingDecorator
This filter link a persistent filter with a StreamingImageVirtualWriter.
Definition: otbPersistentFilterStreamingDecorator.h:47
otb::PersistentOGRDataToClassStatisticsFilter::Superclass
PersistentSamplingFilterBase< TInputImage, TMaskImage > Superclass
Definition: otbOGRDataToClassStatisticsFilter.h:46
otb::OGRDataToClassStatisticsFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbOGRDataToClassStatisticsFilter.h:143
otb::PersistentOGRDataToClassStatisticsFilter::PolygonSizeObjectType
itk::SimpleDataObjectDecorator< PolygonSizeMapType > PolygonSizeObjectType
Definition: otbOGRDataToClassStatisticsFilter.h:59
otb::PersistentOGRDataToClassStatisticsFilter::RegionType
InputImageType::RegionType RegionType
Definition: otbOGRDataToClassStatisticsFilter.h:52
otb::PersistentOGRDataToClassStatisticsFilter::PolygonSizeMapType
std::map< unsigned long, unsigned long > PolygonSizeMapType
Definition: otbOGRDataToClassStatisticsFilter.h:57
otb::PersistentOGRDataToClassStatisticsFilter::m_NbPixelsThread
std::vector< unsigned long > m_NbPixelsThread
Definition: otbOGRDataToClassStatisticsFilter.h:110
otb::ogr::Feature
Geometric object with descriptive fields.
Definition: otbOGRFeatureWrapper.h:63
otbOGRDataToClassStatisticsFilter.hxx
otb::OGRDataToClassStatisticsFilter::PolygonSizeMapType
FilterType::PolygonSizeMapType PolygonSizeMapType
Definition: otbOGRDataToClassStatisticsFilter.h:151
otb::OGRDataToClassStatisticsFilter::ClassCountMapType
FilterType::ClassCountMapType ClassCountMapType
Definition: otbOGRDataToClassStatisticsFilter.h:150
otb::OGRDataToClassStatisticsFilter::Self
OGRDataToClassStatisticsFilter Self
Definition: otbOGRDataToClassStatisticsFilter.h:140
otb::PersistentOGRDataToClassStatisticsFilter::InputImageType
TInputImage InputImageType
Definition: otbOGRDataToClassStatisticsFilter.h:50
otb::OGRDataToClassStatisticsFilter::OGRDataType
otb::ogr::DataSource OGRDataType
Definition: otbOGRDataToClassStatisticsFilter.h:147