Interpolator.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/raster/Interpolator.h
22 
23  \brief It interpolates one pixel based on a selected algorithm.
24 */
25 
26 #ifndef __TERRALIB_RASTER_INTERNAL_INTERPOLATOR_H
27 #define __TERRALIB_RASTER_INTERNAL_INTERPOLATOR_H
28 
29 // TerraLib
30 #include "Raster.h"
31 #include "Enums.h"
32 
33 // STL
34 #include <complex>
35 #include <vector>
36 
37 // Boost
38 #include <boost/noncopyable.hpp>
39 
40 namespace te
41 {
42  namespace rst
43  {
44 // Forward declaration
45  class Raster;
46 
47  /*!
48  \class Interpolator
49 
50  \brief It interpolates one pixel based on a selected algorithm.
51  Methods currently available are Nearest Neighbor, Bilinear, and Bicubic.
52 
53  \ingroup rst
54  */
55  class TERASTEREXPORT Interpolator : public boost::noncopyable
56  {
57  public:
58 
59  /*!
60  \brief Allowed interpolation methods.
61  */
63 
64  /*!
65  \brief Constructor.
66 
67  \param r The raster where to resample.
68  \param m The method of interpolation to apply.
69  */
70  Interpolator(Raster const* r, int m);
71 
72  /*!
73  \brief Constructor.
74 
75  \param r The raster where to resample.
76  \param m The method of interpolation to apply.
77  \param noDataValues A vector with no-data values (will overwride the input raster no-data values) or an empty vectory if the input raster no-data values must be used.
78  */
79  Interpolator(Raster const* r, int m, const std::vector< std::complex<double> >& noDataValues);
80 
81  /*! \brief Destructor. */
82  virtual ~Interpolator();
83 
84  /*!
85  \brief Get the interpolated value at specific band.
86 
87  \param c The column position (double).
88  \param r The row position (double).
89  \param v The output value or the current input raster no-data value if the requested coordinates are outside the valid image bounds.
90  \param b The band to obtain the value.
91  \note The caller of this method must be aware that the returned value may be outside the original input rasters valid values range.
92  */
93  inline void getValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b)
94  {
95  assert(b < m_raster->getNumberOfBands());
96  (this->*(m_function))(c, r, v, b);
97  };
98 
99  /*!
100  \brief Get the interpolated value for all bands.
101 
102  \param c The column position (double).
103  \param r The row position (double).
104  \param v A vector of values, for all bands, or the current input raster no-data values if the requested coordinates are outside the valid image bounds..
105  \note The caller of this method must be aware that the returned values may be outside the original input rasters valid values range.
106  */
107  void getValues(const double& c, const double& r, std::vector<std::complex<double> >& values);
108 
109  /*!
110  \brief Create a clone copy of this instance.
111 
112  \return A clone copy of this instance (the caller of this method must take the ownership of the returned object).
113  */
114  te::rst::Interpolator* clone() const;
115 
116  protected:
117 
118  /*!
119  \brief Nearest neighbor interpolation method.
120 
121  \param c The column position (double).
122  \param r The row position (double).
123  \param v The output value.
124  \param b The band to obtain the value.
125  */
126  void nearestNeighborGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
127 
128  /*!
129  \brief Bilinear interpolation method.
130 
131  \param c The column position (double).
132  \param r The row position (double).
133  \param v The output value.
134  \param b The band to obtain the value.
135  */
136  void bilinearGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
137 
138  /*!
139  \brief Bicubic interpolation method.
140 
141  \param c The column position (double).
142  \param r The row position (double).
143  \param v The output value.
144  \param b The band to obtain the value.
145  */
146  void bicubicGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
147 
148  /*!
149  \brief Type definition for the interpolation function.
150 
151  \param c The column position (double).
152  \param r The row position (double).
153  \param v The output value.
154  \param b The band to obtain the value.
155  */
156  typedef void (Interpolator::*InterpolationFunction)(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
157 
158  /*!
159  \brief Initialize this instance..
160 
161  \param r The raster where to resample.
162  \param method The method of interpolation to apply.
163  \param noDataValues A vector with no-data values (will overwride the input raster no-data values) or an empty vectory if the input raster no-data values must be used.
164  \return true if OK, false on errors.
165  */
166  bool initialize(Raster const * const rasterPointer, int method,
167  const std::vector< std::complex<double> >& noDataValues );
168 
169  protected:
170 
171  Raster const* m_raster; //!< My input raster.
172  int m_method; //!< The interpolation method.
173  InterpolationFunction m_function; //!< The current interpolation function pointer.
174  std::vector< std::complex<double> > m_noDataValues; //!< Raster no-data values (for each band);
175 
176  // nearest Neighbor interpolation variables
177 
178  unsigned int m_nnCR;
179  unsigned int m_nnRR;
180  double m_nnLastRow; //!< Last row available for nearest Neighbor interpolation.
181  double m_nnLastCol; //!< Last column available for nearest Neighbor interpolation.
182 
183 
184  /* Bilinear interapolation variables. */
185  double m_bilRowMin; //!< Minimum row for bilinear interpolation.
186  double m_bilRowMax; //!< Maximum row for bilinear interpolation.
187  double m_bilColMin; //!< Minimum column for bilinear interpolation.
188  double m_bilColMax; //!< Maximum column for bilinear interpolation.
189  double m_bilRowDifMin; //!< Minimum difference between rows (min/max).
190  double m_bilRowDifMax; //!< Maximum difference between rows (min/max).
191  double m_bilColDifMin; //!< Minimum difference between columns (min/max).
192  double m_bilColDifMax; //!< Maximum difference between columns (min/max).
193  double m_bilDistances[4]; //!< Bilinear distances.
194  double m_bilWeights[4]; //!< Bilinear weights;
195  std::vector<std::complex<double> > m_bilValues; //!< Bilinear values;
196  double m_bilLastRow; //!< Last row available for bilinear interpolation.
197  double m_bilLastCol; //!< Last column available for bilinear interpolation.
198 
199  /* Bicubic interapolation variables. */
200  unsigned m_bicGridRow;
201  unsigned m_bicGridCol;
202  unsigned m_bicBufRow;
203  unsigned m_bicBufCol;
206  double m_bicBbufferReal[4][4];
207  double m_bicBbufferImag[4][4];
208  double m_bicOffsetX;
209  double m_bicOffsetY;
210  double m_bicKernel;
211  double m_bicHWeights[4];
212  double m_bicVWeights[4];
213  double m_bicHSum;
214  double m_bicVSum;
217  double m_bicRowsValuesReal[4];
218  double m_bicRowsValuesImag[4];
219  double m_bicRowBound; //!< Last row available for bicubic interpolation.
220  double m_bicColBound; //!< Last column available for bicubic interpolation.
221  };
222 
223  } // end namespace rst
224 } // end namespace te
225 
226 #endif // __TERRALIB_RASTER_INTERNAL_INTERPOLATOR_H
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:62
std::vector< std::complex< double > > m_noDataValues
Raster no-data values (for each band);.
Definition: Interpolator.h:174
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
Definition: Interpolator.h:55
double m_bilRowMin
Minimum row for bilinear interpolation.
Definition: Interpolator.h:185
void getValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Get the interpolated value at specific band.
Definition: Interpolator.h:93
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
InterpolationMethod Method
Allowed interpolation methods.
Definition: Interpolator.h:62
double m_bilColMin
Minimum column for bilinear interpolation.
Definition: Interpolator.h:187
double m_bilLastCol
Last column available for bilinear interpolation.
Definition: Interpolator.h:197
std::vector< std::complex< double > > m_bilValues
Bilinear values;.
Definition: Interpolator.h:195
Interpolator
Definition: Enums.h:54
double m_bilColDifMin
Minimum difference between columns (min/max).
Definition: Interpolator.h:191
InterpolationFunction m_function
The current interpolation function pointer.
Definition: Interpolator.h:173
Enumerations for the Raster module.
An abstract class for raster data strucutures.
double m_bilRowMax
Maximum row for bilinear interpolation.
Definition: Interpolator.h:186
An abstract class for raster data strucutures.
Definition: Raster.h:71
double m_bicColBound
Last column available for bicubic interpolation.
Definition: Interpolator.h:220
double m_nnLastRow
Last row available for nearest Neighbor interpolation.
Definition: Interpolator.h:180
URI C++ Library.
double m_bicRowBound
Last row available for bicubic interpolation.
Definition: Interpolator.h:219
double m_bilLastRow
Last row available for bilinear interpolation.
Definition: Interpolator.h:196
double m_nnLastCol
Last column available for nearest Neighbor interpolation.
Definition: Interpolator.h:181
double m_bilColMax
Maximum column for bilinear interpolation.
Definition: Interpolator.h:188
int m_method
The interpolation method.
Definition: Interpolator.h:172
Raster const * m_raster
My input raster.
Definition: Interpolator.h:171
double m_bilRowDifMax
Maximum difference between rows (min/max).
Definition: Interpolator.h:190
double m_bilColDifMax
Maximum difference between columns (min/max).
Definition: Interpolator.h:192
double m_bilRowDifMin
Minimum difference between rows (min/max).
Definition: Interpolator.h:189