OTB  9.0.0
Orfeo Toolbox
otbGeometriesToGeometriesFilter.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 otbGeometriesToGeometriesFilter_h
22 #define otbGeometriesToGeometriesFilter_h
23 
32 #include "otbGeometriesSource.h"
33 #include <map>
34 #include <boost/mpl/assert.hpp>
35 #include <boost/type_traits/is_same.hpp>
36 #include "otbOGRLayerWrapper.h"
37 
38 #include "otbMacro.h"
39 
40 // forward declarations
41 namespace otb
42 {
43 namespace internal
44 {
45 struct ProcessVisitor;
46 }
47 } // otb::internal namespace
48 
49 namespace otb
50 {
58 class OTBGdalAdapters_EXPORT GeometriesToGeometriesFilter : public GeometriesSource
59 {
60 public:
61 
65  typedef itk::ProcessObject Superclass;
66  typedef itk::SmartPointer<Self> Pointer;
67  typedef itk::SmartPointer<const Self> ConstPointer;
69 
74  // typedef GeometriesSet::Pointer InputGeometriesPointer;
75  // typedef GeometriesSet::Pointer OutputGeometriesPointer;
77 
80 
84 
87  using Superclass::SetInput;
88  virtual void SetInput(const InputGeometriesType* input);
89  const InputGeometriesType* GetInput(void);
91 
92 
93 protected:
98 
102  ~GeometriesToGeometriesFilter() override;
103 
108  void GenerateData(void) override;
109 
110 private:
115  void Process(OutputGeometriesType& inout);
116 
123  void Process(InputGeometriesType const& source, OutputGeometriesType& destination);
124 
130 
139  virtual void DoProcessLayer(ogr::Layer const& source, ogr::Layer& destination) const = 0;
140 
150  virtual OGRSpatialReference* DoDefineNewLayerSpatialReference(ogr::Layer const& source) const;
151 
157  virtual OGRwkbGeometryType DoDefineNewLayerGeometryType(ogr::Layer const& source) const;
158 
165  virtual std::vector<std::string> DoDefineNewLayerOptions(ogr::Layer const& source) const;
166 
172  virtual void DoDefineNewLayerFields(ogr::Layer const& source, ogr::Layer& dest) const = 0;
173 
182  {
183  }
185 
186  friend struct otb::internal::ProcessVisitor;
187 };
188 
193 struct OTBGdalAdapters_EXPORT FieldCopyTransformation
194 {
195  OGRFeatureDefn& getDefinition(ogr::Layer& outLayer) const
196  {
197  return outLayer.GetLayerDefn();
198  }
199 
204  void fieldsTransform(ogr::Feature const& itkNotUsed(inoutFeature)) const
205  {
206  // default => do nothing for in-place transformation
207  }
208 
216  void fieldsTransform(ogr::Feature const& inFeature, ogr::Feature& outFeature) const;
217 
225  void DefineFields(ogr::Layer const& source, ogr::Layer& dest) const;
226 
227 private:
238  mutable std::map<int, int> m_SourceToDestFieldIndicesMap;
239 };
241 
242 
269 template <class TransformationFunctor, class TransformedElementType, class FieldTransformationPolicy = FieldCopyTransformation>
271 {
272 };
274 
286 template <class TransformationFunctor, class FieldTransformationPolicy>
287 struct TransformationFunctorDispatcher<TransformationFunctor, ogr::Layer, FieldTransformationPolicy> : FieldTransformationPolicy
288 {
289  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
290  BOOST_MPL_ASSERT((boost::is_same<ogr::Layer, TransformedElementType>));
292  {
293  }
294  TransformationFunctorDispatcher(TransformationFunctor functor) : m_functor(functor)
295  {
296  }
297  void operator()(ogr::Layer const& in, ogr::Layer& out) const;
298  void operator()(ogr::Layer& inout) const;
299  TransformationFunctor* operator->()
300  {
301  return &m_functor;
302  }
304 
305 private:
306  TransformationFunctor m_functor;
307 };
308 
327 template <class TransformationFunctor, class FieldTransformationPolicy>
328 struct TransformationFunctorDispatcher<TransformationFunctor, OGRGeometry, FieldTransformationPolicy> : FieldTransformationPolicy
329 {
330  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
331  BOOST_MPL_ASSERT((boost::is_same<OGRGeometry, TransformedElementType>));
333  {
334  }
335  TransformationFunctorDispatcher(TransformationFunctor functor) : m_functor(functor)
336  {
337  }
339 
340  void operator()(ogr::Layer const& in, ogr::Layer& out) const;
341  void operator()(ogr::Layer& inout) const;
342  TransformationFunctor* operator->()
343  {
344  return &m_functor;
345  }
346 
347 private:
348  TransformationFunctor m_functor;
349 };
350 
351 
366 template <class TransformationFunctor, class FieldTransformationPolicy = FieldCopyTransformation>
369  public TransformationFunctorDispatcher<TransformationFunctor, typename TransformationFunctor::TransformedElementType, FieldTransformationPolicy>
370 {
371 public:
372 
377  typedef itk::SmartPointer<Self> Pointer;
378  typedef itk::SmartPointer<const Self> ConstPointer;
380 
383  typedef TransformationFunctor TransformationFunctorType;
384  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
387 
390 
392  itkNewMacro(Self);
393 
397 
398 protected:
401 
404 
415  void DoProcessLayer(ogr::Layer const& source, ogr::Layer& destination) const override;
416 
425  void DoDefineNewLayerFields(ogr::Layer const& source, ogr::Layer& dest) const override
426  {
427  this->DefineFields(source, dest);
428  }
429 };
431 
432 } // end namespace otb
433 
434 #ifndef OTB_MANUAL_INSTANTIATION
436 #endif
437 
438 #endif // otbGeometriesToGeometriesFilter_h
otb::GeometriesSource
Definition: otbGeometriesSource.h:72
otb::DefaultGeometriesToGeometriesFilter
Definition: otbGeometriesToGeometriesFilter.h:367
otb::FieldCopyTransformation::m_SourceToDestFieldIndicesMap
std::map< int, int > m_SourceToDestFieldIndicesMap
Definition: otbGeometriesToGeometriesFilter.h:238
otb::GeometriesToGeometriesFilter::InputGeometriesType
GeometriesSet InputGeometriesType
Definition: otbGeometriesToGeometriesFilter.h:72
otb::GeometriesToGeometriesFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbGeometriesToGeometriesFilter.h:66
otb::FieldCopyTransformation::fieldsTransform
void fieldsTransform(ogr::Feature const &) const
Definition: otbGeometriesToGeometriesFilter.h:204
otbGeometriesToGeometriesFilter.hxx
otb::DefaultGeometriesToGeometriesFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbGeometriesToGeometriesFilter.h:378
otb::GeometriesSet
Common ITK type to manipulate any set of geometries: a otb::ogr::DataSource, or a otb::ogr::Layer.
Definition: otbGeometriesSet.h:38
otbOGRLayerWrapper.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbGeometriesSource.h
otb::DefaultGeometriesToGeometriesFilter::TransformationFunctorType
TransformationFunctor TransformationFunctorType
Definition: otbGeometriesToGeometriesFilter.h:383
otbMacro.h
otb::TransformationFunctorDispatcher< TransformationFunctor, ogr::Layer, FieldTransformationPolicy >::TransformationFunctorDispatcher
TransformationFunctorDispatcher(TransformationFunctor functor)
Definition: otbGeometriesToGeometriesFilter.h:294
otb::TransformationFunctorDispatcher
Definition: otbGeometriesToGeometriesFilter.h:270
otb::FieldCopyTransformation::getDefinition
OGRFeatureDefn & getDefinition(ogr::Layer &outLayer) const
Definition: otbGeometriesToGeometriesFilter.h:195
otb::TransformationFunctorDispatcher< TransformationFunctor, ogr::Layer, FieldTransformationPolicy >::operator->
TransformationFunctor * operator->()
Definition: otbGeometriesToGeometriesFilter.h:299
otb::TransformationFunctorDispatcher< TransformationFunctor, ogr::Layer, FieldTransformationPolicy >::TransformedElementType
TransformationFunctor::TransformedElementType TransformedElementType
Definition: otbGeometriesToGeometriesFilter.h:289
otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::m_functor
TransformationFunctor m_functor
Definition: otbGeometriesToGeometriesFilter.h:348
otb::FieldCopyTransformation
Definition: otbGeometriesToGeometriesFilter.h:193
otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::TransformedElementType
TransformationFunctor::TransformedElementType TransformedElementType
Definition: otbGeometriesToGeometriesFilter.h:330
otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::TransformationFunctorDispatcher
TransformationFunctorDispatcher(TransformationFunctor functor)
Definition: otbGeometriesToGeometriesFilter.h:335
otb::GeometriesToGeometriesFilter
Definition: otbGeometriesToGeometriesFilter.h:58
otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator->
TransformationFunctor * operator->()
Definition: otbGeometriesToGeometriesFilter.h:342
otb::GeometriesToGeometriesFilter::Superclass
itk::ProcessObject Superclass
Definition: otbGeometriesToGeometriesFilter.h:65
otb::DefaultGeometriesToGeometriesFilter::Self
DefaultGeometriesToGeometriesFilter Self
Definition: otbGeometriesToGeometriesFilter.h:375
otb::TransformationFunctorDispatcher< TransformationFunctor, ogr::Layer, FieldTransformationPolicy >::TransformationFunctorDispatcher
TransformationFunctorDispatcher()
Definition: otbGeometriesToGeometriesFilter.h:291
otb::DefaultGeometriesToGeometriesFilter::DoDefineNewLayerFields
void DoDefineNewLayerFields(ogr::Layer const &source, ogr::Layer &dest) const override
Definition: otbGeometriesToGeometriesFilter.h:425
otb::ogr::Feature
Geometric object with descriptive fields.
Definition: otbOGRFeatureWrapper.h:63
otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::TransformationFunctorDispatcher
TransformationFunctorDispatcher()
Definition: otbGeometriesToGeometriesFilter.h:332
otb::TransformationFunctorDispatcher< TransformationFunctor, ogr::Layer, FieldTransformationPolicy >::m_functor
TransformationFunctor m_functor
Definition: otbGeometriesToGeometriesFilter.h:306
otb::DefaultGeometriesToGeometriesFilter::TransformationFunctorDispatcherType
TransformationFunctorDispatcher< TransformationFunctorType, TransformedElementType, FieldTransformationPolicy > TransformationFunctorDispatcherType
Definition: otbGeometriesToGeometriesFilter.h:385
otb::DefaultGeometriesToGeometriesFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbGeometriesToGeometriesFilter.h:377
otb::DefaultGeometriesToGeometriesFilter::Superclass
GeometriesToGeometriesFilter Superclass
Definition: otbGeometriesToGeometriesFilter.h:376
otb::GeometriesToGeometriesFilter::Self
GeometriesToGeometriesFilter Self
Definition: otbGeometriesToGeometriesFilter.h:64
otb::ogr::Layer
Layer of geometric objects.
Definition: otbOGRLayerWrapper.h:80
otb::GeometriesToGeometriesFilter::DoFinalizeInitialization
virtual void DoFinalizeInitialization()
Definition: otbGeometriesToGeometriesFilter.h:181
otb::GeometriesToGeometriesFilter::OutputGeometriesType
GeometriesSet OutputGeometriesType
Definition: otbGeometriesToGeometriesFilter.h:73
otb::DefaultGeometriesToGeometriesFilter::TransformedElementType
TransformationFunctor::TransformedElementType TransformedElementType
Definition: otbGeometriesToGeometriesFilter.h:384
otb::GeometriesToGeometriesFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbGeometriesToGeometriesFilter.h:67
otb::ogr::Layer::GetLayerDefn
OGRFeatureDefn & GetLayerDefn() const