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 
80  ~CachedRaster();
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  assert( m_blocksManager.getRaster() );
87  return m_blocksManager.getRaster()->getInfo();
88  };
89 
90  inline std::size_t getNumberOfBands() const
91  {
92  return m_bands.size();
93  };
94 
95  inline int getBandDataType(std::size_t i) const
96  {
97  assert( m_blocksManager.getRaster() );
98  return m_blocksManager.getRaster()->getBandDataType( i );
99  };
100 
101  inline const te::rst::Band* getBand(std::size_t i) const
102  {
103  assert( i < m_bands.size() );
104  return m_bands[ i ];
105  };
106 
107  inline te::rst::Band* getBand(std::size_t i)
108  {
109  assert( i < m_bands.size() );
110  return m_bands[ i ];
111  };
112 
113  inline const te::rst::Band& operator[](std::size_t i) const
114  {
115  assert( i < m_bands.size() );
116  return *(m_bands[ i ]);
117  };
118 
119  inline te::rst::Band& operator[](std::size_t i)
120  {
121  assert( i < m_bands.size() );
122  return *(m_bands[ i ]);
123  };
124 
125  te::dt::AbstractData* clone() const;
126 
127  bool createMultiResolution( const unsigned int levels, const te::rst::InterpolationMethod interpMethod )
128  {
129  return false;
130  };
131 
132  bool removeMultiResolution() { return false; };
133 
134  unsigned int getMultiResLevelsCount() const
135  {
136  return 0;
137  }
138 
139  te::rst::Raster* getMultiResLevel( const unsigned int level ) const
140  {
141  return 0;
142  }
143 
144  protected:
145 
146  /*! \brief Free all allocated internal resources and go back to the initial state. */
147  void free();
148 
149  private :
150 
151  CachedRaster();
152 
154 
155  protected :
156 
157  std::vector< CachedBand* > m_bands; //!< Internal raster bands.
158 
159  CachedBandBlocksManager m_blocksManager; //!< Internal blocks manager.
160  };
161 
162  } // end namespace mem
163 } // end namespace te
164 
165 #endif //__TERRALIB_MEMORY_INTERNAL_CACHEDRASTER_H
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
int getBandDataType(std::size_t i) const
Returns the data type in a particular band (or dimension).
Definition: CachedRaster.h:95
const te::rst::Band * getBand(std::size_t i) const
Returns the raster i-th band.
Definition: CachedRaster.h:101
te::rst::Band * getBand(std::size_t i)
Returns the raster i-th band.
Definition: CachedRaster.h:107
Configuration flags for the TerraLib In-memory Data Access driver.
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
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:139
te::rst::Band & operator[](std::size_t i)
Access band in i position.
Definition: CachedRaster.h:119
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
Definition: CachedRaster.h:84
RAM cached and tiled raster band blocks manager.
RAM cached and tiled raster band.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
Definition: CachedRaster.h:52
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
A raster band description.
Definition: Band.h:63
const te::rst::Band & operator[](std::size_t i) const
Access band in i position.
Definition: CachedRaster.h:113
bool createMultiResolution(const unsigned int levels, const te::rst::InterpolationMethod interpMethod)
Create a sub-sampled multi-resolution pyramid.
Definition: CachedRaster.h:127
unsigned int getMultiResLevelsCount() const
Returns the current number of multi-resolution pyramid levels.
Definition: CachedRaster.h:134
std::vector< CachedBand * > m_bands
Internal raster bands.
Definition: CachedRaster.h:157
RAM cached and tiled raster band blocks manager.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
bool removeMultiResolution()
Remove/Destroy a sub-sampled multi-resolution pyramid, if there is one.
Definition: CachedRaster.h:132
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
Definition: CachedRaster.h:90
CachedBandBlocksManager m_blocksManager
Internal blocks manager.
Definition: CachedRaster.h:159