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 
112  te::dt::AbstractData* clone() const;
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  } // end namespace rst
152 } // end namespace te
153 
154 #endif //__TERRALIB_RASTER_INTERNAL_SYNCHRONIZEDRASTER_H
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:62
const te::rst::Band & operator[](std::size_t i) const
Access band in i position.
An adapter class to allow concurrent access to raster data by multiple threads.
te::rst::Band & operator[](std::size_t i)
Access band in i position.
SynchronizedBandBlocksManager m_blocksManager
Internal blocks manager.
te::rst::Band * getBand(std::size_t i)
Returns the raster i-th band.
bool createMultiResolution(const unsigned int levels, const InterpolationMethod interpMethod)
Create a sub-sampled multi-resolution pyramid.
An access synchronizer to be used in SynchronizedRaster raster instances.
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
bool removeMultiResolution()
Remove/Destroy a sub-sampled multi-resolution pyramid, if there is one.
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
const te::rst::Band * getBand(std::size_t i) const
Returns the raster i-th band.
Syncrhonized raster band.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
An abstract class for raster data strucutures.
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
An access synchronizer to be used in SynchronizedRaster raster instances.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
A raster band description.
Definition: Band.h:63
Synchronized raster raster band blocks manager.
Raster * getMultiResLevel(const unsigned int level) const
Returns the required level of a multi-resolution pyramid or NULL if that level does not exists...
Synchronized raster raster band blocks manager.
std::vector< SynchronizedBand * > m_bands
Internal raster bands.
unsigned int getMultiResLevelsCount() const
Returns the current number of multi-resolution pyramid levels.
Configuration flags for the Raster module of TerraLib.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68