29 #include "../raster/BandProperty.h"
30 #include "../raster/RasterFactory.h"
31 #include "../raster/Band.h"
32 #include "../raster/Grid.h"
33 #include "../geometry/Envelope.h"
34 #include "../common/progress/TaskProgress.h"
35 #include "../memory/ExpansibleRaster.h"
63 m_lowResRasterPtr = 0;
64 m_lowResRasterBands.clear();
65 m_highResRasterPtr = 0;
66 m_highResRasterBand = 0;
67 m_enableProgress =
false;
68 m_enableThreadedProcessing =
true;
113 m_outputRasterPtr.reset();
142 throw( te::rp::Exception )
152 std::auto_ptr< te::common::TaskProgress > progressPtr;
157 progressPtr->setTotalSteps( 4 );
159 progressPtr->setMessage(
"Fusing images" );
164 std::auto_ptr< te::rst::Raster > ressampledRasterPtr;
167 "Ressampled raster data loading error" );
173 progressPtr->pulse();
174 if( ! progressPtr->isActive() )
return false;
179 std::auto_ptr< te::rst::Raster > pcaRasterPtr;
180 boost::numeric::ublas::matrix< double > pcaMatrix;
184 std::vector< te::rst::BandProperty * > bandProperties;
185 std::vector< unsigned int > ressampledRasterBands;
187 for(
unsigned int bandIdx = 0 ; bandIdx <
188 ressampledRasterPtr->getNumberOfBands() ; ++bandIdx )
191 *ressampledRasterPtr->getBand( bandIdx )->getProperty() ) );
194 ressampledRasterBands.push_back( bandIdx );
209 "Principal components generation error" );
216 progressPtr->pulse();
217 if( ! progressPtr->isActive() )
return false;
229 progressPtr->pulse();
230 if( ! progressPtr->isActive() )
return false;
237 std::vector< te::rst::BandProperty * > bandProperties;
239 for(
unsigned int bandIdx = 0 ; bandIdx <
240 pcaRasterPtr->getNumberOfBands() ; ++bandIdx )
243 *pcaRasterPtr->getBand( bandIdx )->getProperty() ) );
244 bandProperties[ bandIdx ]->m_type =
245 ressampledRasterPtr->getBand( bandIdx )->getProperty()->m_type;
257 "Output raster creation error" );
262 "Inverse PCA error" );
267 progressPtr->pulse();
268 if( ! progressPtr->isActive() )
return false;
281 throw( te::rp::Exception )
294 "Invalid low Resolution Raster Pointer" )
300 for(
unsigned int lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
306 "Invalid raster band" );
312 "Invalid high resolution Raster Pointer" )
321 "Invalid raster band" );
339 unsigned int lowResRasterBandsIdx = 0;
340 unsigned int lowResRasterBandIdx = 0;
346 std::vector< te::rst::BandProperty * > ressampledBandProperties;
348 for( lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
360 ressampledBandProperties ) );
367 const double colsRescaleFactor =
370 const double rowsRescaleFactor =
373 unsigned int outRow = 0;
374 unsigned int outCol = 0;
379 std::complex< double > value = 0;
381 double inNoDataValue = 0;
382 double outNoDataValue = 0;
384 for( lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
391 for( outRow = 0 ; outRow < outNRows ; ++outRow )
393 inRow = ((double)outRow) * rowsRescaleFactor;
395 for( outCol = 0 ; outCol < outNCols ; ++outCol )
397 inCol = ((double)outCol) * colsRescaleFactor;
399 interpol.
getValue( inCol, inRow, value, lowResRasterBandIdx );
401 if( value.real() == inNoDataValue )
403 ressampledRaster.
setValue( outCol, outRow, outNoDataValue, lowResRasterBandsIdx );
407 ressampledRaster.
setValue( outCol, outRow, value.real(), lowResRasterBandsIdx );
425 double pcaZeroMean = 0.0;
427 0 : 1, pcaZeroMean ) )
432 double pcaZeroStdDev = 0.0;
434 0 : 1, &pcaZeroMean, pcaZeroStdDev ) )
445 double hrStdDev = 0.0;
451 const double gain = ( ( hrStdDev == 0.0 ) ? 0.0 : ( pcaZeroStdDev / hrStdDev ) );
452 const double offset = ( hrStdDev == 0.0 ) ? 0.0 : ( pcaZeroMean - ( hrMean * gain ) );
457 unsigned int col = 0;
458 unsigned int row = 0;
460 double pcaAllowedMin = 0;
461 double pcaAllowedMax = 0;
465 for( row = 0 ; row < nRows ; ++row )
467 for( col = 0 ; col < nCols ; ++col )
470 if( value == hrNoDataValue )
472 pcaBand.setValue( col, row, pcaNoDataValue );
476 value = ( value * gain ) + offset;
477 value = std::max( pcaAllowedMin, value );
478 value = std::min( pcaAllowedMax, value );
480 pcaBand.setValue( col, row, value );
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
bool swapBandByHighResRaster(te::rst::Raster &pcaRaster, const unsigned int pcaRasterBandIdx)
Swap the band values by the normalized high resolution raster data.
A raster band description.
AbstractParameters * clone() const
Create a clone copy of this instance.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
bool GetMeanValue(const te::rst::Band &band, const unsigned int maxThreads, double &meanValue)
Get the mean of band pixel values.
virtual const char * what() const
It outputs the exception message.
bool m_isInitialized
Tells if this instance is initialized.
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
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)...
This class can be used to inform the progress of a task.
Raster Processing algorithm output parameters base interface.
PCAFusion output parameters.
void getValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Get the interpolated value at specific band.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max().
Raster Processing functions.
#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...
const Algorithm & operator=(const Algorithm &)
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
The generated output fused raster.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
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 reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
BandProperty * getProperty()
Returns the band property.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
bool DirectPrincipalComponents(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &pcaRaster, const unsigned int maxThreads)
Generate all principal components from the given input raster.
A raster band description.
Grid * getGrid()
It returns the raster grid.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Abstract parameters base interface.
int getSRID() const
Returns the raster spatial reference system identifier.
#define TERP_LOG_AND_RETURN_FALSE(message)
Logs a warning message will and return false.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
InputParameters m_inputParameters
Input execution parameters.
bool loadRessampledRaster(std::auto_ptr< te::rst::Raster > &ressampledRasterPtr) const
Load resampled data from the input image.
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
static Raster * make()
It creates and returns an empty raster with default raster driver.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
bool InversePrincipalComponents(const te::rst::Raster &pcaRaster, const boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &outputRaster, const unsigned int maxThreads)
Regenerate the original raster from its principal components.
Near neighborhood interpolation method.
A rectified grid is the spatial support for raster data.
Creation of skeleton imagems.
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
const OutputParameters & operator=(const OutputParameters ¶ms)