TsExpansibleBandBlocksManager.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 TsExpansibleBandBlocksManager.cpp
22 
23  \brief A test suit for the Cached Raster class interface.
24 
25  */
26 
28 #include "../Config.h"
29 
31 
33 {
34  const unsigned int maxNumberRAMBlocks = 2;
35 
36  std::vector< unsigned int> numbersOfBlocksX;
37  numbersOfBlocksX.push_back( 1 );
38  numbersOfBlocksX.push_back( 2 );
39  numbersOfBlocksX.push_back( 2 );
40 
41  std::vector< unsigned int> numbersOfBlocksY;
42  numbersOfBlocksY.push_back( 1 );
43  numbersOfBlocksY.push_back( 3 );
44  numbersOfBlocksY.push_back( 1 );
45 
46  std::vector< unsigned int> blocksSizesBytes;
47  blocksSizesBytes.push_back( 6 * sizeof( unsigned int ) );
48  blocksSizesBytes.push_back( 2 * sizeof( unsigned char ) );
49  blocksSizesBytes.push_back( 3 * sizeof( double ) );
50 
51  const unsigned long int maxDiskFilesSize = 1000000;
52 
54  CPPUNIT_ASSERT( manager.initialize( maxNumberRAMBlocks, numbersOfBlocksX,
55  numbersOfBlocksY, blocksSizesBytes, maxDiskFilesSize ) );
56 
57  // writing values
58 
59  ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 0 ] = (unsigned int)(0);
60  ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 1 ] = (unsigned int)(1);
61  ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 2 ] = (unsigned int)(2);
62  ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 3 ] = (unsigned int)(3);
63  ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 4 ] = (unsigned int)(4);
64  ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 5 ] = (unsigned int)(5);
65 
66  ((unsigned char*)manager.getBlockPointer( 1, 0, 0))[ 0 ] = (unsigned char)(6);
67  ((unsigned char*)manager.getBlockPointer( 1, 0, 1))[ 0 ] = (unsigned char)(7);
68  ((unsigned char*)manager.getBlockPointer( 1, 0, 2))[ 0 ] = (unsigned char)(8);
69  ((unsigned char*)manager.getBlockPointer( 1, 1, 0))[ 0 ] = (unsigned char)(9);
70  ((unsigned char*)manager.getBlockPointer( 1, 1, 1))[ 0 ] = (unsigned char)(10);
71  ((unsigned char*)manager.getBlockPointer( 1, 1, 2))[ 0 ] = (unsigned char)(11);
72 
73  ((double*)manager.getBlockPointer( 2, 0, 0))[ 0 ] = (double)(12);
74  ((double*)manager.getBlockPointer( 2, 0, 0))[ 1 ] = (double)(13);
75  ((double*)manager.getBlockPointer( 2, 0, 0))[ 2 ] = (double)(14);
76  ((double*)manager.getBlockPointer( 2, 1, 0))[ 0 ] = (double)(15);
77  ((double*)manager.getBlockPointer( 2, 1, 0))[ 1 ] = (double)(16);
78  ((double*)manager.getBlockPointer( 2, 1, 0))[ 2 ] = (double)(17);
79 
80  // Verifying the values
81 
82  CPPUNIT_ASSERT( ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 0 ] == (unsigned int)(0) );
83  CPPUNIT_ASSERT( ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 1 ] == (unsigned int)(1) );
84  CPPUNIT_ASSERT( ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 2 ] == (unsigned int)(2) );
85  CPPUNIT_ASSERT( ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 3 ] == (unsigned int)(3) );
86  CPPUNIT_ASSERT( ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 4 ] == (unsigned int)(4) );
87  CPPUNIT_ASSERT( ((unsigned int*)manager.getBlockPointer( 0, 0, 0))[ 5 ] == (unsigned int)(5) );
88 
89  CPPUNIT_ASSERT( ((unsigned char*)manager.getBlockPointer( 1, 0, 0))[ 0 ] == (unsigned char)(6) );
90  CPPUNIT_ASSERT( ((unsigned char*)manager.getBlockPointer( 1, 0, 1))[ 0 ] == (unsigned char)(7) );
91  CPPUNIT_ASSERT( ((unsigned char*)manager.getBlockPointer( 1, 0, 2))[ 0 ] == (unsigned char)(8) );
92  CPPUNIT_ASSERT( ((unsigned char*)manager.getBlockPointer( 1, 1, 0))[ 0 ] == (unsigned char)(9) );
93  CPPUNIT_ASSERT( ((unsigned char*)manager.getBlockPointer( 1, 1, 1))[ 0 ] == (unsigned char)(10) );
94  CPPUNIT_ASSERT( ((unsigned char*)manager.getBlockPointer( 1, 1, 2))[ 0 ] == (unsigned char)(11) );
95 
96  CPPUNIT_ASSERT( ((double*)manager.getBlockPointer( 2, 0, 0))[ 0 ] == (double)(12) );
97  CPPUNIT_ASSERT( ((double*)manager.getBlockPointer( 2, 0, 0))[ 1 ] == (double)(13) );
98  CPPUNIT_ASSERT( ((double*)manager.getBlockPointer( 2, 0, 0))[ 2 ] == (double)(14) );
99  CPPUNIT_ASSERT( ((double*)manager.getBlockPointer( 2, 1, 0))[ 0 ] == (double)(15) );
100  CPPUNIT_ASSERT( ((double*)manager.getBlockPointer( 2, 1, 0))[ 1 ] == (double)(16) );
101  CPPUNIT_ASSERT( ((double*)manager.getBlockPointer( 2, 1, 0))[ 2 ] == (double)(17) );
102 }
103 
105 {
106  const unsigned int maxNumberRAMBlocks = 2;
107 
108  std::vector< unsigned int> numbersOfBlocksX;
109  numbersOfBlocksX.push_back( 1 );
110  numbersOfBlocksX.push_back( 2 );
111  numbersOfBlocksX.push_back( 2 );
112 
113  std::vector< unsigned int> numbersOfBlocksY;
114  numbersOfBlocksY.push_back( 1 );
115  numbersOfBlocksY.push_back( 3 );
116  numbersOfBlocksY.push_back( 1 );
117 
118  std::vector< unsigned int> blocksSizesBytes;
119  blocksSizesBytes.push_back( 6 * sizeof( unsigned int ) );
120  blocksSizesBytes.push_back( 2 * sizeof( unsigned int ) );
121  blocksSizesBytes.push_back( 3 * sizeof( unsigned int ) );
122 
123  const unsigned long int maxDiskFilesSize = 1000000;
124 
126  CPPUNIT_ASSERT( manager.initialize( maxNumberRAMBlocks, numbersOfBlocksX,
127  numbersOfBlocksY, blocksSizesBytes, maxDiskFilesSize ) );
128 
129  FillBlocks< unsigned int >( manager );
130  CheckValues< unsigned int >( manager );
131 
132  std::vector< te::mem::ExpansibleBandBlocksManager::BlockIndex3D > addedBlocksCoords;
133 
134  manager.addTopBlocks( 1, 0, addedBlocksCoords );
135  FillBlocks< unsigned int >( manager );
136  CheckValues< unsigned int >( manager );
137 
138  manager.addTopBlocks( 2, 1, addedBlocksCoords );
139  FillBlocks< unsigned int >( manager );
140  CheckValues< unsigned int >( manager );
141 
142  manager.addTopBlocks( 3, 2, addedBlocksCoords );
143  FillBlocks< unsigned int >( manager );
144  CheckValues< unsigned int >( manager );
145 
146  manager.addBottomBlocks( 1, 0, addedBlocksCoords );
147  FillBlocks< unsigned int >( manager );
148  CheckValues< unsigned int >( manager );
149 
150  manager.addBottomBlocks( 2, 1, addedBlocksCoords );
151  FillBlocks< unsigned int >( manager );
152  CheckValues< unsigned int >( manager );
153 
154  manager.addBottomBlocks( 3, 2, addedBlocksCoords );
155  FillBlocks< unsigned int >( manager );
156  CheckValues< unsigned int >( manager );
157 
158  manager.addLeftBlocks( 1, 0, addedBlocksCoords );
159  FillBlocks< unsigned int >( manager );
160  CheckValues< unsigned int >( manager );
161 
162  manager.addLeftBlocks( 2, 1, addedBlocksCoords );
163  FillBlocks< unsigned int >( manager );
164  CheckValues< unsigned int >( manager );
165 
166  manager.addLeftBlocks( 3, 2, addedBlocksCoords );
167  FillBlocks< unsigned int >( manager );
168  CheckValues< unsigned int >( manager );
169 
170  manager.addRightBlocks( 1, 0, addedBlocksCoords );
171  FillBlocks< unsigned int >( manager );
172  CheckValues< unsigned int >( manager );
173 
174  manager.addRightBlocks( 2, 1, addedBlocksCoords );
175  FillBlocks< unsigned int >( manager );
176  CheckValues< unsigned int >( manager );
177 
178  manager.addRightBlocks( 3, 2, addedBlocksCoords );
179  FillBlocks< unsigned int >( manager );
180  CheckValues< unsigned int >( manager );
181 
182  manager.addTopBands( 1, addedBlocksCoords );
183  FillBlocks< unsigned int >( manager );
184  CheckValues< unsigned int >( manager );
185 
186  manager.addTopBands( 2, addedBlocksCoords );
187  FillBlocks< unsigned int >( manager );
188  CheckValues< unsigned int >( manager );
189 
190  manager.addTopBands( 3, addedBlocksCoords );
191  FillBlocks< unsigned int >( manager );
192  CheckValues< unsigned int >( manager );
193 
194  manager.addBottomBands( 1, addedBlocksCoords );
195  FillBlocks< unsigned int >( manager );
196  CheckValues< unsigned int >( manager );
197 
198  manager.addBottomBands( 2, addedBlocksCoords );
199  FillBlocks< unsigned int >( manager );
200  CheckValues< unsigned int >( manager );
201 
202  manager.addBottomBands( 3, addedBlocksCoords );
203  FillBlocks< unsigned int >( manager );
204  CheckValues< unsigned int >( manager );
205 }
206 
bool addTopBands(const unsigned int &expansionSize, std::vector< BlockIndex3D > &addedBlocksCoords)
New bands will be added at the top of the raster (before the first band).
bool addBottomBlocks(const unsigned int &expansionSize, const unsigned int &band, std::vector< BlockIndex3D > &addedBlocksCoords)
New blocks will be added at the bottom of the raster.
void * getBlockPointer(unsigned int band, unsigned int x, unsigned int y)
Returns a pointer to the required data block.
bool initialize(const unsigned int maxNumberRAMBlocks, const std::vector< unsigned int > &numbersOfBlocksX, const std::vector< unsigned int > &numbersOfBlocksY, const std::vector< unsigned int > &blocksSizesBytes, const unsigned long int maxDiskFilesSize)
Initialize this instance to an initial state.
A test suit for the Expansible Band Blocks Manager Class.
bool addBottomBands(const unsigned int &expansionSize, std::vector< BlockIndex3D > &addedBlocksCoords)
New bands will be added at the bottom of the raster (after de the last band).
RAM cached and tiled raster band blocks manager.
bool addRightBlocks(const unsigned int &expansionSize, const unsigned int &band, std::vector< BlockIndex3D > &addedBlocksCoords)
New blocks will be added at the right of the raster.
A test suit for the Expansible Band Blocks Manager Class.
CPPUNIT_TEST_SUITE_REGISTRATION(TsExpansibleBandBlocksManager)
bool addTopBlocks(const unsigned int &expansionSize, const unsigned int &band, std::vector< BlockIndex3D > &addedBlocksCoords)
New blocks will be added at the top of the raster.
bool addLeftBlocks(const unsigned int &expansionSize, const unsigned int &band, std::vector< BlockIndex3D > &addedBlocksCoords)
New blocks will be added at the left of the raster.