OTB  10.0.0
Orfeo Toolbox
otbPersistentSamplingFilterBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 "otbMacro.h" //for ITK_THREAD_RETURN_TYPE in ITK5
28 #include <string>
29 
30 namespace otb
31 {
42 template <class TInputImage, class TMaskImage = otb::Image<unsigned char, 2>>
43 class ITK_EXPORT PersistentSamplingFilterBase : public otb::PersistentImageFilter<TInputImage, TInputImage>
44 {
45 public:
49  typedef itk::SmartPointer<Self> Pointer;
50  typedef itk::SmartPointer<const Self> ConstPointer;
51 
54 
56  typedef TInputImage InputImageType;
57  typedef TMaskImage MaskImageType;
58 
59  typedef typename TInputImage::RegionType RegionType;
60 
62 
64  void SetOGRData(const ogr::DataSource* vector);
65 
67  const ogr::DataSource* GetOGRData();
68 
70  void SetMask(const TMaskImage* mask);
71 
73  const TMaskImage* GetMask();
74 
76  void SetOGRLayerCreationOptions(const std::vector<std::string>& options);
77 
79  const std::vector<std::string>& GetOGRLayerCreationOptions();
80 
83  itkSetMacro(FieldName, std::string);
84  itkGetMacro(FieldName, std::string);
86 
88  itkGetMacro(FieldIndex, int);
89 
91  itkSetMacro(LayerIndex, int);
92  itkGetMacro(LayerIndex, int);
94 
96  itkSetMacro(OutLayerName, std::string);
97  itkGetMacro(OutLayerName, std::string);
99 
100 protected:
103 
106  {
107  }
108 
111  void GenerateOutputInformation() override;
112 
115  void GenerateInputRequestedRegion() override;
116 
118  void GenerateData(void) override;
119 
121  void AllocateOutputs(void) override;
122 
124  virtual void ThreadedGenerateVectorData(const ogr::Layer& layerForThread, itk::ThreadIdType threadid);
125 
127  void ExploreGeometry(const ogr::Feature& feature, OGRGeometry* geom, RegionType& region, itk::ThreadIdType& threadid);
128 
130  virtual void ProcessLine(const ogr::Feature& feature, OGRLineString* line, RegionType& region, itk::ThreadIdType& threadid);
131 
133  virtual void ProcessPolygon(const ogr::Feature& feature, OGRPolygon* polygon, RegionType& region, itk::ThreadIdType& threadid);
134 
136  virtual void ProcessSample(const ogr::Feature& feature, typename TInputImage::IndexType& imgIndex, typename TInputImage::PointType& imgPoint,
137  itk::ThreadIdType& threadid);
138 
140  virtual void PrepareFeature(const ogr::Feature& feature, itk::ThreadIdType& threadid);
141 
143  bool IsSampleInsidePolygon(OGRPolygon* poly, OGRPoint* tmpPoint);
144 
146  bool IsSampleOnLine(OGRLineString* line, typename TInputImage::PointType& position, typename TInputImage::SpacingType& absSpacing, OGRPolygon& tmpPolygon);
147 
149  RegionType FeatureBoundingRegion(const TInputImage* image, otb::ogr::Layer::const_iterator& featIt) const;
150 
154  virtual void DispatchInputVectors(void);
155 
157  virtual void GatherOutputVectors(void);
158 
160  virtual void FillOneOutput(unsigned int outIdx, ogr::DataSource* outDS, bool update);
161 
163  virtual void InitializeOutputDataSource(ogr::DataSource* inputDS, ogr::DataSource* outputDS);
164 
165  typedef struct
166  {
167  std::string Name;
168  OGRFieldType Type;
169  int Width;
171  } SimpleFieldDefn;
172 
174  void ClearAdditionalFields();
175 
177  void CreateAdditionalField(std::string name, OGRFieldType type, int width = 0, int precision = 0);
178 
180  const std::vector<SimpleFieldDefn>& GetAdditionalFields();
181 
183  static itk::ITK_THREAD_RETURN_TYPE VectorThreaderCallback(void *arg);
184 
187  {
189  };
190 
192  ogr::Layer GetInMemoryInput(unsigned int threadId);
193 
195  ogr::Layer GetInMemoryOutput(unsigned int threadId, unsigned int index = 0);
196 
197 private:
199  void operator=(const Self&) = delete;
200 
202  std::string m_FieldName;
203 
206 
209 
211  std::string m_OutLayerName;
212 
214  std::vector<std::string> m_OGRLayerCreationOptions;
215 
217  std::vector<SimpleFieldDefn> m_AdditionalFields;
218 
220  std::vector<OGRDataPointer> m_InMemoryInputs;
221 
223  std::vector<std::vector<OGRDataPointer>> m_InMemoryOutputs;
224 };
225 } // End namespace otb
226 
227 #ifndef OTB_MANUAL_INSTANTIATION
229 #endif
230 
231 #endif
This filter is the base class for all filter persisting data through multiple update....
Base class for persistent filter doing sampling tasks.
PersistentSamplingFilterBase(const Self &)=delete
void operator=(const Self &)=delete
std::vector< SimpleFieldDefn > m_AdditionalFields
std::vector< std::vector< OGRDataPointer > > m_InMemoryOutputs
PersistentImageFilter< TInputImage, TInputImage > Superclass
itk::SmartPointer< const Self > ConstPointer
Collection of geometric objects.
itk::SmartPointer< Self > Pointer
Geometric object with descriptive fields.
Implementation class for Feature iterator. This iterator is a single pass iterator....
Layer of geometric objects.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.