otbGeometriesProjectionFilter.h 6.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __otbGeometriesProjectionFilter_h
#define __otbGeometriesProjectionFilter_h

#include "otbGeometriesToGeometriesFilter.h"
#include "otbOGRGeometryWrapper.h"
#include "otbImageReference.h"
#include "itkTransform.h"
#include "otbGenericRSTransform.h"

class OGRCoordinateTransformation;

namespace otb
{

struct ReprojectTransformationFunctor
{
  typedef OGRGeometry TransformedElementType;

  struct ByCopy
    {
    ByCopy(ReprojectTransformationFunctor const& reprojector) : m_Reprojector(reprojector){}
    template <typename TGeometry>
      ogr::UniqueGeometryPtr operator()(TGeometry const* in) const;
  private:
    ReprojectTransformationFunctor const& m_Reprojector;
    };

  struct InPlace
    {
    InPlace(ReprojectTransformationFunctor const& reprojector) : m_Reprojector(reprojector){}
    template <typename TGeometry>
      void operator()(TGeometry * inout) const;
  private:
    ReprojectTransformationFunctor const& m_Reprojector;
    };


  ogr::UniqueGeometryPtr operator()(OGRGeometry const* in) const;
  // ogr::UniqueGeometryPtr apply(OGRGeometry const* in) const;
  void apply_inplace          (OGRGeometry * inout) const;

  typedef otb::GenericRSTransform<double, 2, 2>   InternalTransformType;
  typedef InternalTransformType::Pointer          InternalTransformPointerType;
  void SetOnePointTransformation(InternalTransformPointerType transform)
    {
    m_Transform = transform;
    }
private:
  void do_transform(OGRPoint              & g) const;
  // void do_transform(OGRLinearRing         & g) const;
  void do_transform(OGRLineString         & g) const;
  // void do_transform(OGRCurve              & g) const;
  void do_transform(OGRPolygon            & g) const;
#if 0
  void do_transform(OGRSurface            & g) const;
  void do_transform(OGRMultiLineString    & g) const;
  void do_transform(OGRMultiPoint         & g) const;
  void do_transform(OGRMultiPolygon       & g) const;
#endif
  void do_transform(OGRGeometryCollection & g) const;

  InternalTransformPointerType m_Transform;
};


class ITK_EXPORT GeometriesProjectionFilter : public GeometriesToGeometriesFilter
{
public:
  /**\name Standard ITK typedefs */
  //@{
  typedef GeometriesProjectionFilter    Self;
  typedef GeometriesToGeometriesFilter  Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;
  //@}

  /**\name Standard macros */
  //@{
  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Run-time type information (and related methods). */
  itkTypeMacro(GeometriesProjectionFilter, GeometriesToGeometriesFilter);
  //@}

  /**\name I/O typedefs */
  //@{
  typedef Superclass::InputGeometriesType        InputGeometriesType;
  // typedef Superclass::InputGeometriesPointer  InputGeometriesPointer;
  typedef Superclass::OutputGeometriesType       OutputGeometriesType;
  // typedef Superclass::OutputGeometriesPointer OutputGeometriesPointer;
  //@}

  /**\name Class typedefs */
  //@{
  typedef ogr::ImageReference<double>                            ImageReference;
  //@}

private:
  virtual OGRSpatialReference* DoDefineNewLayerSpatialReference(ogr::Layer const& source) const;
  virtual void DoProcessLayer(ogr::Layer const& source, ogr::Layer & destination) const;
  virtual void FinalizeInitialisation();

protected:
  /** Default constructor. */
  GeometriesProjectionFilter();
  /** Destructor. */
  virtual ~GeometriesProjectionFilter();

  virtual void GenerateOutputInformation(void);

public:
  ImageReference InputImageReference;
  ImageReference OutputImageReference;

  /**\name Keywords lists accessors and mutators */
  //@{
  itkGetMacro(InputKeywordList, ImageKeywordlist);
  void SetInputKeywordList(const ImageKeywordlist& kwl)
    {
    this->m_InputKeywordList = kwl;
    this->Modified();
    }

  itkGetMacro(OutputKeywordList, ImageKeywordlist);
  void SetOutputKeywordList(const ImageKeywordlist& kwl)
    {
    this->m_OutputKeywordList = kwl;
    this->Modified();
    }
  //@}

  /**\name Projection references accessors and mutators */
  //@{
  itkSetStringMacro(InputProjectionRef);
  itkGetStringMacro(InputProjectionRef);

  itkSetStringMacro(OutputProjectionRef);
  itkGetStringMacro(OutputProjectionRef);
  //@}
private:
  /**\name Functor definition */
  //@{
  typedef ReprojectTransformationFunctor                          TransformationFunctorType;
  typedef TransformationFunctorType::TransformedElementType       TransformedElementType;
  typedef TransformationFunctorDispatcher<TransformationFunctorType, TransformedElementType>
                                                                  TransformationFunctorDispatcherType;

  TransformationFunctorDispatcherType             m_TransformationFunctor;
  //@}

  /**\name 1 Point Transformation definition */
  //@{
  typedef TransformationFunctorType::InternalTransformType        InternalTransformType;
  typedef TransformationFunctorType::InternalTransformPointerType InternalTransformPointerType;

  InternalTransformPointerType                    m_Transform;
  //@}

  std::string                                     m_InputProjectionRef; // in WKT format!
  std::string                                     m_OutputProjectionRef; // in WKT format!
  ImageKeywordlist                                m_InputKeywordList;
  ImageKeywordlist                                m_OutputKeywordList;

  std::string                                     m_DEMDirectory;
  std::string                                     m_GeoidFile;
};
} // end namespace otb

#ifndef OTB_MANUAL_INSTANTIATION
// #include "otbGeometriesProjectionFilter.txx"
#endif

#endif // __otbGeometriesProjectionFilter_h