File: otbOGRDataToClassStatisticsFilter.h

package info (click to toggle)
otb 8.1.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,030,436 kB
  • sloc: xml: 231,007; cpp: 224,490; ansic: 4,592; sh: 1,790; python: 1,131; perl: 92; makefile: 72
file content (196 lines) | stat: -rw-r--r-- 6,779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef otbOGRDataToClassStatisticsFilter_h
#define otbOGRDataToClassStatisticsFilter_h

#include "otbPersistentSamplingFilterBase.h"
#include "otbPersistentFilterStreamingDecorator.h"
#include "itkSimpleDataObjectDecorator.h"
#include <string>

namespace otb
{

/**
 * \class PersistentOGRDataToClassStatisticsFilter
 *
 * \brief Persistent filter to compute class statistics based on vectors
 *
 * \ingroup OTBSampling
 */
template <class TInputImage, class TMaskImage>
class ITK_EXPORT PersistentOGRDataToClassStatisticsFilter : public PersistentSamplingFilterBase<TInputImage, TMaskImage>
{
public:
  /** Standard Self typedef */
  typedef PersistentOGRDataToClassStatisticsFilter Self;
  typedef PersistentSamplingFilterBase<TInputImage, TMaskImage> Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;

  typedef TInputImage                         InputImageType;
  typedef typename InputImageType::Pointer    InputImagePointer;
  typedef typename InputImageType::RegionType RegionType;
  typedef typename InputImageType::PointType  PointType;

  /** Wrap output type as DataObject */
  typedef std::map<std::string, unsigned long>   ClassCountMapType;
  typedef std::map<unsigned long, unsigned long> PolygonSizeMapType;
  typedef itk::SimpleDataObjectDecorator<ClassCountMapType>  ClassCountObjectType;
  typedef itk::SimpleDataObjectDecorator<PolygonSizeMapType> PolygonSizeObjectType;

  typedef itk::DataObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Runtime information support. */
  itkTypeMacro(PersistentOGRDataToClassStatisticsFilter, PersistentSamplingFilterBase);

  void Synthetize(void) override;

  /** Reset method called before starting the streaming*/
  void Reset(void) override;

  /** the class count map is stored as output #2 */
  const ClassCountObjectType* GetClassCountOutput() const;
  ClassCountObjectType*       GetClassCountOutput();

  /** the polygon size map is stored as output #3 */
  const PolygonSizeObjectType* GetPolygonSizeOutput() const;
  PolygonSizeObjectType*       GetPolygonSizeOutput();

  /** Make a DataObject of the correct type to be used as the specified
   * output. */
  itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override;
  using Superclass::MakeOutput;

protected:
  /** Constructor */
  PersistentOGRDataToClassStatisticsFilter();
  /** Destructor */
  ~PersistentOGRDataToClassStatisticsFilter() override
  {
  }

  /** Implement generic method called at each candidate position */
  void ProcessSample(const ogr::Feature& feature, typename TInputImage::IndexType& imgIndex, typename TInputImage::PointType& imgPoint,
                     itk::ThreadIdType& threadid) override;

  /** Prepare temporary variables for the current feature */
  void PrepareFeature(const ogr::Feature& feature, itk::ThreadIdType& threadid) override;

private:
  PersistentOGRDataToClassStatisticsFilter(const Self&) = delete;
  void operator=(const Self&) = delete;

  /** Number of pixels in all the polygons (per thread) */
  std::vector<unsigned long> m_NbPixelsThread;
  /** Number of pixels in each classes (per thread) */
  std::vector<ClassCountMapType> m_ElmtsInClassThread;
  /** Number of pixels in each polygons (per thread) */
  std::vector<PolygonSizeMapType> m_PolygonThread;
  /** Class name of the current feature (per thread) */
  std::vector<std::string> m_CurrentClass;
  /** FID of the current feature (per thread) */
  std::vector<unsigned long> m_CurrentFID;
};

/**
 * \class OGRDataToClassStatisticsFilter
 *
 * \brief Computes class statistics based on vectors using a persistent filter
 *
 * \sa PersistentOGRDataToClassStatisticsFilter
 *
 * \ingroup OTBSampling
 */
template <class TInputImage, class TMaskImage>
class ITK_EXPORT OGRDataToClassStatisticsFilter : public PersistentFilterStreamingDecorator<PersistentOGRDataToClassStatisticsFilter<TInputImage, TMaskImage>>
{
public:
  /** Standard Self typedef */
  typedef OGRDataToClassStatisticsFilter Self;
  typedef PersistentFilterStreamingDecorator<PersistentOGRDataToClassStatisticsFilter<TInputImage, TMaskImage>> Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;

  typedef TInputImage          InputImageType;
  typedef TMaskImage           MaskImageType;
  typedef otb::ogr::DataSource OGRDataType;

  typedef typename Superclass::FilterType            FilterType;
  typedef typename FilterType::ClassCountMapType     ClassCountMapType;
  typedef typename FilterType::PolygonSizeMapType    PolygonSizeMapType;
  typedef typename FilterType::ClassCountObjectType  ClassCountObjectType;
  typedef typename FilterType::PolygonSizeObjectType PolygonSizeObjectType;

  /** Type macro */
  itkNewMacro(Self);

  /** Creation through object factory macro */
  itkTypeMacro(OGRDataToClassStatisticsFilter, PersistentFilterStreamingDecorator);

  using Superclass::SetInput;
  virtual void SetInput(const TInputImage* image);

  const TInputImage* GetInput();

  void SetOGRData(const otb::ogr::DataSource* data);
  const otb::ogr::DataSource* GetOGRData();

  void SetMask(const TMaskImage* mask);
  const TMaskImage* GetMask();

  void SetFieldName(std::string& key);
  std::string GetFieldName();

  void SetLayerIndex(int index);
  int GetLayerIndex();

  const ClassCountObjectType* GetClassCountOutput() const;
  ClassCountObjectType*       GetClassCountOutput();

  const PolygonSizeObjectType* GetPolygonSizeOutput() const;
  PolygonSizeObjectType*       GetPolygonSizeOutput();

protected:
  /** Constructor */
  OGRDataToClassStatisticsFilter()
  {
  }
  /** Destructor */
  ~OGRDataToClassStatisticsFilter() override
  {
  }

private:
  OGRDataToClassStatisticsFilter(const Self&) = delete;
  void operator=(const Self&) = delete;
};

} // end of namespace otb

#ifndef OTB_MANUAL_INSTANTIATION
#include "otbOGRDataToClassStatisticsFilter.hxx"
#endif

#endif