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  virtual std::complex<double> getMinValue(bool readall = false, unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
106 
107  virtual std::complex<double> getMaxValue(bool readall = false, unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
108 
109  virtual std::complex<double> getStdValue(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
110 
111  virtual std::complex<double> getMeanValue(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
112 
113  void getValueFromBlock(void* block, unsigned int pos, std::complex<double>& value) const;
114 
115  void getValueFromBlock(void* block, unsigned int pos, double& value) const;
116 
117  private:
118 
119  /*!
120  \brief Places the buffer in position adequate to obtain row/column values.
121 
122  \param c The column in band to manipulate value.
123  \param r The row in band to manipulate value.
124 
125  \warning The caller is responsible for providing correct values for the range [c x r].
126  */
127  int placeBuffer(unsigned c, unsigned r) const;
128 
129  /*! \brief The type of function used to insert/extract data from buffers. */
130  //typedef void (*ManipulateBufferValueFPtr)(int index, void* buffer, double* value);
131 
132  private:
133 
134  te::rst::Raster* m_raster; //!< The Raster associated to this band.
135  GDALRasterBand* m_rasterBand; //!< GDAL Raster band.
136  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, ...).
137  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).
138  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, ...).
139  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).
140  GDALDataType m_gdaltype; //!< The GDAL Data type.
141  void* m_buffer; //!< An internal buffer.
142  mutable int m_x; //!< Actual x buffer position.
143  mutable int m_y; //!< Actual y buffer position.
144  mutable bool m_update_buffer; //!< Flag to update buffer.
145 
146  // te::gdal::Band::getValue/setValue internal variables
147  mutable int m_currX; //!< Block x position.
148  mutable int m_currY; //!< Block y position.
149  mutable int m_currC; //!< Block column position.
150  mutable int m_currR; //!< Block row position.
151  mutable int m_i; //!< Block index.
152  };
153  } // end namespace gdal
154 } // end namespace te
155 
156 #endif // __TERRALIB_GDAL_INTERNAL_BAND_H
157 
int m_x
Actual x buffer position.
Definition: Band.h:142
int m_currC
Block column position.
Definition: Band.h:149
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:137
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:141
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:150
int m_currY
Block y position.
Definition: Band.h:148
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:136
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:139
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
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.
TerraLib.
GDALRasterBand * m_rasterBand
GDAL Raster band.
Definition: Band.h:135
A raster band description.
Definition: Band.h:63
int m_y
Actual y buffer position.
Definition: Band.h:143
te::rst::Raster * m_raster
The type of function used to insert/extract data from buffers.
Definition: Band.h:134
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:138
int m_i
Block index.
Definition: Band.h:151
GDALDataType m_gdaltype
The GDAL Data type.
Definition: Band.h:140
int m_currX
Block x position.
Definition: Band.h:147
bool m_update_buffer
Flag to update buffer.
Definition: Band.h:144
Configuration flags for the GDAL Driver of TerraLib.