Go to the documentation of this file.
25 #ifndef __TERRALIB_RP_INTERNAL_FUNCTIONS_H
26 #define __TERRALIB_RP_INTERNAL_FUNCTIONS_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 "../raster/PositionIterator.h"
43 #include "../srs/Converter.h"
44 #include "../geometry/LinearRing.h"
45 #include "../geometry/GTParameters.h"
46 #include "../geometry/MultiPoint.h"
47 #include "../geometry/Surface.h"
57 #include <boost/numeric/ublas/matrix.hpp>
58 #include <boost/shared_ptr.hpp>
85 SpectralSensorParams(
const int &band,
const double &lower,
const double &upper,
const double &min,
const double &max) :
112 const std::vector< te::rst::BandProperty* >& bandsProperties,
113 const std::string& outDataSetName,
114 const std::string& dataSourceType,
129 const std::vector< te::rst::BandProperty* >& bandsProperties,
130 const std::string& outDataSetName,
146 const std::vector< te::rst::BandProperty* >& bandsProperties,
147 const std::map< std::string, std::string>& rasterInfo,
148 const std::string& rasterType,
149 std::unique_ptr< te::rst::Raster >& outRasterPtr );
161 std::vector< te::rst::BandProperty* > bandsProperties,
175 std::vector< te::rst::BandProperty* > bandsProperties,
176 const std::string& fileName,
190 std::vector< te::rst::BandProperty* > bandsProperties,
191 const std::string& fileName,
192 std::unique_ptr< te::rst::Raster >& outRasterPtr );
206 const std::string& fileName );
231 unsigned int inputVectorSize,
double* outputVector );
243 unsigned int inputVectorSize,
const int outputVectorDataType,
244 void* outputVector );
254 template<
typename MatrixElementT >
256 const bool normalize,
const std::string& fileName )
258 std::map<std::string, std::string> rInfo;
259 rInfo[
"URI"] = fileName;
261 std::vector<te::rst::BandProperty*> bandsProperties;
267 bandsProperties[0]->m_noDataValue = -1.0 * std::numeric_limits<double>::max();
272 std::unique_ptr< te::rst::Raster > outputRasterPtr(
276 unsigned int line = 0;
277 unsigned int col = 0;
280 MatrixElementT matrixValue = 0;
282 MatrixElementT gain = 1.0;
283 MatrixElementT offset = 0.0;
286 MatrixElementT matrixValueMin = std::numeric_limits< MatrixElementT >::max();
287 MatrixElementT matrixValueMax = -1.0 * matrixValueMin;
288 for( line = 0 ; line < nLines ; ++line )
290 for( col = 0 ; col < nCols ; ++col )
292 matrixValue = matrix[ line ][ col ];
293 if( matrixValue < matrixValueMin )
294 matrixValueMin = matrixValue;
295 if( matrixValue > matrixValueMax )
296 matrixValueMax = matrixValue;
300 if( matrixValueMax == matrixValueMin )
307 gain = 255.0 / ( matrixValueMax - matrixValueMin );
308 offset = -1.0 * ( matrixValueMin );
312 const MatrixElementT min0 = 0;
313 const MatrixElementT max255 = 255;
315 for( line = 0 ; line < nLines ; ++line )
317 for( col = 0 ; col < nCols ; ++col )
319 matrixValue = matrix[ line ][ col ];
323 matrixValue += offset;
325 matrixValue = std::max( min0, matrixValue );
326 matrixValue = std::min( max255, matrixValue );
329 outputRasterPtr->setValue( col, line,
static_cast<double>(matrixValue), 0 );
433 const unsigned int redBandIdx,
const unsigned int greenBandIdx,
434 const unsigned int blueBandIdx,
const double rgbRangeMin,
454 const te::rst::Raster& inputGreenRaster,
const unsigned int greenBandIdx,
455 const te::rst::Raster& inputBlueRaster,
const unsigned int blueBandIdx,
456 const double rgbRangeMin,
const double rgbRangeMax,
te::rst::Raster& outputIHSRaster);
472 const unsigned int intensityBandIdx,
const unsigned int hueBandIdx,
473 const unsigned int saturationBandIdx,
const double rgbRangeMin,
493 const te::rst::Raster& inputSRaster,
const unsigned int saturationBandIdx,
494 const double rgbRangeMin,
const double rgbRangeMax,
te::rst::Raster& outputRGBRaster);
510 const unsigned int redBandIdx,
const unsigned int greenBandIdx,
511 const unsigned int blueBandIdx,
const double rgbRangeMin,
530 const te::rst::Raster& inputGreenRaster,
const unsigned int greenBandIdx,
531 const te::rst::Raster& inputBlueRaster,
const unsigned int blueBandIdx,
532 const double rgbRangeMin,
const double rgbRangeMax,
te::rst::Raster& outputHLSRaster);
547 const unsigned int hueBandIdx,
const unsigned int lightBandIdx,
548 const unsigned int saturationBandIdx,
const double rgbRangeMin,
567 const te::rst::Raster& inputSRaster,
const unsigned int saturationBandIdx,
568 const double rgbRangeMin,
const double rgbRangeMax,
te::rst::Raster& outputRGBRaster);
582 const unsigned int inputBandIndex,
583 const unsigned int maxThreads,
599 const unsigned int inputBandIndex,
600 const unsigned int maxThreads,
601 double const *
const meanValuePtr,
602 double& stdDevValue );
619 const unsigned int inputBandIndex1,
621 const unsigned int inputBandIndex2,
622 const unsigned int maxThreads,
623 double const *
const mean1ValuePtr,
624 double const *
const mean2ValuePtr,
625 double& covarianceValue );
641 const std::vector< unsigned int >& inputRasterBands,
642 boost::numeric::ublas::matrix< double >& pcaMatrix,
644 const std::vector< unsigned int >& pcaRasterBands,
645 const unsigned int maxThreads );
660 const boost::numeric::ublas::matrix< double >& pcaMatrix,
662 const std::vector< unsigned int >& outputRasterBands,
663 const unsigned int maxThreads );
680 const unsigned int& inputRasterBandIdx,
681 const std::vector< std::pair< double, double > >& targetValues,
682 const bool enableProgress,
683 const std::vector< te::gm::Polygon* >& restrictionPols,
685 const unsigned int& outputRasterBandIdx );
701 const std::vector< unsigned int >& inputRasterBands,
702 const boost::numeric::ublas::matrix< double >& remapMatrix,
704 const std::vector< unsigned int >& outputRasterBands,
705 const unsigned int maxThreads );
719 const std::vector< unsigned int >& inputRasterBands,
720 const std::vector< std::map<std::string, std::string> > & outputRastersInfos,
721 const std::string& outputDataSourceType,
722 std::vector< boost::shared_ptr< te::rst::Raster > > & outputRastersPtrs );
739 const std::vector< unsigned int >& inputRasterBands,
741 const std::map<std::string, std::string>& outputRasterInfo,
742 const std::string& outputDataSourceType,
743 const unsigned int maxThreads,
744 std::unique_ptr< te::rst::Raster >& outputRasterPtr );
772 TERPEXPORT boost::numeric::ublas::matrix< double >
789 const std::vector< unsigned int >& inputRasterBands,
791 const unsigned int levelsNumber,
792 const boost::numeric::ublas::matrix< double >& filter );
808 const unsigned int levelsNumber,
810 const std::vector< unsigned int >& outputRasterBands );
831 const std::vector< unsigned int >& inputRasterBands,
833 const unsigned int interpWindowRadius,
834 const unsigned int firstRow,
835 const unsigned int firstColumn,
836 const unsigned int height,
837 const unsigned int width,
838 const unsigned int newheight,
839 const unsigned int newwidth,
840 const std::map<std::string, std::string>& rinfo,
841 const std::string& dataSourceType,
842 std::unique_ptr< te::rst::Raster >& resampledRasterPtr );
850 template<
typename ContainerT >
852 const bool useTPSecondCoordPair )
854 if( tiePoints.size() < 3 )
862 typename ContainerT::const_iterator it =
864 const typename ContainerT::const_iterator itE =
869 if( useTPSecondCoordPair )
877 std::unique_ptr< te::gm::Geometry > convexHullPolPtr( points.
convexHull() );
896 const unsigned int paletteSize,
897 const bool randomize,
898 std::vector< te::rst::BandProperty::ColorEntry >& palette );
919 const unsigned int inputRasterBand,
920 const bool createPaletteRaster,
921 const unsigned int slicesNumber,
922 const bool eqHistogram,
923 const std::map< std::string, std::string >& rasterInfo,
924 const std::string& rasterType,
925 const bool enableProgress,
926 std::vector< te::rst::BandProperty::ColorEntry >
const *
const palettePtr,
927 std::unique_ptr< te::rst::Raster >& outRasterPtr,
928 std::vector< double >
const* slicesLimitsPtr,
929 std::vector< double >
const* slicesOutputValuesPtr );
943 const unsigned int& inputRasterBandIdx,
944 const unsigned targetRow,
945 const unsigned targetCol,
946 const double& outputValue );
962 const unsigned int& inputRasterBandIdx,
964 const unsigned int& outputRasterBandIdx,
965 const unsigned targetInputRow,
966 const unsigned targetInputCol,
967 const double& outputValue );
985 const unsigned int bandIndex,
986 const std::vector< te::gm::Polygon const* >& rois,
987 const unsigned int histoBins,
988 const unsigned int maxThreads,
990 std::map<double, unsigned>& rHistogram,
991 std::map<double, unsigned>& iHistogram );
1011 const std::map<double, unsigned int>& histogram,
1046 const unsigned int bandIndex1,
1047 const unsigned int bandIndex2,
1048 const std::vector< te::gm::Polygon const* >& rois,
1049 const unsigned int histoBins,
1050 const unsigned int maxThreads,
1052 std::map< std::pair< double, double >,
unsigned int>& realJointHistogram,
1053 std::map< std::pair< double, double >,
unsigned int>& imagJointHistogram,
1054 std::map<double, unsigned int>
const *
const rasterRealHistogram1ptr,
1055 std::map<double, unsigned int>
const *
const rasterImagHistogram1Ptr,
1056 std::map<double, unsigned int>
const *
const rasterRealHistogram2Ptr,
1057 std::map<double, unsigned int>
const *
const rasterImagHistogram2Ptr );
1069 const std::map< std::pair< double, double >,
unsigned int>& jointHistogram,
1070 const std::map<double, unsigned int>& histogram1,
1071 const std::map<double, unsigned int>& histogram2,
1072 double& covariance );
1077 #endif // __TERRALIB_RP_INTERNAL_FUNCTIONS_H
double GetTPConvexHullArea(const ContainerT &tiePoints, const bool useTPSecondCoordPair)
Returns the tie points converx hull area.
MultiPoint is a GeometryCollection whose elements are restricted to points.
TERPEXPORT bool SelectiveReplaceValues(const te::rst::Raster &inputRaster, const unsigned int &inputRasterBandIdx, const std::vector< std::pair< double, double > > &targetValues, const bool enableProgress, const std::vector< te::gm::Polygon * > &restrictionPols, te::rst::Raster &outputRaster, const unsigned int &outputRasterBandIdx)
Remap all pixel values using a user supplied target values (non-target values are just copied from in...
A generic template matrix.
TERPEXPORT bool RasterResample(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const te::rst::Interpolator::Method interpMethod, const unsigned int interpWindowRadius, 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.
@ B3SplineWAFilter
Spline filter type.
TERPEXPORT double GetDigitalNumberBandMax(std::string bandName)
Returns the maximum digital number of a given sensor/band.
@ GrayIdxCInt
Index into a lookup table.
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
SpectralSensorParams(const int &band, const double &lower, const double &upper, const double &min, const double &max)
TERPEXPORT void CreateFixedStepPalette(const unsigned int paletteSize, const bool randomize, std::vector< te::rst::BandProperty::ColorEntry > &palette)
Create a fixed step sequential color palette.
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).
An abstract class for raster data strucutures.
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 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::vector< double > const *slicesLimitsPtr, std::vector< double > const *slicesOutputValuesPtr)
Create a new raster grouping pixel values following the number of slices and/or slice limits.
TERPEXPORT std::vector< std::string > GetBandNames()
Returns a vector os with band's names.
TERPEXPORT bool GetCovarianceValue(const te::rst::Raster &inputRaster1, const unsigned int inputBandIndex1, const te::rst::Raster &inputRaster2, const unsigned int inputBandIndex2, const unsigned int maxThreads, double const *const mean1ValuePtr, double const *const mean2ValuePtr, double &covarianceValue)
Get the covariance of band pixel values.
Feeder from a input rasters.
void add(Geometry *g)
It adds the geometry into the collection.
TERPEXPORT void SaveSensorParams(std::map< std::string, SpectralSensorParams > &)
Saves in SpectralSensor.json file the spectral sensors parameters.
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 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.
TERPEXPORT bool GetMeanValue(const te::rst::Raster &inputRaster, const unsigned int inputBandIndex, const unsigned int maxThreads, double &meanValue)
Get the mean of band pixel values.
Surface is an abstract class that represents a 2-dimensional geometric objects.
@ TriangleWAFilter
Triangle filter type.
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.
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.
TERPEXPORT std::pair< double, double > GetDigitalNumberBandInfo(std::string bandName)
Returns the maximun and minimum digital numbers of a given sensor/band.
bool CreateRasterFileFromMatrix(const te::rp::Matrix< MatrixElementT > &matrix, const bool normalize, const std::string &fileName)
Create a tiff file from a matrix.
TERPEXPORT double GetDigitalNumberBandMin(std::string bandName)
Returns the minimum digital number of a given sensor/band.
bool TERPEXPORT Copy2DiskRaster(const te::rst::Raster &inputRaster, const std::string &fileName)
Create a new raster into a GDAL datasource.
TERPEXPORT double GetSpectralBandMax(std::string bandName)
Returns the maximum reflectance value of a given sensor/band.
A rectified grid is the spatial support for raster data.
virtual Geometry * convexHull() const _NOEXCEPT_OP(false)
This method calculates the Convex Hull of a geometry.
static Raster * make()
It creates and returns an empty raster with default raster driver.
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 getJointHistogramStats(const std::map< std::pair< double, double >, unsigned int > &jointHistogram, const std::map< double, unsigned int > &histogram1, const std::map< double, unsigned int > &histogram2, double &covariance)
Compute statiscts from the given histogram.
TERPEXPORT bool NormalizeRaster(te::rst::Raster &inputRaster, double nmin=0.0, double nmax=255.0)
Normalizes one raster in a given interval.
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.
InterpolationMethod
Allowed interpolation methods.
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, const unsigned int maxThreads, std::unique_ptr< te::rst::Raster > &outputRasterPtr)
Compose a set of bands into one multi-band raster.
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.
TERPEXPORT void getHistogramStats(const std::map< double, unsigned int > &histogram, double &min, double &max, double &mean, double &stdDev, double &mode, double &entropy, double &sum, double &sum2, double &sum3, double &sum4, double &variance, double &median)
Compute statiscts from the given histogram.
TERPEXPORT std::map< std::string, SpectralSensorParams > getSensorParams()
Returns a map with spectral sensors parameters defined in SpectralSensor.json file.
TERPEXPORT bool GetDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &detailedExtent)
Create a datailed extent from the given grid.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
unsigned int getColumnsNumber() const
The number of current matrix columns.
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.
void TERPEXPORT Convert2DoublesVector(void *inputVector, const int inputVectorDataType, unsigned int inputVectorSize, double *outputVector)
Convert vector elements.
TERPEXPORT boost::numeric::ublas::matrix< double > CreateWaveletAtrousFilter(const WaveletAtrousFilterType &filterType)
Create a Wavele Atrous Filter.
A raster band description.
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.
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.
#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...
TERPEXPORT double GetSpectralBandMin(std::string bandName)
Returns the minimum reflectance value of a given sensor/band.
TERPEXPORT bool getJointHistograms(const te::rst::Raster &raster, const unsigned int bandIndex1, const unsigned int bandIndex2, const std::vector< te::gm::Polygon const * > &rois, const unsigned int histoBins, const unsigned int maxThreads, const te::rst::PolygonIterator< double >::IterationType roisItType, std::map< std::pair< double, double >, unsigned int > &realJointHistogram, std::map< std::pair< double, double >, unsigned int > &imagJointHistogram, std::map< double, unsigned int > const *const rasterRealHistogram1ptr, std::map< double, unsigned int > const *const rasterImagHistogram1Ptr, std::map< double, unsigned int > const *const rasterRealHistogram2Ptr, std::map< double, unsigned int > const *const rasterImagHistogram2Ptr)
Compute and return the joint histogram of occurring values (real and imaginary) inside defined region...
An abstract class for data providers like a DBMS, Web Services or a regular file.
TERPEXPORT SpectralSensorParams GetSpectralBandInfo(std::string bandName)
Returns the maximun and minimum reflectance values of a given sensor/band.
@ InvalidWAFilter
Invalid filter type.
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.
TERPEXPORT bool getHistograms(const te::rst::Raster &raster, const unsigned int bandIndex, const std::vector< te::gm::Polygon const * > &rois, const unsigned int histoBins, const unsigned int maxThreads, const te::rst::PolygonIterator< double >::IterationType roisItType, std::map< double, unsigned > &rHistogram, std::map< double, unsigned > &iHistogram)
Compute and return the histogram soccurring values (real and imaginary) inside defined regions of int...
Proxy configuration file for TerraView (see terraview_config.h).
TERPEXPORT bool ReplaceContiguousSegmentValues(te::rst::Raster &inputRaster, const unsigned int &inputRasterBandIdx, const unsigned targetRow, const unsigned targetCol, const double &outputValue)
Replace a contiguos segment pixel values.
TERPEXPORT bool GetStdDevValue(const te::rst::Raster &inputRaster, const unsigned int inputBandIndex, const unsigned int maxThreads, double const *const meanValuePtr, double &stdDevValue)
Get the standard deviation of band pixel values.
A LinearRing is a LineString that is both closed and simple.
unsigned int getLinesNumber() const
The number of current matrix lines.
void TERPEXPORT ConvertDoublesVector(double *inputVector, unsigned int inputVectorSize, const int outputVectorDataType, void *outputVector)
Convert a doubles vector.
A point with x and y coordinate values.
TERPEXPORT std::string GetSensorFilename()
Returns a json filename with spectral sensors parameters.