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