30 #include "../raster/BandProperty.h" 
   31 #include "../raster/RasterFactory.h" 
   32 #include "../raster/Band.h" 
   33 #include "../raster/Grid.h" 
   34 #include "../raster/Utils.h" 
   35 #include "../geometry/Envelope.h" 
   36 #include "../common/progress/TaskProgress.h" 
   37 #include "../memory/ExpansibleRaster.h" 
   65       m_lowResRasterPtr = 0;
 
   66       m_lowResRasterBands.clear();
 
   67       m_lowResRasterBandSensors.clear();
 
   68       m_lowResRasterBandsSRFs.clear();
 
   69       m_highResRasterPtr = 0;
 
   70       m_highResRasterBand = 0;
 
   72       m_hiResRasterBandsSRFs.clear();
 
   73       m_hiResRasterWaveletLevels = 0;
 
   74       m_enableProgress = 
false;
 
   77       m_userWaveletFilterPtr = 0;
 
   78       m_enableMultiThread = 
true;
 
  129       m_outputRasterPtr.reset();
 
  158       throw( te::rp::Exception )
 
  168       std::auto_ptr< te::common::TaskProgress > progressPtr;
 
  173         progressPtr->setTotalSteps( 3 );
 
  175         progressPtr->setMessage( 
"Fusing images" );
 
  180       boost::numeric::ublas::matrix< double > waveletFilter;
 
  194       std::vector< std::map< double, double > > lowResSRFs;
 
  195       std::map< double, double > highResSRFs;
 
  200           std::map< double, double > auxMap;
 
  202           for( 
unsigned int sensorIdx = 0 ; sensorIdx < 
 
  208             lowResSRFs.push_back( auxMap );
 
  231       std::vector< unsigned int > lRInterceptedBandIndex; 
 
  232       std::vector< double > lowResBandsSRFAreas;
 
  233       std::vector< double > lRBandXHRBandIntersectionAreas;
 
  234       double lRBandsXHRBandTotalExclusiveIntersectionSRFArea = 0.0; 
 
  238         unsigned int lowResBandIdx1 = 0;
 
  239         unsigned int lowResBandIdx2 = 0;
 
  244         std::map< double, double > lRBandsXHRBandTotalExclusiveIntersectionSRF;
 
  246         lRBandXlRBandSRFIntersectionAreas.
reset( nLowResBands, nLowResBands );
 
  247         lowResBandsSRFAreas.resize( nLowResBands, 0.0 );
 
  248         lRBandXHRBandIntersectionAreas.resize( nLowResBands, 0.0 );
 
  249         for( lowResBandIdx1 = 0 ; lowResBandIdx1 < nLowResBands ; ++lowResBandIdx1 )
 
  251           for( lowResBandIdx2 = lowResBandIdx1 ; lowResBandIdx2 < nLowResBands ; 
 
  254             if( lowResBandIdx1 != lowResBandIdx2 )
 
  256               std::map< double, double > lRXLRIntersectionSRF;
 
  258                 lowResSRFs[ lowResBandIdx2 ], lRXLRIntersectionSRF );
 
  260               lRBandXlRBandSRFIntersectionAreas[ lowResBandIdx1 ][ lowResBandIdx2 ] = 
 
  262               lRBandXlRBandSRFIntersectionAreas[ lowResBandIdx2 ][ lowResBandIdx1 ] =
 
  263                 lRBandXlRBandSRFIntersectionAreas[ lowResBandIdx1 ][ lowResBandIdx2 ];
 
  267               lRBandXlRBandSRFIntersectionAreas[ lowResBandIdx1 ][ lowResBandIdx2 ] = 0.0;
 
  273             "One low resolution band SRF is invalid" );          
 
  275           std::map< double, double > lRXHRIntersectionSRF;
 
  280             "One low resolution band SRF does not intersects the high resolution band SRF" );
 
  282           std::map< double, double > auxUnionSRF;
 
  284           lRBandsXHRBandTotalExclusiveIntersectionSRF = auxUnionSRF;
 
  288           lRBandsXHRBandTotalExclusiveIntersectionSRF );
 
  290         std::multimap< double, unsigned int > centralFrequency2BandIdxMap;
 
  291         for( lowResBandIdx1 = 0 ; lowResBandIdx1 < nLowResBands ; ++lowResBandIdx1 )
 
  293           std::map< double, double >::const_iterator lowResSRFsIt = 
 
  294             lowResSRFs[ lowResBandIdx1 ].begin();
 
  295           std::map< double, double >::const_iterator lowResSRFsItEnd = 
 
  296             lowResSRFs[ lowResBandIdx1 ].end();
 
  297           double highestResponse = -1.0 * std::numeric_limits< double >::max();
 
  298           double highestResponseFrequency = 0;
 
  300           while( lowResSRFsIt != lowResSRFsItEnd )
 
  302             if( highestResponse < lowResSRFsIt->second )
 
  304               highestResponse = lowResSRFsIt->second;
 
  305               highestResponseFrequency = lowResSRFsIt->first;
 
  311           centralFrequency2BandIdxMap.insert( std::pair< double, unsigned int>( 
 
  312             highestResponseFrequency, lowResBandIdx1 ) );
 
  315         lRInterceptedBandIndex.resize( nLowResBands, nLowResBands + 1 );
 
  316         std::multimap< double, unsigned int >::iterator centralFrequency2BandIdxMapIt =
 
  317           centralFrequency2BandIdxMap.begin();
 
  318         std::multimap< double, unsigned int >::iterator centralFrequency2BandIdxMapItPrev;
 
  319         std::multimap< double, unsigned int >::iterator centralFrequency2BandIdxMapItEnd =
 
  320           centralFrequency2BandIdxMap.end();          
 
  321         while( centralFrequency2BandIdxMapIt != centralFrequency2BandIdxMapItEnd )
 
  323           if( centralFrequency2BandIdxMapIt == centralFrequency2BandIdxMap.begin() )
 
  325             lRInterceptedBandIndex[ centralFrequency2BandIdxMapIt->second ] = 
 
  326               centralFrequency2BandIdxMapIt->second;
 
  327             centralFrequency2BandIdxMapItPrev = centralFrequency2BandIdxMapIt;
 
  331             lRInterceptedBandIndex[ centralFrequency2BandIdxMapIt->second ] =
 
  332               centralFrequency2BandIdxMapItPrev->second;
 
  334             ++centralFrequency2BandIdxMapItPrev;
 
  337           ++centralFrequency2BandIdxMapIt;
 
  343       const unsigned int highResWaveletLevels = (
unsigned int)
 
  385         "Minimal number of wavelet decompositions not reached" );   
 
  389       std::auto_ptr< te::rst::Raster > resampledLlowResRasterPtr;
 
  392         std::map< std::string, std::string > rinfo;
 
  393         rinfo[
"MAXMEMPERCENTUSED"] = 
"30";  
 
  407           resampledLlowResRasterPtr ), 
 
  408           "Low resolution raster resample error" );
 
  416         progressPtr->pulse();
 
  417         if( ! progressPtr->isActive() ) 
return false;
 
  423       std::auto_ptr< te::rst::Raster > highResWaveletsRasterPtr;
 
  426         std::map<std::string, std::string> auxRasterInfo;
 
  428         std::vector< te::rst::BandProperty * > bandProps;
 
  430         for( 
unsigned int levelIdx = 0 ; levelIdx < highResWaveletLevels ;
 
  436           bandProps.back()->m_blkh = 1;
 
  438           bandProps.back()->m_nblocksx = 1;
 
  445           bandProps.back()->m_blkh = 1;
 
  447           bandProps.back()->m_nblocksx = 1;
 
  452         std::vector< unsigned int > rasterBands;
 
  464           *highResWaveletsRasterPtr,
 
  465           highResWaveletLevels,
 
  467           "Low resolution raster wavelets creation error" ); 
 
  475         progressPtr->pulse();
 
  476         if( ! progressPtr->isActive() ) 
return false;
 
  484         std::vector< te::rst::BandProperty * > bandProperties;
 
  485         std::vector< unsigned int > outputRasterBands;
 
  487         for( 
unsigned int bandIdx = 0 ; bandIdx <
 
  488           resampledLlowResRasterPtr->getNumberOfBands() ; ++bandIdx )
 
  491             *resampledLlowResRasterPtr->getBand( bandIdx )->getProperty() ) );
 
  493           outputRasterBands.push_back( bandIdx );
 
  505           "Output raster creation error" );
 
  512         const unsigned int nCols = outParamsPtr->
m_outputRasterPtr->getNumberOfColumns();
 
  517         const unsigned int highResWaveletsRasterBands = highResWaveletsRaster.
getNumberOfBands();
 
  518         unsigned int row = 0;
 
  519         unsigned int col = 0;
 
  520         unsigned int bandIdx = 0;
 
  521         std::vector< double > resLRRasterValues( nBands );
 
  522         unsigned int waveletBandIdx = 0;
 
  523         double outputRasterValue = 0;
 
  524         double resampledLlowResRasterValue = 0;
 
  525         double wisperTerm = 0;
 
  526         double highResWaveletsValue = 0.0;
 
  527         std::vector< double > ropi( nBands );
 
  530         std::vector< double > outBandsMinValue( nBands );
 
  531         std::vector< double > outBandsMaxValue( nBands );
 
  532         std::vector< double > resampledLlowResBandsGains( nBands );
 
  533         for( bandIdx = 0 ; bandIdx < nBands ;  ++bandIdx )
 
  537             outBandsMinValue[ bandIdx ], outBandsMaxValue[ bandIdx ] );
 
  540         for( row = 0 ; row < nRows ; ++row )
 
  542           for( col = 0 ; col < nCols ; ++col )
 
  545             for( bandIdx = 0 ; bandIdx < nBands ;  ++bandIdx )
 
  547               resampledLlowResRaster.
getValue( col, row, resampledLlowResRasterValue, bandIdx );
 
  549               resLRRasterValues[ bandIdx ] = resampledLlowResRasterValue;
 
  551               assert( lRBandXHRBandIntersectionAreas[ bandIdx ] > 0.0 );
 
  555                     lRBandXHRBandIntersectionAreas[ bandIdx ]
 
  557                     lRBandXHRBandIntersectionAreas[ bandIdx ]
 
  559                     resLRRasterValues[ bandIdx ]
 
  562                   lowResBandsSRFAreas[ bandIdx ]
 
  565               ropiMean += ropi[ bandIdx ];
 
  567             ropiMean /= ((double)nBands);
 
  569             for( bandIdx = 0 ; bandIdx < nBands ;  ++bandIdx )
 
  583                       lRBandsXHRBandTotalExclusiveIntersectionSRFArea
 
  590                       lRBandXHRBandIntersectionAreas[ bandIdx ]
 
  592                       lRBandsXHRBandTotalExclusiveIntersectionSRFArea
 
  597                       lRBandXHRBandIntersectionAreas[ bandIdx ]
 
  599                       lowResBandsSRFAreas[ bandIdx ]
 
  609                         lRBandXlRBandSRFIntersectionAreas[ bandIdx ][ lRInterceptedBandIndex[ bandIdx ] ]
 
  611                         lRBandXHRBandIntersectionAreas[ bandIdx ]
 
  619               outputRasterValue = resLRRasterValues[ bandIdx ];
 
  621               for( waveletBandIdx = 1 ; waveletBandIdx < highResWaveletsRasterBands ; 
 
  622                 waveletBandIdx += 2 )
 
  624                 highResWaveletsRaster.
getValue( col, row, highResWaveletsValue, 
 
  626                 outputRasterValue += ( wisperTerm * highResWaveletsValue );
 
  629               outputRasterValue = std::max( outBandsMinValue[ bandIdx ], 
 
  631               outputRasterValue = std::min( outBandsMaxValue[ bandIdx ], 
 
  634               outputRaster.
setValue( col, row, outputRasterValue, bandIdx );
 
  643         progressPtr->pulse();
 
  644         if( ! progressPtr->isActive() ) 
return false;
 
  657       throw( te::rp::Exception )
 
  670         "Invalid low Resolution Raster Pointer" )
 
  676       for( 
unsigned int lowResRasterBandsIdx = 0; lowResRasterBandsIdx <
 
  678         ++lowResRasterBandsIdx )
 
  683           "Invalid low resolution raster band" );   
 
  690           "Invalid low resolution bands sensors" );
 
  703           "Missing low resolution bands SRFs" );
 
  709             "Invalid low resolution SRF" );
 
  716         "Invalid high resolution Raster Pointer" )
 
  725         "Invalid raster band" );   
 
  741           "Invalid user filter" );
 
bool m_isInitialized
Tells if this instance is initialized. 
 
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. 
 
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
The generated output fused raster. 
 
Near neighborhood interpolation method. 
 
void getSRF(const SensorType &sensor, ContainerT &container)
Returns a Spectral Response Function from the given sensor. 
 
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state. 
 
AbstractParameters * clone() const 
Create a clone copy of this instance. 
 
A raster band description. 
 
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. 
 
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. 
 
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution. 
 
Spectral Response Functions. 
 
bool isInitialized() const 
Returns true if the algorithm instance is initialized and ready for execution. 
 
WisperFusion output parameters. 
 
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. 
 
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters. 
 
const OutputParameters & operator=(const OutputParameters ¶ms)
 
An abstract class for raster data strucutures. 
 
unsigned int getNumberOfRows() const 
Returns the raster number of rows. 
 
void getIntersectionSRF(const std::map< double, double > &sRF1, const std::map< double, double > &sRF2, std::map< double, double > &intersectionSRF)
Return the intersetction SRF. 
 
BandProperty * getProperty()
Returns the band property. 
 
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster. 
 
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. 
 
void getUnionSRF(const std::map< double, double > &sRF1, const std::map< double, double > &sRF2, std::map< double, double > &unionSRF)
Return the union SRF. 
 
Grid * getGrid()
It returns the raster grid. 
 
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory). 
 
void reset()
Reset (clear) the active instance data. 
 
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const 
Returns the attribute value of a band of a cell. 
 
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
 
boost::numeric::ublas::matrix< double > CreateWaveletAtrousFilter(const WaveletAtrousFilterType &filterType)
Create a Wavele Atrous Filter. 
 
Abstract parameters base interface. 
 
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. 
 
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ). 
 
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. 
 
A rectified grid is the spatial support for raster data. 
 
double getSRFArea(const std::map< double, double > &sRFs)
Return the SRF area. 
 
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.