Loading...
Searching...
No Matches
SynchronizedBandBlocksManager.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/SynchronizedBandBlocksManager.h
22
23 \brief Synchronized raster raster band blocks manager.
24*/
25
26#ifndef __TERRALIB_RASTER_INTERNAL_SYNCHRONIZEDBANDBLOCKSMANAGER_H
27#define __TERRALIB_RASTER_INTERNAL_SYNCHRONIZEDBANDBLOCKSMANAGER_H
28
29// TerraLib
30#include "RasterSynchronizer.h"
31#include "Config.h"
32#include "../raster/Raster.h"
33
34// STL
35#include <memory>
36#include <vector>
37
38namespace te
39{
40 namespace rst
41 {
42 /*!
43 \class SynchronizedBandBlocksManager
44
45 \brief Synchronized raster raster band blocks manager.
46 */
48 {
49 public:
50
52
54
55 /*!
56 \brief Initialize this instance to an initial state.
57
58 \param sync The synchronized used by this instance.
59
60 \param maxMemPercentUsed The maximum free memory percentual to use valid range: [1:100].
61
62 \return true if OK, false on errors.
63
64 \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!
65 */
67 const unsigned char maxMemPercentUsed );
68
69 /*!
70 \brief Initialize this instance to an initial state.
71
72 \param sync The synchronized used by this instance.
73
74 \param maxNumberOfCacheBlocks The maximum number of cache blocks.
75
76 \return true if OK, false on errors.
77
78 \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!
79 */
80 bool initialize( const unsigned int maxNumberOfCacheBlocks,
81 RasterSynchronizer& sync );
82
83 /*!
84 \brief Returns true if this instance is initialized.
85
86 \return true if this instance is initialized.
87 */
88 bool isInitialized() const
89 {
90 return m_syncPtr ? true : false;
91 };
92
93 /*!
94 \note Free all allocated internal resources and go back to the initial state.
95 */
96 void free();
97
98 /*!
99 \brief Returns a pointer to the required data block.
100
101 \param band The band index.
102 \param x The block-id in x (or x-offset).
103 \param y The block-id in y (or y-offset).
104
105 \return Pointer to the required data block.
106 */
107 void* getBlockPointer(unsigned int band, unsigned int x, unsigned int y );
108
109
110 /*! \brief Returns the associated raster. */
112
113 /*! \brief The maximum number of cache blocks. */
114 unsigned int getMaxNumberOfCacheBlocks() const
115 {
116 return m_maxNumberOfCacheBlocks;
117 };
118
119 /*! \brief Return a pointer to the assotiated synchronizer instance or NULL if there is none. */
121 {
122 return m_syncPtr;
123 };
124
125 protected :
126
127 /*!
128 \class BlockIndex
129
130 \brief Internal blocks indexes.
131 */
133 {
134 public :
135
136 unsigned int m_b; //!< Block band index
137 unsigned int m_y; //!< Block index over the Y axis.
138 unsigned int m_x; //!< Block index over the X axis.
139
141 : m_b( 0 ), m_y( 0 ), m_x( 0 )
142 {
143 }
144
146 {
147 }
148 };
149
150 RasterSynchronizer* m_syncPtr; //!< A pointer to the synchronizer used by this instance, of null if not initialized.
151
152 unsigned int m_globalBlocksNumberX; //!< The maximum number of blocks (X axis) for all bands.
153
154 unsigned int m_globalBlocksNumberY; //!< The maximum number of blocks (Y axis) for all bands.
155
156 unsigned int m_globalBlockSizeBytes; //!< The maximum block size for all bands.
157
158 unsigned int m_maxNumberOfCacheBlocks; //!< The maximum number of cache blocks.
159
160 unsigned int m_blocksFifoNextSwapBlockIndex; //!< The next block swapp index over m_blocksFifo.
161
162 // variables used by internal methods
164
165 std::vector< std::vector< std::vector< unsigned char* > > > m_blocksPointers; //!< 3D Matrix of block pointers indexed as [band][blockYIndex][blockXIndex].
166
167 std::vector< unsigned char* > m_blocksHandler; //!< Cache blocks handler.
168
169 std::vector< BlockIndex > m_blocksFifo; //!< blocks swap FIFO.
170
171 private :
172
174
175 /*! \brief Initialize this instance to an initial state. */
176 void initState();
177 };
178
179 } // end namespace mem
180} // end namespace te
181
182#endif // __TERRALIB_RASTER_INTERNAL_SYNCHRONIZEDBANDBLOCKSMANAGER_H
An access synchronizer to be used in SynchronizedRaster raster instances.
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.
RasterSynchronizer * getSynchronizer() const
Return a pointer to the assotiated synchronizer instance or NULL if there is none.
unsigned int m_globalBlockSizeBytes
The maximum block size for all bands.
void * getBlockPointer(unsigned int band, unsigned int x, unsigned int y)
Returns a pointer to the required data block.
te::rst::Raster * getRaster() const
Returns the associated raster.
std::vector< unsigned char * > m_blocksHandler
Cache blocks handler.
bool isInitialized() const
Returns true if this instance is initialized.
unsigned int getMaxNumberOfCacheBlocks() const
The maximum number of cache blocks.
RasterSynchronizer * m_syncPtr
A pointer to the synchronizer used by this instance, of null if not initialized.
SynchronizedBandBlocksManager(const SynchronizedBandBlocksManager &other)
bool initialize(RasterSynchronizer &sync, const unsigned char maxMemPercentUsed)
Initialize this instance to an initial state.
unsigned int m_globalBlocksNumberX
The maximum number of blocks (X axis) for all bands.
unsigned int m_maxNumberOfCacheBlocks
The maximum number of cache blocks.
unsigned int m_globalBlocksNumberY
The maximum number of blocks (Y axis) for all bands.
std::vector< BlockIndex > m_blocksFifo
blocks swap FIFO.
unsigned int m_blocksFifoNextSwapBlockIndex
The next block swapp index over m_blocksFifo.
std::vector< std::vector< std::vector< unsigned char * > > > m_blocksPointers
3D Matrix of block pointers indexed as [band][blockYIndex][blockXIndex].
void initState()
Initialize this instance to an initial state.
bool initialize(const unsigned int maxNumberOfCacheBlocks, RasterSynchronizer &sync)
Initialize this instance to an initial state.
TerraLib.
#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).