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 
38 namespace 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
163  unsigned char* m_getBlockPointer_BlkPtr;
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
te::rst::SynchronizedBandBlocksManager::getSynchronizer
RasterSynchronizer * getSynchronizer() const
Return a pointer to the assotiated synchronizer instance or NULL if there is none.
Definition: SynchronizedBandBlocksManager.h:120
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rst::SynchronizedBandBlocksManager::SynchronizedBandBlocksManager
SynchronizedBandBlocksManager(const SynchronizedBandBlocksManager &other)
Definition: SynchronizedBandBlocksManager.h:173
te::rst::SynchronizedBandBlocksManager::m_blocksFifo
std::vector< BlockIndex > m_blocksFifo
blocks swap FIFO.
Definition: SynchronizedBandBlocksManager.h:169
te::rst::SynchronizedBandBlocksManager::free
void free()
te::rst::SynchronizedBandBlocksManager::getMaxNumberOfCacheBlocks
unsigned int getMaxNumberOfCacheBlocks() const
The maximum number of cache blocks.
Definition: SynchronizedBandBlocksManager.h:114
te::rst::SynchronizedBandBlocksManager::m_globalBlocksNumberY
unsigned int m_globalBlocksNumberY
The maximum number of blocks (Y axis) for all bands.
Definition: SynchronizedBandBlocksManager.h:154
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::rst::RasterSynchronizer
An access synchronizer to be used in SynchronizedRaster raster instances.
Definition: RasterSynchronizer.h:55
te::rst::SynchronizedBandBlocksManager::BlockIndex::BlockIndex
BlockIndex()
Definition: SynchronizedBandBlocksManager.h:140
te::rst::SynchronizedBandBlocksManager::getBlockPointer
void * getBlockPointer(unsigned int band, unsigned int x, unsigned int y)
Returns a pointer to the required data block.
te::rst::SynchronizedBandBlocksManager::m_blocksPointers
std::vector< std::vector< std::vector< unsigned char * > > > m_blocksPointers
3D Matrix of block pointers indexed as [band][blockYIndex][blockXIndex].
Definition: SynchronizedBandBlocksManager.h:165
te::rst::SynchronizedBandBlocksManager::BlockIndex::m_y
unsigned int m_y
Block index over the Y axis.
Definition: SynchronizedBandBlocksManager.h:137
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::SynchronizedBandBlocksManager::m_syncPtr
RasterSynchronizer * m_syncPtr
A pointer to the synchronizer used by this instance, of null if not initialized.
Definition: SynchronizedBandBlocksManager.h:150
te::rst::SynchronizedBandBlocksManager::m_blocksFifoNextSwapBlockIndex
unsigned int m_blocksFifoNextSwapBlockIndex
The next block swapp index over m_blocksFifo.
Definition: SynchronizedBandBlocksManager.h:160
te::rst::SynchronizedBandBlocksManager::BlockIndex::m_b
unsigned int m_b
Block band index.
Definition: SynchronizedBandBlocksManager.h:136
te::rst::SynchronizedBandBlocksManager::initialize
bool initialize(const unsigned int maxNumberOfCacheBlocks, RasterSynchronizer &sync)
Initialize this instance to an initial state.
te::rst::SynchronizedBandBlocksManager::getRaster
te::rst::Raster * getRaster() const
Returns the associated raster.
te::rst::SynchronizedBandBlocksManager::m_globalBlocksNumberX
unsigned int m_globalBlocksNumberX
The maximum number of blocks (X axis) for all bands.
Definition: SynchronizedBandBlocksManager.h:152
te::rst::SynchronizedBandBlocksManager::m_getBlockPointer_BlkPtr
unsigned char * m_getBlockPointer_BlkPtr
Definition: SynchronizedBandBlocksManager.h:163
te::rst::SynchronizedBandBlocksManager::SynchronizedBandBlocksManager
SynchronizedBandBlocksManager()
te::rst::SynchronizedBandBlocksManager::isInitialized
bool isInitialized() const
Returns true if this instance is initialized.
Definition: SynchronizedBandBlocksManager.h:88
te::rst::SynchronizedBandBlocksManager::BlockIndex::~BlockIndex
~BlockIndex()
Definition: SynchronizedBandBlocksManager.h:145
te::rst::SynchronizedBandBlocksManager::m_globalBlockSizeBytes
unsigned int m_globalBlockSizeBytes
The maximum block size for all bands.
Definition: SynchronizedBandBlocksManager.h:156
te::rst::SynchronizedBandBlocksManager::m_maxNumberOfCacheBlocks
unsigned int m_maxNumberOfCacheBlocks
The maximum number of cache blocks.
Definition: SynchronizedBandBlocksManager.h:158
te::rst::SynchronizedBandBlocksManager::initialize
bool initialize(RasterSynchronizer &sync, const unsigned char maxMemPercentUsed)
Initialize this instance to an initial state.
te::rst::SynchronizedBandBlocksManager
Synchronized raster raster band blocks manager.
Definition: SynchronizedBandBlocksManager.h:48
te::rst::SynchronizedBandBlocksManager::m_blocksHandler
std::vector< unsigned char * > m_blocksHandler
Cache blocks handler.
Definition: SynchronizedBandBlocksManager.h:167
te::rst::SynchronizedBandBlocksManager::BlockIndex::m_x
unsigned int m_x
Block index over the X axis.
Definition: SynchronizedBandBlocksManager.h:138
te::rst::SynchronizedBandBlocksManager::BlockIndex
Internal blocks indexes.
Definition: SynchronizedBandBlocksManager.h:133
te::rst::SynchronizedBandBlocksManager::~SynchronizedBandBlocksManager
~SynchronizedBandBlocksManager()
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
RasterSynchronizer.h
An access synchronizer to be used in SynchronizedRaster raster instances.
te::rst::SynchronizedBandBlocksManager::initState
void initState()
Initialize this instance to an initial state.