36 #define BICUBIC_MODULE( x ) ( ( x < 0 ) ? ( -1 * x ) : x ) 
   37 #define BICUBIC_K1( x , a ) ( ( ( a + 2 ) * x * x * x ) - \ 
   38   ( ( a + 3 ) * x * x ) + 1 ) 
   39 #define BICUBIC_K2( x , a ) ( ( a * x * x * x ) - ( 5 * a * x * x ) + \ 
   40   ( 8 * a * x ) - ( 4 * a ) ) 
   41 #define BICUBIC_RANGES(x,a) \ 
   42   ( ( ( 0 <= x ) && ( x <= 1 ) ) ? \ 
   44   : ( ( ( 1 < x ) && ( x <= 2 ) ) ? \ 
   47 #define BICUBIC_KERNEL( x , a ) BICUBIC_RANGES( BICUBIC_MODULE(x) , a ) 
   51   if( ! 
initialize( r, m, std::vector< std::complex<double> >()  ) )
 
   53     throw te::rst::Exception(
"Interpolator initialization error");
 
   58   const std::vector< std::complex<double> >& noDataValues )
 
   60   if( ! initialize( r, m, noDataValues ) )
 
   62     throw te::rst::Exception(
"Interpolator initialization error");
 
   75   std::complex<double> v;
 
   77   for(std::size_t b = 0; b < m_raster->getNumberOfBands(); b++)
 
   88   return newInstancePtr;
 
   93   if( ( c > (-0.5) ) && ( r > (-0.5) ) && ( c < m_nnLastCol ) && ( r < m_nnLastRow ) )
 
   98     m_raster->getValue(m_nnCR, m_nnRR, v, b);
 
  102     v = m_noDataValues[ b ];
 
  108   if( (r < 0.0) || (c < 0.0) || (r > m_bilLastRow) || (c > m_bilLastCol) )
 
  110     nearestNeighborGetValue(c, r, v, b);
 
  114   m_bilRowMin = std::floor(r);
 
  115   m_bilRowMax = (m_bilRowMin == r)? m_bilRowMin: (m_bilRowMin + 1.0);
 
  117   m_bilColMin = std::floor(c);
 
  118   m_bilColMax = (m_bilColMin == c)? m_bilColMin: (m_bilColMin + 1.0);
 
  120   m_bilRowDifMin = r - m_bilRowMin;
 
  121   m_bilRowDifMax = m_bilRowMax - r;
 
  123   m_bilColDifMin = c - m_bilColMin;
 
  124   m_bilColDifMax = m_bilColMax - c;
 
  126   m_bilDistances[0] = std::sqrt((m_bilRowDifMin * m_bilRowDifMin) + (m_bilColDifMin * m_bilColDifMin));
 
  127   m_bilDistances[1] = std::sqrt((m_bilRowDifMin * m_bilRowDifMin) + (m_bilColDifMax * m_bilColDifMax));
 
  128   m_bilDistances[2] = std::sqrt((m_bilRowDifMax * m_bilRowDifMax) + (m_bilColDifMin * m_bilColDifMin));
 
  129   m_bilDistances[3] = std::sqrt((m_bilRowDifMax * m_bilRowDifMax) + (m_bilColDifMin * m_bilColDifMax));
 
  131   m_bilWeights[0] = (m_bilDistances[0] == 0)? 1.0: (1 / m_bilDistances[0]);
 
  132   m_bilWeights[1] = (m_bilDistances[1] == 0)? 1.0: (1 / m_bilDistances[1]);
 
  133   m_bilWeights[2] = (m_bilDistances[2] == 0)? 1.0: (1 / m_bilDistances[2]);
 
  134   m_bilWeights[3] = (m_bilDistances[3] == 0)? 1.0: (1 / m_bilDistances[3]);
 
  136   m_raster->getValue((
unsigned) m_bilColMin, (
unsigned) m_bilRowMin, m_bilValues[0], b);
 
  137   if( m_bilValues[0] == m_noDataValues[ b ] )
 
  139     nearestNeighborGetValue(c, r, v, b);
 
  143   m_raster->getValue((
unsigned) m_bilColMax, (
unsigned) m_bilRowMin, m_bilValues[1], b);
 
  144   if( m_bilValues[1] == m_noDataValues[ b ] )
 
  146     nearestNeighborGetValue(c, r, v, b);
 
  150   m_raster->getValue((
unsigned) m_bilColMin, (
unsigned) m_bilRowMax, m_bilValues[2], b);
 
  151   if( m_bilValues[2] == m_noDataValues[ b ] )
 
  153     nearestNeighborGetValue(c, r, v, b);
 
  157   m_raster->getValue((
unsigned) m_bilColMax, (
unsigned) m_bilRowMax, m_bilValues[3], b);
 
  158   if( m_bilValues[3] == m_noDataValues[ b ] )
 
  160     nearestNeighborGetValue(c, r, v, b);
 
  164   double vr = ( (m_bilValues[0].real() * m_bilWeights[0]) +
 
  165             (m_bilValues[1].real() * m_bilWeights[1]) +
 
  166             (m_bilValues[2].real() * m_bilWeights[2]) +
 
  167             (m_bilValues[3].real() * m_bilWeights[3]) ) /
 
  168             (m_bilWeights[0] + m_bilWeights[1] + m_bilWeights[2] + m_bilWeights[3]);
 
  169   double vi = ( (m_bilValues[0].imag() * m_bilWeights[0]) +
 
  170             (m_bilValues[1].imag() * m_bilWeights[1]) +
 
  171             (m_bilValues[2].imag() * m_bilWeights[2]) +
 
  172             (m_bilValues[3].imag() * m_bilWeights[3]) ) /
 
  173             (m_bilWeights[0] + m_bilWeights[1] + m_bilWeights[2] + m_bilWeights[3]);
 
  174   v = std::complex<double>(vr,vi);
 
  179   if( (r <= 1.0) || (c <= 1.0) || (r >= m_bicRowBound) || (c >= m_bicColBound) )
 
  181     nearestNeighborGetValue(c, r, v, b);
 
  185   m_bicGridRow = ((unsigned) std::floor(r)) - 1;
 
  186   m_bicGridCol = ((unsigned) std::floor(c)) - 1;
 
  189   for(m_bicBufRow = 0; m_bicBufRow < 4; ++m_bicBufRow)
 
  191     for(m_bicBufCol = 0; m_bicBufCol < 4 ; ++m_bicBufCol)
 
  194       m_raster->getValue(m_bicGridCol + m_bicBufCol, m_bicGridRow + m_bicBufRow,
 
  195                          m_bicReadRealValue, b);
 
  196       m_raster->getIValue(m_bicGridCol + m_bicBufCol, m_bicGridRow + m_bicBufRow,
 
  197                           m_bicReadImagValue, b);
 
  199       if( ( m_bicReadRealValue == m_noDataValues[ b ].real() ) &&
 
  200         ( m_bicReadImagValue == m_noDataValues[ b ] ) )
 
  202         nearestNeighborGetValue(c, r, v, b);
 
  206       m_bicBbufferReal[m_bicBufRow][m_bicBufCol] = m_bicReadRealValue;
 
  207       m_bicBbufferImag[m_bicBufRow][m_bicBufCol] = m_bicReadImagValue;
 
  212   m_bicOffsetX = c - (double)(m_bicGridCol + 1);
 
  213   m_bicOffsetY = r - (double)(m_bicGridRow + 1);
 
  215   m_bicHWeights[0] = 
BICUBIC_KERNEL(1.0 + m_bicOffsetX, m_bicKernel);
 
  217   m_bicHWeights[2] = 
BICUBIC_KERNEL(1.0 - m_bicOffsetX, m_bicKernel);
 
  218   m_bicHWeights[3] = 
BICUBIC_KERNEL(2.0 - m_bicOffsetX, m_bicKernel);
 
  220   m_bicVWeights[0] = 
BICUBIC_KERNEL(1.0 + m_bicOffsetY, m_bicKernel);
 
  222   m_bicVWeights[2] = 
BICUBIC_KERNEL(1.0 - m_bicOffsetY, m_bicKernel);
 
  223   m_bicVWeights[3] = 
BICUBIC_KERNEL(2.0 - m_bicOffsetY, m_bicKernel);
 
  225   m_bicHSum = m_bicHWeights[0] + m_bicHWeights[1] + m_bicHWeights[2] + m_bicHWeights[3];
 
  226   m_bicVSum = m_bicVWeights[0] + m_bicVWeights[1] + m_bicVWeights[2] + m_bicVWeights[3];
 
  229   for(m_bicBufRow = 0 ; m_bicBufRow < 4 ; ++m_bicBufRow)
 
  231     m_bicRowAccumReal = 0.0;
 
  232     m_bicRowAccumImag = 0.0;
 
  233     for(m_bicBufCol = 0; m_bicBufCol < 4; ++m_bicBufCol)
 
  235       m_bicRowAccumReal += m_bicBbufferReal[m_bicBufRow][m_bicBufCol] *
 
  236                            m_bicHWeights[m_bicBufCol];
 
  237       m_bicRowAccumImag += m_bicBbufferImag[m_bicBufRow][m_bicBufCol] *
 
  238                            m_bicHWeights[m_bicBufCol];
 
  241     m_bicRowsValuesReal[m_bicBufRow] = m_bicRowAccumReal / m_bicHSum;
 
  242     m_bicRowsValuesImag[m_bicBufRow] = m_bicRowAccumImag / m_bicHSum;
 
  244   double vr = ( m_bicRowsValuesReal[0] * m_bicVWeights[0] +
 
  245             m_bicRowsValuesReal[1] * m_bicVWeights[1] +
 
  246             m_bicRowsValuesReal[2] * m_bicVWeights[2] +
 
  247             m_bicRowsValuesReal[3] * m_bicVWeights[3] ) / m_bicVSum;
 
  249   double vi = ( m_bicRowsValuesImag[0] * m_bicVWeights[0] +
 
  250             m_bicRowsValuesImag[1] * m_bicVWeights[1] +
 
  251             m_bicRowsValuesImag[2] * m_bicVWeights[2] +
 
  252                m_bicRowsValuesImag[3] * m_bicVWeights[3] ) / m_bicVSum;
 
  253   v = std::complex<double>(vr,vi);
 
  257   const std::vector< std::complex<double> >& noDataValues )
 
  259   if( rasterPointer == 0 )
 
  268   m_raster = rasterPointer;
 
  282       throw te::rst::Exception(
"Invalid interpolation method");
 
  290   m_noDataValues.clear();
 
  292   if( noDataValues.empty() )
 
  294     std::complex<double> auxC;
 
  296     for( 
unsigned int bandIdx = 0 ; bandIdx < rasterPointer->
getNumberOfBands() ; ++bandIdx )
 
  299       m_noDataValues.push_back( auxC );
 
  306       throw te::rst::Exception(
"Invalid no-data values");
 
  309     m_noDataValues = noDataValues;
 
  314   m_nnLastRow = ( (double) m_raster->getNumberOfRows() ) - 0.5;
 
  315   m_nnLastCol = ( (double) m_raster->getNumberOfColumns() ) - 0.5;
 
  318   m_bilValues.resize(4, 0);
 
  320   m_bilLastRow = (double) m_raster->getNumberOfRows() - 1.0;
 
  322   m_bilLastCol = (double) m_raster->getNumberOfColumns() - 1.0;
 
  327   m_bicRowBound = m_bilLastRow - 1.0;
 
  329   m_bicColBound = m_bilLastCol - 1.0;
 
void getValues(const double &c, const double &r, std::vector< std::complex< double > > &values)
Get the interpolated value for all bands. 
void nearestNeighborGetValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Nearest neighbor interpolation method. 
Near neighborhood interpolation method. 
It describes one band (or dimension) of a raster. 
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band. 
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
bool initialize(Raster const *const rasterPointer, int method, const std::vector< std::complex< double > > &noDataValues)
Initialize this instance.. 
void bilinearGetValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Bilinear interpolation method. 
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max(). 
te::common::AccessPolicy getAccessPolicy() const 
Returns the raster access policy. 
An exception class for the Raster module. 
te::rst::Interpolator * clone() const 
Create a clone copy of this instance. 
#define BICUBIC_KERNEL(x, a)
TERASTEREXPORT int Round(double val)
Round a double value to a integer value. 
An abstract class for raster data strucutures. 
BandProperty * getProperty()
Returns the band property. 
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster. 
Utility functions for the raster module. 
virtual ~Interpolator()
Destructor. 
It gives access to values in one band (dimension) of a raster. 
Interpolator(Raster const *r, int m)
Constructor. 
Bicubic interpolation method. 
void bicubicGetValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Bicubic interpolation method. 
Bilinear interpolation method. 
It interpolates one pixel based on a selected algorithm.