CachedRaster.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/memory/CachedRaster.h
22 
23  \brief A RAM cache adaptor to an external existent raster that must always be avaliable.
24 */
25 
26 #ifndef __TERRALIB_MEMORY_INTERNAL_CACHEDRASTER_H
27 #define __TERRALIB_MEMORY_INTERNAL_CACHEDRASTER_H
28 
29 // TerraLib
30 #include "../raster/Raster.h"
31 #include "CachedBand.h"
33 #include "Config.h"
34 
35 // STL
36 #include <cassert>
37 #include <vector>
38 
39 namespace te
40 {
41  namespace mem
42  {
43  /*!
44  \class CachedRaster
45 
46  \brief A RAM cache adaptor to an external existent raster that must always be avaliable.
47 
48  \ingroup mem
49 
50  \details A RAM cache adaptor to an external existent raster that must always be avaliable.
51  */
53  {
54  public:
55 
56  /*!
57  \brief Constructor.
58 
59  \param rhs The external raster where the data will be read/written.
60 
61  \param maxMemPercentUsed The maximum free memory percentual to use valid range: [1:100].
62 
63  \param dataPrefetchThreshold The read-ahead data prefetch threshold (0-will disable prefetch, 1-data always prefetched, higher values will do prefetch when necessary).
64  */
65  CachedRaster( const te::rst::Raster& rhs, const unsigned char maxMemPercentUsed,
66  const unsigned int dataPrefetchThreshold );
67 
68  /*!
69  \brief Constructor.
70 
71  \param rhs The external raster where the data will be read/written.
72 
73  \param maxNumberOfCacheBlocks The maximum number of cache blocks.
74 
75  \param dataPrefetchThreshold The read-ahead data prefetch threshold (0-will disable prefetch, 1-data always prefetched, higher values will do prefetch when necessary).
76  */
77  CachedRaster( const unsigned int maxNumberOfCacheBlocks, const te::rst::Raster& rhs,
78  const unsigned int dataPrefetchThreshold );
79 
81 
82  void open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
83 
84  std::map<std::string, std::string> getInfo() const;
85 
86  inline std::size_t getNumberOfBands() const
87  {
88  return m_bands.size();
89  };
90 
91  inline int getBandDataType(std::size_t i) const
92  {
93  assert( m_blocksManager.getRaster() );
94  return m_blocksManager.getRaster()->getBandDataType( i );
95  };
96 
97  inline const te::rst::Band* getBand(std::size_t i) const
98  {
99  assert( i < m_bands.size() );
100  return m_bands[ i ];
101  };
102 
103  inline te::rst::Band* getBand(std::size_t i)
104  {
105  assert( i < m_bands.size() );
106  return m_bands[ i ];
107  };
108 
109  inline const te::rst::Band& operator[](std::size_t i) const
110  {
111  assert( i < m_bands.size() );
112  return *(m_bands[ i ]);
113  };
114 
115  inline te::rst::Band& operator[](std::size_t i)
116  {
117  assert( i < m_bands.size() );
118  return *(m_bands[ i ]);
119  };
120 
122 
123  bool createMultiResolution( const unsigned int levels, const te::rst::InterpolationMethod interpMethod )
124  {
125  return false;
126  };
127 
128  bool removeMultiResolution() { return false; };
129 
130  unsigned int getMultiResLevelsCount() const
131  {
132  return 0;
133  }
134 
135  te::rst::Raster* getMultiResLevel( const unsigned int level ) const
136  {
137  return 0;
138  }
139 
140  protected:
141 
142  /*! \brief Free all allocated internal resources and go back to the initial state. */
143  void free();
144 
145  private :
146 
148 
150 
151  protected :
152 
153  std::vector< CachedBand* > m_bands; //!< Internal raster bands.
154 
155  CachedBandBlocksManager m_blocksManager; //!< Internal blocks manager.
156 
157  /*!
158  \brief This instance info.
159  */
160  std::map<std::string, std::string> m_rasterInfo;
161 
162  /*!
163  \brief update This instance raster info.
164  */
166  };
167 
168  } // end namespace mem
169 } // end namespace te
170 
171 #endif //__TERRALIB_MEMORY_INTERNAL_CACHEDRASTER_H
te::mem::CachedRaster::free
void free()
Free all allocated internal resources and go back to the initial state.
te::mem::CachedRaster::operator[]
const te::rst::Band & operator[](std::size_t i) const
Access band in i position.
Definition: CachedRaster.h:109
te::mem::CachedRaster::createMultiResolution
bool createMultiResolution(const unsigned int levels, const te::rst::InterpolationMethod interpMethod)
Create a sub-sampled multi-resolution pyramid.
Definition: CachedRaster.h:123
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rst::Band
A raster band description.
Definition: Band.h:64
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::common::RAccess
@ RAccess
Definition: Enums.h:43
te::mem::CachedRaster::getMultiResLevelsCount
unsigned int getMultiResLevelsCount() const
Returns the current number of multi-resolution pyramid levels.
Definition: CachedRaster.h:130
te::mem::CachedRaster
A RAM cache adaptor to an external existent raster that must always be avaliable.
Definition: CachedRaster.h:53
te::mem::CachedRaster::m_blocksManager
CachedBandBlocksManager m_blocksManager
Internal blocks manager.
Definition: CachedRaster.h:155
te::mem::CachedRaster::getBand
const te::rst::Band * getBand(std::size_t i) const
Returns the raster i-th band.
Definition: CachedRaster.h:97
te::mem::CachedRaster::CachedRaster
CachedRaster(const te::rst::Raster &rhs, const unsigned char maxMemPercentUsed, const unsigned int dataPrefetchThreshold)
Constructor.
te::mem::CachedRaster::getBandDataType
int getBandDataType(std::size_t i) const
Returns the data type in a particular band (or dimension).
Definition: CachedRaster.h:91
te::mem::CachedRaster::open
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.
te::mem::CachedRaster::m_bands
std::vector< CachedBand * > m_bands
Internal raster bands.
Definition: CachedRaster.h:153
te::mem::CachedRaster::getNumberOfBands
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
Definition: CachedRaster.h:86
te::mem::CachedRaster::CachedRaster
CachedRaster()
te::rst::Grid
A rectified grid is the spatial support for raster data.
Definition: Grid.h:69
te::rst::InterpolationMethod
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:93
CachedBandBlocksManager.h
RAM cached and tiled raster band blocks manager.
te::mem::CachedRaster::removeMultiResolution
bool removeMultiResolution()
Remove/Destroy a sub-sampled multi-resolution pyramid, if there is one.
Definition: CachedRaster.h:128
te::mem::CachedRaster::updateRasterInfo
void updateRasterInfo()
update This instance raster info.
te::mem::CachedRaster::operator[]
te::rst::Band & operator[](std::size_t i)
Access band in i position.
Definition: CachedRaster.h:115
te::mem::CachedRaster::CachedRaster
CachedRaster(te::rst::Grid *grid, te::common::AccessPolicy p=te::common::RAccess)
te::mem::CachedBandBlocksManager
RAM cached and tiled raster band blocks manager.
Definition: CachedBandBlocksManager.h:52
te::mem::CachedRaster::getBand
te::rst::Band * getBand(std::size_t i)
Returns the raster i-th band.
Definition: CachedRaster.h:103
te::mem::CachedRaster::~CachedRaster
~CachedRaster()
te::mem::CachedRaster::getMultiResLevel
te::rst::Raster * getMultiResLevel(const unsigned int level) const
Returns the required level of a multi-resolution pyramid or NULL if that level does not exists.
Definition: CachedRaster.h:135
te::dt::AbstractData
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
TEMEMORYEXPORT
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
te::mem::CachedRaster::getInfo
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::mem::CachedRaster::clone
te::dt::AbstractData * clone() const
It returns a clone of this object.
CachedBand.h
RAM cached and tiled raster band.
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
te::mem::CachedRaster::CachedRaster
CachedRaster(const unsigned int maxNumberOfCacheBlocks, const te::rst::Raster &rhs, const unsigned int dataPrefetchThreshold)
Constructor.
te::mem::CachedRaster::m_rasterInfo
std::map< std::string, std::string > m_rasterInfo
This instance info.
Definition: CachedRaster.h:160