All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CachedRaster.cpp
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/dataaccess/memory/CachedRaster.cpp
22 
23  \brief A RAM cache adaptor to an external existent raster that must always be avaliable.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "CachedBand.h"
29 #include "CachedRaster.h"
30 #include "Exception.h"
31 
33 {
34 }
35 
37 : te::rst::Raster( grid, p )
38 {
39 }
40 
42  const unsigned char maxMemPercentUsed,
43  const unsigned int dataPrefetchThreshold )
44 : te::rst::Raster( rhs )
45 {
46  if( ! m_blocksManager.initialize( rhs, maxMemPercentUsed, dataPrefetchThreshold) )
47  throw Exception(TR_MEMORY("Cannot initialize the blocks menager") );
48 
49  for( unsigned int bandsIdx = 0 ; bandsIdx < rhs.getNumberOfBands() ;
50  ++bandsIdx )
51  m_bands.push_back( new te::mem::CachedBand( m_blocksManager, bandsIdx ) );
52 }
53 
54 te::mem::CachedRaster::CachedRaster( const unsigned int maxNumberOfCacheBlocks,
55  const te::rst::Raster& rhs,
56  const unsigned int dataPrefetchThreshold )
57 : te::rst::Raster( rhs )
58 {
59  if( ! m_blocksManager.initialize( maxNumberOfCacheBlocks, rhs,
60  dataPrefetchThreshold) )
61  throw Exception(TR_MEMORY("Cannot initialize the blocks menager") );
62 
63  for( unsigned int bandsIdx = 0 ; bandsIdx < rhs.getNumberOfBands() ;
64  ++bandsIdx )
65  m_bands.push_back( new te::mem::CachedBand( m_blocksManager, bandsIdx ) );
66 }
67 
69 {
70  free();
71 }
72 
73 void te::mem::CachedRaster::open(const std::map<std::string, std::string>& /*rinfo*/,
75 {
76 }
77 
79 {
80  assert( m_blocksManager.isInitialized() );
81  return new CachedRaster( m_blocksManager.getMaxNumberOfCacheBlocks(),
82  *m_blocksManager.getRaster(), m_blocksManager.getDataPrefetchThreshold() );
83 }
84 
86 {
87  if( m_bands.size() > 0 )
88  {
89  for( unsigned int bandsIdx = 0 ; bandsIdx < m_bands.size() ; ++bandsIdx )
90  delete m_bands[ bandsIdx ];
91  m_bands.clear();
92  }
93 
94  m_blocksManager.free();
95 }
#define TR_MEMORY(message)
Definition: Config.h:82
RAM cached and tiled raster band.
An exception class for the TerraLib In-Memory Data Access driver.
RAM cached and tiled raster band.
Definition: CachedBand.h:53
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
void free()
Free all allocated internal resources and go back to the initial state.
CachedBandBlocksManager m_blocksManager
Internal blocks manager.
Definition: CachedRaster.h:140
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
A raster class for memory.
Definition: Raster.h:44
A rectified grid is the spatial support for raster data.
Definition: Grid.h:55
std::vector< CachedBand * > m_bands
Internal raster bands.
Definition: CachedRaster.h:138
bool initialize(const te::rst::Raster &externalRaster, const unsigned char maxMemPercentUsed, const unsigned int dataPrefetchThreshold)
Initialize this instance to an initial state.
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
Definition: CachedRaster.h:50
te::dt::AbstractData * clone() const
It returns a clone of this object.
An abstract class for raster data strucutures.
Definition: Raster.h:70