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::unique_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::unique_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::unique_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, static_cast<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  */
363  TERPEXPORT SpectralSensorParams GetSpectralBandInfo(std::string bandName);
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 Normalizes a raster in a given interval.
409 
410  \param inputRaster The given raster.
411 
412  \return a raster normalized.
413  \ingroup rp_func
414  */
416 
417  /*!
418  \brief RGB to IHS conversion.
419  \param inputRGBRaster The input raster.
420  \param redBandIdx The red band index.
421  \param greenBandIdx The red band index.
422  \param blueBandIdx The red band index.
423  \param rgbRangeMin The minimum RGB value.
424  \param rgbRangeMax The maximum RGB value.
425  \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).
426  \return true if OK, false on errors.
427  \note The outputIHSRaster mas have a float or double data type.
428  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
429  \ingroup rp_func
430  */
431  TERPEXPORT bool ConvertRGB2IHS( const te::rst::Raster& inputRGBRaster,
432  const unsigned int redBandIdx, const unsigned int greenBandIdx,
433  const unsigned int blueBandIdx, const double rgbRangeMin,
434  const double rgbRangeMax, te::rst::Raster& outputIHSRaster );
435 
436  /*!
437  \brief RGB to IHS conversion.
438  \param inputRedRaster The input red raster.
439  \param redBandIdx The red band index.
440  \param inputGreenRaster The input green raster.
441  \param greenBandIdx The green band index.
442  \param inputBlueRaster The input blue raster.
443  \param blueBandIdx The blue band index.
444  \param rgbRangeMin The minimum RGB value.
445  \param rgbRangeMax The maximum RGB value.
446  \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).
447  \return true if OK, false on errors.
448  \note The outputIHSRaster mas have a float or double data type.
449  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
450  \ingroup rp_func
451  */
452  TERPEXPORT bool ConvertRGB2IHS(const te::rst::Raster& inputRedRaster, const unsigned int redBandIdx,
453  const te::rst::Raster& inputGreenRaster, const unsigned int greenBandIdx,
454  const te::rst::Raster& inputBlueRaster, const unsigned int blueBandIdx,
455  const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster& outputIHSRaster);
456 
457  /*!
458  \brief IHS to RGB conversion.
459  \param inputIHSRaster The input raster.
460  \param intensityBandIdx The intensity band index.
461  \param hueBandIdx The hue band index.
462  \param saturationBandIdx The saturation band index.
463  \param rgbRangeMin The minimum RGB value.
464  \param rgbRangeMax The maximum RGB value.
465  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputIHSRaster) where the RGB data will be written.
466  \return true if OK, false on errors.
467  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
468  \ingroup rp_func
469  */
470  TERPEXPORT bool ConvertIHS2RGB( const te::rst::Raster& inputIHSRaster,
471  const unsigned int intensityBandIdx, const unsigned int hueBandIdx,
472  const unsigned int saturationBandIdx, const double rgbRangeMin,
473  const double rgbRangeMax, te::rst::Raster& outputRGBRaster );
474 
475  /*!
476  \brief IHS to RGB conversion.
477  \param inputIRaster The input intensity raster.
478  \param intensityBandIdx The intensity band index.
479  \param inputHRaster The input hue raster.
480  \param hueBandIdx The hue band index.
481  \param inputSRaster The input saturation raster.
482  \param saturationBandIdx The saturation band index.
483  \param rgbRangeMin The minimum RGB value.
484  \param rgbRangeMax The maximum RGB value.
485  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputIHSRaster) where the RGB data will be written.
486  \return true if OK, false on errors.
487  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
488  \ingroup rp_func
489  */
490  TERPEXPORT bool ConvertIHS2RGB(const te::rst::Raster& inputIRaster, const unsigned int intensityBandIdx,
491  const te::rst::Raster& inputHRaster, const unsigned int hueBandIdx,
492  const te::rst::Raster& inputSRaster, const unsigned int saturationBandIdx,
493  const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster& outputRGBRaster);
494 
495  /*!
496  \brief RGB to HLS conversion.
497  \param inputRGBRaster The input raster.
498  \param redBandIdx The red band index.
499  \param greenBandIdx The red band index.
500  \param blueBandIdx The red band index.
501  \param rgbRangeMin The minimum RGB value.
502  \param rgbRangeMax The maximum RGB value.
503  \param outputHLSRaster An output pré-initiated raster (with the same dimensions of inputRGBRaster) where the HLS data will be written (double or float as the data type).
504  \return true if OK, false on errors.
505  \note The outputHLSRaster mas have a float or double data type.
506  \ingroup rp_func
507  */
508  TERPEXPORT bool ConvertRGB2HLS(const te::rst::Raster& inputRGBRaster,
509  const unsigned int redBandIdx, const unsigned int greenBandIdx,
510  const unsigned int blueBandIdx, const double rgbRangeMin,
511  const double rgbRangeMax, te::rst::Raster& outputHLSRaster);
512 
513  /*!
514  \brief RGB to HLS conversion.
515  \param inputRedRaster The input red raster.
516  \param redBandIdx The red band index.
517  \param inputGreenRaster The input green raster.
518  \param greenBandIdx The green band index.
519  \param inputBlueRaster The input blue raster.
520  \param blueBandIdx The blue band index.
521  \param rgbRangeMin The minimum RGB value.
522  \param rgbRangeMax The maximum RGB value.
523  \param outputHLSRaster An output pré-initiated raster (with the same dimensions of inputRGBRaster) where the HLS data will be written (double or float as the data type).
524  \return true if OK, false on errors.
525  \note The outputHLSRaster mas have a float or double data type.
526  \ingroup rp_func
527  */
528  TERPEXPORT bool ConvertRGB2HLS(const te::rst::Raster& inputRedRaster, const unsigned int redBandIdx,
529  const te::rst::Raster& inputGreenRaster, const unsigned int greenBandIdx,
530  const te::rst::Raster& inputBlueRaster, const unsigned int blueBandIdx,
531  const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster& outputHLSRaster);
532 
533  /*!
534  \brief HLS to RGB conversion.
535  \param inputHLSRaster The input raster.
536  \param hueBandIdx The hue band index.
537  \param lightBandIdx The light band index.
538  \param saturationBandIdx The saturation band index.
539  \param rgbRangeMin The minimum RGB value.
540  \param rgbRangeMax The maximum RGB value.
541  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputHLSRaster) where the RGB data will be written.
542  \return true if OK, false on errors.
543  \ingroup rp_func
544  */
545  TERPEXPORT bool ConvertHLS2RGB(const te::rst::Raster& inputHLSRaster,
546  const unsigned int hueBandIdx, const unsigned int lightBandIdx,
547  const unsigned int saturationBandIdx, const double rgbRangeMin,
548  const double rgbRangeMax, te::rst::Raster& outputRGBRaster);
549 
550  /*!
551  \brief HLS to RGB conversion.
552  \param inputHRaster The input hue raster.
553  \param hueBandIdx The hue band index.
554  \param inputLRaster The input light raster.
555  \param lightBandIdx The light band index.
556  \param inputSRaster The input saturation raster.
557  \param saturationBandIdx The saturation band index.
558  \param rgbRangeMin The minimum RGB value.
559  \param rgbRangeMax The maximum RGB value.
560  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputHLSRaster) where the RGB data will be written.
561  \return true if OK, false on errors.
562  \ingroup rp_func
563  */
564  TERPEXPORT bool ConvertHLS2RGB(const te::rst::Raster& inputHRaster, const unsigned int hueBandIdx,
565  const te::rst::Raster& inputLRaster, const unsigned int lightBandIdx,
566  const te::rst::Raster& inputSRaster, const unsigned int saturationBandIdx,
567  const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster& outputRGBRaster);
568 
569  /*!
570  \brief Get the mean of band pixel values.
571  \param band The input raster band.
572  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
573  \param meanValue The calculated mean value.
574  \return true if OK, false on errors.
575  \note Optimized for rasters where the used bands have the same blocking scheme.
576  \ingroup rp_func
577  */
578  TERPEXPORT bool GetMeanValue(
579  const te::rst::Band& band,
580  const unsigned int maxThreads,
581  double& meanValue );
582 
583  /*!
584  \brief Get the standard deviation of band pixel values.
585  \param band The input raster band.
586  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
587  \param meanValuePtr A pointer to a pre-calculated band mean value or zero if it does not exist.
588  \param stdDevValue The calculated standard deviation value.
589  \return true if OK, false on errors.
590  \note Optimized for rasters where the used bands have the same blocking scheme.
591  \ingroup rp_func
592  */
594  const te::rst::Band& band,
595  const unsigned int maxThreads,
596  double const * const meanValuePtr,
597  double& stdDevValue );
598 
599  /*!
600  \brief Get the covariance of band pixel values.
601  \param band1 The input band 1.
602  \param band2 The input band 2.
603  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
604  \param mean1ValuePtr A pointer to a pre-calculated band1 mean value or zero if it does not exist.
605  \param mean2ValuePtr A pointer to a pre-calculated band2 mean value or zero if it does not exist.
606  \param covarianceValue The calculated covariance value.
607  \return true if OK, false on errors.
608  \note Optimized for rasters where the used bands have the same blocking scheme.
609  \ingroup rp_func
610  */
612  const te::rst::Band& band1,
613  const te::rst::Band& band2,
614  const unsigned int maxThreads,
615  double const * const mean1ValuePtr,
616  double const * const mean2ValuePtr,
617  double& covarianceValue );
618 
619  /*!
620  \brief Generate all principal components from the given input raster.
621  \param inputRaster Input raster.
622  \param inputRasterBands Input raster bands.
623  \param pcaMatrix The matrix generated over the principal components process.
624  \param pcaRaster The pré-initiated output PCA raster (with the same dimensions of inputRaster) and double as the data type.
625  \param pcaRasterBands Output raster bands.
626  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
627  \return true if OK, false on errors.
628  \note Optimized for rasters where the used bands have the same blocking scheme.
629  \ingroup rp_func
630  */
632  const te::rst::Raster& inputRaster,
633  const std::vector< unsigned int >& inputRasterBands,
634  boost::numeric::ublas::matrix< double >& pcaMatrix,
635  te::rst::Raster& pcaRaster,
636  const std::vector< unsigned int >& pcaRasterBands,
637  const unsigned int maxThreads );
638 
639  /*!
640  \brief Regenerate the original raster from its principal components.
641  \param pcaRaster The principal components raster (with the same dimensions of outputRaster).
642  \param pcaMatrix The matrix generated by the direct principal components process.
643  \param outputRaster The regenerated output raster (with the same dimentions.
644  \param outputRasterBands Output raster bands.
645  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
646  \return true if OK, false on errors.
647  \note Optimized for rasters where the used bands have the same blocking scheme.
648  \ingroup rp_func
649  */
651  const te::rst::Raster& pcaRaster,
652  const boost::numeric::ublas::matrix< double >& pcaMatrix,
653  te::rst::Raster& outputRaster,
654  const std::vector< unsigned int >& outputRasterBands,
655  const unsigned int maxThreads );
656 
657  /*!
658  \brief Remap pixel values using a remap function matrix.
659  \param inputRaster Input raster.
660  \param inputRasterBands Input raster bands.
661  \param remapMatrix The remap function matrix.
662  \param outputRaster The pré-initiated output raster (with the same dimentions of inputRaster).
663  \param outputRasterBands Output raster bands.
664  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
665  \return true if OK, false on errors.
666  \note Optimized for rasters where the used bands have the same blocking scheme.
667  \ingroup rp_func
668  */
669  TERPEXPORT bool RemapValues(
670  const te::rst::Raster& inputRaster,
671  const std::vector< unsigned int >& inputRasterBands,
672  const boost::numeric::ublas::matrix< double >& remapMatrix,
673  te::rst::Raster& outputRaster,
674  const std::vector< unsigned int >& outputRasterBands,
675  const unsigned int maxThreads );
676 
677  /*!
678  \brief Decompose a multi-band raster into a set of one-band rasters.
679  \param inputRaster Input raster.
680  \param inputRasterBands Input raster bands.
681  \param outputRastersInfos Output rasters connections infos. (one info for each decomposed band).
682  \param outputDataSourceType Output raster datasource type.
683  \param outputRastersPtrs Pointers to the generated outputs rasters.
684  \return true if OK, false on errors.
685  \ingroup rp_func
686  */
688  const te::rst::Raster& inputRaster,
689  const std::vector< unsigned int >& inputRasterBands,
690  const std::vector< std::map<std::string, std::string> > & outputRastersInfos,
691  const std::string& outputDataSourceType,
692  std::vector< boost::shared_ptr< te::rst::Raster > > & outputRastersPtrs );
693 
694  /*!
695  \brief Compose a set of bands into one multi-band raster.
696  \param feeder Input rasters feeder.
697  \param inputRasterBands Input raster bands (one band for each input raster).
698  \param interpMethod The interpolator method to use.
699  \param outputRasterInfo Output raster connection info.
700  \param outputDataSourceType Output raster datasource type.
701  \param outputRasterPtr A pointer to the generated output raster.
702  \return true if OK, false on errors.
703  \note The first raster Grid will be taken as reference for the composed raster.
704  \ingroup rp_func
705  */
706  TERPEXPORT bool ComposeBands(
708  const std::vector< unsigned int >& inputRasterBands,
709  const te::rst::Interpolator::Method& interpMethod,
710  const std::map<std::string, std::string>& outputRasterInfo,
711  const std::string& outputDataSourceType,
712  std::unique_ptr< te::rst::Raster >& outputRasterPtr );
713 
714  /*!
715  \brief Create a datailed extent from the given grid.
716  \param grid Input grid.
717  \param detailedExtent The created detailed extent.
718  \return true if ok, false on errors.
719  \ingroup rp_func
720  */
721  TERPEXPORT bool GetDetailedExtent( const te::rst::Grid& grid,
722  te::gm::LinearRing& detailedExtent );
723 
724  /*!
725  \brief Create a indexed (lines,columns) datailed extent from the given grid.
726  \param grid Input grid.
727  \param indexedDetailedExtent The created detailed extent.
728  \return true if ok, false on errors.
729  \ingroup rp_func
730  */
732  te::gm::LinearRing& indexedDetailedExtent );
733 
734  /*!
735  \brief Create a Wavele Atrous Filter.
736  \param filterType The filter type.
737  \return the created filter.
738  \ingroup rp_func
739  */
740  TERPEXPORT boost::numeric::ublas::matrix< double >
742 
743  /*!
744  \brief Generate all wavelet planes from the given input raster.
745  \param inputRaster Input raster.
746  \param inputRasterBands Input raster bands.
747  \param waveletRaster The pré-initiated output wavelet raster (with the same dimensions of inputRaster) and double as the data type.
748  \param levelsNumber The number of decomposed wavelet levels to generate for each input raster band;
749  \param filter The square filter to use.
750  \return true if OK, false on errors.
751  \note The band order of the generated wavelet levels: { [ band0-smoothed0, band0-wavelet0, ... , band0-smoothedN, band0-waveletN ], ... }
752  \note The number of bands of waveletRaster must be ( inputRasterBands.size() * 2 * levelsNumber ) at least.
753  \ingroup rp_func
754  */
756  const te::rst::Raster& inputRaster,
757  const std::vector< unsigned int >& inputRasterBands,
758  te::rst::Raster& waveletRaster,
759  const unsigned int levelsNumber,
760  const boost::numeric::ublas::matrix< double >& filter );
761 
762  /*!
763  \brief Regenerate the original raster from its wavelets planes.
764  \param waveletRaster The input wavelet raster (with the same dimensions of outputRaster).
765  \param levelsNumber The number of decomposed wavelet levels present inside the wavelet raster.
766  \param outputRaster The regenerated output raster.
767  \param outputRasterBands Output raster bands.
768  \return true if OK, false on errors.
769  \note The band order of the expected wavelet levels: { [ band0-smoothed0, band0-wavelet0, ... , band0-smoothedN, band0-waveletN ], ... }
770  \note The number of bands of waveletRaster must be ( outputRasterBands.size() * 2 * levelsNumber ) at least.
771  \note Only the wavelet bands and the last smoothed band are used.
772  \ingroup rp_func
773  */
775  const te::rst::Raster& waveletRaster,
776  const unsigned int levelsNumber,
777  te::rst::Raster& outputRaster,
778  const std::vector< unsigned int >& outputRasterBands );
779 
780  /*!
781  \brief Resample a subset of the raster, given a box.
782  \param inputRaster Input raster.
783  \param inputRasterBands Input raster bands to process.
784  \param interpMethod The method of interpolation. \sa te::rst::Interpolator
785  \param firstRow The starting row to make a subset of the image.
786  \param firstColumn The starting column to make a subset of the image.
787  \param height The height of the subset.
788  \param width The width of the subset.
789  \param newheight The resampled height of the new raster.
790  \param newwidth The resampled width of the new raster.
791  \param rinfo The parameters needed to build the output raster (see RasterFactory documentation).
792  \param dataSourceType Data source type (raster type. I.E. GDAL).
793  \param resampledRasterPtr The resampled raster pointer.
794  \return true if ok, false on errors.
795  */
797  const te::rst::Raster& inputRaster,
798  const std::vector< unsigned int >& inputRasterBands,
799  const te::rst::Interpolator::Method interpMethod,
800  const unsigned int firstRow,
801  const unsigned int firstColumn,
802  const unsigned int height,
803  const unsigned int width,
804  const unsigned int newheight,
805  const unsigned int newwidth,
806  const std::map<std::string, std::string>& rinfo,
807  const std::string& dataSourceType,
808  std::unique_ptr< te::rst::Raster >& resampledRasterPtr );
809 
810  /*!
811  \brief Returns the tie points converx hull area.
812  \param tiePoints Input tie-points (container of te::gm::GTParameters::TiePoint).
813  \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.
814  \return Returns the tie points converx hull area.
815  */
816  template< typename ContainerT >
817  double GetTPConvexHullArea( const ContainerT& tiePoints,
818  const bool useTPSecondCoordPair )
819  {
820  if( tiePoints.size() < 3 )
821  {
822  return 0;
823  }
824  else
825  {
827 
828  typename ContainerT::const_iterator it =
829  tiePoints.begin();
830  const typename ContainerT::const_iterator itE =
831  tiePoints.end();
832 
833  while( it != itE )
834  {
835  if( useTPSecondCoordPair )
836  points.add(new te::gm::Point(it->second.x, it->second.y));
837  else
838  points.add(new te::gm::Point(it->first.x, it->first.y));
839 
840  ++it;
841  }
842 
843  std::unique_ptr< te::gm::Geometry > convexHullPolPtr( points.convexHull() );
844 
845  if( dynamic_cast< te::gm::Surface* >( convexHullPolPtr.get() ) )
846  {
847  return ( (te::gm::Surface*)( convexHullPolPtr.get() ) )->getArea();
848  }
849  else
850  {
851  return 0.0;
852  }
853  }
854  }
855 
856  /*!
857  \brief Create a fixed step sequential color palette.
858  \param paletteSize The desired palette size.
859  \param palette The crated palette.
860  */
862  const unsigned int paletteSize,
863  const bool randomize,
864  std::vector< te::rst::BandProperty::ColorEntry >& palette );
865 
866  /*!
867  \brief Generate all wavelet planes from the given input raster.
868  \param inputRaster Input raster.
869  \param inputRasterBand Input raster band.
870  \param createPaletteRaster If true a paletted raster will be created instead of a multi-band raster..
871  \param slicesNumber The number of histogram slices to create;
872  \param eqHistogram If true, the input raster will be equalized before the slicing process.
873  \param rasterInfo The output raster info (specific driver info).
874  \param rasterType The output raster type (specific driver name - See te::rst::RasterFactory dictorary for more info).
875  \param enableProgress Enable/disable the progress interface.
876  \param palettePtr A pointer to an optional user given palette (if null, an fixed step pallete will be generated).
877  \param outRasterPtr The output sliced raster pointer.
878  \param limits slice limits values
879  \return true if OK, false on errors.
880  \ingroup rp_func
881  */
883  const te::rst::Raster& inputRaster,
884  const unsigned int inputRasterBand,
885  const bool createPaletteRaster,
886  const unsigned int slicesNumber,
887  const bool eqHistogram,
888  const std::map< std::string, std::string >& rasterInfo,
889  const std::string& rasterType,
890  const bool enableProgress,
891  std::vector< te::rst::BandProperty::ColorEntry > const * const palettePtr,
892  std::unique_ptr< te::rst::Raster >& outRasterPtr,
893  std::map< double, double > limits);
894 
895  } // end namespace rp
896 } // end namespace te
897 
898 #endif // __TERRALIB_RP_INTERNAL_FUNCTIONS_H
899 
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
double GetTPConvexHullArea(const ContainerT &tiePoints, const bool useTPSecondCoordPair)
Returns the tie points converx hull area.
Definition: Functions.h:817
Spline filter type.
Definition: Functions.h:76
TERPEXPORT void SaveSensorParams(std::map< std::string, SpectralSensorParams > &)
Saves in SpectralSensor.json file the spectral sensors parameters.
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::unique_ptr< te::rst::Raster > &outRasterPtr, std::map< double, double > limits)
Generate all wavelet planes from the given input raster.
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
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.
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
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::unique_ptr< te::rst::Raster > &outputRasterPtr)
Compose a set of bands into one multi-band raster.
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:185
TERPEXPORT bool ConvertHLS2RGB(const te::rst::Raster &inputHLSRaster, const unsigned int hueBandIdx, const unsigned int lightBandIdx, const unsigned int saturationBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputRGBRaster)
HLS to RGB conversion.
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
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
virtual Geometry * convexHull() const _NOEXCEPT_OP(false)
This method calculates the Convex Hull of a geometry.
TerraLib.
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
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 bool ConvertRGB2HLS(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 &outputHLSRaster)
RGB to HLS conversion.
bool TERPEXPORT CreateNewRaster(const te::rst::Grid &rasterGrid, const std::vector< te::rst::BandProperty * > &bandsProperties, const std::string &outDataSetName, const std::string &dataSourceType, RasterHandler &outRasterHandler)
Create a new raster into the givem data source.
Invalid filter type.
Definition: Functions.h:75
TERPEXPORT boost::numeric::ublas::matrix< double > CreateWaveletAtrousFilter(const WaveletAtrousFilterType &filterType)
Create a Wavele Atrous Filter.
unsigned int getLinesNumber() const
The number of current matrix lines.
Definition: Matrix.h:791
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.
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::unique_ptr< te::rst::Raster > &resampledRasterPtr)
Resample a subset of the raster, given a box.
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:55
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 void CreateFixedStepPalette(const unsigned int paletteSize, const bool randomize, std::vector< te::rst::BandProperty::ColorEntry > &palette)
Create a fixed step sequential color palette.
bool TERPEXPORT CreateNewGdalRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, const std::string &fileName, RasterHandler &outRasterHandler)
Create a new raster into a GDAL datasource.
static Raster * make()
It creates and returns an empty raster with default raster driver.
Raster objects feeders.
unsigned int getColumnsNumber() const
The number of current matrix columns.
Definition: Matrix.h:798
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.
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.
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