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 ),
54 {
55  m_getBuff = nullptr;
56  m_getBuffI = nullptr;
57  m_setBuff = nullptr;
58  m_setBuffI = nullptr;
59 }
60 
62 
63 void te::mem::ExpansibleBand::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::ExpansibleBand::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::ExpansibleBand::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::ExpansibleBand::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::ExpansibleBand::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::ExpansibleBand::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 
122 
123 
unsigned int m_blkHeight
Block width in pixels (for pixel access optimization purposes).
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.
void * getBlockPointer(unsigned int band, unsigned int x, unsigned int y)
Returns a pointer to the required data block.
int m_type
The data type of the elements in the band ( See te::dt namespace basic data types for reference )...
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.
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.
URI C++ Library.
Definition: Attributes.h:37
ExpansibleBandBlocksManager & m_blocksManager
The external blocks manager reference.
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.
bool isInitialized() const
Returns true if this instance is initialized.
TERASTEREXPORT int GetPixelSize(int datatype)
Returns the byte size of a given datatype.
unsigned int m_blkWidth
Block width in pixels(for pixel access optimization purposes).
Band implementation for the In-Memory Raster.
unsigned int m_blkSizeBytes
Blosk size bytes (for pixel access optimization purposes).
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...
std::size_t m_idx
The band index.
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.