Band.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/gdal/Band.h
22 
23  \brief It gives access to values in one band (dimension) of a raster.
24  */
25 
26 #ifndef __TERRALIB_GDAL_INTERNAL_BAND_H
27 #define __TERRALIB_GDAL_INTERNAL_BAND_H
28 
29 // TerraLib
30 #include "../raster/Band.h"
31 #include "../raster/BandProperty.h"
32 #include "../raster/BlockUtils.h"
33 #include "../raster/Raster.h"
34 #include "Config.h"
35 
36 // STL
37 #include <complex>
38 #include <string>
39 #include <vector>
40 
41 // GDAL
42 #include <gdal.h>
43 
44 // Forward declaration
45 class GDALRasterBand;
46 
47 namespace te
48 {
49  namespace gdal
50  {
51  // Forward declaration.
52  class Raster;
53 
54  /*!
55  \class Band
56 
57  \brief This class represents raster band description.
58 
59  This class is a concrete implementation of a Raster Band using the GDAL library to access
60  the data.
61 
62  \sa te::rst::Band, te::rst::BandProperty
63  */
65  {
66  public:
67 
68  /*!
69  \brief Constructor
70 
71  \param rstPtr A pointer to the parent raster.
72  \param idx This band index.
73  \param gdalRasterBandPtr The GDAL band related to this terralib band.
74 
75  \warning The caller is responsible for providing correct values for the range [c x r].
76  */
77  Band( Raster* rstPtr, std::size_t idx, GDALRasterBand* gdalRasterBandPtr );
78 
79  Band(const Band& rhs);
80 
81  ~Band();
82 
83  te::rst::Raster* getRaster() const;
84 
85  Band& operator=(const Band& rhs);
86 
87  void getValue(unsigned int c, unsigned int r, double& value) const;
88 
89  void setValue(unsigned int c, unsigned int r, const double value);
90 
91  void getIValue(unsigned int c, unsigned int r, double& value) const;
92 
93  void setIValue(unsigned int c, unsigned int r, const double value);
94 
95  void getValue(unsigned int c, unsigned int r, std::complex<double>& value) const { te::rst::Band::getValue(c, r, value); }
96 
97  void setValue(unsigned int c, unsigned int r, const std::complex<double>& value) { te::rst::Band::setValue(c, r, value); }
98 
99  void read(int x, int y, void* buffer) const;
100 
101  void* read(int /*x*/, int /*y*/);
102 
103  void write(int x, int y, void* buffer);
104 
105  void getValueFromBlock(void* block, unsigned int pos, std::complex<double>& value) const;
106 
107  void getValueFromBlock(void* block, unsigned int pos, double& value) const;
108 
109  private:
110 
111  /*!
112  \brief Places the buffer in position adequate to obtain row/column values.
113 
114  \param c The column in band to manipulate value.
115  \param r The row in band to manipulate value.
116 
117  \warning The caller is responsible for providing correct values for the range [c x r].
118  */
119  int placeBuffer(unsigned c, unsigned r) const;
120 
121  /*! \brief The type of function used to insert/extract data from buffers. */
122  //typedef void (*ManipulateBufferValueFPtr)(int index, void* buffer, double* value);
123 
124  private:
125 
126  te::rst::Raster* m_raster; //!< The Raster associated to this band.
127  GDALRasterBand* m_rasterBand; //!< GDAL Raster band.
128  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, ...).
129  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).
130  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, ...).
131  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).
132  GDALDataType m_gdaltype; //!< The GDAL Data type.
133  void* m_buffer; //!< An internal buffer.
134  mutable int m_x; //!< Actual x buffer position.
135  mutable int m_y; //!< Actual y buffer position.
136  mutable bool m_update_buffer; //!< Flag to update buffer.
137 
138  // te::gdal::Band::getValue/setValue internal variables
139  mutable int m_currX; //!< Block x position.
140  mutable int m_currY; //!< Block y position.
141  mutable int m_currC; //!< Block column position.
142  mutable int m_currR; //!< Block row position.
143  mutable int m_i; //!< Block index.
144  };
145  } // end namespace gdal
146 } // end namespace te
147 
148 #endif // __TERRALIB_GDAL_INTERNAL_BAND_H
149 
void getValue(unsigned int c, unsigned int r, std::complex< double > &value) const
Returns the imaginary attribute value in a complex band of a cell.
Definition: Band.h:95
int m_x
Actual x buffer position.
Definition: Band.h:134
int m_currC
Block column position.
Definition: Band.h:141
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: Band.h:129
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
void * m_buffer
An internal buffer.
Definition: Band.h:133
This class represents Raster data.
Definition: Raster.h:61
#define TEGDALEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:67
void setValue(unsigned int c, unsigned int r, const std::complex< double > &value)
Sets the imaginary attribute value in a complex band of a cell.
Definition: Band.h:97
void(* SetBufferValueFPtr)(int index, void *buffer, const double *value)
The type of function used to extract data from a buffer.
Definition: BlockUtils.h:40
int m_currR
Block row position.
Definition: Band.h:142
int m_currY
Block y position.
Definition: Band.h:140
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: Band.h:128
This class represents raster band description.
Definition: Band.h:64
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: Band.h:131
void(* GetBufferValueFPtr)(int index, void *buffer, double *value)
The type of function used to extract data from a buffer.
Definition: BlockUtils.h:37
An abstract class for raster data strucutures.
Definition: Raster.h:71
This file contains include headers for the TerraLib GDAL driver.
URI C++ Library.
GDALRasterBand * m_rasterBand
GDAL Raster band.
Definition: Band.h:127
A raster band description.
Definition: Band.h:63
int m_y
Actual y buffer position.
Definition: Band.h:135
te::rst::Raster * m_raster
The type of function used to insert/extract data from buffers.
Definition: Band.h:126
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
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: Band.h:130
int m_i
Block index.
Definition: Band.h:143
GDALDataType m_gdaltype
The GDAL Data type.
Definition: Band.h:132
int m_currX
Block x position.
Definition: Band.h:139
bool m_update_buffer
Flag to update buffer.
Definition: Band.h:136
Configuration flags for the GDAL Driver of TerraLib.