All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../common/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 {
39 }
40 
42 : te::rst::Raster( grid, p )
43 {
44 }
45 
47  const unsigned char maxMemPercentUsed )
48 : te::rst::Raster()
49 {
50  sync.m_mutex.lock();
51  m_grid = new te::rst::Grid( *sync.m_raster.getGrid() );
52  sync.m_mutex.unlock();
53 
54  if( ! m_blocksManager.initialize( sync, maxMemPercentUsed ) )
55  throw Exception(TE_TR("Cannot initialize the blocks menager") );
56 
57  for( unsigned int bandsIdx = 0 ; bandsIdx < sync.m_raster.getNumberOfBands() ;
58  ++bandsIdx )
59  m_bands.push_back( new te::rst::SynchronizedBand( m_blocksManager, *this,
60  bandsIdx ) );
61 }
62 
63 te::rst::SynchronizedRaster::SynchronizedRaster( const unsigned int maxNumberOfCacheBlocks,
64  RasterSynchronizer& sync )
65 : te::rst::Raster()
66 {
67  sync.m_mutex.lock();
68  m_grid = new te::rst::Grid( *sync.m_raster.getGrid() );
69  sync.m_mutex.unlock();
70 
71  if( ! m_blocksManager.initialize( maxNumberOfCacheBlocks, sync ) )
72  throw Exception(TE_TR("Cannot initialize the blocks menager") );
73 
74  for( unsigned int bandsIdx = 0 ; bandsIdx < sync.m_raster.getNumberOfBands() ;
75  ++bandsIdx )
76  m_bands.push_back( new te::rst::SynchronizedBand( m_blocksManager, *this,
77  bandsIdx ) );
78 }
79 
81 {
82  free();
83 }
84 
85 std::map<std::string, std::string> te::rst::SynchronizedRaster::getInfo() const
86 {
87  std::map<std::string, std::string> info;
88 
89  m_blocksManager.getSynchronizer()->m_mutex.lock();
90  assert( m_blocksManager.getRaster() );
91  info = m_blocksManager.getRaster()->getInfo();
92  m_blocksManager.getSynchronizer()->m_mutex.unlock();
93 
94  return info;
95 }
96 
98 {
99  int returnValue = 0;
100 
101  m_blocksManager.getSynchronizer()->m_mutex.lock();
102  assert( m_blocksManager.getRaster() );
103  returnValue = m_blocksManager.getRaster()->getBandDataType( i );
104  m_blocksManager.getSynchronizer()->m_mutex.unlock();
105 
106  return returnValue;
107 }
108 
109 void te::rst::SynchronizedRaster::open(const std::map<std::string, std::string>& /*rinfo*/,
111 {
112 }
113 
115 {
116  assert( m_blocksManager.isInitialized() );
117  return new SynchronizedRaster( m_blocksManager.getMaxNumberOfCacheBlocks(),
118  *m_blocksManager.getSynchronizer() );
119 }
120 
122 {
123  if( m_bands.size() > 0 )
124  {
125  for( unsigned int bandsIdx = 0 ; bandsIdx < m_bands.size() ; ++bandsIdx )
126  delete m_bands[ bandsIdx ];
127  m_bands.clear();
128  }
129 
130  m_blocksManager.free();
131 }
void free()
Free all allocated internal resources and go back to the initial state.
An adapter class to allow concurrent access to raster data by multiple threads.
It describes one band (or dimension) of a raster.
SynchronizedBandBlocksManager m_blocksManager
Internal blocks manager.
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:347
boost::mutex m_mutex
General sync mutex;.
Grid * m_grid
The spatial support for raster data.
Definition: Raster.h:681
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
An exception class for the Raster module.
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.
Definition: Raster.h:71
Syncrhonized raster band.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
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.
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: Grid.h:68
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.