Loading...
Searching...
No Matches
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
36namespace 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
An access synchronizer to be used in SynchronizedRaster raster instances.
Synchronized raster raster band blocks manager.
Syncrhonized raster band.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
A raster band description.
Definition: Band.h:64
A rectified grid is the spatial support for raster data.
Definition: Grid.h:69
An access synchronizer to be used in SynchronizedRaster raster instances.
An abstract class for raster data strucutures.
Definition: Raster.h:72
Synchronized raster raster band blocks manager.
An adapter class to allow concurrent access to raster data by multiple threads.
const te::rst::Band & operator[](std::size_t i) const
Access band in i position.
SynchronizedRaster(RasterSynchronizer &sync, const unsigned char maxMemPercentUsed)
Constructor.
void free()
Free all allocated internal resources and go back to the initial state.
bool removeMultiResolution()
Remove/Destroy a sub-sampled multi-resolution pyramid, if there is one.
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
const te::rst::Band * getBand(std::size_t i) const
Returns the raster i-th band.
SynchronizedRaster(te::rst::Grid *grid, te::common::AccessPolicy p=te::common::RAccess)
unsigned int getMultiResLevelsCount() const
Returns the current number of multi-resolution pyramid levels.
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
te::dt::AbstractData * clone() const
It returns a clone of this object.
std::map< std::string, std::string > m_rasterInfo
This instance info.
te::rst::Band * getBand(std::size_t i)
Returns the raster i-th band.
te::rst::Band & operator[](std::size_t i)
Access band in i position.
Raster * getMultiResLevel(const unsigned int level) const
Returns the required level of a multi-resolution pyramid or NULL if that level does not exists.
SynchronizedRaster(const unsigned int maxNumberOfCacheBlocks, RasterSynchronizer &sync)
Constructor.
bool createMultiResolution(const unsigned int levels, const InterpolationMethod interpMethod)
Create a sub-sampled multi-resolution pyramid.
void updateRasterInfo()
update This instance raster info.
std::vector< SynchronizedBand * > m_bands
Internal raster bands.
int getBandDataType(std::size_t i) const
Returns the data type in a particular band (or dimension).
SynchronizedBandBlocksManager m_blocksManager
Internal blocks manager.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
@ RAccess
Definition: Enums.h:43
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:93
TerraLib.
Raster implementaton for TerraLib 4.x.
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
Proxy configuration file for TerraView (see terraview_config.h).