OTB  9.0.0
Orfeo Toolbox
otbOGRDataToSamplePositionFilter.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 otbOGRDataToSamplePositionFilter_h
22 #define otbOGRDataToSamplePositionFilter_h
23 
27 #include "otbPeriodicSampler.h"
28 #include "otbImage.h"
29 #include <string>
30 
31 namespace otb
32 {
33 
52 template <class TInputImage, class TMaskImage, class TSampler>
53 class ITK_EXPORT PersistentOGRDataToSamplePositionFilter : public PersistentSamplingFilterBase<TInputImage, TMaskImage>
54 {
55 public:
56 
60  typedef itk::SmartPointer<Self> Pointer;
61  typedef itk::SmartPointer<const Self> ConstPointer;
62 
63  typedef TInputImage InputImageType;
64  typedef typename InputImageType::Pointer InputImagePointer;
65  typedef typename InputImageType::RegionType RegionType;
66  typedef typename InputImageType::PointType PointType;
67 
68  typedef TMaskImage MaskImageType;
69  typedef typename MaskImageType::Pointer MaskImagePointer;
70 
73 
74  typedef TSampler SamplerType;
75  typedef typename SamplerType::Pointer SamplerPointerType;
77  typedef typename std::map<std::string, SamplerPointerType> SamplerMapType;
78 
79  typedef std::map<std::string, unsigned int> ClassPartitionType;
80 
81  typedef itk::DataObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
82 
84  itkNewMacro(Self);
85 
88 
89  void Synthetize(void) override
90  {
91  }
92 
94  void Reset(void) override;
95 
97  SamplerMapType& GetSamplers(unsigned int level);
98 
101  void SetOutputPositionContainerAndRates(otb::ogr::DataSource* data, const SamplingRateCalculator::MapRateType& map, unsigned int level);
102 
104  const otb::ogr::DataSource* GetOutputPositionContainer(unsigned int level) const;
105  otb::ogr::DataSource* GetOutputPositionContainer(unsigned int level);
107 
109  unsigned int GetNumberOfLevels();
110 
112  void ClearOutputs();
113 
116  itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override;
117  using Superclass::MakeOutput;
118 
120  itkSetMacro(OriginFieldName, std::string);
121  itkGetMacro(OriginFieldName, std::string);
123 
124 protected:
127 
130  {
131  }
132 
134  void ProcessSample(const ogr::Feature& feature, typename TInputImage::IndexType& imgIndex, typename TInputImage::PointType& imgPoint,
135  itk::ThreadIdType& threadid) override;
136 
140  void DispatchInputVectors(void) override;
141 
143  void FillOneOutput(unsigned int outIdx, ogr::DataSource* outDS, bool update) override;
144 
145 private:
146  PersistentOGRDataToSamplePositionFilter(const Self&) = delete;
147  void operator=(const Self&) = delete;
148 
149  void ComputeClassPartition(void);
150 
153 
155  std::vector<SamplerMapType> m_Samplers;
156 
159  std::string m_OriginFieldName;
160 
163 };
164 
174 template <class TInputImage, class TMaskImage = otb::Image<unsigned char>, class TSampler = otb::PeriodicSampler>
176  : public PersistentFilterStreamingDecorator<PersistentOGRDataToSamplePositionFilter<TInputImage, TMaskImage, TSampler>>
177 {
178 public:
179 
183  typedef itk::SmartPointer<Self> Pointer;
184  typedef itk::SmartPointer<const Self> ConstPointer;
185 
186  typedef TInputImage InputImageType;
187  typedef TMaskImage MaskImageType;
189 
191 
192  typedef TSampler SamplerType;
193  typedef typename SamplerType::Pointer SamplerPointerType;
195  typedef typename std::map<std::string, SamplerPointerType> SamplerMapType;
196 
198  itkNewMacro(Self);
199 
202 
203  using Superclass::SetInput;
204 
206  virtual void SetInput(const TInputImage* image);
207 
209  const TInputImage* GetInput();
210 
212  void SetOGRData(const otb::ogr::DataSource* data);
213 
215  const otb::ogr::DataSource* GetOGRData();
216 
218  void SetMask(const TMaskImage* mask);
219 
221  const TMaskImage* GetMask();
222 
224  void SetFieldName(std::string key);
225 
227  std::string GetFieldName();
228 
230  void SetLayerIndex(int index);
231 
233  int GetLayerIndex();
234 
236  void SetSamplerParameters(SamplerParameterType param, unsigned int level = 0);
237 
239  SamplerMapType& GetSamplers(unsigned int level = 0);
240 
242  void SetOutputPositionContainerAndRates(otb::ogr::DataSource* data, const SamplingRateCalculator::MapRateType& map, unsigned int level = 0);
243 
245  otb::ogr::DataSource* GetOutputPositionContainer(unsigned int level = 0);
246 
248  void SetOriginFieldName(std::string key);
249 
251  std::string GetOriginFieldName();
252 
253 protected:
256  {
257  }
258 
261  {
262  }
263 
264 private:
265  OGRDataToSamplePositionFilter(const Self&) = delete;
266  void operator=(const Self&) = delete;
267 };
268 
269 } // end of namespace otb
270 
271 #ifndef OTB_MANUAL_INSTANTIATION
273 #endif
274 
275 #endif
otb::OGRDataToSamplePositionFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbOGRDataToSamplePositionFilter.h:184
otb::OGRDataToSamplePositionFilter
Extracts sample position from an image using a persistent filter.
Definition: otbOGRDataToSamplePositionFilter.h:175
otb::PersistentOGRDataToSamplePositionFilter::MaskImageType
TMaskImage MaskImageType
Definition: otbOGRDataToSamplePositionFilter.h:68
otb::OGRDataToSamplePositionFilter::MaskImageType
TMaskImage MaskImageType
Definition: otbOGRDataToSamplePositionFilter.h:187
otb::PersistentOGRDataToSamplePositionFilter::SamplerParameterType
SamplerType::ParameterType SamplerParameterType
Definition: otbOGRDataToSamplePositionFilter.h:76
otb::PersistentOGRDataToSamplePositionFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOGRDataToSamplePositionFilter.h:60
otb::PersistentOGRDataToSamplePositionFilter::PointType
InputImageType::PointType PointType
Definition: otbOGRDataToSamplePositionFilter.h:66
otb::PersistentOGRDataToSamplePositionFilter::m_UseOriginField
bool m_UseOriginField
Definition: otbOGRDataToSamplePositionFilter.h:162
otb::OGRDataToSamplePositionFilter::Superclass
PersistentFilterStreamingDecorator< PersistentOGRDataToSamplePositionFilter< TInputImage, TMaskImage, TSampler > > Superclass
Definition: otbOGRDataToSamplePositionFilter.h:182
otb::OGRDataToSamplePositionFilter::SamplerPointerType
SamplerType::Pointer SamplerPointerType
Definition: otbOGRDataToSamplePositionFilter.h:193
otbImage.h
otb::PersistentOGRDataToSamplePositionFilter::Synthetize
void Synthetize(void) override
Definition: otbOGRDataToSamplePositionFilter.h:89
otb::PersistentOGRDataToSamplePositionFilter::SamplerPointerType
SamplerType::Pointer SamplerPointerType
Definition: otbOGRDataToSamplePositionFilter.h:75
otb::PersistentOGRDataToSamplePositionFilter::m_ClassPartition
ClassPartitionType m_ClassPartition
Definition: otbOGRDataToSamplePositionFilter.h:152
otb::OGRDataToSamplePositionFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOGRDataToSamplePositionFilter.h:183
otbPersistentFilterStreamingDecorator.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ogr::DataSource
Collection of geometric objects.
Definition: otbOGRDataSourceWrapper.h:83
otb::OGRDataToSamplePositionFilter::Self
OGRDataToSamplePositionFilter Self
Definition: otbOGRDataToSamplePositionFilter.h:181
otb::PersistentOGRDataToSamplePositionFilter::OGRDataType
ogr::DataSource OGRDataType
Definition: otbOGRDataToSamplePositionFilter.h:71
otbPersistentSamplingFilterBase.h
otb::PersistentOGRDataToSamplePositionFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbOGRDataToSamplePositionFilter.h:61
otb::OGRDataToSamplePositionFilter::~OGRDataToSamplePositionFilter
~OGRDataToSamplePositionFilter() override
Definition: otbOGRDataToSamplePositionFilter.h:260
otb::PersistentSamplingFilterBase
Base class for persistent filter doing sampling tasks.
Definition: otbPersistentSamplingFilterBase.h:42
otb::PersistentOGRDataToSamplePositionFilter::SamplerType
TSampler SamplerType
Definition: otbOGRDataToSamplePositionFilter.h:74
otb::PersistentOGRDataToSamplePositionFilter
Persistent filter to extract sample position from an image.
Definition: otbOGRDataToSamplePositionFilter.h:53
otb::OGRDataToSamplePositionFilter::OGRDataType
otb::ogr::DataSource OGRDataType
Definition: otbOGRDataToSamplePositionFilter.h:188
otb::PersistentFilterStreamingDecorator::FilterType
TFilter FilterType
Definition: otbPersistentFilterStreamingDecorator.h:60
otb::OGRDataToSamplePositionFilter::OGRDataToSamplePositionFilter
OGRDataToSamplePositionFilter()
Definition: otbOGRDataToSamplePositionFilter.h:255
otb::PersistentOGRDataToSamplePositionFilter::DataObjectPointerArraySizeType
itk::DataObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbOGRDataToSamplePositionFilter.h:81
otb::PersistentOGRDataToSamplePositionFilter::RegionType
InputImageType::RegionType RegionType
Definition: otbOGRDataToSamplePositionFilter.h:65
otb::SamplingRateCalculator::MapRateType
std::map< std::string, TripletType > MapRateType
Definition: otbSamplingRateCalculator.h:60
otbPeriodicSampler.h
otb::OGRDataToSamplePositionFilter::SamplerType
TSampler SamplerType
Definition: otbOGRDataToSamplePositionFilter.h:192
otb::PersistentOGRDataToSamplePositionFilter::m_OriginFieldName
std::string m_OriginFieldName
Definition: otbOGRDataToSamplePositionFilter.h:159
otb::PersistentFilterStreamingDecorator
This filter link a persistent filter with a StreamingImageVirtualWriter.
Definition: otbPersistentFilterStreamingDecorator.h:47
otb::OGRDataToSamplePositionFilter::SamplerParameterType
SamplerType::ParameterType SamplerParameterType
Definition: otbOGRDataToSamplePositionFilter.h:194
otb::PersistentOGRDataToSamplePositionFilter::ClassPartitionType
std::map< std::string, unsigned int > ClassPartitionType
Definition: otbOGRDataToSamplePositionFilter.h:79
otb::ogr::DataSource::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOGRDataSourceWrapper.h:90
otb::PersistentOGRDataToSamplePositionFilter::Self
PersistentOGRDataToSamplePositionFilter Self
Definition: otbOGRDataToSamplePositionFilter.h:58
otb::PersistentOGRDataToSamplePositionFilter::m_Samplers
std::vector< SamplerMapType > m_Samplers
Definition: otbOGRDataToSamplePositionFilter.h:155
otb::PersistentOGRDataToSamplePositionFilter::InputImagePointer
InputImageType::Pointer InputImagePointer
Definition: otbOGRDataToSamplePositionFilter.h:64
otb::PersistentOGRDataToSamplePositionFilter::InputImageType
TInputImage InputImageType
Definition: otbOGRDataToSamplePositionFilter.h:63
otbOGRDataToSamplePositionFilter.hxx
otb::ogr::Feature
Geometric object with descriptive fields.
Definition: otbOGRFeatureWrapper.h:63
otb::PersistentOGRDataToSamplePositionFilter::MaskImagePointer
MaskImageType::Pointer MaskImagePointer
Definition: otbOGRDataToSamplePositionFilter.h:69
otb::OGRDataToSamplePositionFilter::SamplerMapType
std::map< std::string, SamplerPointerType > SamplerMapType
Definition: otbOGRDataToSamplePositionFilter.h:195
otb::PersistentOGRDataToSamplePositionFilter::SamplerMapType
std::map< std::string, SamplerPointerType > SamplerMapType
Definition: otbOGRDataToSamplePositionFilter.h:77
otb::PersistentOGRDataToSamplePositionFilter::~PersistentOGRDataToSamplePositionFilter
~PersistentOGRDataToSamplePositionFilter() override
Definition: otbOGRDataToSamplePositionFilter.h:129
otb::OGRDataToSamplePositionFilter::FilterType
Superclass::FilterType FilterType
Definition: otbOGRDataToSamplePositionFilter.h:190
otb::PersistentOGRDataToSamplePositionFilter::Superclass
PersistentSamplingFilterBase< TInputImage, TMaskImage > Superclass
Definition: otbOGRDataToSamplePositionFilter.h:59
otbSamplingRateCalculator.h
otb::PersistentOGRDataToSamplePositionFilter::OGRDataPointer
ogr::DataSource::Pointer OGRDataPointer
Definition: otbOGRDataToSamplePositionFilter.h:72
otb::Wrapper::ParameterType
ParameterType
Definition: otbWrapperTypes.h:37
otb::OGRDataToSamplePositionFilter::InputImageType
TInputImage InputImageType
Definition: otbOGRDataToSamplePositionFilter.h:186