All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TiledBand.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/memory/TiledBand.cpp
22 
23  \brief A tiled band implementation for the In-Memory Raster.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../raster/BandProperty.h"
29 #include "Exception.h"
30 #include "Raster.h"
31 #include "TiledBand.h"
32 
33 // STL
34 #include <cassert>
35 #include <cstring>
36 
38  : te::rst::Band(p, idx),
39  m_raster(r),
40  m_buff(0),
41  m_getBuff(0),
42  m_getBuffI(0),
43  m_setBuff(0),
44  m_setBuffI(0),
45  m_ncols(0),
46  m_nrows(0),
47  m_blksize(0),
48  m_nblksx(0),
49  m_nblksy(0),
50  m_blkw(0),
51  m_blkh(0)
52 {
54 
55  m_blkw = p->m_blkw;
56  m_blkh = p->m_blkh;
57 
58  m_nblksx = p->m_nblocksx;
59  m_nblksy = p->m_nblocksy;
60 
61  m_buff = new unsigned char**[m_nblksy];
62 
63  for(int i = 0; i < m_nblksy; ++i)
64  {
65  m_buff[i] = new unsigned char*[m_nblksx];
66 
67  for(int j = 0; j < m_nblksx; ++j)
68  {
69  m_buff[i][j] = new unsigned char[m_blksize];
70  }
71  }
72 
75 
77 }
78 
80  : te::rst::Band(rhs),
81  m_raster(0),
82  m_buff(0),
83  m_getBuff(rhs.m_getBuff),
84  m_getBuffI(rhs.m_getBuffI),
85  m_setBuff(rhs.m_setBuff),
86  m_setBuffI(rhs.m_setBuffI),
87  m_ncols(rhs.m_ncols),
88  m_nrows(rhs.m_nrows),
89  m_blksize(rhs.m_blksize),
90  m_nblksx(rhs.m_nblksx),
91  m_nblksy(rhs.m_nblksy),
92  m_blkw(rhs.m_blkw),
93  m_blkh(rhs.m_blkh)
94 {
95  m_buff = new unsigned char**[m_nblksy];
96 
97  for(int i = 0; i < m_nblksy; ++i)
98  {
99  m_buff[i] = new unsigned char*[m_nblksx];
100 
101  for(int j = 0; j < m_nblksx; ++j)
102  {
103  m_buff[i][j] = new unsigned char[m_blksize];
104 
105  memcpy(m_buff[i][j], rhs.m_buff[i][j], m_blksize);
106  }
107  }
108 }
109 
111 {
112  for(int i = 0; i < m_nblksy; ++i)
113  {
114  for(int j = 0; j < m_nblksx; ++j)
115  {
116 // kill tiles
117  delete [] m_buff[i][j];
118  }
119 
120 // kill rows
121  delete [] m_buff[i];
122  }
123 
124 // kill col
125  delete [] m_buff;
126 }
127 
129 {
130  return m_raster;
131 }
132 
134 {
135  if(&rhs != this)
136  {
137  if((m_blksize != rhs.m_blksize) ||
138  (m_nblksx != rhs.m_nblksx) ||
139  (m_nblksy != rhs.m_nblksy))
140  throw Exception(TE_TR("You can not assign a band to another one with different block size or tile dimesinsions"));
141 
143 
144  for(int i = 0; i < m_nblksy; ++i)
145  {
146  m_buff[i] = new unsigned char*[m_nblksx];
147 
148  for(int j = 0; j < m_nblksx; ++j)
149  {
150  m_buff[i][j] = new unsigned char[m_blksize];
151 
152  memcpy(m_buff[i][j], rhs.m_buff[i][j], m_blksize);
153  }
154  }
155 
156  m_getBuff = rhs.m_getBuff;
157  m_getBuffI = rhs.m_getBuffI;
158  m_setBuff = rhs.m_setBuff;
159  m_setBuffI = rhs.m_setBuffI;
160  m_ncols = rhs.m_ncols;
161  m_nrows = rhs.m_nrows;
162  }
163 
164  return *this;
165 }
166 
167 void te::mem::TiledBand::getValue(unsigned int c, unsigned int r, double& value) const
168 {
169  int blkx = c / m_blkw;
170 
171  int blky = r / m_blkh;
172 
173  int pos = c % m_blkw + ((r % m_blkh) * m_blkw);
174 
175  assert(pos < m_blksize);
176 
177  m_getBuff(pos, m_buff[blky][blkx], &value);
178 }
179 
180 void te::mem::TiledBand::setValue(unsigned int c, unsigned int r, const double value)
181 {
182  int blkx = c / m_blkw;
183 
184  int blky = r / m_blkh;
185 
186  int pos = c % m_blkw + ((r % m_blkh) * m_blkw);
187 
188  assert(pos < m_blksize);
189 
190  m_setBuff(pos, m_buff[blky][blkx], &value);
191 }
192 
193 void te::mem::TiledBand::getIValue(unsigned int c, unsigned int r, double& value) const
194 {
195  int blkx = c / m_blkw;
196 
197  int blky = r / m_blkh;
198 
199  int pos = c % m_blkw + ((r % m_blkh) * m_blkw);
200 
201  assert(pos < m_blksize);
202 
203  m_getBuffI(pos, m_buff[blky][blkx], &value);
204 }
205 
206 void te::mem::TiledBand::setIValue(unsigned int c, unsigned int r, const double value)
207 {
208  int blkx = c / m_blkw;
209 
210  int blky = r / m_blkh;
211 
212  int pos = c % m_blkw + ((r % m_blkh) * m_blkw);
213 
214  assert(pos < m_blksize);
215 
216  m_setBuffI(pos, m_buff[blky][blkx], &value);
217 }
218 
219 void te::mem::TiledBand::read(int x, int y, void* buffer) const
220 {
221  assert(x < m_nblksx && y < m_nblksy);
222 
223  memcpy(buffer, m_buff[y][x], m_blksize);
224 }
225 
226 void* te::mem::TiledBand::read(int x, int y)
227 {
228  assert(x < m_nblksx && y < m_nblksy);
229 
230  return m_buff[y][x];
231 }
232 
233 void te::mem::TiledBand::write(int x, int y, void* buffer)
234 {
235  assert(x < m_nblksx && y < m_nblksy);
236 
237  memcpy(m_buff[y][x], buffer, m_blksize);
238 }
239 
241 {
242  m_raster = r;
243 }
A raster class for memory.
Definition: Raster.h:44
A raster band description.
Definition: BandProperty.h:61
A tiled band implementation for the In-Memory Raster.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Definition: Raster.cpp:213
int m_nblocksx
The number of blocks in x.
Definition: BandProperty.h:145
virtual Band & operator=(const Band &rhs)
Assignment operator.
Definition: Band.cpp:48
void setRaster(Raster *r)
Definition: TiledBand.cpp:240
int m_nblocksy
The number of blocks in y.
Definition: BandProperty.h:146
te::rst::Raster * getRaster() const
Returns the associated raster.
Definition: TiledBand.cpp:128
TiledBand(Raster *r, te::rst::BandProperty *p, std::size_t idx)
Definition: TiledBand.cpp:37
te::rst::GetBufferValueFPtr m_getBuffI
A pointer to a function that helps to extract the imaginary part value from a specific buffer data ty...
Definition: TiledBand.h:84
void setIValue(unsigned int c, unsigned int r, const double value)
Sets the imaginary attribute value in a complex band of a cell.
Definition: TiledBand.cpp:206
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
An exception class for the TerraLib In-Memory Data Access driver.
unsigned char *** m_buff
A internal block buffer.
Definition: TiledBand.h:82
int m_ncols
Buffered number of cols.
Definition: TiledBand.h:87
void write(int x, int y, void *buffer)
It writes a data block from the specified buffer.
Definition: TiledBand.cpp:233
te::rst::GetBufferValueFPtr m_getBuff
A pointer to a function that helps to extract a double or complex value from a specific buffer data t...
Definition: TiledBand.h:83
An abstract class for raster data strucutures.
Definition: Raster.h:71
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Definition: Raster.cpp:208
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
int m_nrows
Buffered number of rows.
Definition: TiledBand.h:88
A raster class for memory.
te::rst::SetBufferValueFPtr m_setBuffI
A pointer to a function that helps to insert the imaginary part value into a specific buffer data typ...
Definition: TiledBand.h:86
void getValue(unsigned int c, unsigned int r, double &value) const
Returns the cell attribute value.
Definition: TiledBand.cpp:167
Band implementation for the In-Memory Raster.
Definition: Band.h:46
void setValue(unsigned int c, unsigned int r, const double value)
Sets the cell attribute value.
Definition: TiledBand.cpp:180
te::rst::SetBufferValueFPtr m_setBuff
A pointer to a function that helps to insert a double or complex value into a specific buffer data ty...
Definition: TiledBand.h:85
int getType() const
It returns the data type of the elements in the band.
Definition: BandProperty.h:113
void read(int x, int y, void *buffer) const
It reads a data block to the specified buffer.
Definition: TiledBand.cpp:219
int m_blkh
Block height (pixels).
Definition: BandProperty.h:144
TiledBand & operator=(const TiledBand &rhs)
Definition: TiledBand.cpp:133
int m_blksize
The data block size.
Definition: TiledBand.h:89
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
Definition: Band.cpp:630
TERASTEREXPORT void SetBlockFunctions(GetBufferValueFPtr *gb, GetBufferValueFPtr *gbi, SetBufferValueFPtr *sb, SetBufferValueFPtr *sbi, int type)
Sets the pointers to functions that helps to extract a double or complex value from a specific buffer...
Definition: BlockUtils.cpp:295
BandProperty * m_property
The band information.
Definition: Band.h:474
void getIValue(unsigned int c, unsigned int r, double &value) const
Returns the imaginary attribute value in a complex band of a cell.
Definition: TiledBand.cpp:193