All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Band.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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/Band.h
22 
23  \brief It gives access to values in one band (dimension) of a raster.
24 */
25 
26 #ifndef __TERRALIB_RASTER_INTERNAL_BAND_H
27 #define __TERRALIB_RASTER_INTERNAL_BAND_H
28 
29 // TerraLib
30 #include "Config.h"
31 #include "Raster.h"
32 #include "RasterProperty.h"
33 
34 // STL
35 #include <complex>
36 #include <string>
37 #include <vector>
38 
39 namespace te
40 {
41  namespace rst
42  {
43 // Forward declaration
44  class BandProperty;
45  class Raster;
46 
47  /*!
48  \class Band
49 
50  \brief A raster band description.
51 
52  The raster band describes how to interpret (and use) values that
53  can be associated to each element of a raster, in one given dimension
54  (e.g. a band of multi-hiperspectral remote sensing image).
55  Each instance of this class refers to a particular dimension.
56  This implementation defines a set of information commonly used to describe any
57  raster.
58 
59  \ingroup rst
60 
61  \sa Raster, BandProperty
62  */
64  {
65  public:
66 
67  /*!
68  \brief Constructor.
69 
70  \param p The band property. The Band will take its ownership.
71  \param idx The band index.
72 
73  \warning The class takes the ownership of the passed pointer. Do not pass a null pointer.
74  */
75  Band(BandProperty* p, std::size_t idx);
76 
77  /*! \brief Virtual destructor. */
78  virtual ~Band();
79 
80  /*! \brief Returns the associated raster. */
81  virtual Raster* getRaster() const = 0;
82 
83  /*!
84  \brief Assignment operator.
85 
86  \param rhs The right-hand-side copy used to copy from.
87 
88  \return A reference to this object.
89  */
90  virtual Band& operator=(const Band& rhs);
91 
92  /*!
93  \brief Returns the cell attribute value.
94 
95  \param c The column location of the cell.
96  \param r The row location of the cell.
97  \param value To return the attribute value.
98 
99  \warning The caller is responsible for providing correct values for the range [c x r].
100 
101  \exception Exception Subclasses may throw an exception if the data value can not be read.
102  */
103  virtual void getValue(unsigned int c, unsigned int r, double& value) const = 0;
104 
105  /*!
106  \brief Sets the cell attribute value.
107 
108  \param c The column location of the cell.
109  \param r The row location of the cell.
110  \param value The attribute value to be assigned.
111 
112  \warning The caller is responsible for providing correct values for the range [c x r].
113 
114  \exception Exception Subclasses may throw an exception if the data value can not be write.
115  */
116  virtual void setValue(unsigned int c, unsigned int r, const double value) = 0;
117 
118  /*!
119  \brief Returns the imaginary attribute value in a complex band of a cell.
120 
121  \param c The column location of the cell.
122  \param r The row location of the cell.
123  \param value The attribute value to be assigned.
124 
125  \warning The caller is responsible for providing correct values for the range [c x r].
126 
127  \exception Exception Subclasses may throw an exception if the data value can not be read.
128  */
129  virtual void getIValue(unsigned int c, unsigned int r, double& value) const = 0;
130 
131  /*!
132  \brief Sets the imaginary attribute value in a complex band of a cell.
133 
134  \param c The column location of the cell.
135  \param r The row location of the cell.
136  \param value The attribute value to be assigned.
137 
138  \warning The caller is responsible for providing correct values for the range [c x r].
139 
140  \exception Exception Subclasses may throw an exception if the data value can not be write.
141  */
142  virtual void setIValue(unsigned int c, unsigned int r, const double value) = 0;
143 
144  /*!
145  \brief Returns the imaginary attribute value in a complex band of a cell.
146 
147  \param c The column location of the cell.
148  \param r The row location of the cell.
149  \param value The complex attribute value to be assigned (real, imaginary).
150 
151  \warning The caller is responsible for providing correct values for the range [c x r].
152 
153  \exception Exception Subclasses may throw an exception if the data value can not be read.
154  */
155  virtual void getValue(unsigned int c, unsigned int r, std::complex<double>& value) const;
156 
157  /*!
158  \brief Sets the imaginary attribute value in a complex band of a cell.
159 
160  \param c The column location of the cell.
161  \param r The row location of the cell.
162  \param value The complex attribute value to be assigned (real, imaginary).
163 
164  \warning The caller is responsible for providing correct values for the range [c x r].
165 
166  \exception Exception Subclasses may throw an exception if the data value can not be write.
167  */
168  virtual void setValue(unsigned int c, unsigned int r, const std::complex<double>& value);
169 
170  /*!
171  \brief It reads a data block to the specified buffer.
172 
173  \param x The block-id in x (or x-offset).
174  \param y The block-id in y (or y-offset).
175  \param buffer The buffer to be used to read from the band.
176 
177  \note The upper-left corner is (0, 0).
178 
179  \warning The buffer must have been previously allocated and must have enough capacity.
180  */
181  virtual void read(int x, int y, void* buffer) const = 0;
182 
183  /*!
184  \brief It reads and returns a data block.
185 
186  \param x The block-id in x (or x-offset).
187  \param y The block-id in y (or y-offset).
188 
189  \note The upper-left corner is (0, 0).
190 
191  \return The specified data block.
192  */
193  virtual void* read(int x, int y) = 0;
194 
195  /*!
196  \brief It writes a data block from the specified buffer.
197 
198  \param x The block-id in x (or x-offset).
199  \param y The block-id in y (or y-offset).
200  \param buffer The buffer to be used to write to the band.
201 
202  \note The upper-left corner is (0, 0).
203 
204  \warning The method will copy the same amount of bytes used by the internal band block representation.
205  */
206  virtual void write(int x, int y, void* buffer) = 0;
207 
208  /*!
209  \brief It computes and returns the minimum occurring value in a window of the band.
210 
211  \param rs The starting row.
212  \param cs The starting column.
213  \param rf The final row.
214  \param cf The final column.
215 
216  \note This method without parameters will compute for the entire image.
217 
218  \warning The caller is responsible for providing correct values for the range [rs, cs x rf, cf x b].
219 
220  \return The minimum occurring value in the window, real and imaginary (if present).
221  */
222  virtual std::complex<double> getMinValue(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
223 
224  /*!
225  \brief It computes and returns the maximum occurring value in a window of the band.
226 
227  \param rs The starting row.
228  \param cs The starting column.
229  \param rf The final row.
230  \param cf The final column.
231 
232  \note This method without parameters will compute for the entire raster band.
233 
234  \warning The caller is responsible for providing correct values for the range [rs, cs x rf, cf].
235 
236  \return The maximum occurring value in the window, real and imaginary (if present).
237  */
238  virtual std::complex<double> getMaxValue(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
239 
240  /*!
241  \brief It computes and returns the standard deviation of the occurring values in a window of the band.
242 
243  \param rs The starting row.
244  \param cs The starting column.
245  \param rf The final row.
246  \param cf The final column.
247 
248  \note This method without parameters will compute for the entire raster band.
249 
250  \warning The caller is responsible for providing correct values for the range [rs, cs x rf, cf].
251 
252  \return The standard deviation of the occurring values in the window, real and imaginary (if present).
253  */
254  virtual std::complex<double> getStdValue(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
255 
256  /*!
257  \brief It computes and returns the mean of the occurring values in a window of the band.
258 
259  \param rs The starting row.
260  \param cs The starting column.
261  \param rf The final row.
262  \param cf The final column.
263 
264  \note This method without parameters will compute for the entire raster band.
265 
266  \warning The caller is responsible for providing correct values for the range [rs, cs x rf, cf].
267 
268  \return The mean of the occurring values in the window, real and imaginary (if present).
269  */
270  virtual std::complex<double> getMeanValue(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0) const;
271 
272  /*!
273  \brief It computes and returns the histogram occurring values (real part) in a window of the band.
274 
275  \param rs The starting row.
276  \param cs The starting column.
277  \param rf The final row.
278  \param cf The final column.
279  \param b The number of bins (intervals from minimum pixel to maximum). When b = 0, the histogram will be divided according to all pixel values.
280 
281  \note This method without parameters will compute for the entire raster band.
282 
283  \warning The caller is responsible for providing correct values for the range [rs, cs x rf, cf].
284 
285  \return The histogram of the occurring values (real part) in the window.
286  */
287  virtual std::map<double, unsigned> getHistogramR(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0, unsigned int b = 0) const;
288 
289  /*!
290  \brief It computes and returns the histogram occurring values (imaginary part) in a window of the band.
291 
292  \param rs The starting row.
293  \param cs The starting column.
294  \param rf The final row.
295  \param cf The final column.
296  \param b The number of bins (intervals from minimum pixel to maximum). When b = 0, the histogram will be divided according to all pixel values.
297 
298  \note This method without parameters will compute for the entire raster band.
299 
300  \warning The caller is responsible for providing correct values for the range [rs, cs x rf, cf].
301 
302  \return The histogram of the occurring values (imaginary part) in the window.
303  */
304  virtual std::map<double, unsigned> getHistogramI(unsigned int rs = 0, unsigned int cs = 0, unsigned int rf = 0, unsigned int cf = 0, unsigned int b = 0) const;
305 
306  /*! \brief It returns the scale values (real and imaginary) to be applied to the band. */
307  std::complex<double> getScaleValue() const;
308 
309  /*!
310  \brief Sets the scale values (real and imaginary) to be applied to the band.
311 
312  \param s The new scale.
313  */
314  void setScaleValue(const std::complex<double> s);
315 
316  /*! \brief It returns the offset values (real and imaginary) to be applied to the band. */
317  std::complex<double> getOffsetValue() const;
318 
319  /*!
320  \brief Sets the offset values (real and imaginary) to be applied to the band.
321 
322  \param o The new offset.
323  */
324  void setOffsetValue(const std::complex<double> o);
325 
326  /*! \brief Returns the band property. */
327  BandProperty* getProperty();
328 
329  /*! \brief Returns the band property. */
330  const BandProperty* getProperty() const;
331 
332  /*!
333  \brief It calls a parameter function f to apply in all pixels from two bands, e.g. pixel = f(lhs, rhs);
334 
335  \param (*f) a function with the signature complex<double>(*f)(complex<double>, complex<double>)
336 
337  \param rhs The rhs band to apply the function.
338 
339  \return The resultant band.
340  */
341  Band& callOperator(std::complex<double>(*f)(std::complex<double>, std::complex<double>), Band& rhs);
342 
343  /*!
344  \brief It calls a parameter function f to apply in all pixels from the band, e.g. pixel = f(lhs, rhs);
345 
346  \param (*f) a function with the signature complex<double>(*f)(complex<double>, complex<double>)
347 
348  \param cvalue The constant value that will work with the generic function.
349 
350  \return The resultant band.
351  */
352  Band& callOperator(std::complex<double>(*f)(std::complex<double>, std::complex<double>), std::complex<double>& cvalue);
353 
354  /*!
355  \brief It returns the band sum (pixel by pixel).
356 
357  \param rhs The band to be added, right-hand side.
358 
359  \note Both bands must have the same properties, #columns, #rows, and data type.
360 
361  \note The caller is responsible to guarantee that resultant values
362  will not exceed the range of the data type.
363 
364  \return The band sum.
365  */
366  virtual Band& operator+=(Band& rhs);
367 
368  /*!
369  \brief It returns the sum of a constant value to all pixels in the band.
370 
371  \param cvalue The constant value to be added.
372 
373  \note The caller is responsible to guarantee that resultant values
374  will not exceed the range of the data type.
375 
376  \return The band sum.
377  */
378  virtual Band& operator+=(std::complex<double>& cvalue);
379 
380  /*!
381  \brief It returns the band subtraction (pixel by pixel).
382 
383  \param rhs The band to be subtracted, right-hand side.
384 
385  \note Both bands must have the same properties, #columns, #rows, and data type.
386 
387  \note The caller is responsible to guarantee that resultant values
388  will not exceed the range of the data type.
389 
390  \return The band subtraction.
391  */
392  virtual Band& operator-=(Band& rhs);
393 
394  /*!
395  \brief It returns the difference from all pixels in the band to a constant value (pixel - constant).
396 
397  \param cvalue The constant value to be subtracted.
398 
399  \note The caller is responsible to guarantee that resultant values
400  will not exceed the range of the data type.
401 
402  \return The band difference.
403  */
404  virtual Band& operator-=(std::complex<double>& cvalue);
405 
406  /*!
407  \brief It returns the band product (pixel by pixel).
408 
409  \param rhs The band to be multiplied, right-hand side.
410 
411  \note Both bands must have the same properties, #columns, #rows, and data type.
412 
413  \note The caller is responsible to guarantee that resultant values
414  will not exceed the range of the data type.
415 
416  \return The band product.
417  */
418  virtual Band& operator*=(Band& rhs);
419 
420  /*!
421  \brief It returns the product of a constant value to all pixels in the band.
422 
423  \param cvalue The constant value to be multiplied.
424 
425  \note The caller is responsible to guarantee that resultant values
426  will not exceed the range of the data type.
427 
428  \return The band product.
429  */
430  virtual Band& operator*=(std::complex<double>& cvalue);
431 
432  /*!
433  \brief It returns the band division (pixel by pixel).
434 
435  \param rhs The band to be divided, right-hand side.
436 
437  \note Both bands must have the same properties, #columns, #rows, and data type.
438 
439  \note The caller is responsible to guarantee that resultant values
440  will not exceed the range of the data type.
441 
442  \return The band division.
443  */
444  virtual Band& operator/=(Band& rhs);
445 
446  /*!
447  \brief It returns the division of all pixels in the band by a constant value (pixel / constant).
448 
449  \param cvalue The constant value to be divided.
450 
451  \note The caller is responsible to guarantee that resultant values
452  will not exceed the range of the data type.
453 
454  \return The band division.
455  */
456  virtual Band& operator/=(std::complex<double>& cvalue);
457 
458  /*! \brief It returns the number of bytes ocuppied by a data block. */
459  virtual int getBlockSize() const;
460 
461  protected:
462 
463  /*!
464  \brief Copy constructor.
465 
466  \param rhs The right-hand-side copy used to copy from.
467  */
468  Band(const Band& rhs);
469 
470  protected:
471 
472  BandProperty* m_property; //!< The band information.
473  std::size_t m_idx; //!< The band index.
474  };
475 
476  } // end namespace rst
477 } // end namespace te
478 
479 #endif // __TERRALIB_RASTER_INTERNAL_BAND_H
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
A raster band description.
Definition: BandProperty.h:61
Raster property.
An abstract class for raster data strucutures.
An abstract class for raster data strucutures.
Definition: Raster.h:71
A raster band description.
Definition: Band.h:63
std::size_t m_idx
The band index.
Definition: Band.h:473
Configuration flags for the Raster module of TerraLib.
BandProperty * m_property
The band information.
Definition: Band.h:472