All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Interpolator.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 
32 // STL
33 #include <complex>
34 #include <vector>
35 
36 // Boost
37 #include <boost/noncopyable.hpp>
38 
39 namespace te
40 {
41  namespace rst
42  {
43 // Forward declaration
44  class Raster;
45 
46  /*!
47  \class Interpolator
48 
49  \brief It interpolates one pixel based on a selected algorithm.
50  Methods currently available are Nearest Neighbor, Bilinear, and Bicubic.
51 
52  \ingroup rst
53  */
54  class TERASTEREXPORT Interpolator : public boost::noncopyable
55  {
56  public:
57 
58  /*!
59  \brief Allowed interpolation methods.
60  */
61  enum Method
62  {
63  NearestNeighbor = 1, //!< Near neighborhood interpolation method.
64  Bilinear = 2, //!< Bilinear interpolation method.
65  Bicubic = 3 //!< Bicubic interpolation method.
66  };
67 
68  /*!
69  \brief Constructor.
70 
71  \param r The raster where to resample.
72  \param m The method of interpolation to apply.
73  */
74  Interpolator(Raster const* r, int m);
75 
76  /*!
77  \brief Constructor.
78 
79  \param r The raster where to resample.
80  \param m The method of interpolation to apply.
81  \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.
82  */
83  Interpolator(Raster const* r, int m, const std::vector< std::complex<double> >& noDataValues);
84 
85  /*! \brief Destructor. */
86  virtual ~Interpolator();
87 
88  /*!
89  \brief Get the interpolated value at specific band.
90 
91  \param c The column position (double).
92  \param r The row position (double).
93  \param v The output value or the current input raster no-data value if the requested coordinates are outside the valid image bounds.
94  \param b The band to obtain the value.
95  */
96  inline void getValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b)
97  {
98  assert(b < m_raster->getNumberOfBands());
99  (this->*(m_function))(c, r, v, b);
100  };
101 
102  /*!
103  \brief Get the interpolated value for all bands.
104 
105  \param c The column position (double).
106  \param r The row position (double).
107  \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..
108  */
109  void getValues(const double& c, const double& r, std::vector<std::complex<double> >& values);
110 
111  /*!
112  \brief Create a clone copy of this instance.
113 
114  \return A clone copy of this instance (the caller of this method must take the ownership of the returned object).
115  */
116  te::rst::Interpolator* clone() const;
117 
118  protected:
119 
120  /*!
121  \brief Nearest neighbor interpolation method.
122 
123  \param c The column position (double).
124  \param r The row position (double).
125  \param v The output value.
126  \param b The band to obtain the value.
127  */
128  void nearestNeighborGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
129 
130  /*!
131  \brief Bilinear interpolation method.
132 
133  \param c The column position (double).
134  \param r The row position (double).
135  \param v The output value.
136  \param b The band to obtain the value.
137  */
138  void bilinearGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
139 
140  /*!
141  \brief Bicubic interpolation method.
142 
143  \param c The column position (double).
144  \param r The row position (double).
145  \param v The output value.
146  \param b The band to obtain the value.
147  */
148  void bicubicGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
149 
150  /*!
151  \brief Type definition for the interpolation function.
152 
153  \param c The column position (double).
154  \param r The row position (double).
155  \param v The output value.
156  \param b The band to obtain the value.
157  */
158  typedef void (Interpolator::*InterpolationFunction)(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
159 
160  /*!
161  \brief Initialize this instance..
162 
163  \param r The raster where to resample.
164  \param method The method of interpolation to apply.
165  \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.
166  \return true if OK, false on errors.
167  */
168  bool initialize(Raster const * const rasterPointer, int method,
169  const std::vector< std::complex<double> >& noDataValues );
170 
171  protected:
172 
173  Raster const* m_raster; //!< My input raster.
174  int m_method; //!< The interpolation method.
175  InterpolationFunction m_function; //!< The current interpolation function pointer.
176  std::vector< std::complex<double> > m_noDataValues; //!< Raster no-data values (for each band);
177 
178  // nearest Neighbor interpolation variables
179 
180  unsigned int m_nnCR;
181  unsigned int m_nnRR;
182  double m_nnLastRow; //!< Last row available for nearest Neighbor interpolation.
183  double m_nnLastCol; //!< Last column available for nearest Neighbor interpolation.
184 
185 
186  /* Bilinear interapolation variables. */
187  double m_bilRowMin; //!< Minimum row for bilinear interpolation.
188  double m_bilRowMax; //!< Maximum row for bilinear interpolation.
189  double m_bilColMin; //!< Minimum column for bilinear interpolation.
190  double m_bilColMax; //!< Maximum column for bilinear interpolation.
191  double m_bilRowDifMin; //!< Minimum difference between rows (min/max).
192  double m_bilRowDifMax; //!< Maximum difference between rows (min/max).
193  double m_bilColDifMin; //!< Minimum difference between columns (min/max).
194  double m_bilColDifMax; //!< Maximum difference between columns (min/max).
195  double m_bilDistances[4]; //!< Bilinear distances.
196  double m_bilWeights[4]; //!< Bilinear weights;
197  std::vector<std::complex<double> > m_bilValues; //!< Bilinear values;
198  double m_bilLastRow; //!< Last row available for bilinear interpolation.
199  double m_bilLastCol; //!< Last column available for bilinear interpolation.
200 
201  /* Bicubic interapolation variables. */
202  unsigned m_bicGridRow;
203  unsigned m_bicGridCol;
204  unsigned m_bicBufRow;
205  unsigned m_bicBufCol;
208  double m_bicBbufferReal[4][4];
209  double m_bicBbufferImag[4][4];
210  double m_bicOffsetX;
211  double m_bicOffsetY;
212  double m_bicKernel;
213  double m_bicHWeights[4];
214  double m_bicVWeights[4];
215  double m_bicHSum;
216  double m_bicVSum;
219  double m_bicRowsValuesReal[4];
220  double m_bicRowsValuesImag[4];
221  double m_bicRowBound; //!< Last row available for bicubic interpolation.
222  double m_bicColBound; //!< Last column available for bicubic interpolation.
223  };
224 
225  } // end namespace rst
226 } // end namespace te
227 
228 #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:65
std::vector< std::complex< double > > m_noDataValues
Raster no-data values (for each band);.
Definition: Interpolator.h:176
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
Definition: Interpolator.h:54
double m_bilRowMin
Minimum row for bilinear interpolation.
Definition: Interpolator.h:187
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:96
double m_bilColMin
Minimum column for bilinear interpolation.
Definition: Interpolator.h:189
double m_bilLastCol
Last column available for bilinear interpolation.
Definition: Interpolator.h:199
std::vector< std::complex< double > > m_bilValues
Bilinear values;.
Definition: Interpolator.h:197
double m_bilColDifMin
Minimum difference between columns (min/max).
Definition: Interpolator.h:193
InterpolationFunction m_function
The current interpolation function pointer.
Definition: Interpolator.h:175
An abstract class for raster data strucutures.
double m_bilRowMax
Maximum row for bilinear interpolation.
Definition: Interpolator.h:188
An abstract class for raster data strucutures.
Definition: Raster.h:71
double m_bicColBound
Last column available for bicubic interpolation.
Definition: Interpolator.h:222
double m_nnLastRow
Last row available for nearest Neighbor interpolation.
Definition: Interpolator.h:182
double m_bicRowBound
Last row available for bicubic interpolation.
Definition: Interpolator.h:221
double m_bilLastRow
Last row available for bilinear interpolation.
Definition: Interpolator.h:198
double m_nnLastCol
Last column available for nearest Neighbor interpolation.
Definition: Interpolator.h:183
Method
Allowed interpolation methods.
Definition: Interpolator.h:61
double m_bilColMax
Maximum column for bilinear interpolation.
Definition: Interpolator.h:190
int m_method
The interpolation method.
Definition: Interpolator.h:174
Raster const * m_raster
My input raster.
Definition: Interpolator.h:173
double m_bilRowDifMax
Maximum difference between rows (min/max).
Definition: Interpolator.h:192
double m_bilColDifMax
Maximum difference between columns (min/max).
Definition: Interpolator.h:194
double m_bilRowDifMin
Minimum difference between rows (min/max).
Definition: Interpolator.h:191