OTB  6.7.0
Orfeo Toolbox
otbOGRDataToClassStatisticsFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 
27 #include <string>
28 
29 namespace otb
30 {
31 
39 template<class TInputImage, class TMaskImage>
41  public PersistentSamplingFilterBase<TInputImage, TMaskImage>
42 {
43 public:
44 
48  TInputImage,
49  TMaskImage> Superclass;
52 
53  typedef TInputImage InputImageType;
54  typedef typename InputImageType::Pointer InputImagePointer;
55  typedef typename InputImageType::RegionType RegionType;
57 
59  typedef std::map<std::string, unsigned long> ClassCountMapType;
60  typedef std::map<unsigned long, unsigned long> PolygonSizeMapType;
63 
65 
67  itkNewMacro(Self);
68 
71 
72  void Synthetize(void) override;
73 
75  void Reset(void) override;
76 
78  const ClassCountObjectType* GetClassCountOutput() const;
79  ClassCountObjectType* GetClassCountOutput();
81 
83  const PolygonSizeObjectType* GetPolygonSizeOutput() const;
84  PolygonSizeObjectType* GetPolygonSizeOutput();
86 
90  using Superclass::MakeOutput;
91 
92 protected:
95 
98 
100  void ProcessSample(const ogr::Feature& feature,
101  typename TInputImage::IndexType& imgIndex,
102  typename TInputImage::PointType& imgPoint,
103  itk::ThreadIdType& threadid) override;
104 
106  void PrepareFeature(const ogr::Feature& feature,
107  itk::ThreadIdType& threadid) override;
108 
109 private:
110  PersistentOGRDataToClassStatisticsFilter(const Self &) = delete;
111  void operator =(const Self&) = delete;
112 
114  std::vector<unsigned long> m_NbPixelsThread;
115 
117  std::vector<ClassCountMapType> m_ElmtsInClassThread;
118 
120  std::vector<PolygonSizeMapType> m_PolygonThread;
121 
123  std::vector<std::string> m_CurrentClass;
124 
126  std::vector<unsigned long> m_CurrentFID;
127 
128 };
129 
139 template<class TInputImage, class TMaskImage>
141  public PersistentFilterStreamingDecorator<PersistentOGRDataToClassStatisticsFilter<TInputImage,TMaskImage> >
142 {
143 public:
144 
149  <TInputImage,TMaskImage> > Superclass;
152 
153  typedef TInputImage InputImageType;
154  typedef TMaskImage MaskImageType;
156 
158  typedef typename FilterType::ClassCountMapType ClassCountMapType;
159  typedef typename FilterType::PolygonSizeMapType PolygonSizeMapType;
160  typedef typename FilterType::ClassCountObjectType ClassCountObjectType;
161  typedef typename FilterType::PolygonSizeObjectType PolygonSizeObjectType;
162 
164  itkNewMacro(Self);
165 
168 
169  using Superclass::SetInput;
170  virtual void SetInput(const TInputImage* image);
171 
172  const TInputImage* GetInput();
173 
174  void SetOGRData(const otb::ogr::DataSource* data);
175  const otb::ogr::DataSource* GetOGRData();
176 
177  void SetMask(const TMaskImage* mask);
178  const TMaskImage* GetMask();
179 
180  void SetFieldName(std::string &key);
181  std::string GetFieldName();
182 
183  void SetLayerIndex(int index);
184  int GetLayerIndex();
185 
186  const ClassCountObjectType* GetClassCountOutput() const;
187  ClassCountObjectType* GetClassCountOutput();
188 
189  const PolygonSizeObjectType* GetPolygonSizeOutput() const;
190  PolygonSizeObjectType* GetPolygonSizeOutput();
191 
192 protected:
195 
198 
199 private:
200  OGRDataToClassStatisticsFilter(const Self &) = delete;
201  void operator =(const Self&) = delete;
202 };
203 
204 } // end of namespace otb
205 
206 #ifndef OTB_MANUAL_INSTANTIATION
208 #endif
209 
210 #endif
Superclass::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Base class for persistent filter doing sampling tasks.
Collection of geometric objects.
itk::SimpleDataObjectDecorator< ClassCountMapType > ClassCountObjectType
std::vector< Pointer >::size_type DataObjectPointerArraySizeType
PersistentSamplingFilterBase< TInputImage, TMaskImage > Superclass
Persistent filter to compute class statistics based on vectors.
FilterType::ClassCountObjectType ClassCountObjectType
Computes class statistics based on vectors using a persistent filter.
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
FilterType::PolygonSizeObjectType PolygonSizeObjectType
PersistentFilterStreamingDecorator< PersistentOGRDataToClassStatisticsFilter< TInputImage, TMaskImage > > Superclass
std::map< unsigned long, unsigned long > PolygonSizeMapType
unsigned int ThreadIdType
std::map< std::string, unsigned long > ClassCountMapType
Geometric objet with descriptive fields.
VectorImageType::PointType PointType
Definition: mvdTypes.h:189
itk::DataObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
itk::SimpleDataObjectDecorator< PolygonSizeMapType > PolygonSizeObjectType
This filter link a persistent filter with a StreamingImageVirtualWriter.