All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CachedRaster.cpp
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/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 #include "../raster/Grid.h"
32 
34 {
35 }
36 
38 : te::rst::Raster( grid, p )
39 {
40 }
41 
43  const unsigned char maxMemPercentUsed,
44  const unsigned int dataPrefetchThreshold )
45 : te::rst::Raster( new te::rst::Grid( *rhs.getGrid() ), rhs.getAccessPolicy() )
46 {
47  if( ! m_blocksManager.initialize( rhs, maxMemPercentUsed, dataPrefetchThreshold) )
48  throw Exception(TE_TR("Cannot initialize the blocks menager") );
49 
50  for( unsigned int bandsIdx = 0 ; bandsIdx < rhs.getNumberOfBands() ;
51  ++bandsIdx )
52  m_bands.push_back( new te::mem::CachedBand( m_blocksManager, bandsIdx ) );
53 }
54 
55 te::mem::CachedRaster::CachedRaster( const unsigned int maxNumberOfCacheBlocks,
56  const te::rst::Raster& rhs,
57  const unsigned int dataPrefetchThreshold )
58 : te::rst::Raster( new te::rst::Grid( *rhs.getGrid() ), rhs.getAccessPolicy() )
59 {
60  if( ! m_blocksManager.initialize( maxNumberOfCacheBlocks, rhs,
61  dataPrefetchThreshold) )
62  throw Exception(TE_TR("Cannot initialize the blocks menager") );
63 
64  for( unsigned int bandsIdx = 0 ; bandsIdx < rhs.getNumberOfBands() ;
65  ++bandsIdx )
66  m_bands.push_back( new te::mem::CachedBand( m_blocksManager, bandsIdx ) );
67 }
68 
70 {
71  free();
72 }
73 
74 void te::mem::CachedRaster::open(const std::map<std::string, std::string>& /*rinfo*/,
76 {
77 }
78 
80 {
81  assert( m_blocksManager.isInitialized() );
82  return new CachedRaster( m_blocksManager.getMaxNumberOfCacheBlocks(),
83  *m_blocksManager.getRaster(), m_blocksManager.getDataPrefetchThreshold() );
84 }
85 
87 {
88  if( m_bands.size() > 0 )
89  {
90  for( unsigned int bandsIdx = 0 ; bandsIdx < m_bands.size() ; ++bandsIdx )
91  delete m_bands[ bandsIdx ];
92  m_bands.clear();
93  }
94 
95  m_blocksManager.free();
96 }
A raster class for memory.
Definition: Raster.h:44
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
An exception class for the TerraLib In-Memory Data Access driver.
void free()
Free all allocated internal resources and go back to the initial state.
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
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
RAM cached and tiled raster band.
Definition: CachedBand.h:53
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
bool initialize(const te::rst::Raster &externalRaster, const unsigned char maxMemPercentUsed, const unsigned int dataPrefetchThreshold)
Initialize this instance to an initial state.
te::dt::AbstractData * clone() const
It returns a clone of this object.
std::vector< CachedBand * > m_bands
Internal raster bands.
Definition: CachedRaster.h:157
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
CachedBandBlocksManager m_blocksManager
Internal blocks manager.
Definition: CachedRaster.h:159
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.