All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CachedBand.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/CachedBand.cpp
22 
23  \brief RAM cached and tiled raster band.
24 */
25 
26 // TerraLib
27 #include "../raster/BandProperty.h"
28 #include "CachedBand.h"
29 
30 // STL
31 #include <cstring>
32 
34 
36  std::size_t idx )
37  : te::rst::Band( new te::rst::BandProperty(
38  *(blocksManager.getRaster()->getBand( idx )->getProperty()) ), idx ),
39  m_blocksManager( blocksManager )
40 {
41  m_blkHeight = blocksManager.getRaster()->getBand( idx )->getProperty()->m_blkh;
42  m_blkWidth = blocksManager.getRaster()->getBand( idx )->getProperty()->m_blkw;
43  m_blkSizeBytes = blocksManager.getRaster()->getBand( idx )->getBlockSize();
44 
46  blocksManager.getRaster()->getBand( idx )->getProperty()->getType());
47 }
48 
50  : te::rst::Band( new te::rst::BandProperty( 0, 0 ), 0 ), m_blocksManager( dummyBlocksManager )
51 {
52  m_blkWidth = 0;
53  m_blkHeight = 0;
54  m_blkSizeBytes = 0;
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::CachedBand::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::CachedBand::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::CachedBand::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::CachedBand::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::CachedBand::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::CachedBand::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 
void write(int x, int y, void *buffer)
It writes a data block from the specified buffer.
Definition: CachedBand.cpp:116
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
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: CachedBand.h:100
te::rst::Raster * getRaster() const
Returns the associated raster.
unsigned int m_blkWidth
The current band blocks width.
Definition: CachedBand.h:96
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: CachedBand.h:102
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: CachedBand.h:101
RAM cached and tiled raster band.
BandProperty * getProperty()
Returns the band property.
Definition: Band.cpp:428
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
unsigned int m_blkSizeBytes
The blocks size (bytes);.
Definition: CachedBand.h:98
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: CachedBand.h:103
void setValue(unsigned int c, unsigned int r, const double value)
Sets the cell attribute value.
Definition: CachedBand.cpp:76
Band implementation for the In-Memory Raster.
Definition: Band.h:46
void setIValue(unsigned int c, unsigned int r, const double value)
Sets the imaginary attribute value in a complex band of a cell.
Definition: CachedBand.cpp:98
static CachedBandBlocksManager dummyBlocksManager
A global static dummy blocks manager.
Definition: CachedBand.h:113
unsigned int m_blkHeight
The current band blocks height.
Definition: CachedBand.h:97
void read(int x, int y, void *buffer) const
It reads a data block to the specified buffer.
Definition: CachedBand.cpp:109
void getValue(unsigned int c, unsigned int r, double &value) const
Returns the cell attribute value.
Definition: CachedBand.cpp:65
int getType() const
It returns the data type of the elements in the band.
Definition: BandProperty.h:113
int m_blkh
Block height (pixels).
Definition: BandProperty.h:144
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.
Definition: CachedBand.cpp:87
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