TsInterpolator.cpp
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/unittest/raster/TsInterpolator.cpp
22 
23  \brief A test suit for the Raster Interpolator class.
24  */
25 
26 // TerraLib
27 #include <terralib_buildconfig.h>
28 
29 #include <terralib/raster.h>
30 #include "../Config.h"
31 
32 // Boost
33 #include <boost/test/unit_test.hpp>
34 
35 BOOST_AUTO_TEST_SUITE ( interpolator_tests )
36 
37 void createTestRaster( unsigned int nBands, unsigned int nLines,
38  unsigned int nCols, std::unique_ptr< te::rst::Raster >& rasterPointer )
39 {
40  std::vector< te::rst::BandProperty * > bandsProps;
41  for( unsigned int bandsPropsIdx = 0 ; bandsPropsIdx < nBands ; ++bandsPropsIdx )
42  {
43  bandsProps.push_back( new te::rst::BandProperty( bandsPropsIdx, te::dt::UINT32_TYPE ) );
44  }
45 
46  rasterPointer.reset( te::rst::RasterFactory::make( "MEM",
47  new te::rst::Grid( nCols, nLines ), bandsProps,
48  std::map< std::string, std::string >(), 0, 0 ) );
49 
50  unsigned int band = 0;
51  unsigned int line = 0;
52  unsigned int col = 0;
53  double pixelValue = 0;
54 
55  for( band = 0 ; band < nBands ; ++band )
56  {
57  for( line = 0 ; line < nLines ; ++line )
58  {
59  for( col = 0 ; col < nCols ; ++col )
60  {
61  rasterPointer->setValue( col, line, pixelValue, band );
62  ++pixelValue;
63  }
64  }
65  }
66 }
67 
68 BOOST_AUTO_TEST_CASE (nearestNeighbor_test)
69 {
70  std::unique_ptr< te::rst::Raster > rasterPointer;
71  createTestRaster( 2, 4, 4, rasterPointer );
72 
73  std::vector< std::complex<double> > noDataValues;
74  noDataValues.resize( rasterPointer->getNumberOfBands(), std::complex<double>(
75  0.0, 0.0 ) );
76 
77  te::rst::Interpolator interp( rasterPointer.get(), te::rst::NearestNeighbor,
78  noDataValues );
79 
80  std::complex<double> v;
81 
82  interp.getValue( -0.7, -0.7, v, 0 );
83  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
84  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
85 
86  interp.getValue( ((double)rasterPointer->getNumberOfColumns()) - 0.3 , -0.7, v, 0 );
87  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
88  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
89 
90  interp.getValue( ((double)rasterPointer->getNumberOfColumns()) - 0.3 ,
91  ((double)rasterPointer->getNumberOfRows()) - 0.3, v, 0 );
92  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
93  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
94 
95  interp.getValue( -0.7 ,
96  ((double)rasterPointer->getNumberOfRows()) - 0.3, v, 0 );
97  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
98  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
99 
100  interp.getValue( 1.5 , 1.5, v, 0 );
101  BOOST_CHECK_CLOSE( 10.0, v.real(), 0.0000000001 );
102  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
103 
104  interp.getValue( 1.5 , 1.5, v, 1 );
105  BOOST_CHECK_CLOSE( 26.0, v.real(), 0.0000000001 );
106  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
107 }
108 
109 BOOST_AUTO_TEST_CASE (bilinear_test)
110 {
111  std::unique_ptr< te::rst::Raster > rasterPointer;
112  createTestRaster( 2, 4, 4, rasterPointer );
113 
114  std::vector< std::complex<double> > noDataValues;
115  noDataValues.resize( rasterPointer->getNumberOfBands(), std::complex<double>(
116  0.0, 0.0 ) );
117 
118  te::rst::Interpolator interp( rasterPointer.get(), te::rst::Bilinear,
119  noDataValues );
120 
121  std::complex<double> v;
122 
123  interp.getValue( -0.7, -0.7, v, 0 );
124  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
125  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
126 
127  interp.getValue( ((double)rasterPointer->getNumberOfColumns()) - 0.3 , -0.7, v, 0 );
128  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
129  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
130 
131  interp.getValue( ((double)rasterPointer->getNumberOfColumns()) - 0.3 ,
132  ((double)rasterPointer->getNumberOfRows()) - 0.3, v, 0 );
133  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
134  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
135 
136  interp.getValue( -0.7 ,
137  ((double)rasterPointer->getNumberOfRows()) - 0.3, v, 0 );
138  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
139  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
140 
141  interp.getValue( 1.5 , 1.5, v, 0 );
142  BOOST_CHECK_CLOSE( 7.5, v.real(), 0.0000000001 );
143  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
144 
145  interp.getValue( 1.5 , 1.5, v, 1 );
146  BOOST_CHECK_CLOSE( 23.5, v.real(), 0.0000000001 );
147  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
148 }
149 
150 BOOST_AUTO_TEST_CASE (bicubic_test)
151 {
152  std::unique_ptr< te::rst::Raster > rasterPointer;
153  createTestRaster( 2, 4, 4, rasterPointer );
154 
155  std::vector< std::complex<double> > noDataValues;
156  noDataValues.resize( rasterPointer->getNumberOfBands(), std::complex<double>(
157  0.0, 0.0 ) );
158 
159  te::rst::Interpolator interp( rasterPointer.get(), te::rst::Bicubic,
160  noDataValues );
161 
162  std::complex<double> v;
163 
164  interp.getValue( -0.7, -0.7, v, 0 );
165  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
166  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
167 
168  interp.getValue( ((double)rasterPointer->getNumberOfColumns()) - 0.3 , -0.7, v, 0 );
169  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
170  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
171 
172  interp.getValue( ((double)rasterPointer->getNumberOfColumns()) - 0.3 ,
173  ((double)rasterPointer->getNumberOfRows()) - 0.3, v, 0 );
174  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
175  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
176 
177  interp.getValue( -0.7 ,
178  ((double)rasterPointer->getNumberOfRows()) - 0.3, v, 0 );
179  BOOST_CHECK_CLOSE( 0.0, v.real(), 0.0000000001 );
180  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
181 
182  interp.getValue( 1.5 , 1.5, v, 0 );
183  BOOST_CHECK_CLOSE( 7.5, v.real(), 0.0000000001 );
184  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
185 
186  interp.getValue( 1.5 , 1.5, v, 1 );
187  BOOST_CHECK_CLOSE( 23.5, v.real(), 0.0000000001 );
188  BOOST_CHECK_CLOSE( 0.0, v.imag(), 0.0000000001 );
189 }
190 
191 BOOST_AUTO_TEST_SUITE_END ()
unsigned int unsigned int std::unique_ptr< te::rst::Raster > & rasterPointer
unsigned int band
Near neighborhood interpolation method.
BOOST_AUTO_TEST_SUITE(interpolator_tests) void createTestRaster(unsigned int nBands
A raster band description.
Definition: BandProperty.h:61
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
Definition: Interpolator.h:55
BOOST_AUTO_TEST_CASE(nearestNeighbor_test)
double pixelValue
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
unsigned int line
unsigned int unsigned int nCols
URI C++ Library.
Definition: Attributes.h:37
Bicubic interpolation method.
static Raster * make()
It creates and returns an empty raster with default raster driver.
Bilinear interpolation method.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
unsigned int nLines
unsigned int col