OTB  6.7.0
Orfeo Toolbox
otbPersistentSamplingFilterBase.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 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> >
43  : public otb::PersistentImageFilter<TInputImage, TInputImage>
44 {
45 public:
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 
109  void GenerateOutputInformation() override;
110 
113  void GenerateInputRequestedRegion() override;
114 
116  void GenerateData(void) override;
117 
119  void AllocateOutputs(void) override;
120 
122  virtual void ThreadedGenerateVectorData(const ogr::Layer& layerForThread, itk::ThreadIdType threadid);
123 
125  void ExploreGeometry(const ogr::Feature& feature,
126  OGRGeometry* geom,
127  RegionType& region,
128  itk::ThreadIdType& threadid);
129 
131  virtual void ProcessLine(const ogr::Feature& feature,
132  OGRLineString* line,
133  RegionType& region,
134  itk::ThreadIdType& threadid);
135 
137  virtual void ProcessPolygon(const ogr::Feature& feature,
138  OGRPolygon* polygon,
139  RegionType& region,
140  itk::ThreadIdType& threadid);
141 
143  virtual void ProcessSample(const ogr::Feature& feature,
144  typename TInputImage::IndexType& imgIndex,
145  typename TInputImage::PointType& imgPoint,
146  itk::ThreadIdType& threadid);
147 
149  virtual void PrepareFeature(const ogr::Feature& feature,
150  itk::ThreadIdType& threadid);
151 
153  bool IsSampleInsidePolygon(OGRPolygon* poly,
154  OGRPoint* tmpPoint);
155 
157  bool IsSampleOnLine(OGRLineString* line,
158  typename TInputImage::PointType& position,
159  typename TInputImage::SpacingType& absSpacing,
160  OGRPolygon& tmpPolygon);
161 
163  RegionType FeatureBoundingRegion(const TInputImage* image, otb::ogr::Layer::const_iterator& featIt) const;
164 
168  virtual void DispatchInputVectors(void);
169 
171  virtual void GatherOutputVectors(void);
172 
174  virtual void FillOneOutput(unsigned int outIdx, ogr::DataSource* outDS, bool update);
175 
177  virtual void InitializeOutputDataSource(ogr::DataSource* inputDS, ogr::DataSource* outputDS);
178 
179  typedef struct {
180  std::string Name;
181  OGRFieldType Type;
182  int Width;
184  } SimpleFieldDefn;
185 
187  void ClearAdditionalFields();
188 
190  void CreateAdditionalField(std::string name,
191  OGRFieldType type,
192  int width=0,
193  int precision=0);
194 
196  const std::vector<SimpleFieldDefn>& GetAdditionalFields();
197 
199  static ITK_THREAD_RETURN_TYPE VectorThreaderCallback(void *arg);
200 
203  {
205  };
206 
208  ogr::Layer GetInMemoryInput(unsigned int threadId);
209 
211  ogr::Layer GetInMemoryOutput(unsigned int threadId, unsigned int index=0);
212 
213 private:
214  PersistentSamplingFilterBase(const Self &) = delete;
215  void operator =(const Self&) = delete;
216 
218  std::string m_FieldName;
219 
222 
225 
227  std::string m_OutLayerName;
228 
230  std::vector<std::string> m_OGRLayerCreationOptions;
231 
233  std::vector<SimpleFieldDefn> m_AdditionalFields;
234 
236  std::vector<OGRDataPointer> m_InMemoryInputs;
237 
239  std::vector<std::vector<OGRDataPointer> > m_InMemoryOutputs;
240 
241 };
242 } // End namespace otb
243 
244 #ifndef OTB_MANUAL_INSTANTIATION
246 #endif
247 
248 #endif
Base class for persistent filter doing sampling tasks.
Collection of geometric objects.
Layer of geometric objets.
#define ITK_THREAD_RETURN_TYPE
Implementation class for Feature iterator. This iterator is a single pass iterator. We may fetch the Feature referenced by an iterator previously stored, but never resume the iteration after a call to Layer::begin(), Layer::start_at(), Layer::CreateFeature(), Layer::DeleteFeature(), Layer::GetFeature(), Layer::SetFeature(), nor fork the iteration.
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
unsigned int ThreadIdType
PersistentImageFilter< TInputImage, TInputImage > Superclass
itk::SmartPointer< const Self > ConstPointer
Geometric objet with descriptive fields.
VectorImageType::SpacingType SpacingType
Definition: mvdTypes.h:181
std::vector< SimpleFieldDefn > m_AdditionalFields
VectorImageType::PointType PointType
Definition: mvdTypes.h:189
This filter is the base class for all filter persisting data through multiple update. For instance, a filter computing global statistics on an image with streaming capabilities will have to keep the temporary results for each streamed piece of the image in order to synthesize the global statistics at the end. This filter is an itk::ImageToImageFilter, providing two additional methods. The first one, Synthetize(), allows the user to synthesize temporary data produced by the multiple updates on different pieces of the image to the global result. The second one, Reset(), allows the user to reset the temporary data for a new input image for instance.
std::vector< std::vector< OGRDataPointer > > m_InMemoryOutputs