All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CachedRaster.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/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  \details A RAM cache adaptor to an external existent raster that must always be avaliable.
49  */
51  {
52  public:
53 
54  /*!
55  \brief Constructor.
56 
57  \param rhs The external raster where the data will be read/written.
58 
59  \param maxMemPercentUsed The maximum free memory percentual to use valid range: [1:100].
60 
61  \param dataPrefetchThreshold The read-ahead data prefetch threshold (0-will disable prefetch, 1-data always prefetched, higher values will do prefetch when necessary).
62  */
63  CachedRaster( const te::rst::Raster& rhs, const unsigned char maxMemPercentUsed,
64  const unsigned int dataPrefetchThreshold );
65 
66  /*!
67  \brief Constructor.
68 
69  \param rhs The external raster where the data will be read/written.
70 
71  \param maxNumberOfCacheBlocks The maximum number of cache blocks.
72 
73  \param dataPrefetchThreshold The read-ahead data prefetch threshold (0-will disable prefetch, 1-data always prefetched, higher values will do prefetch when necessary).
74  */
75  CachedRaster( const unsigned int maxNumberOfCacheBlocks, const te::rst::Raster& rhs,
76  const unsigned int dataPrefetchThreshold );
77 
78  ~CachedRaster();
79 
80  void open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
81 
82  std::map<std::string, std::string> getInfo() const
83  {
84  assert( m_blocksManager.getRaster() );
85  return m_blocksManager.getRaster()->getInfo();
86  };
87 
88  inline std::size_t getNumberOfBands() const
89  {
90  return m_bands.size();
91  };
92 
93  inline int getBandDataType(std::size_t i) const
94  {
95  assert( m_blocksManager.getRaster() );
96  return m_blocksManager.getRaster()->getBandDataType( i );
97  };
98 
99  inline const te::rst::Band* getBand(std::size_t i) const
100  {
101  assert( i < m_bands.size() );
102  return m_bands[ i ];
103  };
104 
105  inline te::rst::Band* getBand(std::size_t i)
106  {
107  assert( i < m_bands.size() );
108  return m_bands[ i ];
109  };
110 
111  inline const te::rst::Band& operator[](std::size_t i) const
112  {
113  assert( i < m_bands.size() );
114  return *(m_bands[ i ]);
115  };
116 
117  inline te::rst::Band& operator[](std::size_t i)
118  {
119  assert( i < m_bands.size() );
120  return *(m_bands[ i ]);
121  };
122 
123  te::dt::AbstractData* clone() const;
124 
125  protected:
126 
127  /*! \brief Free all allocated internal resources and go back to the initial state. */
128  void free();
129 
130  private :
131 
132  CachedRaster();
133 
135 
136  protected :
137 
138  std::vector< CachedBand* > m_bands; //!< Internal raster bands.
139 
140  CachedBandBlocksManager m_blocksManager; //!< Internal blocks manager.
141  };
142 
143  } // end namespace mem
144 } // end namespace te
145 
146 #endif //__TERRALIB_MEMORY_INTERNAL_CACHEDRASTER_H
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
Definition: CachedRaster.h:88
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
Definition: CachedRaster.h:82
RAM cached and tiled raster band blocks manager.
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:122
Configuration flags for the TerraLib In-memory Data Access driver.
RAM cached and tiled raster band blocks manager.
RAM cached and tiled raster band.
const te::rst::Band * getBand(std::size_t i) const
Returns the raster i-th band.
Definition: CachedRaster.h:99
CachedBandBlocksManager m_blocksManager
Internal blocks manager.
Definition: CachedRaster.h:140
const te::rst::Band & operator[](std::size_t i) const
Access band in i position.
Definition: CachedRaster.h:111
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
A rectified grid is the spatial support for raster data.
Definition: Grid.h:55
A raster band description.
Definition: Band.h:63
std::vector< CachedBand * > m_bands
Internal raster bands.
Definition: CachedRaster.h:138
int getBandDataType(std::size_t i) const
Returns the data type in a particular band (or dimension).
Definition: CachedRaster.h:93
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
te::rst::Band & operator[](std::size_t i)
Access band in i position.
Definition: CachedRaster.h:117
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
Definition: CachedRaster.h:50
An abstract class for raster data strucutures.
Definition: Raster.h:70
te::rst::Band * getBand(std::size_t i)
Returns the raster i-th band.
Definition: CachedRaster.h:105