TsCachedRaster.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 TsCachedRaster.cpp
22 
23  \brief A test suit for the Cached Raster class.
24  */
25 
26 #include "TsCachedRaster.h"
27 #include "../Config.h"
28 
29 #include <terralib/raster.h>
30 #include <terralib/dataaccess.h>
31 
32 #include <boost/shared_ptr.hpp>
33 
35 
36 void TsCachedRaster::CreateTestRaster( unsigned int nBands, unsigned int nLines,
37  unsigned int nCols, boost::shared_ptr< te::rst::Raster >& rasterPointer )
38 {
39  std::vector< te::rst::BandProperty * > bandsProps;
40  for( unsigned int bandsPropsIdx = 0 ; bandsPropsIdx < nBands ; ++bandsPropsIdx )
41  {
42  bandsProps.push_back( new te::rst::BandProperty( bandsPropsIdx,
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  for( line = 0 ; line < nLines ; ++line )
57  for( col = 0 ; col < nCols ; ++col )
58  {
59  rasterPointer->setValue( col, line, pixelValue, band );
60  ++pixelValue;
61  }
62 }
63 
65 {
66  // create the input test raster
67 
68  const unsigned int nBands = 10;
69  const unsigned int nLines = 10;
70  const unsigned int nCols = 10;
71 
72  boost::shared_ptr< te::rst::Raster > inputRasterPointer;
73  CreateTestRaster( nBands, nLines, nCols, inputRasterPointer );
74 
75  // using the cached raster adaptor.
76  {
77  te::mem::CachedRaster cachedRaster( 2, *inputRasterPointer, 0 );
78 
79  unsigned int band = 0;
80  unsigned int line = 0;
81  unsigned int col = 0;
82  double pixelValue = 0;
83 
84  for( band = 0 ; band < nBands ; ++band )
85  for( line = 0 ; line < nLines ; ++line )
86  for( col = 0 ; col < nCols ; ++col )
87  {
88  cachedRaster.getValue( col, line, pixelValue, band );
89  cachedRaster.setValue( col, line, pixelValue + 10.0, band );
90  }
91  }
92 
93  // Verifying the values
94 
95  {
96  unsigned int band = 0;
97  unsigned int line = 0;
98  unsigned int col = 0;
99  double pixelValue = 0;
100  double readPixelValue = 0;
101 
102  for( band = 0 ; band < nBands ; ++band )
103  for( line = 0 ; line < nLines ; ++line )
104  for( col = 0 ; col < nCols ; ++col )
105  {
106  inputRasterPointer->getValue( col, line, readPixelValue, band );
107  CPPUNIT_ASSERT_DOUBLES_EQUAL( pixelValue + 10.0, readPixelValue, 0.0000001 );
108  ++pixelValue;
109  }
110  }
111 }
112 
114 {
115  // create the input test raster
116 
117  const unsigned int nBands = 10;
118  const unsigned int nLines = 10;
119  const unsigned int nCols = 10;
120 
121  boost::shared_ptr< te::rst::Raster > inputRasterPointer;
122  CreateTestRaster( nBands, nLines, nCols, inputRasterPointer );
123 
124  // using the cached raster adaptor.
125  {
126  te::mem::CachedRaster cachedRaster( 2, *inputRasterPointer, 1 );
127 
128  unsigned int band = 0;
129  unsigned int line = 0;
130  unsigned int col = 0;
131  double pixelValue = 0;
132 
133  for( band = 0 ; band < nBands ; ++band )
134  for( line = 0 ; line < nLines ; ++line )
135  for( col = 0 ; col < nCols ; ++col )
136  {
137  cachedRaster.getValue( col, line, pixelValue, band );
138  cachedRaster.setValue( col, line, pixelValue + 10.0, band );
139  }
140  }
141 
142  // Verifying the values
143 
144  {
145  unsigned int band = 0;
146  unsigned int line = 0;
147  unsigned int col = 0;
148  double pixelValue = 0;
149  double readPixelValue = 0;
150 
151  for( band = 0 ; band < nBands ; ++band )
152  for( line = 0 ; line < nLines ; ++line )
153  for( col = 0 ; col < nCols ; ++col )
154  {
155  inputRasterPointer->getValue( col, line, readPixelValue, band );
156  CPPUNIT_ASSERT_DOUBLES_EQUAL( pixelValue + 10.0, readPixelValue, 0.0000001 );
157  ++pixelValue;
158  }
159  }
160 }
unsigned int unsigned int std::unique_ptr< te::rst::Raster > & rasterPointer
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
unsigned int band
A raster band description.
Definition: BandProperty.h:61
double pixelValue
A test suit for the Cached Raster class interface.
unsigned int line
unsigned int unsigned int nCols
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
Definition: CachedRaster.h:52
void CreateTestRaster(unsigned int nBands, unsigned int nLines, unsigned int nCols, boost::shared_ptr< te::rst::Raster > &rasterPointer)
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
static Raster * make()
It creates and returns an empty raster with default raster driver.
A test suit for the Cached Raster Class.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
This file contains include headers for the Data Access module of TerraLib.
unsigned int nLines
unsigned int col
CPPUNIT_TEST_SUITE_REGISTRATION(TsCachedRaster)