File: otbGenericRSResampleImageFilter.h

package info (click to toggle)
otb 5.8.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,496 kB
  • ctags: 40,282
  • sloc: cpp: 306,573; ansic: 3,575; python: 450; sh: 214; perl: 74; java: 72; makefile: 70
file content (309 lines) | stat: -rw-r--r-- 10,818 bytes parent folder | download
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*=========================================================================

  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 otbGenericRSResampleImageFilter_h
#define otbGenericRSResampleImageFilter_h

#include "otbStreamingResampleImageFilter.h"
#include "otbPhysicalToRPCSensorModelImageFilter.h"

namespace otb
{

/** \class GenericRSResampleImageFilter
 *  \brief This class is a composite filter that allows you to project
 *  an input image from any  coordinate system to any other one. The
 *  coordinate systems can be  defined by their projection reference,
 *  the keyword list or a meta data dictionary.
 *
 *  This class uses the otb::StreamingResampleImageFilter. It defines
 *  and uses a otb::GenericRSTransform using the input/output coordinate
 *  system information listed below. This class can resample the input to an
 *  output image with the Size/Origin/Spacing/StartIndex defined by
 *  the user. Note that there are no default values for all the
 *  parmeters, so it is mandatory to set correct parameters to have a
 *  correct result.
 *
 *  The methods SetOutputParmatersFromMap can estimate the output
 *  image parameters Size/Origin/Spacing so the hole image can be
 *  reprojected without setting any output parameter.
 *
 * \ingroup Projection
 *
 *
 * \ingroup OTBProjection
 **/

template <class TInputImage, class TOutputImage>
class ITK_EXPORT GenericRSResampleImageFilter :
    public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
  /** Standard class typedefs. */
  typedef GenericRSResampleImageFilter                          Self;
  typedef itk::ImageToImageFilter<TInputImage, TOutputImage>    Superclass;
  typedef itk::SmartPointer<Self>                               Pointer;
  typedef itk::SmartPointer<const Self>                         ConstPointer;

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Run-time type information (and related methods). */
  itkTypeMacro(GenericRSResampleImageFilter, itk::ImageToImageFilter);

  /** Typedef parameters*/
  typedef TInputImage                                     InputImageType;
  typedef TOutputImage                                    OutputImageType;
  typedef typename OutputImageType::InternalPixelType     OutputInternalPixelType;
  typedef typename OutputImageType::PointType             OutputPointType;

  /** Internal filters typedefs*/
  typedef StreamingResampleImageFilter<InputImageType,
                                 OutputImageType>          ResamplerType;
  typedef typename ResamplerType::Pointer                  ResamplerPointerType;
  typedef typename ResamplerType::TransformType            TransformType;
  typedef typename ResamplerType::SizeType                 SizeType;
  typedef typename ResamplerType::SpacingType              SpacingType;
  typedef typename ResamplerType::OriginType               OriginType;
  typedef typename ResamplerType::IndexType                IndexType;
  typedef typename ResamplerType::RegionType               RegionType;
  typedef typename ResamplerType::InterpolatorType         InterpolatorType;

  /** Estimate the rpc model */
  typedef PhysicalToRPCSensorModelImageFilter<InputImageType>  InputRpcModelEstimatorType;
  typedef typename InputRpcModelEstimatorType::Pointer         InputRpcModelEstimatorPointerType;

  typedef PhysicalToRPCSensorModelImageFilter<OutputImageType> OutputRpcModelEstimatorType;
  typedef typename OutputRpcModelEstimatorType::Pointer        OutputRpcModelEstimatorPointerType;


  /** Specialisation of OptResampleFilter with a remote
    * sensing  transform
    */
  typedef GenericRSTransform<>                       GenericRSTransformType;
  typedef typename GenericRSTransformType::Pointer   GenericRSTransformPointerType;

  typedef itk::ImageBase<OutputImageType::ImageDimension>      ImageBaseType;

  /** The Displacement field spacing & size */
  otbSetObjectMemberMacro(Resampler, DisplacementFieldSpacing, SpacingType);

  otbGetObjectMemberConstReferenceMacro(Resampler,
                                        DisplacementFieldSpacing,
                                        SpacingType);

  /** The resampled image parameters */
  /** Output Origin */
  void SetOutputOrigin(const OriginType & origin)
  {
    m_Resampler->SetOutputOrigin(origin);
    this->Modified();
  }
  otbGetObjectMemberConstReferenceMacro(Resampler, OutputOrigin, OriginType);

  /** Output Start index */
  otbSetObjectMemberMacro(Resampler, OutputStartIndex, IndexType);
  otbGetObjectMemberConstReferenceMacro(Resampler, OutputStartIndex, IndexType);

  /** Output Size */
  otbSetObjectMemberMacro(Resampler, OutputSize, SizeType);
  otbGetObjectMemberConstReferenceMacro(Resampler, OutputSize, SizeType);

  /** Output Spacing */
  otbSetObjectMemberMacro(Resampler, OutputSpacing, SpacingType);
  otbGetObjectMemberConstReferenceMacro(Resampler, OutputSpacing, SpacingType);

  /** Methods to Set/Get the interpolator */
  void SetInterpolator(InterpolatorType * interpolator)
  {
    m_Resampler->SetInterpolator(interpolator);
    this->Modified();
  }
  otbGetObjectMemberConstMacro(Resampler, Interpolator, const InterpolatorType *);

  /** Default Edge padding value */
  otbSetObjectMemberMacro(Resampler,
                          EdgePaddingValue,
                          typename OutputImageType::PixelType);
  otbGetObjectMemberMacro(Resampler,
                          EdgePaddingValue,
                          typename OutputImageType::PixelType);

  /**
   * Set/Get input & output projections.
   * Set/Get input & output keywordlist
   * The macro are not used here cause the input and the output are
   * inversed.
   */
  void SetInputProjectionRef(const std::string&  ref)
  {
    m_Transform->SetOutputProjectionRef(ref);
    this->Modified();
  }

  std::string GetInputProjectionRef() const
  {
    return m_Transform->GetOutputProjectionRef();
  }

  void SetOutputProjectionRef(const std::string&  ref)
  {
  m_Transform->SetInputProjectionRef(ref);
  this->Modified();
  }

  std::string GetOutputProjectionRef() const
  {
    return m_Transform->GetInputProjectionRef();
  }

  /** Set/Get Input Keywordlist*/
  void SetInputKeywordList(const ImageKeywordlist& kwl)
  {
    m_Transform->SetOutputKeywordList(kwl);
    this->Modified();
  }
  const ImageKeywordlist GetInputKeywordList()
  {
    return m_Transform->GetOutputKeywordList();
  }

  /** Set/Get output Keywordlist*/
  void SetOutputKeywordList(const ImageKeywordlist& kwl)
  {
    m_Transform->SetInputKeywordList(kwl);
    this->Modified();
  }

  const ImageKeywordlist GetOutputKeywordList()
  {
    return m_Transform->GetInputKeywordList();
  }

  /** Useful to set the output parameters from an existing image*/
  void SetOutputParametersFromImage(const ImageBaseType * image);

  /** Useful to set output parmaters form an existing image with type
    * different from input or output image
    */
  template <class TImageType> void SetOutputParametersFromImage(const TImageType * image);

  /** Useful to set the output parameters using a map (UTM|WGS84) and
   * a spacing set by the user
   */
  void SetOutputParametersFromMap(const std::string map, const SpacingType& spacing);

  /** Useful to set the output parameters from a projectionRef, the
    * output size, spacing and origin are estimated
    */
  void SetOutputParametersFromMap(const std::string projectionRef);

  /** Set/Get the grid size for rpc estimator*/
  void SetInputRpcGridSize(const SizeType& gridSize)
  {
    m_InputRpcEstimator->SetGridSize(gridSize);
    this->Modified();
  }
  /** unsigned int as parameter */
  void SetInputRpcGridSize(unsigned int gridSize)
  {
    m_InputRpcEstimator->SetGridSize(gridSize);
    this->Modified();
  }
  /** Get the input rpc model estimator  grid size used */
  const SizeType & GetInputRpcGridSize() const
  {
    return m_InputRpcEstimator->GetGridSize();
  }

  /** Macro to tune the EstimateInputRpcModel flag */
  itkSetMacro(EstimateInputRpcModel, bool);
  itkGetMacro(EstimateInputRpcModel, bool);
  itkBooleanMacro(EstimateInputRpcModel);

  /** Macro to Set/Get the grid size for rpc estimator*/
  void SetOutputRpcGridSize(const SizeType& gridSize)
  {
    m_OutputRpcEstimator->SetGridSize(gridSize);
    this->Modified();
  }
  /** unsigned int as parameter */
  void SetOutputRpcGridSize(unsigned int gridSize)
  {
    m_OutputRpcEstimator->SetGridSize(gridSize);
    this->Modified();
  }
  /** Get the output rpc model estimator grid size used */
  const SizeType & GetOutputRpcGridSize() const
  {
    return m_OutputRpcEstimator->GetGridSize();
  }

  /** Macro to tune the EstimateOutputRpcModel flag */
  itkSetMacro(EstimateOutputRpcModel, bool);
  itkGetMacro(EstimateOutputRpcModel, bool);
  itkBooleanMacro(EstimateOutputRpcModel);

  /** Set number of threads for Displacement field generator */
  void SetDisplacementFilterNumberOfThreads(unsigned int nbThread)
  {
    m_Resampler->SetDisplacementFilterNumberOfThreads(nbThread);
  }

  /** Override itk::ProcessObject method to let the internal filter do the propagation */
  void PropagateRequestedRegion(itk::DataObject *output) ITK_OVERRIDE;

protected:
  GenericRSResampleImageFilter();
  /** Destructor */
  ~GenericRSResampleImageFilter() ITK_OVERRIDE {};

  void GenerateData() ITK_OVERRIDE;

  void GenerateOutputInformation() ITK_OVERRIDE;

  virtual void UpdateTransform();

  void PrintSelf(std::ostream& os, itk::Indent indent) const ITK_OVERRIDE;

private:
  GenericRSResampleImageFilter(const Self &); //purposely not implemented
  void operator =(const Self&); //purposely not implemented

  // Method to estimate the input & output rpc model
  void EstimateOutputRpcModel();
  void EstimateInputRpcModel();

  // boolean that allow the estimation of the input rpc model
  bool                               m_EstimateInputRpcModel;
  bool                               m_EstimateOutputRpcModel;
  bool                               m_RpcEstimationUpdated;

  // Filters pointers
  ResamplerPointerType               m_Resampler;
  InputRpcModelEstimatorPointerType  m_InputRpcEstimator;
  OutputRpcModelEstimatorPointerType m_OutputRpcEstimator;
  GenericRSTransformPointerType      m_Transform;
};

} // namespace otb

#ifndef OTB_MANUAL_INSTANTIATION
#include "otbGenericRSResampleImageFilter.txx"
#endif

#endif