OTB  9.0.0
Orfeo Toolbox
otbPersistentSamplingFilterBase.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 otbPersistentSamplingFilterBase_h
22 #define otbPersistentSamplingFilterBase_h
23 
26 #include "otbImage.h"
27 #include <string>
28 
29 namespace otb
30 {
41 template <class TInputImage, class TMaskImage = otb::Image<unsigned char, 2>>
42 class ITK_EXPORT PersistentSamplingFilterBase : public otb::PersistentImageFilter<TInputImage, TInputImage>
43 {
44 public:
48  typedef itk::SmartPointer<Self> Pointer;
49  typedef itk::SmartPointer<const Self> ConstPointer;
50 
53 
55  typedef TInputImage InputImageType;
56  typedef TMaskImage MaskImageType;
57 
58  typedef typename TInputImage::RegionType RegionType;
59 
61 
63  void SetOGRData(const ogr::DataSource* vector);
64 
66  const ogr::DataSource* GetOGRData();
67 
69  void SetMask(const TMaskImage* mask);
70 
72  const TMaskImage* GetMask();
73 
75  void SetOGRLayerCreationOptions(const std::vector<std::string>& options);
76 
78  const std::vector<std::string>& GetOGRLayerCreationOptions();
79 
82  itkSetMacro(FieldName, std::string);
83  itkGetMacro(FieldName, std::string);
85 
87  itkGetMacro(FieldIndex, int);
88 
90  itkSetMacro(LayerIndex, int);
91  itkGetMacro(LayerIndex, int);
93 
95  itkSetMacro(OutLayerName, std::string);
96  itkGetMacro(OutLayerName, std::string);
98 
99 protected:
102 
105  {
106  }
107 
110  void GenerateOutputInformation() override;
111 
114  void GenerateInputRequestedRegion() override;
115 
117  void GenerateData(void) override;
118 
120  void AllocateOutputs(void) override;
121 
123  virtual void ThreadedGenerateVectorData(const ogr::Layer& layerForThread, itk::ThreadIdType threadid);
124 
126  void ExploreGeometry(const ogr::Feature& feature, OGRGeometry* geom, RegionType& region, itk::ThreadIdType& threadid);
127 
129  virtual void ProcessLine(const ogr::Feature& feature, OGRLineString* line, RegionType& region, itk::ThreadIdType& threadid);
130 
132  virtual void ProcessPolygon(const ogr::Feature& feature, OGRPolygon* polygon, RegionType& region, itk::ThreadIdType& threadid);
133 
135  virtual void ProcessSample(const ogr::Feature& feature, typename TInputImage::IndexType& imgIndex, typename TInputImage::PointType& imgPoint,
136  itk::ThreadIdType& threadid);
137 
139  virtual void PrepareFeature(const ogr::Feature& feature, itk::ThreadIdType& threadid);
140 
142  bool IsSampleInsidePolygon(OGRPolygon* poly, OGRPoint* tmpPoint);
143 
145  bool IsSampleOnLine(OGRLineString* line, typename TInputImage::PointType& position, typename TInputImage::SpacingType& absSpacing, OGRPolygon& tmpPolygon);
146 
148  RegionType FeatureBoundingRegion(const TInputImage* image, otb::ogr::Layer::const_iterator& featIt) const;
149 
153  virtual void DispatchInputVectors(void);
154 
156  virtual void GatherOutputVectors(void);
157 
159  virtual void FillOneOutput(unsigned int outIdx, ogr::DataSource* outDS, bool update);
160 
162  virtual void InitializeOutputDataSource(ogr::DataSource* inputDS, ogr::DataSource* outputDS);
163 
164  typedef struct
165  {
166  std::string Name;
167  OGRFieldType Type;
168  int Width;
170  } SimpleFieldDefn;
171 
173  void ClearAdditionalFields();
174 
176  void CreateAdditionalField(std::string name, OGRFieldType type, int width = 0, int precision = 0);
177 
179  const std::vector<SimpleFieldDefn>& GetAdditionalFields();
180 
182  static ITK_THREAD_RETURN_TYPE VectorThreaderCallback(void* arg);
183 
186  {
188  };
189 
191  ogr::Layer GetInMemoryInput(unsigned int threadId);
192 
194  ogr::Layer GetInMemoryOutput(unsigned int threadId, unsigned int index = 0);
195 
196 private:
197  PersistentSamplingFilterBase(const Self&) = delete;
198  void operator=(const Self&) = delete;
199 
201  std::string m_FieldName;
202 
205 
208 
210  std::string m_OutLayerName;
211 
213  std::vector<std::string> m_OGRLayerCreationOptions;
214 
216  std::vector<SimpleFieldDefn> m_AdditionalFields;
217 
219  std::vector<OGRDataPointer> m_InMemoryInputs;
220 
222  std::vector<std::vector<OGRDataPointer>> m_InMemoryOutputs;
223 };
224 } // End namespace otb
225 
226 #ifndef OTB_MANUAL_INSTANTIATION
228 #endif
229 
230 #endif
otb::PersistentSamplingFilterBase::VectorThreadStruct::Filter
Pointer Filter
Definition: otbPersistentSamplingFilterBase.h:187
otb::PersistentSamplingFilterBase::m_InMemoryOutputs
std::vector< std::vector< OGRDataPointer > > m_InMemoryOutputs
Definition: otbPersistentSamplingFilterBase.h:222
otbPersistentImageFilter.h
otb::PersistentSamplingFilterBase::m_OutLayerName
std::string m_OutLayerName
Definition: otbPersistentSamplingFilterBase.h:210
otb::PersistentImageFilter
This filter is the base class for all filter persisting data through multiple update....
Definition: otbPersistentImageFilter.h:47
otbImage.h
otb::PersistentSamplingFilterBase::Superclass
PersistentImageFilter< TInputImage, TInputImage > Superclass
Definition: otbPersistentSamplingFilterBase.h:47
otb::PersistentSamplingFilterBase::InputImageType
TInputImage InputImageType
Definition: otbPersistentSamplingFilterBase.h:52
otb::PersistentSamplingFilterBase::MaskImageType
TMaskImage MaskImageType
Definition: otbPersistentSamplingFilterBase.h:56
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::PersistentSamplingFilterBase::VectorThreadStruct
Definition: otbPersistentSamplingFilterBase.h:185
otb::PersistentSamplingFilterBase::m_OGRLayerCreationOptions
std::vector< std::string > m_OGRLayerCreationOptions
Definition: otbPersistentSamplingFilterBase.h:213
otb::PersistentSamplingFilterBase
Base class for persistent filter doing sampling tasks.
Definition: otbPersistentSamplingFilterBase.h:42
otb::PersistentSamplingFilterBase::m_LayerIndex
int m_LayerIndex
Definition: otbPersistentSamplingFilterBase.h:207
otb::PersistentSamplingFilterBase::m_FieldName
std::string m_FieldName
Definition: otbPersistentSamplingFilterBase.h:201
otb::PersistentSamplingFilterBase::SimpleFieldDefn::Precision
int Precision
Definition: otbPersistentSamplingFilterBase.h:169
otb::PersistentSamplingFilterBase::Self
PersistentSamplingFilterBase Self
Definition: otbPersistentSamplingFilterBase.h:46
otb::ogr::Layer::feature_iter
Implementation class for Feature iterator. This iterator is a single pass iterator....
Definition: otbOGRLayerWrapper.h:348
otb::PersistentSamplingFilterBase::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbPersistentSamplingFilterBase.h:48
otbPersistentSamplingFilterBase.hxx
otb::PersistentSamplingFilterBase::m_AdditionalFields
std::vector< SimpleFieldDefn > m_AdditionalFields
Definition: otbPersistentSamplingFilterBase.h:216
otb::ogr::DataSource::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOGRDataSourceWrapper.h:90
otb::PersistentSamplingFilterBase::RegionType
TInputImage::RegionType RegionType
Definition: otbPersistentSamplingFilterBase.h:58
otb::PersistentSamplingFilterBase::SimpleFieldDefn
Definition: otbPersistentSamplingFilterBase.h:164
otb::PersistentSamplingFilterBase::SimpleFieldDefn::Name
std::string Name
Definition: otbPersistentSamplingFilterBase.h:166
otb::PersistentSamplingFilterBase::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbPersistentSamplingFilterBase.h:49
otb::PersistentSamplingFilterBase::m_FieldIndex
int m_FieldIndex
Definition: otbPersistentSamplingFilterBase.h:204
otb::PersistentSamplingFilterBase::m_InMemoryInputs
std::vector< OGRDataPointer > m_InMemoryInputs
Definition: otbPersistentSamplingFilterBase.h:219
otb::ogr::Feature
Geometric object with descriptive fields.
Definition: otbOGRFeatureWrapper.h:63
otb::PersistentSamplingFilterBase::OGRDataPointer
ogr::DataSource::Pointer OGRDataPointer
Definition: otbPersistentSamplingFilterBase.h:60
otb::ogr::Layer
Layer of geometric objects.
Definition: otbOGRLayerWrapper.h:80
otb::PersistentSamplingFilterBase::~PersistentSamplingFilterBase
~PersistentSamplingFilterBase() override
Definition: otbPersistentSamplingFilterBase.h:104
otb::PersistentSamplingFilterBase::SimpleFieldDefn::Type
OGRFieldType Type
Definition: otbPersistentSamplingFilterBase.h:167
otb::PersistentSamplingFilterBase::SimpleFieldDefn::Width
int Width
Definition: otbPersistentSamplingFilterBase.h:168
otbOGRDataSourceWrapper.h