Functions.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/rp/Functions.h
22  \brief Raster Processing functions.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_FUNCTIONS_H
26 #define __TERRALIB_RP_INTERNAL_FUNCTIONS_H
27 
28 #include "Config.h"
29 
30 #include "FeedersRaster.h"
31 #include "Matrix.h"
32 #include "Macros.h"
33 #include "RasterHandler.h"
34 #include "../dataaccess/datasource/DataSource.h"
35 #include "../raster/Raster.h"
36 #include "../raster/RasterFactory.h"
37 #include "../raster/Grid.h"
38 #include "../raster/BandProperty.h"
39 #include "../raster/RasterFactory.h"
40 #include "../raster/Interpolator.h"
41 #include "../raster/Utils.h"
42 #include "../srs/Converter.h"
43 #include "../geometry/LinearRing.h"
44 #include "../geometry/GTParameters.h"
45 #include "../geometry/MultiPoint.h"
46 #include "../geometry/Surface.h"
47 
48 // STL
49 #include <memory>
50 #include <map>
51 #include <vector>
52 #include <string>
53 #include <limits>
54 
55 // Boost
56 #include <boost/numeric/ublas/matrix.hpp>
57 #include <boost/shared_ptr.hpp>
58 
59 namespace te
60 {
61  namespace rst
62  {
63  class BandProperty;
64  class Grid;
65  }
66 
67  namespace rp
68  {
69  /*!
70  \brief Wavelet Atrous Filter types.
71  \ingroup rp_func
72  */
74  {
75  InvalidWAFilter, //!< Invalid filter type
76  B3SplineWAFilter, //!< Spline filter type.
77  TriangleWAFilter //!< Triangle filter type.
78  };
79 
81  {
83 
84  SpectralSensorParams(const int &band, const double &lower, const double &upper, const double &min, const double &max) :
85  m_band(band),
86  m_lower(lower),
87  m_upper(upper),
88  m_min(min),
89  m_max(max)
90  {}
91 
92  int m_band;
93  double m_lower;
94  double m_upper;
95  double m_min;
96  double m_max;
97  };
98 
99  /*!
100  \brief Create a new raster into the givem data source.
101  \param rasterGrid The template grid used to create the output raster.
102  \param bandsProperties The template band properties used to create the output raster.
103  \param outDataSetName The data set name to give to the created data set.
104  \param dataSourceType The data source type string (i.e. GDAL, MEM.)( See te::rst::RasterFactory dictionary for valid registered values ).
105  \param outRasterHandler The created raster handler.
106  \return true if OK, false on errors.
107  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
108  \ingroup rp_func
109  */
110  bool TERPEXPORT CreateNewRaster( const te::rst::Grid& rasterGrid,
111  const std::vector< te::rst::BandProperty* >& bandsProperties,
112  const std::string& outDataSetName,
113  const std::string& dataSourceType,
114  RasterHandler& outRasterHandler );
115 
116  /*!
117  \brief Create a new raster into the givem data source.
118  \param rasterGrid The template grid used to create the output raster.
119  \param bandsProperties The template band properties used to create the output raster.
120  \param outDataSetName The data set name to give to the created data set.
121  \param outDataSource The data source to use when creating the output data set.
122  \param outRasterHandler The created raster handler.
123  \return true if OK, false on errors.
124  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
125  \ingroup rp_func
126  */
127  bool TERPEXPORT CreateNewRaster( const te::rst::Grid& rasterGrid,
128  const std::vector< te::rst::BandProperty* >& bandsProperties,
129  const std::string& outDataSetName,
130  te::da::DataSource& outDataSource,
131  RasterHandler& outRasterHandler );
132 
133  /*!
134  \brief Create a new raster into the givem data source.
135  \param rasterGrid The template grid used to create the output raster.
136  \param bandsProperties The template band properties used to create the output raster.
137  \param rasterInfo The output raster info (specific driver info).
138  \param rasterType The output raster type (specific driver name - See te::rst::RasterFactory dictorary for more info).
139  \param outRasterPtr The created raster pointer.
140  \return true if OK, false on errors.
141  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
142  \ingroup rp_func
143  */
144  bool TERPEXPORT CreateNewRaster( const te::rst::Grid& rasterGrid,
145  const std::vector< te::rst::BandProperty* >& bandsProperties,
146  const std::map< std::string, std::string>& rasterInfo,
147  const std::string& rasterType,
148  std::auto_ptr< te::rst::Raster >& outRasterPtr );
149 
150  /*!
151  \brief Create a new raster into a new memory datasource.
152  \param rasterGrid The template grid used to create the output raster.
153  \param bandsProperties The template band properties used to create the output raster.
154  \param outRasterHandler The created raster handler.
155  \return true if OK, false on errors.
156  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
157  \ingroup rp_func
158  */
159  bool TERPEXPORT CreateNewMemRaster( const te::rst::Grid& rasterGrid,
160  std::vector< te::rst::BandProperty* > bandsProperties,
161  RasterHandler& outRasterHandler );
162 
163  /*!
164  \brief Create a new raster into a GDAL datasource.
165  \param rasterGrid The template grid used to create the output raster.
166  \param bandsProperties The template band properties used to create the output raster.
167  \param fileName The output tif file name.
168  \param outRasterHandler The created raster handler.
169  \return true if OK, false on errors.
170  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
171  \ingroup rp_func
172  */
173  bool TERPEXPORT CreateNewGdalRaster( const te::rst::Grid& rasterGrid,
174  std::vector< te::rst::BandProperty* > bandsProperties,
175  const std::string& fileName,
176  RasterHandler& outRasterHandler );
177 
178  /*!
179  \brief Create a new raster into a GDAL datasource.
180  \param rasterGrid The template grid used to create the output raster.
181  \param bandsProperties The template band properties used to create the output raster.
182  \param fileName The output tif file name.
183  \param outRasterPtr The created raster pointer.
184  \return true if OK, false on errors.
185  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
186  \ingroup rp_func
187  */
188  bool TERPEXPORT CreateNewGdalRaster( const te::rst::Grid& rasterGrid,
189  std::vector< te::rst::BandProperty* > bandsProperties,
190  const std::string& fileName,
191  std::auto_ptr< te::rst::Raster >& outRasterPtr );
192 
193  /*!
194  \brief Create a new raster into a GDAL datasource.
195  \param rasterGrid The template grid used to create the output raster.
196  \param bandsProperties The template band properties used to create the output raster.
197  \param fileName The output tif file name.
198  \param outRasterHandler The created raster handler.
199  \return true if OK, false on errors.
200  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
201  \ingroup rp_func
202  */
204  const te::rst::Raster& inputRaster,
205  const std::string& fileName );
206 
207  /*!
208  \brief Returns the real data type range (all values that can be represented by the given data type).
209  \param dataType The data type.
210  \param min The minimum value.
211  \param max The maximum value.
212  \note The types are listed in terralib/datatype/DataTypes.h
213  \ingroup rp_func
214  */
215  inline void TERPEXPORT GetDataTypeRange( const int dataType, double& min, double& max )
216  {
217  te::rst::GetDataTypeRanges( dataType, min, max );
218  }
219 
220  /*!
221  \brief Convert vector elements.
222  \param inputVector Input vector.
223  \param inputVectorDataType Input vector data type.
224  \param inputVectorSize The numer of input vector elements.
225  \param outputVector A pré-allocated output vector.
226  \note The types are listed in terralib/datatype/DataTypes.h
227  \ingroup rp_func
228  */
229  void TERPEXPORT Convert2DoublesVector( void* inputVector, const int inputVectorDataType,
230  unsigned int inputVectorSize, double* outputVector );
231 
232  /*!
233  \brief Convert a doubles vector.
234  \param inputVector Input vector.
235  \param inputVectorSize The numer of input vector elements.
236  \param inputVectorDataType Input vector data type.
237  \param outputVector A pré-allocated output vector.
238  \note The types are listed in terralib/datatype/DataTypes.h
239  \ingroup rp_func
240  */
241  void TERPEXPORT ConvertDoublesVector( double* inputVector,
242  unsigned int inputVectorSize, const int outputVectorDataType,
243  void* outputVector );
244 
245  /*!
246  \brief Create a tiff file from a matrix.
247  \param matrix The matrix.
248  \param normalize Enable/disable pixel normalization (8bit);
249  \param tifFileName Tif file name.
250  \param return true if OK, false on errors.
251  \ingroup rp_func
252  */
253  template< typename MatrixElementT >
255  const bool normalize, const std::string& fileName )
256  {
257  std::map<std::string, std::string> rInfo;
258  rInfo["URI"] = fileName;
259 
260  std::vector<te::rst::BandProperty*> bandsProperties;
261  if( normalize )
262  bandsProperties.push_back(new te::rst::BandProperty( 0, te::dt::UCHAR_TYPE, "" ));
263  else
264  bandsProperties.push_back(new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE, "" ));
265  bandsProperties[0]->m_colorInterp = te::rst::GrayIdxCInt;
266  bandsProperties[0]->m_noDataValue = -1.0 * std::numeric_limits<double>::max();
267 
268  te::rst::Grid* newgrid = new te::rst::Grid( matrix.getColumnsNumber(),
269  matrix.getLinesNumber(), 0, -1 );
270 
271  std::auto_ptr< te::rst::Raster > outputRasterPtr(
272  te::rst::RasterFactory::make( "GDAL", newgrid, bandsProperties, rInfo, 0, 0));
273  TERP_TRUE_OR_RETURN_FALSE( outputRasterPtr.get(), "Output raster creation error");
274 
275  unsigned int line = 0;
276  unsigned int col = 0;
277  const unsigned int nLines = matrix.getLinesNumber();
278  const unsigned int nCols = matrix.getColumnsNumber();
279  MatrixElementT matrixValue = 0;
280 
281  MatrixElementT gain = 1.0;
282  MatrixElementT offset = 0.0;
283  if( normalize )
284  {
285  MatrixElementT matrixValueMin = std::numeric_limits< MatrixElementT >::max();
286  MatrixElementT matrixValueMax = -1.0 * matrixValueMin;
287  for( line = 0 ; line < nLines ; ++line )
288  {
289  for( col = 0 ; col < nCols ; ++col )
290  {
291  matrixValue = matrix[ line ][ col ];
292  if( matrixValue < matrixValueMin )
293  matrixValueMin = matrixValue;
294  if( matrixValue > matrixValueMax )
295  matrixValueMax = matrixValue;
296  }
297  }
298 
299  if( matrixValueMax == matrixValueMin )
300  {
301  gain = 0.0;
302  offset = 0.0;
303  }
304  else
305  {
306  gain = 255.0 / ( matrixValueMax - matrixValueMin );
307  offset = -1.0 * ( matrixValueMin );
308  }
309  }
310 
311  const MatrixElementT min0 = 0;
312  const MatrixElementT max255 = 255;
313 
314  for( line = 0 ; line < nLines ; ++line )
315  {
316  for( col = 0 ; col < nCols ; ++col )
317  {
318  matrixValue = matrix[ line ][ col ];
319 
320  if( normalize )
321  {
322  matrixValue += offset;
323  matrixValue *= gain;
324  matrixValue = std::max( min0, matrixValue );
325  matrixValue = std::min( max255, matrixValue );
326  }
327 
328  outputRasterPtr->setValue( col, line, (double)matrixValue, 0 );
329  }
330  }
331 
332  return true;
333  }
334 
335  /*!
336  \brief Returns a json filename with spectral sensors parameters.
337  \ingroup rp_func
338  */
339  TERPEXPORT std::string GetSensorFilename();
340 
341  /*!
342  \brief Returns a vector os with band's names.
343  \ingroup rp_func
344  */
345  TERPEXPORT std::vector<std::string> GetBandNames();
346 
347  /*!
348  \brief Returns a map with spectral sensors parameters defined in SpectralSensor.json file.
349  \ingroup rp_func
350  */
351  TERPEXPORT std::map<std::string, SpectralSensorParams > getSensorParams();
352 
353  /*!
354  \brief Saves in SpectralSensor.json file the spectral sensors parameters.
355  \ingroup rp_func
356  */
357  TERPEXPORT void SaveSensorParams(std::map<std::string, SpectralSensorParams > &);
358 
359  /*!
360  \brief Returns the maximun and minimum reflectance values of a given sensor/band.
361  \ingroup rp_func
362  */
364 
365  /*!
366  \brief Returns the minimum reflectance value of a given sensor/band.
367  \ingroup rp_func
368  */
369  TERPEXPORT double GetSpectralBandMin(std::string bandName);
370 
371  /*!
372  \brief Returns the maximum reflectance value of a given sensor/band.
373  \ingroup rp_func
374  */
375  TERPEXPORT double GetSpectralBandMax(std::string bandName);
376 
377  /*!
378  \brief Returns the maximun and minimum digital numbers of a given sensor/band.
379  \ingroup rp_func
380  */
381  TERPEXPORT std::pair<double, double> GetDigitalNumberBandInfo(std::string bandName);
382 
383  /*!
384  \brief Returns the maximum digital number of a given sensor/band.
385  \ingroup rp_func
386  */
387  TERPEXPORT double GetDigitalNumberBandMax(std::string bandName);
388 
389  /*!
390  \brief Returns the minimum digital number of a given sensor/band.
391  \ingroup rp_func
392  */
393  TERPEXPORT double GetDigitalNumberBandMin(std::string bandName);
394 
395  /*!
396  \brief Normalizes one raster in a given interval.
397 
398  \param inputRaster The given raster.
399  \param nmin The new minimum value (default = 0.0).
400  \param nmax The new maximum value (default = 255.0).
401 
402  \return true if normalization occurs and false otherwise.
403  \ingroup rp_func
404  */
405  TERPEXPORT bool NormalizeRaster(te::rst::Raster& inputRaster, double nmin = 0.0, double nmax = 255.0);
406 
407  /*!
408  \brief RGB to IHS conversion.
409  \param inputRGBRaster The input raster.
410  \param redBandIdx The red band index.
411  \param greenBandIdx The red band index.
412  \param blueBandIdx The red band index.
413  \param rgbRangeMin The minimum RGB value.
414  \param rgbRangeMax The maximum RGB value.
415  \param outputIHSRaster An output pré-initiated raster (with the same dimensions of inputRGBRaster) where the IHS data will be written (double or float as the data type).
416  \return true if OK, false on errors.
417  \note The outputIHSRaster mas have a float or double data type.
418  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
419  \ingroup rp_func
420  */
421  TERPEXPORT bool ConvertRGB2IHS( const te::rst::Raster& inputRGBRaster,
422  const unsigned int redBandIdx, const unsigned int greenBandIdx,
423  const unsigned int blueBandIdx, const double rgbRangeMin,
424  const double rgbRangeMax, te::rst::Raster& outputIHSRaster );
425 
426  /*!
427  \brief IHS to RGB conversion.
428  \param inputIHSRaster The input raster.
429  \param intensityBandIdx The intensity band index.
430  \param hueBandIdx The hue band index.
431  \param saturationBandIdx The saturation band index.
432  \param rgbRangeMin The minimum RGB value.
433  \param rgbRangeMax The maximum RGB value.
434  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputIHSRaster) where the RGB data will be written.
435  \return true if OK, false on errors.
436  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
437  \ingroup rp_func
438  */
439  TERPEXPORT bool ConvertIHS2RGB( const te::rst::Raster& inputIHSRaster,
440  const unsigned int intensityBandIdx, const unsigned int hueBandIdx,
441  const unsigned int saturationBandIdx, const double rgbRangeMin,
442  const double rgbRangeMax, te::rst::Raster& outputRGBRaster );
443 
444  /*!
445  \brief Get the mean of band pixel values.
446  \param band The input raster band.
447  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
448  \param meanValue The calculated mean value.
449  \return true if OK, false on errors.
450  \note Optimized for rasters where the used bands have the same blocking scheme.
451  \ingroup rp_func
452  */
453  TERPEXPORT bool GetMeanValue(
454  const te::rst::Band& band,
455  const unsigned int maxThreads,
456  double& meanValue );
457 
458  /*!
459  \brief Get the standard deviation of band pixel values.
460  \param band The input raster band.
461  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
462  \param meanValuePtr A pointer to a pre-calculated band mean value or zero if it does not exist.
463  \param stdDevValue The calculated standard deviation value.
464  \return true if OK, false on errors.
465  \note Optimized for rasters where the used bands have the same blocking scheme.
466  \ingroup rp_func
467  */
469  const te::rst::Band& band,
470  const unsigned int maxThreads,
471  double const * const meanValuePtr,
472  double& stdDevValue );
473 
474  /*!
475  \brief Get the covariance of band pixel values.
476  \param band1 The input band 1.
477  \param band2 The input band 2.
478  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
479  \param mean1ValuePtr A pointer to a pre-calculated band1 mean value or zero if it does not exist.
480  \param mean2ValuePtr A pointer to a pre-calculated band2 mean value or zero if it does not exist.
481  \param covarianceValue The calculated covariance value.
482  \return true if OK, false on errors.
483  \note Optimized for rasters where the used bands have the same blocking scheme.
484  \ingroup rp_func
485  */
487  const te::rst::Band& band1,
488  const te::rst::Band& band2,
489  const unsigned int maxThreads,
490  double const * const mean1ValuePtr,
491  double const * const mean2ValuePtr,
492  double& covarianceValue );
493 
494  /*!
495  \brief Generate all principal components from the given input raster.
496  \param inputRaster Input raster.
497  \param inputRasterBands Input raster bands.
498  \param pcaMatrix The matrix generated over the principal components process.
499  \param pcaRaster The pré-initiated output PCA raster (with the same dimensions of inputRaster) and double as the data type.
500  \param pcaRasterBands Output raster bands.
501  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
502  \return true if OK, false on errors.
503  \note Optimized for rasters where the used bands have the same blocking scheme.
504  \ingroup rp_func
505  */
507  const te::rst::Raster& inputRaster,
508  const std::vector< unsigned int >& inputRasterBands,
509  boost::numeric::ublas::matrix< double >& pcaMatrix,
510  te::rst::Raster& pcaRaster,
511  const std::vector< unsigned int >& pcaRasterBands,
512  const unsigned int maxThreads );
513 
514  /*!
515  \brief Regenerate the original raster from its principal components.
516  \param pcaRaster The principal components raster (with the same dimensions of outputRaster).
517  \param pcaMatrix The matrix generated by the direct principal components process.
518  \param outputRaster The regenerated output raster (with the same dimentions.
519  \param outputRasterBands Output raster bands.
520  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
521  \return true if OK, false on errors.
522  \note Optimized for rasters where the used bands have the same blocking scheme.
523  \ingroup rp_func
524  */
526  const te::rst::Raster& pcaRaster,
527  const boost::numeric::ublas::matrix< double >& pcaMatrix,
528  te::rst::Raster& outputRaster,
529  const std::vector< unsigned int >& outputRasterBands,
530  const unsigned int maxThreads );
531 
532  /*!
533  \brief Remap pixel values using a remap function matrix.
534  \param inputRaster Input raster.
535  \param inputRasterBands Input raster bands.
536  \param remapMatrix The remap function matrix.
537  \param outputRaster The pré-initiated output raster (with the same dimentions of inputRaster).
538  \param outputRasterBands Output raster bands.
539  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
540  \return true if OK, false on errors.
541  \note Optimized for rasters where the used bands have the same blocking scheme.
542  \ingroup rp_func
543  */
544  TERPEXPORT bool RemapValues(
545  const te::rst::Raster& inputRaster,
546  const std::vector< unsigned int >& inputRasterBands,
547  const boost::numeric::ublas::matrix< double >& remapMatrix,
548  te::rst::Raster& outputRaster,
549  const std::vector< unsigned int >& outputRasterBands,
550  const unsigned int maxThreads );
551 
552  /*!
553  \brief Decompose a multi-band raster into a set of one-band rasters.
554  \param inputRaster Input raster.
555  \param inputRasterBands Input raster bands.
556  \param outputRastersInfos Output rasters connections infos. (one info for each decomposed band).
557  \param outputDataSourceType Output raster datasource type.
558  \param outputRastersPtrs Pointers to the generated outputs rasters.
559  \return true if OK, false on errors.
560  \ingroup rp_func
561  */
563  const te::rst::Raster& inputRaster,
564  const std::vector< unsigned int >& inputRasterBands,
565  const std::vector< std::map<std::string, std::string> > & outputRastersInfos,
566  const std::string& outputDataSourceType,
567  std::vector< boost::shared_ptr< te::rst::Raster > > & outputRastersPtrs );
568 
569  /*!
570  \brief Compose a set of bands into one multi-band raster.
571  \param feeder Input rasters feeder.
572  \param inputRasterBands Input raster bands (one band for each input raster).
573  \param interpMethod The interpolator method to use.
574  \param outputRasterInfo Output raster connection info.
575  \param outputDataSourceType Output raster datasource type.
576  \param outputRasterPtr A pointer to the generated output raster.
577  \return true if OK, false on errors.
578  \note The first raster Grid will be taken as reference for the composed raster.
579  \ingroup rp_func
580  */
581  TERPEXPORT bool ComposeBands(
583  const std::vector< unsigned int >& inputRasterBands,
584  const te::rst::Interpolator::Method& interpMethod,
585  const std::map<std::string, std::string>& outputRasterInfo,
586  const std::string& outputDataSourceType,
587  std::auto_ptr< te::rst::Raster >& outputRasterPtr );
588 
589  /*!
590  \brief Create a datailed extent from the given grid.
591  \param grid Input grid.
592  \param detailedExtent The created detailed extent.
593  \return true if ok, false on errors.
594  \ingroup rp_func
595  */
596  TERPEXPORT bool GetDetailedExtent( const te::rst::Grid& grid,
597  te::gm::LinearRing& detailedExtent );
598 
599  /*!
600  \brief Create a indexed (lines,columns) datailed extent from the given grid.
601  \param grid Input grid.
602  \param indexedDetailedExtent The created detailed extent.
603  \return true if ok, false on errors.
604  \ingroup rp_func
605  */
607  te::gm::LinearRing& indexedDetailedExtent );
608 
609  /*!
610  \brief Create a Wavele Atrous Filter.
611  \param filterType The filter type.
612  \return the created filter.
613  \ingroup rp_func
614  */
615  TERPEXPORT boost::numeric::ublas::matrix< double >
617 
618  /*!
619  \brief Generate all wavelet planes from the given input raster.
620  \param inputRaster Input raster.
621  \param inputRasterBands Input raster bands.
622  \param waveletRaster The pré-initiated output wavelet raster (with the same dimensions of inputRaster) and double as the data type.
623  \param levelsNumber The number of decomposed wavelet levels to generate for each input raster band;
624  \param filter The square filter to use.
625  \return true if OK, false on errors.
626  \note The band order of the generated wavelet levels: { [ band0-smoothed0, band0-wavelet0, ... , band0-smoothedN, band0-waveletN ], ... }
627  \note The number of bands of waveletRaster must be ( inputRasterBands.size() * 2 * levelsNumber ) at least.
628  \ingroup rp_func
629  */
631  const te::rst::Raster& inputRaster,
632  const std::vector< unsigned int >& inputRasterBands,
633  te::rst::Raster& waveletRaster,
634  const unsigned int levelsNumber,
635  const boost::numeric::ublas::matrix< double >& filter );
636 
637  /*!
638  \brief Regenerate the original raster from its wavelets planes.
639  \param waveletRaster The input wavelet raster (with the same dimensions of outputRaster).
640  \param levelsNumber The number of decomposed wavelet levels present inside the wavelet raster.
641  \param outputRaster The regenerated output raster.
642  \param outputRasterBands Output raster bands.
643  \return true if OK, false on errors.
644  \note The band order of the expected wavelet levels: { [ band0-smoothed0, band0-wavelet0, ... , band0-smoothedN, band0-waveletN ], ... }
645  \note The number of bands of waveletRaster must be ( outputRasterBands.size() * 2 * levelsNumber ) at least.
646  \note Only the wavelet bands and the last smoothed band are used.
647  \ingroup rp_func
648  */
650  const te::rst::Raster& waveletRaster,
651  const unsigned int levelsNumber,
652  te::rst::Raster& outputRaster,
653  const std::vector< unsigned int >& outputRasterBands );
654 
655  /*!
656  \brief Resample a subset of the raster, given a box.
657  \param inputRaster Input raster.
658  \param inputRasterBands Input raster bands to process.
659  \param interpMethod The method of interpolation. \sa te::rst::Interpolator
660  \param firstRow The starting row to make a subset of the image.
661  \param firstColumn The starting column to make a subset of the image.
662  \param height The height of the subset.
663  \param width The width of the subset.
664  \param newheight The resampled height of the new raster.
665  \param newwidth The resampled width of the new raster.
666  \param rinfo The parameters needed to build the output raster (see RasterFactory documentation).
667  \param dataSourceType Data source type (raster type. I.E. GDAL).
668  \param resampledRasterPtr The resampled raster pointer.
669  \return true if ok, false on errors.
670  */
672  const te::rst::Raster& inputRaster,
673  const std::vector< unsigned int >& inputRasterBands,
674  const te::rst::Interpolator::Method interpMethod,
675  const unsigned int firstRow,
676  const unsigned int firstColumn,
677  const unsigned int height,
678  const unsigned int width,
679  const unsigned int newheight,
680  const unsigned int newwidth,
681  const std::map<std::string, std::string>& rinfo,
682  const std::string& dataSourceType,
683  std::auto_ptr< te::rst::Raster >& resampledRasterPtr );
684 
685  /*!
686  \brief Returns the tie points converx hull area.
687  \param tiePoints Input tie-points (container of te::gm::GTParameters::TiePoint).
688  \param useTPSecondCoordPair If true the sencond tie-point component (te::gm::GTParameters::TiePoint::second) will be used for the area calcule, otherwize the first component will be used.
689  \return Returns the tie points converx hull area.
690  */
691  template< typename ContainerT >
692  double GetTPConvexHullArea( const ContainerT& tiePoints,
693  const bool useTPSecondCoordPair )
694  {
695  if( tiePoints.size() < 3 )
696  {
697  return 0;
698  }
699  else
700  {
702 
703  typename ContainerT::const_iterator it =
704  tiePoints.begin();
705  const typename ContainerT::const_iterator itE =
706  tiePoints.end();
707 
708  while( it != itE )
709  {
710  if( useTPSecondCoordPair )
711  points.add(new te::gm::Point(it->second.x, it->second.y));
712  else
713  points.add(new te::gm::Point(it->first.x, it->first.y));
714 
715  ++it;
716  }
717 
718  std::auto_ptr< te::gm::Geometry > convexHullPolPtr( points.convexHull() );
719 
720  if( dynamic_cast< te::gm::Surface* >( convexHullPolPtr.get() ) )
721  {
722  return ( (te::gm::Surface*)( convexHullPolPtr.get() ) )->getArea();
723  }
724  else
725  {
726  return 0.0;
727  }
728  }
729  }
730 
731  /*!
732  \brief Create a fixed step sequential color palette.
733  \param paletteSize The desired palette size.
734  \param palette The crated palette.
735  */
737  const double paletteSize,
738  const bool randomize,
739  std::vector< te::rst::BandProperty::ColorEntry >& palette );
740 
741  /*!
742  \brief Generate all wavelet planes from the given input raster.
743  \param inputRaster Input raster.
744  \param inputRasterBand Input raster band.
745  \param createPaletteRaster If true a paletted raster will be created instead of a multi-band raster..
746  \param slicesNumber The number of historgram slices to create;
747  \param eqHistogram If true, the input raster will historgram will be equalized before the slicing process.
748  \param rasterInfo The output raster info (specific driver info).
749  \param rasterType The output raster type (specific driver name - See te::rst::RasterFactory dictorary for more info).
750  \param enableProgress Enable/disable the progress interface.
751  \param palettePtr A pointer to an optional user given palette (if null, an fixed step pallete will be generated).
752  \param outRasterPtr The output sliced raster pointer.
753  \return true if OK, false on errors.
754  \ingroup rp_func
755  */
757  const te::rst::Raster& inputRaster,
758  const unsigned int inputRasterBand,
759  const bool createPaletteRaster,
760  const unsigned int slicesNumber,
761  const bool eqHistogram,
762  const std::map< std::string, std::string >& rasterInfo,
763  const std::string& rasterType,
764  const bool enableProgress,
765  std::vector< te::rst::BandProperty::ColorEntry > const * const palettePtr,
766  std::auto_ptr< te::rst::Raster >& outRasterPtr );
767 
768  } // end namespace rp
769 } // end namespace te
770 
771 #endif // __TERRALIB_RP_INTERNAL_FUNCTIONS_H
772 
TERPEXPORT bool GetMeanValue(const te::rst::Band &band, const unsigned int maxThreads, double &meanValue)
Get the mean of band pixel values.
TERPEXPORT double GetDigitalNumberBandMax(std::string bandName)
Returns the maximum digital number of a given sensor/band.
Index into a lookup table.
Definition: Enums.h:57
A raster band description.
Definition: BandProperty.h:61
virtual Geometry * convexHull() const
This method calculates the Convex Hull of a geometry.
double GetTPConvexHullArea(const ContainerT &tiePoints, const bool useTPSecondCoordPair)
Returns the tie points converx hull area.
Definition: Functions.h:692
Spline filter type.
Definition: Functions.h:76
TERPEXPORT void SaveSensorParams(std::map< std::string, SpectralSensorParams > &)
Saves in SpectralSensor.json file the spectral sensors parameters.
Triangle filter type.
Definition: Functions.h:77
TERPEXPORT bool ConvertIHS2RGB(const te::rst::Raster &inputIHSRaster, const unsigned int intensityBandIdx, const unsigned int hueBandIdx, const unsigned int saturationBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputRGBRaster)
IHS to RGB conversion.
void TERPEXPORT GetDataTypeRange(const int dataType, double &min, double &max)
Returns the real data type range (all values that can be represented by the given data type)...
Definition: Functions.h:215
TERPEXPORT bool ComposeBands(te::rp::FeederConstRaster &feeder, const std::vector< unsigned int > &inputRasterBands, const te::rst::Interpolator::Method &interpMethod, const std::map< std::string, std::string > &outputRasterInfo, const std::string &outputDataSourceType, std::auto_ptr< te::rst::Raster > &outputRasterPtr)
Compose a set of bands into one multi-band raster.
bool TERPEXPORT CreateNewMemRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, RasterHandler &outRasterHandler)
Create a new raster into a new memory datasource.
TERPEXPORT std::vector< std::string > GetBandNames()
Returns a vector os with band&#39;s names.
bool TERPEXPORT CreateNewGdalRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, const std::string &fileName, std::auto_ptr< te::rst::Raster > &outRasterPtr)
Create a new raster into a GDAL datasource.
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
TERPEXPORT std::pair< double, double > GetDigitalNumberBandInfo(std::string bandName)
Returns the maximun and minimum digital numbers of a given sensor/band.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:119
TERPEXPORT bool DirectPrincipalComponents(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &pcaRaster, const std::vector< unsigned int > &pcaRasterBands, const unsigned int maxThreads)
Generate all principal components from the given input raster.
TERPEXPORT bool DecomposeBands(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< std::map< std::string, std::string > > &outputRastersInfos, const std::string &outputDataSourceType, std::vector< boost::shared_ptr< te::rst::Raster > > &outputRastersPtrs)
Decompose a multi-band raster into a set of one-band rasters.
TERPEXPORT double GetDigitalNumberBandMin(std::string bandName)
Returns the minimum digital number of a given sensor/band.
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
TERPEXPORT double GetSpectralBandMax(std::string bandName)
Returns the maximum reflectance value of a given sensor/band.
TERPEXPORT bool RemapValues(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const boost::numeric::ublas::matrix< double > &remapMatrix, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands, const unsigned int maxThreads)
Remap pixel values using a remap function matrix.
TERPEXPORT bool ConvertRGB2IHS(const te::rst::Raster &inputRGBRaster, const unsigned int redBandIdx, const unsigned int greenBandIdx, const unsigned int blueBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputIHSRaster)
RGB to IHS conversion.
#define TERP_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged and a return of context wi...
Definition: Macros.h:184
bool CreateRasterFileFromMatrix(const te::rp::Matrix< MatrixElementT > &matrix, const bool normalize, const std::string &fileName)
Create a tiff file from a matrix.
Definition: Functions.h:254
bool TERPEXPORT Copy2DiskRaster(const te::rst::Raster &inputRaster, const std::string &fileName)
Create a new raster into a GDAL datasource.
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
TERPEXPORT std::map< std::string, SpectralSensorParams > getSensorParams()
Returns a map with spectral sensors parameters defined in SpectralSensor.json file.
A point with x and y coordinate values.
Definition: Point.h:50
TERPEXPORT bool NormalizeRaster(te::rst::Raster &inputRaster, double nmin=0.0, double nmax=255.0)
Normalizes one raster in a given interval.
An abstract class for raster data strucutures.
Definition: Raster.h:71
unsigned int getColumnsNumber() const
The number of current matrix columns.
Definition: Matrix.h:681
TERPEXPORT bool InverseWaveletAtrous(const te::rst::Raster &waveletRaster, const unsigned int levelsNumber, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands)
Regenerate the original raster from its wavelets planes.
WaveletAtrousFilterType
Wavelet Atrous Filter types.
Definition: Functions.h:73
URI C++ Library.
TERPEXPORT bool DirectWaveletAtrous(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, te::rst::Raster &waveletRaster, const unsigned int levelsNumber, const boost::numeric::ublas::matrix< double > &filter)
Generate all wavelet planes from the given input raster.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Raster tuple.
void TERPEXPORT Convert2DoublesVector(void *inputVector, const int inputVectorDataType, unsigned int inputVectorSize, double *outputVector)
Convert vector elements.
RasterHandler.
Definition: RasterHandler.h:47
bool TERPEXPORT CreateNewRaster(const te::rst::Grid &rasterGrid, const std::vector< te::rst::BandProperty * > &bandsProperties, const std::map< std::string, std::string > &rasterInfo, const std::string &rasterType, std::auto_ptr< te::rst::Raster > &outRasterPtr)
Create a new raster into the givem data source.
A raster band description.
Definition: Band.h:63
TERPEXPORT bool GetDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &detailedExtent)
Create a datailed extent from the given grid.
Generic template matrix.
SpectralSensorParams(const int &band, const double &lower, const double &upper, const double &min, const double &max)
Definition: Functions.h:84
TERPEXPORT void CreateFixedStepPalette(const double paletteSize, const bool randomize, std::vector< te::rst::BandProperty::ColorEntry > &palette)
Create a fixed step sequential color palette.
Invalid filter type.
Definition: Functions.h:75
TERPEXPORT boost::numeric::ublas::matrix< double > CreateWaveletAtrousFilter(const WaveletAtrousFilterType &filterType)
Create a Wavele Atrous Filter.
TERPEXPORT bool GetCovarianceValue(const te::rst::Band &band1, const te::rst::Band &band2, const unsigned int maxThreads, double const *const mean1ValuePtr, double const *const mean2ValuePtr, double &covarianceValue)
Get the covariance of band pixel values.
Configuration flags for the Raster Processing module of TerraLib.
TERPEXPORT double GetSpectralBandMin(std::string bandName)
Returns the minimum reflectance value of a given sensor/band.
TERPEXPORT SpectralSensorParams GetSpectralBandInfo(std::string bandName)
Returns the maximun and minimum reflectance values of a given sensor/band.
Feeder from a input rasters.
Definition: FeedersRaster.h:46
void add(Geometry *g)
It adds the geometry into the collection.
A generic template matrix.
Definition: Matrix.h:54
TERPEXPORT bool GetIndexedDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &indexedDetailedExtent)
Create a indexed (lines,columns) datailed extent from the given grid.
TERPEXPORT bool InversePrincipalComponents(const te::rst::Raster &pcaRaster, const boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands, const unsigned int maxThreads)
Regenerate the original raster from its principal components.
TERPEXPORT bool RasterResample(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const te::rst::Interpolator::Method interpMethod, const unsigned int firstRow, const unsigned int firstColumn, const unsigned int height, const unsigned int width, const unsigned int newheight, const unsigned int newwidth, const std::map< std::string, std::string > &rinfo, const std::string &dataSourceType, std::auto_ptr< te::rst::Raster > &resampledRasterPtr)
Resample a subset of the raster, given a box.
static Raster * make()
It creates and returns an empty raster with default raster driver.
Raster objects feeders.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
TERPEXPORT std::string GetSensorFilename()
Returns a json filename with spectral sensors parameters.
unsigned int getLinesNumber() const
The number of current matrix lines.
Definition: Matrix.h:674
TERPEXPORT bool GetStdDevValue(const te::rst::Band &band, const unsigned int maxThreads, double const *const meanValuePtr, double &stdDevValue)
Get the standard deviation of band pixel values.
TERPEXPORT bool RasterSlicing(const te::rst::Raster &inputRaster, const unsigned int inputRasterBand, const bool createPaletteRaster, const unsigned int slicesNumber, const bool eqHistogram, const std::map< std::string, std::string > &rasterInfo, const std::string &rasterType, const bool enableProgress, std::vector< te::rst::BandProperty::ColorEntry > const *const palettePtr, std::auto_ptr< te::rst::Raster > &outRasterPtr)
Generate all wavelet planes from the given input raster.
void TERPEXPORT ConvertDoublesVector(double *inputVector, unsigned int inputVectorSize, const int outputVectorDataType, void *outputVector)
Convert a doubles vector.
Surface is an abstract class that represents a 2-dimensional geometric objects.
Definition: Surface.h:54