CachedBand.h
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/memory/CachedBand.h
22 
23  \brief RAM cached and tiled raster band.
24 */
25 
26 #ifndef __TERRALIB_MEMORY_INTERNAL_CACHEDBAND_H
27 #define __TERRALIB_MEMORY_INTERNAL_CACHEDBAND_H
28 
29 // TerraLib
30 #include "../raster/Band.h"
31 #include "../raster/BlockUtils.h"
32 #include "Config.h"
34 
35 // STL
36 #include <cassert>
37 #include <cstddef>
38 
39 // Boost
40 #include <boost/noncopyable.hpp>
41 
42 namespace te
43 {
44  namespace mem
45  {
46  /*!
47  \class CachedBand
48 
49  \brief RAM cached and tiled raster band.
50 
51  \details A cache adaptor to an external existent raster band that must always be avaliable.
52  */
53  class TEMEMORYEXPORT CachedBand : public te::rst::Band, public boost::noncopyable
54  {
55  public:
56 
57  /*!
58  \brief Constructor.
59 
60  \param blocksManager The blocks manager where to read/write data.
61  \param idx The band index.
62  */
63  CachedBand( CachedBandBlocksManager& blocksManager, std::size_t idx );
64 
65  ~CachedBand();
66 
67  inline te::rst::Raster* getRaster() const
68  {
69  return m_blocksManager.getRaster();
70  };
71 
72  void getValue(unsigned int c, unsigned int r, double& value) const;
73 
74  void setValue(unsigned int c, unsigned int r, const double value);
75 
76  void getIValue(unsigned int c, unsigned int r, double& value) const;
77 
78  void setIValue(unsigned int c, unsigned int r, const double value);
79 
80  void read(int x, int y, void* buffer) const;
81 
82  void* read(int x, int y)
83  {
84  assert( m_blocksManager.isInitialized() );
85  return m_blocksManager.getBlockPointer( m_idx, x, y );
86  };
87 
88  void write(int x, int y, void* buffer);
89 
90  private:
91 
92  CachedBand();
93 
94  protected :
95 
96  unsigned int m_blkWidth; //!< The current band blocks width
97  unsigned int m_blkHeight; //!< The current band blocks height
98  unsigned int m_blkSizeBytes; //!< The blocks size (bytes);
99 
100  te::rst::GetBufferValueFPtr m_getBuff; //!< A pointer to a function that helps to extract a double or complex value from a specific buffer data type (char, int16, int32, float, ...).
101  te::rst::GetBufferValueFPtr m_getBuffI; //!< A pointer to a function that helps to extract the imaginary part value from a specific buffer data type (cint16, cint32, cfloat, cdouble).
102  te::rst::SetBufferValueFPtr m_setBuff; //!< A pointer to a function that helps to insert a double or complex value into a specific buffer data type (char, int16, int32, float, ...).
103  te::rst::SetBufferValueFPtr m_setBuffI; //!< A pointer to a function that helps to insert the imaginary part value into a specific buffer data type (cint16, cint32, cfloat, cdouble).
104 
105 // Variable used by setValue/getValue methods
106  mutable unsigned int m_setGetBlkX;
107  mutable unsigned int m_setGetBlkY;
108  mutable unsigned int m_setGetPos;
109  mutable void* m_setGetBufPtr;
110 
111  CachedBandBlocksManager& m_blocksManager; //!< The external blocks manager reference.
112 
113  static CachedBandBlocksManager dummyBlocksManager; //!< A global static dummy blocks manager.
114  };
115 
116  } // end namespace mem
117 } // end namespace te
118 
119 #endif // __TERRALIB_MEMORY_INTERNAL_CACHEDBAND_H
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
te::rst::GetBufferValueFPtr m_getBuff
A pointer to a function that helps to extract a double or complex value from a specific buffer data t...
Definition: CachedBand.h:100
static CachedBandBlocksManager dummyBlocksManager
A global static dummy blocks manager.
Definition: CachedBand.h:113
Configuration flags for the TerraLib In-memory Data Access driver.
unsigned int m_blkWidth
The current band blocks width.
Definition: CachedBand.h:96
te::rst::SetBufferValueFPtr m_setBuff
A pointer to a function that helps to insert a double or complex value into a specific buffer data ty...
Definition: CachedBand.h:102
void(* SetBufferValueFPtr)(int index, void *buffer, const double *value)
The type of function used to extract data from a buffer.
Definition: BlockUtils.h:40
te::rst::GetBufferValueFPtr m_getBuffI
A pointer to a function that helps to extract the imaginary part value from a specific buffer data ty...
Definition: CachedBand.h:101
RAM cached and tiled raster band blocks manager.
void(* GetBufferValueFPtr)(int index, void *buffer, double *value)
The type of function used to extract data from a buffer.
Definition: BlockUtils.h:37
te::rst::Raster * getRaster() const
Returns the associated raster.
Definition: CachedBand.h:67
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
RAM cached and tiled raster band.
Definition: CachedBand.h:53
unsigned int m_setGetPos
Definition: CachedBand.h:108
A raster band description.
Definition: Band.h:63
unsigned int m_blkSizeBytes
The blocks size (bytes);.
Definition: CachedBand.h:98
te::rst::SetBufferValueFPtr m_setBuffI
A pointer to a function that helps to insert the imaginary part value into a specific buffer data typ...
Definition: CachedBand.h:103
CachedBandBlocksManager & m_blocksManager
The external blocks manager reference.
Definition: CachedBand.h:111
unsigned int m_blkHeight
The current band blocks height.
Definition: CachedBand.h:97
void * read(int x, int y)
It reads and returns a data block.
Definition: CachedBand.h:82
unsigned int m_setGetBlkY
Definition: CachedBand.h:107
RAM cached and tiled raster band blocks manager.
unsigned int m_setGetBlkX
Definition: CachedBand.h:106