All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ExpansibleBand.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/ExpansibleBand.cpp
22 
23  \brief Expansible raster band.
24 */
25 
26 // TerraLib
27 #include "../raster/BandProperty.h"
28 #include "../raster/Utils.h"
29 #include "ExpansibleBand.h"
30 
31 // STL
32 #include <cstring>
33 
35 
37  te::rst::Raster& parentRaster,
38  const te::rst::BandProperty& bandProperty, std::size_t idx )
39 : te::rst::Band( new te::rst::BandProperty( bandProperty ), idx ),
40  m_blocksManager( blocksManager ),
41  m_parentRasterPtr( &parentRaster ),
42  m_blkWidth( (unsigned int)bandProperty.m_blkw ),
43  m_blkHeight( (unsigned int)bandProperty.m_blkh ),
44  m_blkSizeBytes( (unsigned int)( bandProperty.m_blkw * bandProperty.m_blkh *
45  te::rst::GetPixelSize( bandProperty.m_type ) ) )
46 {
48  m_property->m_type );
49 }
50 
52 : te::rst::Band( new te::rst::BandProperty( 0, 0 ), 0 ),
53  m_blocksManager( dummyBlocksManager )
54 {
55  m_getBuff = 0;
56  m_getBuffI = 0;
57  m_setBuff = 0;
58  m_setBuffI = 0;
59 }
60 
62 {
63 }
64 
65 void te::mem::ExpansibleBand::getValue(unsigned int c, unsigned int r, double& value) const
66 {
67  m_setGetBlkX = c / m_blkWidth;
68  m_setGetBlkY = r / m_blkHeight;
69  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
70  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
71  m_setGetBufPtr = m_blocksManager.getBlockPointer( m_idx, m_setGetBlkX,
72  m_setGetBlkY );
73  m_getBuff(m_setGetPos, m_setGetBufPtr, &value );
74 }
75 
76 void te::mem::ExpansibleBand::setValue(unsigned int c, unsigned int r, const double value)
77 {
78  m_setGetBlkX = c / m_blkWidth;
79  m_setGetBlkY = r / m_blkHeight;
80  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
81  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
82  m_setGetBufPtr = m_blocksManager.getBlockPointer( m_idx, m_setGetBlkX,
83  m_setGetBlkY );
84  m_setBuff(m_setGetPos, m_setGetBufPtr, &value );
85 }
86 
87 void te::mem::ExpansibleBand::getIValue(unsigned int c, unsigned int r, double& value) const
88 {
89  m_setGetBlkX = c / m_blkWidth;
90  m_setGetBlkY = r / m_blkHeight;
91  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
92  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
93  m_setGetBufPtr = m_blocksManager.getBlockPointer( m_idx, m_setGetBlkX,
94  m_setGetBlkY );
95  m_getBuffI(m_setGetPos, m_setGetBufPtr, &value );
96 }
97 
98 void te::mem::ExpansibleBand::setIValue(unsigned int c, unsigned int r, const double value)
99 {
100  m_setGetBlkX = c / m_blkWidth;
101  m_setGetBlkY = r / m_blkHeight;
102  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
103  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
104  m_setGetBufPtr = m_blocksManager.getBlockPointer( m_idx, m_setGetBlkX,
105  m_setGetBlkY );
106  m_setBuffI(m_setGetPos, m_setGetBufPtr, &value );
107 }
108 
109 void te::mem::ExpansibleBand::read(int x, int y, void* buffer) const
110 {
111  assert( m_blocksManager.isInitialized() );
112  memcpy( buffer, m_blocksManager.getBlockPointer( m_idx, x, y ),
113  m_blkSizeBytes );
114 }
115 
116 void te::mem::ExpansibleBand::write(int x, int y, void* buffer)
117 {
118  assert( m_blocksManager.isInitialized() );
119  memcpy( m_blocksManager.getBlockPointer( m_idx, x, y ), buffer,
120  m_blkSizeBytes );
121 }
122 
123 
124 
125 
void setIValue(unsigned int c, unsigned int r, const double value)
Sets the imaginary attribute value in a complex band of a cell.
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...
A raster band description.
Definition: BandProperty.h:61
Expansible raster band.
int m_type
The data type of the elements in the band.
Definition: BandProperty.h:133
void write(int x, int y, void *buffer)
It writes a data block from the specified buffer.
void getValue(unsigned int c, unsigned int r, double &value) const
Returns the cell attribute value.
An abstract class for raster data strucutures.
Definition: Raster.h:71
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...
RAM cached and tiled raster band blocks manager.
void getIValue(unsigned int c, unsigned int r, double &value) const
Returns the imaginary attribute value in a complex band of a cell.
void read(int x, int y, void *buffer) const
It reads a data block to the specified buffer.
TERASTEREXPORT int GetPixelSize(int datatype)
Returns the byte size of a given datatype.
Definition: Utils.cpp:80
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.
te::rst::SetBufferValueFPtr m_setBuffI
A pointer to a function that helps to insert the imaginary part value into a specific buffer data typ...
static ExpansibleBandBlocksManager dummyBlocksManager
A global static dummy blocks manager.
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
te::rst::GetBufferValueFPtr m_getBuffI
A pointer to a function that helps to extract the imaginary part value from a specific buffer data ty...
BandProperty * m_property
The band information.
Definition: Band.h:474