SynchronizedRaster.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/raster/ProxyRaster.cpp
22 
23  \brief A proxy class for bands of several rasters over the same region.
24 */
25 
26 // TerraLib
27 #include "SynchronizedRaster.h"
28 #include "../core/translator/Translator.h"
29 #include "BandProperty.h"
30 #include "Exception.h"
31 #include "Grid.h"
32 
33 // STL
34 #include <cassert>
35 #include <utility>
36 
38 
40 : te::rst::Raster( grid, p )
41 {
42 }
43 
45  const unsigned char maxMemPercentUsed )
46 
47 {
48  sync.m_mutex.lock();
49  m_grid = new te::rst::Grid( *sync.m_raster.getGrid() );
50  sync.m_mutex.unlock();
51 
52  if( ! m_blocksManager.initialize( sync, maxMemPercentUsed ) )
53  throw Exception(TE_TR("Cannot initialize the blocks menager") );
54 
55  for( unsigned int bandsIdx = 0 ; bandsIdx < sync.m_raster.getNumberOfBands() ;
56  ++bandsIdx )
57  m_bands.push_back( new te::rst::SynchronizedBand( m_blocksManager, *this,
58  bandsIdx ) );
59 }
60 
61 te::rst::SynchronizedRaster::SynchronizedRaster( const unsigned int maxNumberOfCacheBlocks,
62  RasterSynchronizer& sync )
63 
64 {
65  sync.m_mutex.lock();
66  m_grid = new te::rst::Grid( *sync.m_raster.getGrid() );
67  sync.m_mutex.unlock();
68 
69  if( ! m_blocksManager.initialize( maxNumberOfCacheBlocks, sync ) )
70  throw Exception(TE_TR("Cannot initialize the blocks menager") );
71 
72  for( unsigned int bandsIdx = 0 ; bandsIdx < sync.m_raster.getNumberOfBands() ;
73  ++bandsIdx )
74  m_bands.push_back( new te::rst::SynchronizedBand( m_blocksManager, *this,
75  bandsIdx ) );
76 }
77 
79 {
80  free();
81 }
82 
83 std::map<std::string, std::string> te::rst::SynchronizedRaster::getInfo() const
84 {
85  std::map<std::string, std::string> info;
86 
88  assert( m_blocksManager.getRaster() );
89  info = m_blocksManager.getRaster()->getInfo();
91 
92  return info;
93 }
94 
96 {
97  int returnValue = 0;
98 
100  assert( m_blocksManager.getRaster() );
101  returnValue = m_blocksManager.getRaster()->getBandDataType( i );
103 
104  return returnValue;
105 }
106 
107 void te::rst::SynchronizedRaster::open(const std::map<std::string, std::string>& /*rinfo*/,
109 {
110 }
111 
113 {
114  assert( m_blocksManager.isInitialized() );
117 }
118 
120 {
121  if( m_bands.size() > 0 )
122  {
123  for( unsigned int bandsIdx = 0 ; bandsIdx < m_bands.size() ; ++bandsIdx )
124  delete m_bands[ bandsIdx ];
125  m_bands.clear();
126  }
127 
129 }
An exception class for the Raster module.
void free()
Free all allocated internal resources and go back to the initial state.
It describes one band (or dimension) of a raster.
SynchronizedBandBlocksManager m_blocksManager
Internal blocks manager.
Base exception class for plugin module.
te::dt::AbstractData * clone() const
It returns a clone of this object.
An access synchronizer to be used in SynchronizedRaster raster instances.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
boost::mutex m_mutex
General sync mutex;.
Grid * m_grid
The spatial support for raster data.
AccessPolicy
Supported data access policies (can be used as bitfield).
unsigned int getMaxNumberOfCacheBlocks() const
The maximum number of cache blocks.
virtual std::map< std::string, std::string > getInfo() const =0
It returns additional information about the raster.
Raster & m_raster
The input raster.
An adapter class to allow concurrent access to raster data by multiple threads.
An abstract class for raster data strucutures.
Syncrhonized raster band.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
URI C++ Library.
Definition: Attributes.h:37
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).
te::gm::Polygon * p
te::rst::Raster * getRaster() const
Returns the associated raster.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
bool isInitialized() const
Returns true if this instance is initialized.
Grid * getGrid()
It returns the raster grid.
bool initialize(RasterSynchronizer &sync, const unsigned char maxMemPercentUsed)
Initialize this instance to an initial state.
std::vector< SynchronizedBand * > m_bands
Internal raster bands.
A rectified grid is the spatial support for raster data.
RasterSynchronizer * getSynchronizer() const
Return a pointer to the assotiated synchronizer instance or NULL if there is none.
int getBandDataType(std::size_t i) const
Returns the data type in a particular band (or dimension).
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.