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 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  */
92  inline void getValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b)
93  {
94  assert(b < m_raster->getNumberOfBands());
95  (this->*(m_function))(c, r, v, b);
96  };
97 
98  /*!
99  \brief Get the interpolated value for all bands.
100 
101  \param c The column position (double).
102  \param r The row position (double).
103  \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..
104  */
105  void getValues(const double& c, const double& r, std::vector<std::complex<double> >& values);
106 
107  /*!
108  \brief Create a clone copy of this instance.
109 
110  \return A clone copy of this instance (the caller of this method must take the ownership of the returned object).
111  */
112  te::rst::Interpolator* clone() const;
113 
114  protected:
115 
116  /*!
117  \brief Nearest neighbor interpolation method.
118 
119  \param c The column position (double).
120  \param r The row position (double).
121  \param v The output value.
122  \param b The band to obtain the value.
123  */
124  void nearestNeighborGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
125 
126  /*!
127  \brief Bilinear interpolation method.
128 
129  \param c The column position (double).
130  \param r The row position (double).
131  \param v The output value.
132  \param b The band to obtain the value.
133  */
134  void bilinearGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
135 
136  /*!
137  \brief Bicubic interpolation method.
138 
139  \param c The column position (double).
140  \param r The row position (double).
141  \param v The output value.
142  \param b The band to obtain the value.
143  */
144  void bicubicGetValue(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
145 
146  /*!
147  \brief Type definition for the interpolation function.
148 
149  \param c The column position (double).
150  \param r The row position (double).
151  \param v The output value.
152  \param b The band to obtain the value.
153  */
154  typedef void (Interpolator::*InterpolationFunction)(const double& c, const double& r, std::complex<double>& v, const std::size_t& b);
155 
156  /*!
157  \brief Initialize this instance..
158 
159  \param r The raster where to resample.
160  \param method The method of interpolation to apply.
161  \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.
162  \return true if OK, false on errors.
163  */
164  bool initialize(Raster const * const rasterPointer, int method,
165  const std::vector< std::complex<double> >& noDataValues );
166 
167  protected:
168 
169  Raster const* m_raster; //!< My input raster.
170  int m_method; //!< The interpolation method.
171  InterpolationFunction m_function; //!< The current interpolation function pointer.
172  std::vector< std::complex<double> > m_noDataValues; //!< Raster no-data values (for each band);
173 
174  // nearest Neighbor interpolation variables
175 
176  unsigned int m_nnCR;
177  unsigned int m_nnRR;
178  double m_nnLastRow; //!< Last row available for nearest Neighbor interpolation.
179  double m_nnLastCol; //!< Last column available for nearest Neighbor interpolation.
180 
181 
182  /* Bilinear interapolation variables. */
183  double m_bilRowMin; //!< Minimum row for bilinear interpolation.
184  double m_bilRowMax; //!< Maximum row for bilinear interpolation.
185  double m_bilColMin; //!< Minimum column for bilinear interpolation.
186  double m_bilColMax; //!< Maximum column for bilinear interpolation.
187  double m_bilRowDifMin; //!< Minimum difference between rows (min/max).
188  double m_bilRowDifMax; //!< Maximum difference between rows (min/max).
189  double m_bilColDifMin; //!< Minimum difference between columns (min/max).
190  double m_bilColDifMax; //!< Maximum difference between columns (min/max).
191  double m_bilDistances[4]; //!< Bilinear distances.
192  double m_bilWeights[4]; //!< Bilinear weights;
193  std::vector<std::complex<double> > m_bilValues; //!< Bilinear values;
194  double m_bilLastRow; //!< Last row available for bilinear interpolation.
195  double m_bilLastCol; //!< Last column available for bilinear interpolation.
196 
197  /* Bicubic interapolation variables. */
198  unsigned m_bicGridRow;
199  unsigned m_bicGridCol;
200  unsigned m_bicBufRow;
201  unsigned m_bicBufCol;
204  double m_bicBbufferReal[4][4];
205  double m_bicBbufferImag[4][4];
206  double m_bicOffsetX;
207  double m_bicOffsetY;
208  double m_bicKernel;
209  double m_bicHWeights[4];
210  double m_bicVWeights[4];
211  double m_bicHSum;
212  double m_bicVSum;
215  double m_bicRowsValuesReal[4];
216  double m_bicRowsValuesImag[4];
217  double m_bicRowBound; //!< Last row available for bicubic interpolation.
218  double m_bicColBound; //!< Last column available for bicubic interpolation.
219  };
220 
221  } // end namespace rst
222 } // end namespace te
223 
224 #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:172
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:183
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:92
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:185
double m_bilLastCol
Last column available for bilinear interpolation.
Definition: Interpolator.h:195
std::vector< std::complex< double > > m_bilValues
Bilinear values;.
Definition: Interpolator.h:193
double m_bilColDifMin
Minimum difference between columns (min/max).
Definition: Interpolator.h:189
InterpolationFunction m_function
The current interpolation function pointer.
Definition: Interpolator.h:171
Enumerations for the Raster module.
An abstract class for raster data strucutures.
double m_bilRowMax
Maximum row for bilinear interpolation.
Definition: Interpolator.h:184
An abstract class for raster data strucutures.
Definition: Raster.h:71
double m_bicColBound
Last column available for bicubic interpolation.
Definition: Interpolator.h:218
double m_nnLastRow
Last row available for nearest Neighbor interpolation.
Definition: Interpolator.h:178
double m_bicRowBound
Last row available for bicubic interpolation.
Definition: Interpolator.h:217
double m_bilLastRow
Last row available for bilinear interpolation.
Definition: Interpolator.h:194
double m_nnLastCol
Last column available for nearest Neighbor interpolation.
Definition: Interpolator.h:179
double m_bilColMax
Maximum column for bilinear interpolation.
Definition: Interpolator.h:186
int m_method
The interpolation method.
Definition: Interpolator.h:170
Raster const * m_raster
My input raster.
Definition: Interpolator.h:169
double m_bilRowDifMax
Maximum difference between rows (min/max).
Definition: Interpolator.h:188
double m_bilColDifMax
Maximum difference between columns (min/max).
Definition: Interpolator.h:190
double m_bilRowDifMin
Minimum difference between rows (min/max).
Definition: Interpolator.h:187