SynchronizedBand.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/raster/SynchronizedBand.cpp
22 
23  \brief Syncrhonized raster band.
24 */
25 
26 // TerraLib
27 #include "../raster/BandProperty.h"
28 #include "SynchronizedBand.h"
29 
30 // STL
31 #include <cstring>
32 
33 // initiating the dummy blocks manager
35 
37  SynchronizedRaster& raster, std::size_t idx )
38  : te::rst::Band( new te::rst::BandProperty( 0, 0 ), idx ),
39  m_blocksManager( blocksManager )
40 {
41  blocksManager.getSynchronizer()->m_mutex.lock();
42 
43  m_syncRasterPtr = &raster;
44 
46  *(blocksManager.getRaster()->getBand( idx )->getProperty()) );
47 
48  m_blkHeight = blocksManager.getRaster()->getBand( idx )->getProperty()->m_blkh;
49  m_blkWidth = blocksManager.getRaster()->getBand( idx )->getProperty()->m_blkw;
50  m_blkSizeBytes = blocksManager.getRaster()->getBand( idx )->getBlockSize();
51 
53  blocksManager.getRaster()->getBand( idx )->getProperty()->getType());
54 
55  blocksManager.getSynchronizer()->m_mutex.unlock();
56 }
57 
59  : te::rst::Band( new te::rst::BandProperty( 0, 0 ), 0 ),
61 {
62  m_syncRasterPtr = nullptr;
63  m_blkWidth = 0;
64  m_blkHeight = 0;
65  m_blkSizeBytes = 0;
66  m_getBuff = nullptr;
67  m_getBuffI = nullptr;
68  m_setBuff = nullptr;
69  m_setBuffI = nullptr;
70 }
71 
73 
74 void te::rst::SynchronizedBand::getValue(unsigned int c, unsigned int r, double& value) const
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::rst::SynchronizedBand::setValue(unsigned int c, unsigned int r, const double value)
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::rst::SynchronizedBand::getIValue(unsigned int c, unsigned int r, double& value) const
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::rst::SynchronizedBand::setIValue(unsigned int c, unsigned int r, const double value)
108 {
109  m_setGetBlkX = c / m_blkWidth;
111  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
112  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
113  m_setGetBufPtr = m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), m_setGetBlkX,
114  m_setGetBlkY );
116 }
117 
118 void te::rst::SynchronizedBand::read(int x, int y, void* buffer) const
119 {
120  assert( m_blocksManager.isInitialized() );
121  memcpy(buffer, m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), x, y),
122  m_blkSizeBytes );
123 }
124 
126 {
127  assert( m_blocksManager.isInitialized() );
128  return m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), x, y);
129 }
130 
131 void te::rst::SynchronizedBand::write(int x, int y, void* buffer)
132 {
133  assert( m_blocksManager.isInitialized() );
134  memcpy(m_blocksManager.getBlockPointer(static_cast<unsigned int>(m_idx), x, y), buffer,
135  m_blkSizeBytes );
136 }
137 
138 
An adapter class to allow concurrent access to raster data by multiple threads.
A raster band description.
Definition: BandProperty.h:61
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...
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...
te::rst::SetBufferValueFPtr m_setBuffI
A pointer to a function that helps to insert the imaginary part value into a specific buffer data typ...
te::rst::GetBufferValueFPtr m_getBuffI
A pointer to a function that helps to extract the imaginary part value from a specific buffer data ty...
unsigned int m_blkHeight
The current band blocks height.
void read(int x, int y, void *buffer) const
It reads a data block to the specified buffer.
boost::mutex m_mutex
General sync mutex;.
void write(int x, int y, void *buffer)
It writes a data block from the specified buffer.
Syncrhonized raster band.
unsigned int m_blkWidth
The current band blocks width.
void getValue(unsigned int c, unsigned int r, double &value) const
Returns the cell attribute value.
static SynchronizedBandBlocksManager dummyBlocksManager
A global static dummy blocks manager.
void setValue(unsigned int c, unsigned int r, const double value)
Sets the cell attribute value.
BandProperty * getProperty()
Returns the band property.
URI C++ Library.
Definition: Attributes.h:37
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
te::rst::Raster * getRaster() const
Returns the associated raster.
A raster band description.
Synchronized raster raster band blocks manager.
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);.
SynchronizedRaster * m_syncRasterPtr
The synchronized raster instance (parent raster).
RasterSynchronizer * getSynchronizer() const
Return a pointer to the assotiated synchronizer instance or NULL if there is none.
void setIValue(unsigned int c, unsigned int r, const double value)
Sets the imaginary attribute value in a complex band of a cell.
std::size_t m_idx
The band index.
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
void getIValue(unsigned int c, unsigned int r, double &value) const
Returns the imaginary attribute value in a complex band of a cell.
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
void * getBlockPointer(unsigned int band, unsigned int x, unsigned int y)
Returns a pointer to the required 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
SynchronizedBandBlocksManager & m_blocksManager
The external blocks manager.
BandProperty * m_property
The band information.