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 
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 getBlockBuffer(void* buffer, int x0, int y0, int width, int height, int outWidth, int outHeight, int dataType);
106 
107  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;
108 
109  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;
110 
111  virtual std::complex<double> getStdValue(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
112 
113  virtual std::complex<double> getMeanValue(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
114 
115  virtual void getHistogramR(const unsigned int rowStart, const unsigned int colStart, const unsigned int finalRow, const unsigned int finalCol, const unsigned int histoBins,
116  const unsigned int sampleStep, std::map<double, unsigned>& histogram) const;
117 
118  void getValueFromBlock(void* block, unsigned int pos, std::complex<double>& value) const;
119 
120  void getValueFromBlock(void* block, unsigned int pos, double& value) const;
121 
122  private:
123 
124  /*!
125  \brief Places the buffer in position adequate to obtain row/column values.
126 
127  \param c The column in band to manipulate value.
128  \param r The row in band to manipulate value.
129 
130  \warning The caller is responsible for providing correct values for the range [c x r].
131  */
132  int placeBuffer(unsigned c, unsigned r) const;
133 
134  /*! \brief The type of function used to insert/extract data from buffers. */
135  //typedef void (*ManipulateBufferValueFPtr)(int index, void* buffer, double* value);
136 
137  private:
138 
139  te::rst::Raster* m_raster; //!< The Raster associated to this band.
140  GDALRasterBand* m_rasterBand; //!< GDAL Raster band.
141  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, ...).
142  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).
143  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, ...).
144  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).
145  GDALDataType m_gdaltype; //!< The GDAL Data type.
146  void* m_buffer; //!< An internal buffer.
147  mutable int m_x; //!< Actual x buffer position.
148  mutable int m_y; //!< Actual y buffer position.
149  mutable bool m_update_buffer; //!< Flag to update buffer.
150 
151  // te::gdal::Band::getValue/setValue internal variables
152  mutable int m_currX; //!< Block x position.
153  mutable int m_currY; //!< Block y position.
154  mutable int m_currC; //!< Block column position.
155  mutable int m_currR; //!< Block row position.
156  mutable int m_i; //!< Block index.
157  };
158  } // end namespace gdal
159 } // end namespace te
160 
161 #endif // __TERRALIB_GDAL_INTERNAL_BAND_H
162 
te::gdal::Band::getMaxValue
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
It computes and returns the maximum occurring value in a window of the band.
te::gdal::Band::Band
Band(const Band &rhs)
te
TerraLib.
Definition: AddressGeocodingOp.h:52
gdal.h
This file contains include headers for the TerraLib GDAL driver.
te::rst::Band
A raster band description.
Definition: Band.h:64
te::rst::SetBufferValueFPtr
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::gdal::Band::m_gdaltype
GDALDataType m_gdaltype
The GDAL Data type.
Definition: Band.h:145
te::gdal::Band::m_currY
int m_currY
Block y position.
Definition: Band.h:153
te::gdal::Band::m_update_buffer
bool m_update_buffer
Flag to update buffer.
Definition: Band.h:149
te::gdal::Band::getValueFromBlock
void getValueFromBlock(void *block, unsigned int pos, double &value) const
te::gdal::Band::getValue
void getValue(unsigned int c, unsigned int r, double &value) const
Returns the cell attribute value.
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::gdal::Band::getRaster
te::rst::Raster * getRaster() const
Returns the associated raster.
te::gdal::Band::m_setBuff
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:143
te::gdal::Band::m_currR
int m_currR
Block row position.
Definition: Band.h:155
te::gdal::Band::m_x
int m_x
Actual x buffer position.
Definition: Band.h:147
te::gdal::Band::m_buffer
void * m_buffer
An internal buffer.
Definition: Band.h:146
te::gdal::Band::getIValue
void getIValue(unsigned int c, unsigned int r, double &value) const
Returns the imaginary attribute value in a complex band of a cell.
te::gdal::Band::read
void read(int x, int y, void *buffer) const
It reads a data block to the specified buffer.
te::gdal::Band::m_rasterBand
GDALRasterBand * m_rasterBand
GDAL Raster band.
Definition: Band.h:140
te::gdal::Band::setIValue
void setIValue(unsigned int c, unsigned int r, const double value)
Sets the imaginary attribute value in a complex band of a cell.
te::gdal::Band::operator=
Band & operator=(const Band &rhs)
te::gdal::Band::getHistogramR
virtual void getHistogramR(const unsigned int rowStart, const unsigned int colStart, const unsigned int finalRow, const unsigned int finalCol, const unsigned int histoBins, const unsigned int sampleStep, std::map< double, unsigned > &histogram) const
It computes and returns the histogram occurring values (real part) in a window of the band.
te::gdal::Band::setValue
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
TEGDALEXPORT
#define TEGDALEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:67
te::gdal::Band::m_i
int m_i
Block index.
Definition: Band.h:156
te::gdal::Band
This class represents raster band description.
Definition: Band.h:65
te::rst::Band::setValue
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
te::gdal::Band::getStdValue
virtual std::complex< double > getStdValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the standard deviation of the occurring values in a window of the band.
te::gdal::Band::m_getBuffI
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:142
te::gdal::Band::m_setBuffI
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:144
te::gdal::Band::m_currC
int m_currC
Block column position.
Definition: Band.h:154
te::gdal::Raster
This class represents Raster data.
Definition: Raster.h:63
te::gdal::Band::getMeanValue
virtual std::complex< double > getMeanValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the mean of the occurring values in a window of the band.
te::gdal::Band::placeBuffer
int placeBuffer(unsigned c, unsigned r) const
Places the buffer in position adequate to obtain row/column values.
te::gdal::Band::getMinValue
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
It computes and returns the minimum occurring value in a window of the band.
te::gdal::Band::getValueFromBlock
void getValueFromBlock(void *block, unsigned int pos, std::complex< double > &value) const
te::gdal::Band::read
void * read(int, int)
It reads and returns a data block.
te::gdal::Band::write
void write(int x, int y, void *buffer)
It writes a data block from the specified buffer.
te::gdal::Band::m_currX
int m_currX
Block x position.
Definition: Band.h:152
te::gdal::Band::Band
Band(Raster *rstPtr, std::size_t idx, GDALRasterBand *gdalRasterBandPtr)
Constructor.
te::gdal::Band::m_y
int m_y
Actual y buffer position.
Definition: Band.h:148
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::gdal::Band::~Band
~Band()
Virtual destructor.
te::rst::GetBufferValueFPtr
void(* GetBufferValueFPtr)(int index, void *buffer, double *value)
The type of function used to extract data from a buffer.
Definition: BlockUtils.h:37
te::gdal::Band::m_getBuff
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:141
te::gdal::Band::getBlockBuffer
void getBlockBuffer(void *buffer, int x0, int y0, int width, int height, int outWidth, int outHeight, int dataType)
It gets the buffer in just only one block that represents the region informed.
te::gdal::Band::setValue
void setValue(unsigned int c, unsigned int r, const double value)
Sets the cell attribute value.
te::gdal::Band::m_raster
te::rst::Raster * m_raster
The type of function used to insert/extract data from buffers.
Definition: Band.h:139
te::rst::Band::getValue
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
te::gdal::Band::getValue
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