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 = nullptr;
56  m_getBuffI = nullptr;
57  m_setBuff = nullptr;
58  m_setBuffI = nullptr;
59 }
60 
62 
63 void te::mem::CachedBand::getValue(unsigned int c, unsigned int r, double& value) const
64 {
67  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
68  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
69  m_setGetBufPtr = m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), m_setGetBlkX,
70  m_setGetBlkY );
72 }
73 
74 void te::mem::CachedBand::setValue(unsigned int c, unsigned int r, const double value)
75 {
78  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
79  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
80  m_setGetBufPtr = m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), m_setGetBlkX,
81  m_setGetBlkY );
83 }
84 
85 void te::mem::CachedBand::getIValue(unsigned int c, unsigned int r, double& value) const
86 {
89  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
90  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
91  m_setGetBufPtr = m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), m_setGetBlkX,
92  m_setGetBlkY );
94 }
95 
96 void te::mem::CachedBand::setIValue(unsigned int c, unsigned int r, const double value)
97 {
100  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
101  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
102  m_setGetBufPtr = m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), m_setGetBlkX,
103  m_setGetBlkY );
105 }
106 
107 void te::mem::CachedBand::read(int x, int y, void* buffer) const
108 {
109  assert( m_blocksManager.isInitialized() );
110  memcpy(buffer, m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), x, y),
111  m_blkSizeBytes );
112 }
113 
114 void te::mem::CachedBand::write(int x, int y, void* buffer)
115 {
116  assert( m_blocksManager.isInitialized() );
117  memcpy(m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), x, y), buffer,
118  m_blkSizeBytes );
119 }
120 
121 
void * getBlockPointer(unsigned int band, unsigned int x, unsigned int y)
Returns a pointer to the required data block.
void write(int x, int y, void *buffer)
It writes a data block from the specified buffer.
Definition: CachedBand.cpp:114
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:101
te::rst::Raster * getRaster() const
Returns the associated raster.
unsigned int m_blkWidth
The current band blocks width.
Definition: CachedBand.h:97
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:103
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:102
RAM cached and tiled raster band.
BandProperty * getProperty()
Returns the band property.
URI C++ Library.
Definition: Attributes.h:37
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
unsigned int m_setGetPos
Definition: CachedBand.h:109
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
bool isInitialized() const
Returns true if this instance is initialized.
unsigned int m_blkSizeBytes
The blocks size (bytes);.
Definition: CachedBand.h:99
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:104
void setValue(unsigned int c, unsigned int r, const double value)
Sets the cell attribute value.
Definition: CachedBand.cpp:74
Band implementation for the In-Memory Raster.
CachedBandBlocksManager & m_blocksManager
The external blocks manager reference.
Definition: CachedBand.h:112
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:96
std::size_t m_idx
The band index.
static CachedBandBlocksManager dummyBlocksManager
A global static dummy blocks manager.
Definition: CachedBand.h:114
unsigned int m_blkHeight
The current band blocks height.
Definition: CachedBand.h:98
void read(int x, int y, void *buffer) const
It reads a data block to the specified buffer.
Definition: CachedBand.cpp:107
void getValue(unsigned int c, unsigned int r, double &value) const
Returns the cell attribute value.
Definition: CachedBand.cpp:63
int getType() const
It returns the data type of the elements in the band.
Definition: BandProperty.h:113
unsigned int m_setGetBlkY
Definition: CachedBand.h:108
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:85
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
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
unsigned int m_setGetBlkX
Definition: CachedBand.h:107