SynchronizedRaster.h
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/SynchronizedRaster.h
22 
23  \brief An adapter class to allow concurrent access to raster data by multiple threads.
24 */
25 
26 #ifndef __TERRALIB_RASTER_INTERNAL_SYNCHRONIZEDRASTER_H
27 #define __TERRALIB_RASTER_INTERNAL_SYNCHRONIZEDRASTER_H
28 
29 // TerraLib
30 #include "Raster.h"
31 #include "RasterSynchronizer.h"
32 #include "SynchronizedBand.h"
34 #include "Config.h"
35 
36 namespace te
37 {
38  namespace rst
39  {
40  /*!
41  \class SynchronizedRaster
42 
43  \brief An adapter class to allow concurrent access to raster data by multiple threads.
44 
45  \ingroup rst
46 
47  \note One unique RasterSynchronizer must be instantiated on the main process. That RasterSynchronizer is used by each thread to instantiate multiple SynchronizedRaster instances.
48 
49  \note More efficient access can be achieved by following the bands internal blocking scheme.
50  */
52  {
53  public:
54 
55  /*!
56  \brief Constructor.
57 
58  \param sync The raster synchronizer instance.
59 
60  \param maxMemPercentUsed The maximum free memory percentual to use valid range: [1:100].
61 
62  \note For the case where using the write raster access policy: The use of multiple cached blocks can cause deadlocks if multiple threads are locking blocks needed by other threads, use it with caution!
63  */
64  SynchronizedRaster( RasterSynchronizer& sync, const unsigned char maxMemPercentUsed );
65 
66  /*!
67  \brief Constructor.
68 
69  \param sync The raster synchronizer instance.
70 
71  \param maxNumberOfCacheBlocks The maximum number of cache blocks.
72 
73  \note For the case where using the write raster access policy: The use of multiple cached blocks can cause deadlocks if multiple threads are locking blocks needed by other threads, use it with caution!
74  */
75  SynchronizedRaster( const unsigned int maxNumberOfCacheBlocks, RasterSynchronizer& sync );
76 
78 
79  std::map<std::string, std::string> getInfo() const;
80 
81  inline std::size_t getNumberOfBands() const
82  {
83  return m_bands.size();
84  };
85 
86  int getBandDataType(std::size_t i) const;
87 
88  inline const te::rst::Band* getBand(std::size_t i) const
89  {
90  assert( i < m_bands.size() );
91  return m_bands[ i ];
92  };
93 
94  inline te::rst::Band* getBand(std::size_t i)
95  {
96  assert( i < m_bands.size() );
97  return m_bands[ i ];
98  };
99 
100  inline const te::rst::Band& operator[](std::size_t i) const
101  {
102  assert( i < m_bands.size() );
103  return *(m_bands[ i ]);
104  };
105 
106  inline te::rst::Band& operator[](std::size_t i)
107  {
108  assert( i < m_bands.size() );
109  return *(m_bands[ i ]);
110  };
111 
113 
114  bool createMultiResolution( const unsigned int levels, const InterpolationMethod interpMethod )
115  {
116  return false;
117  };
118 
119  bool removeMultiResolution() { return false; };
120 
121  unsigned int getMultiResLevelsCount() const
122  {
123  return 0;
124  }
125 
126  Raster* getMultiResLevel( const unsigned int level ) const
127  {
128  return 0;
129  }
130 
131  protected:
132 
133  /*! \brief Free all allocated internal resources and go back to the initial state. */
134  void free();
135 
136  private :
137 
139 
141 
142  void open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
143 
144  protected :
145 
146  SynchronizedBandBlocksManager m_blocksManager; //!< Internal blocks manager.
147 
148  std::vector< SynchronizedBand* > m_bands; //!< Internal raster bands.
149 
150  /*!
151  \brief This instance info.
152  */
153  std::map<std::string, std::string> m_rasterInfo;
154 
155  /*!
156  \brief update This instance raster info.
157  */
159  };
160 
161  } // end namespace rst
162 } // end namespace te
163 
164 #endif //__TERRALIB_RASTER_INTERNAL_SYNCHRONIZEDRASTER_H
Raster.h
Raster implementaton for TerraLib 4.x.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rst::SynchronizedRaster::getBand
te::rst::Band * getBand(std::size_t i)
Returns the raster i-th band.
Definition: SynchronizedRaster.h:94
te::rst::SynchronizedRaster::getNumberOfBands
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
Definition: SynchronizedRaster.h:81
te::rst::Band
A raster band description.
Definition: Band.h:64
te::rst::SynchronizedRaster::free
void free()
Free all allocated internal resources and go back to the initial state.
te::rst::SynchronizedRaster::~SynchronizedRaster
~SynchronizedRaster()
te::rst::SynchronizedRaster::getBand
const te::rst::Band * getBand(std::size_t i) const
Returns the raster i-th band.
Definition: SynchronizedRaster.h:88
te::rst::SynchronizedRaster::operator[]
te::rst::Band & operator[](std::size_t i)
Access band in i position.
Definition: SynchronizedRaster.h:106
te::rst::SynchronizedRaster::getBandDataType
int getBandDataType(std::size_t i) const
Returns the data type in a particular band (or dimension).
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::common::RAccess
@ RAccess
Definition: Enums.h:43
te::rst::RasterSynchronizer
An access synchronizer to be used in SynchronizedRaster raster instances.
Definition: RasterSynchronizer.h:55
te::rst::SynchronizedRaster::operator[]
const te::rst::Band & operator[](std::size_t i) const
Access band in i position.
Definition: SynchronizedRaster.h:100
te::rst::SynchronizedRaster::SynchronizedRaster
SynchronizedRaster()
te::rst::SynchronizedRaster::getMultiResLevelsCount
unsigned int getMultiResLevelsCount() const
Returns the current number of multi-resolution pyramid levels.
Definition: SynchronizedRaster.h:121
te::rst::SynchronizedRaster::SynchronizedRaster
SynchronizedRaster(RasterSynchronizer &sync, const unsigned char maxMemPercentUsed)
Constructor.
te::rst::Grid
A rectified grid is the spatial support for raster data.
Definition: Grid.h:69
te::rst::SynchronizedRaster::open
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.
TERASTEREXPORT
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
te::rst::InterpolationMethod
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:93
SynchronizedBandBlocksManager.h
Synchronized raster raster band blocks manager.
te::rst::SynchronizedRaster::m_bands
std::vector< SynchronizedBand * > m_bands
Internal raster bands.
Definition: SynchronizedRaster.h:148
te::rst::SynchronizedRaster::removeMultiResolution
bool removeMultiResolution()
Remove/Destroy a sub-sampled multi-resolution pyramid, if there is one.
Definition: SynchronizedRaster.h:119
te::rst::SynchronizedRaster::SynchronizedRaster
SynchronizedRaster(te::rst::Grid *grid, te::common::AccessPolicy p=te::common::RAccess)
te::rst::SynchronizedRaster::getMultiResLevel
Raster * getMultiResLevel(const unsigned int level) const
Returns the required level of a multi-resolution pyramid or NULL if that level does not exists.
Definition: SynchronizedRaster.h:126
te::rst::SynchronizedRaster
An adapter class to allow concurrent access to raster data by multiple threads.
Definition: SynchronizedRaster.h:52
te::rst::SynchronizedRaster::updateRasterInfo
void updateRasterInfo()
update This instance raster info.
te::dt::AbstractData
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
te::rst::SynchronizedBandBlocksManager
Synchronized raster raster band blocks manager.
Definition: SynchronizedBandBlocksManager.h:48
te::rst::SynchronizedRaster::SynchronizedRaster
SynchronizedRaster(const unsigned int maxNumberOfCacheBlocks, RasterSynchronizer &sync)
Constructor.
te::rst::SynchronizedRaster::clone
te::dt::AbstractData * clone() const
It returns a clone of this object.
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::rst::SynchronizedRaster::createMultiResolution
bool createMultiResolution(const unsigned int levels, const InterpolationMethod interpMethod)
Create a sub-sampled multi-resolution pyramid.
Definition: SynchronizedRaster.h:114
te::rst::SynchronizedRaster::m_blocksManager
SynchronizedBandBlocksManager m_blocksManager
Internal blocks manager.
Definition: SynchronizedRaster.h:146
RasterSynchronizer.h
An access synchronizer to be used in SynchronizedRaster raster instances.
te::rst::SynchronizedRaster::getInfo
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
SynchronizedBand.h
Syncrhonized raster band.
te::rst::SynchronizedRaster::m_rasterInfo
std::map< std::string, std::string > m_rasterInfo
This instance info.
Definition: SynchronizedRaster.h:153
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41