All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ),
60  m_blocksManager( dummyBlocksManager )
61 {
62  m_syncRasterPtr = 0;
63  m_blkWidth = 0;
64  m_blkHeight = 0;
65  m_blkSizeBytes = 0;
66  m_getBuff = 0;
67  m_getBuffI = 0;
68  m_setBuff = 0;
69  m_setBuffI = 0;
70 }
71 
73 {
74 }
75 
76 void te::rst::SynchronizedBand::getValue(unsigned int c, unsigned int r, double& value) const
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_getBuff(m_setGetPos, m_setGetBufPtr, &value );
85 }
86 
87 void te::rst::SynchronizedBand::setValue(unsigned int c, unsigned int r, const double value)
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_setBuff(m_setGetPos, m_setGetBufPtr, &value );
96 }
97 
98 void te::rst::SynchronizedBand::getIValue(unsigned int c, unsigned int r, double& value) const
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_getBuffI(m_setGetPos, m_setGetBufPtr, &value );
107 }
108 
109 void te::rst::SynchronizedBand::setIValue(unsigned int c, unsigned int r, const double value)
110 {
111  m_setGetBlkX = c / m_blkWidth;
112  m_setGetBlkY = r / m_blkHeight;
113  m_setGetPos = c % m_blkWidth + ((r % m_blkHeight) * m_blkWidth);
114  assert(m_setGetPos < ( m_blkWidth * m_blkHeight ) );
115  m_setGetBufPtr = m_blocksManager.getBlockPointer( m_idx, m_setGetBlkX,
116  m_setGetBlkY );
117  m_setBuffI(m_setGetPos, m_setGetBufPtr, &value );
118 }
119 
120 void te::rst::SynchronizedBand::read(int x, int y, void* buffer) const
121 {
122  assert( m_blocksManager.isInitialized() );
123  memcpy( buffer, m_blocksManager.getBlockPointer( m_idx, x, y ),
124  m_blkSizeBytes );
125 }
126 
128 {
129  assert( m_blocksManager.isInitialized() );
130  return m_blocksManager.getBlockPointer( m_idx, x, y );
131 }
132 
133 void te::rst::SynchronizedBand::write(int x, int y, void* buffer)
134 {
135  assert( m_blocksManager.isInitialized() );
136  memcpy( m_blocksManager.getBlockPointer( m_idx, x, y ), buffer,
137  m_blkSizeBytes );
138 }
139 
140 
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...
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...
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.
Definition: Band.cpp:428
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
te::rst::Raster * getRaster() const
Returns the associated raster.
A raster band description.
Definition: Band.h:63
Synchronized raster raster band blocks manager.
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.
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.
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
BandProperty * m_property
The band information.
Definition: Band.h:474