All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SynchronizedBandBlocksManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 // Boost
39 #include <boost/noncopyable.hpp>
40 
41 namespace te
42 {
43  namespace rst
44  {
45  /*!
46  \class SynchronizedBandBlocksManager
47 
48  \brief Synchronized raster raster band blocks manager.
49  */
50  class TERASTEREXPORT SynchronizedBandBlocksManager : public boost::noncopyable
51  {
52  public:
53 
55 
57 
58  /*!
59  \brief Initialize this instance to an initial state.
60 
61  \param sync The synchronized used by this instance.
62 
63  \param maxMemPercentUsed The maximum free memory percentual to use valid range: [1:100].
64 
65  \return true if OK, false on errors.
66  */
67  bool initialize( RasterSynchronizer& sync,
68  const unsigned char maxMemPercentUsed );
69 
70  /*!
71  \brief Initialize this instance to an initial state.
72 
73  \param sync The synchronized used by this instance.
74 
75  \param maxNumberOfCacheBlocks The maximum number of cache blocks.
76 
77  \return true if OK, false on errors.
78  */
79  bool initialize( const unsigned int maxNumberOfCacheBlocks,
80  RasterSynchronizer& sync );
81 
82  /*!
83  \brief Returns true if this instance is initialized.
84 
85  \return true if this instance is initialized.
86  */
87  bool isInitialized() const
88  {
89  return m_syncPtr ? true : false;
90  };
91 
92  /*!
93  \note Free all allocated internal resources and go back to the initial state.
94  */
95  void free();
96 
97  /*!
98  \brief Returns a pointer to the required data block.
99 
100  \param band The band index.
101  \param x The block-id in x (or x-offset).
102  \param y The block-id in y (or y-offset).
103 
104  \return Pointer to the required data block.
105  */
106  void* getBlockPointer(unsigned int band, unsigned int x, unsigned int y );
107 
108 
109  /*! \brief Returns the associated raster. */
110  te::rst::Raster* getRaster() const;
111 
112  /*! \brief The maximum number of cache blocks. */
113  unsigned int getMaxNumberOfCacheBlocks() const
114  {
115  return m_maxNumberOfCacheBlocks;
116  };
117 
118  /*! \brief Return a pointer to the assotiated synchronizer instance or NULL if there is none. */
120  {
121  return m_syncPtr;
122  };
123 
124  protected :
125 
126  /*!
127  \class BlockIndex
128 
129  \brief Internal blocks indexes.
130  */
132  {
133  public :
134 
135  unsigned int m_b; //!< Block band index
136  unsigned int m_y; //!< Block index over the Y axis.
137  unsigned int m_x; //!< Block index over the X axis.
138 
140  : m_b( 0 ), m_y( 0 ), m_x( 0 )
141  {
142  }
143 
145  {
146  }
147  };
148 
149  RasterSynchronizer* m_syncPtr; //!< A pointer to the synchronizer used by this instance, of null if not initialized.
150 
151  unsigned int m_globalBlocksNumberX; //!< The maximum number of blocks (X axis) for all bands.
152 
153  unsigned int m_globalBlocksNumberY; //!< The maximum number of blocks (Y axis) for all bands.
154 
155  unsigned int m_globalBlockSizeBytes; //!< The maximum block size for all bands.
156 
157  unsigned int m_maxNumberOfCacheBlocks; //!< The maximum number of cache blocks.
158 
159  unsigned int m_blocksFifoNextSwapBlockIndex; //!< The next block swapp index over m_blocksFifo.
160 
161  // variables used by internal methods
162  unsigned char* m_getBlockPointer_BlkPtr;
163 
164  std::vector< std::vector< std::vector< unsigned char* > > > m_blocksPointers; //!< 3D Matrix of block pointers indexed as [band][blockYIndex][blockXIndex].
165 
166  std::vector< unsigned char* > m_blocksHandler; //!< Cache blocks handler.
167 
168  std::vector< BlockIndex > m_blocksFifo; //!< blocks swap FIFO.
169 
170  private :
171 
172  /*! \brief Initialize this instance to an initial state. */
173  void initState();
174  };
175 
176  } // end namespace mem
177 } // end namespace te
178 
179 #endif // __TERRALIB_RASTER_INTERNAL_SYNCHRONIZEDBANDBLOCKSMANAGER_H
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
std::vector< std::vector< std::vector< unsigned char * > > > m_blocksPointers
3D Matrix of block pointers indexed as [band][blockYIndex][blockXIndex].
RasterSynchronizer * m_syncPtr
A pointer to the synchronizer used by this instance, of null if not initialized.
An access synchronizer to be used in SynchronizedRaster raster instances.
unsigned int m_blocksFifoNextSwapBlockIndex
The next block swapp index over m_blocksFifo.
std::vector< BlockIndex > m_blocksFifo
blocks swap FIFO.
std::vector< unsigned char * > m_blocksHandler
Cache blocks handler.
unsigned int m_maxNumberOfCacheBlocks
The maximum number of cache blocks.
unsigned int getMaxNumberOfCacheBlocks() const
The maximum number of cache blocks.
An abstract class for raster data strucutures.
Definition: Raster.h:71
An access synchronizer to be used in SynchronizedRaster raster instances.
Synchronized raster raster band blocks manager.
bool isInitialized() const
Returns true if this instance is initialized.
unsigned int m_globalBlockSizeBytes
The maximum block size for all bands.
RasterSynchronizer * getSynchronizer() const
Return a pointer to the assotiated synchronizer instance or NULL if there is none.
Configuration flags for the Raster module of TerraLib.
unsigned int m_globalBlocksNumberY
The maximum number of blocks (Y axis) for all bands.
unsigned int m_globalBlocksNumberX
The maximum number of blocks (X axis) for all bands.