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" 113 m_outputRasterPtr.reset();
140 throw( te::rp::Exception )
150 std::unique_ptr< te::common::TaskProgress > progressPtr;
155 progressPtr->setTotalSteps( 4 );
157 progressPtr->setMessage(
"Fusing images" );
162 std::unique_ptr< te::rst::Raster > ressampledRasterPtr;
165 "Ressampled raster data loading error" );
171 progressPtr->pulse();
172 if( ! progressPtr->isActive() )
return false;
177 std::unique_ptr< te::rst::Raster > pcaRasterPtr;
178 boost::numeric::ublas::matrix< double > pcaMatrix;
182 std::vector< te::rst::BandProperty * > bandProperties;
183 std::vector< unsigned int > ressampledRasterBands;
185 for(
unsigned int bandIdx = 0 ; bandIdx <
186 ressampledRasterPtr->getNumberOfBands() ; ++bandIdx )
189 *ressampledRasterPtr->getBand( bandIdx )->getProperty() ) );
191 bandProperties[ bandIdx ]->m_noDataValue = std::numeric_limits< double >::max();
193 ressampledRasterBands.push_back( bandIdx );
207 ressampledRasterBands, pcaMatrix, *pcaRasterPtr, ressampledRasterBands,
209 "Principal components generation error" );
216 progressPtr->pulse();
217 if( ! progressPtr->isActive() )
return false;
229 progressPtr->pulse();
230 if( ! progressPtr->isActive() )
return false;
238 std::vector< te::rst::BandProperty * > bandProperties;
239 std::vector< unsigned int > outputRasterBands;
241 for(
unsigned int bandIdx = 0 ; bandIdx <
242 pcaRasterPtr->getNumberOfBands() ; ++bandIdx )
245 *pcaRasterPtr->getBand( bandIdx )->getProperty() ) );
246 bandProperties[ bandIdx ]->m_type =
247 ressampledRasterPtr->getBand( bandIdx )->getProperty()->m_type;
248 bandProperties[ bandIdx ]->m_noDataValue =
249 ressampledRasterPtr->getBand( bandIdx )->getProperty()->m_noDataValue;
251 outputRasterBands.push_back( bandIdx );
263 "Output raster creation error" );
268 "Inverse PCA error" );
273 progressPtr->pulse();
274 if( ! progressPtr->isActive() )
return false;
289 throw( te::rp::Exception )
302 "Invalid low Resolution Raster Pointer" )
308 for(
unsigned int lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
314 "Invalid raster band" );
320 "Invalid high resolution Raster Pointer" )
329 "Invalid raster band" );
347 unsigned int lowResRasterBandsIdx = 0;
348 unsigned int lowResRasterBandIdx = 0;
354 std::vector< te::rst::BandProperty * > ressampledBandProperties;
356 for( lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
363 ressampledBandProperties[ lowResRasterBandsIdx ]->m_blkw = outNCols;
364 ressampledBandProperties[ lowResRasterBandsIdx ]->m_blkh = 1;
365 ressampledBandProperties[ lowResRasterBandsIdx ]->m_nblocksx = 1;
366 ressampledBandProperties[ lowResRasterBandsIdx ]->m_nblocksy = outNRows;
372 ressampledBandProperties ) );
379 const double colsRescaleFactor =
382 const double rowsRescaleFactor =
385 unsigned int outRow = 0;
386 unsigned int outCol = 0;
391 std::complex< double > value = 0;
393 double inNoDataValue = 0;
394 double outNoDataValue = 0;
396 for( lowResRasterBandsIdx = 0 ; lowResRasterBandsIdx <
403 for( outRow = 0 ; outRow < outNRows ; ++outRow )
405 inRow = ((double)outRow) * rowsRescaleFactor;
407 for( outCol = 0 ; outCol < outNCols ; ++outCol )
409 inCol = ((double)outCol) * colsRescaleFactor;
411 interpol.
getValue( inCol, inRow, value, lowResRasterBandIdx );
413 if( value.real() == inNoDataValue )
415 ressampledRaster.
setValue( outCol, outRow, outNoDataValue, lowResRasterBandsIdx );
419 ressampledRaster.
setValue( outCol, outRow, value.real(), lowResRasterBandsIdx );
437 double pcaZeroMean = 0.0;
439 0 : 1, pcaZeroMean ) )
444 double pcaZeroStdDev = 0.0;
446 0 : 1, &pcaZeroMean, pcaZeroStdDev ) )
457 double hrStdDev = 0.0;
463 const double gain = ( ( hrStdDev == 0.0 ) ? 0.0 : ( pcaZeroStdDev / hrStdDev ) );
468 unsigned int col = 0;
469 unsigned int row = 0;
471 double pcaAllowedMin = 0;
472 double pcaAllowedMax = 0;
476 for( row = 0 ; row < nRows ; ++row )
478 for( col = 0 ; col <
nCols ; ++
col )
481 if( value == hrNoDataValue )
483 pcaBand.setValue( col, row, pcaNoDataValue );
487 value = ( ( value - hrMean ) * gain ) + pcaZeroMean;
488 value = std::max( pcaAllowedMin, value );
489 value = std::min( pcaAllowedMax, value );
491 pcaBand.setValue( col, row, value );
bool GetMeanValue(const te::rst::Band &band, const unsigned int maxThreads, double &meanValue)
Get the mean of band pixel values.
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.
Near neighborhood interpolation method.
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...
Base exception class for plugin module.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
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.
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
The generated output fused raster.
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<double>::max().
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.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
bool loadRessampledRaster(std::unique_ptr< te::rst::Raster > &ressampledRasterPtr) const
Load resampled data from the input image.
unsigned int unsigned int nCols
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
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.
A raster band description.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
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.
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 std::vector< unsigned int > &outputRasterBands, const unsigned int maxThreads)
Regenerate the original raster from its principal components.
Raster Processing functions.
virtual void reset() _NOEXCEPT_OP(false)
Clear all internal allocated objects and reset the algorithm to its initial state.
A rectified grid is the spatial support for raster data.
Creation of skeleton imagems.
#define TERP_INSTANCE_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged, the current instance erro...
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.
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
const OutputParameters & operator=(const OutputParameters ¶ms)
#define TERP_INSTANCE_LOG_AND_RETURN_FALSE(message)
Logs a warning message, update the current instance error messsage and return false.