27 #include "../raster/Raster.h"
28 #include "../raster/Band.h"
29 #include "../raster/BandIterator.h"
30 #include "../raster/BandProperty.h"
31 #include "../raster/Grid.h"
32 #include "../raster/RasterProperty.h"
33 #include "../raster/RasterSummaryManager.h"
34 #include "../raster/RasterFactory.h"
35 #include "../common/progress/TaskProgress.h"
44 #include <boost/concept_check.hpp>
65 m_hECMaxInput.clear();
66 m_sMASCMeanInput.clear();
67 m_sMASCStdInput.clear();
70 m_inRasterBands.clear();
71 m_enableProgress =
false;
117 m_createdOutRasterPtr.reset();
118 m_outRasterBands.clear();
119 m_createdOutRasterDSType.clear();
120 m_createdOutRasterInfo.clear();
151 throw( te::rp::Exception )
165 std::vector< te::rst::BandProperty* > bandsProperties;
166 for(
unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
189 "Output raster creation error" );
202 for(
unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
208 "Invalid output raster band" )
252 throw( te::rp::Exception )
261 "Invalid raster pointer" );
267 "Invalid bands number" );
269 for(
unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
275 "Invalid input raster band" );
280 switch( inputParamsPtr->
m_type )
286 "Invalid parameter m_lCMinInput" );
289 "Invalid parameter m_lCMaxInput" );
297 "Invalid parameter m_hECMaxInput" );
305 "Invalid parameter m_sMASCMeanInput" );
308 "Invalid parameter m_sMASCStdInput" );
336 std::auto_ptr< te::common::TaskProgress > progressPtr;
337 if( enableGlobalProgress )
340 progressPtr->setMessage(
"Contrast" );
344 for(
unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
352 double outRangeMin = 0.0;
353 double outRangeMax = 0.0;
355 outRangeMin, outRangeMax );
356 const double outRasterRange = outRangeMax - outRangeMin;
361 if( ( outRasterRange != 0.0 ) && ( inRasterRange != 0.0 ) )
369 (!enableGlobalProgress) ) )
374 if( enableGlobalProgress )
376 progressPtr->pulse();
377 if( ! progressPtr->isActive() )
return false;
398 std::auto_ptr< te::common::TaskProgress > progressPtr;
402 progressPtr->setMessage(
"Contrast" );
408 const double lutfactor =
417 double outRangeMin = 0.0;
418 double outRangeMax = 0.0;
420 outRangeMin, outRangeMax );
427 std::map<double, double> lut;
428 const double minp = rsummary->at(niband).m_minVal->real();
429 const double maxp = rsummary->at(niband).m_maxVal->real();
430 for (
double pixel = minp; pixel <= maxp; pixel++)
433 for (
double nj = minp; nj <= pixel; nj++)
434 newvalue += rsummary->at(niband).m_histogramR->operator[](nj);
435 lut[pixel] = lutfactor * newvalue;
438 while (ibandit != ibanditend)
440 value = lut[ *ibandit ];
441 value = std::max( outRangeMin, value );
442 value = std::min( outRangeMax, value );
443 oband->
setValue(ibandit.getColumn(), ibandit.getRow(), value);
449 progressPtr->pulse();
450 if( ! progressPtr->isActive() )
return false;
467 std::auto_ptr< te::common::TaskProgress > progressPtr;
471 progressPtr->setMessage(
"Contrast" );
484 double outRangeMin = 0.0;
485 double outRangeMax = 0.0;
487 outRangeMin, outRangeMax );
494 const double meanp = rsummary->at(niband).m_meanVal->real();
495 const double stdp = rsummary->at(niband).m_stdVal->real();
509 newvalue = (value - meanp) * c1 + c2;
510 newvalue = std::max( outRangeMin, newvalue );
511 newvalue = std::min( outRangeMax, newvalue );
517 progressPtr->pulse();
518 if( ! progressPtr->isActive() )
return false;
528 const bool enableProgress )
534 double outRangeMin = 0.0;
535 double outRangeMax = 0.0;
537 outRangeMin, outRangeMax );
539 std::auto_ptr< te::common::TaskProgress > progressPtr;
543 progressPtr->setMessage(
"Contrast" );
546 if( ( inBlkWidthPixels == outBlkWidthPixels ) &&
547 ( inBlkHeightPixels == outBlkHeightPixels ) )
549 const unsigned int blockSizePixels = inBlkWidthPixels *
553 unsigned char* inputBuffer =
new unsigned char[ inRasterBand.
getBlockSize() ];
554 unsigned char* outputBuffer =
new unsigned char[ outRasterBand.
getBlockSize() ];
555 double* inDoublesBuffer =
new double[ blockSizePixels ];
556 double* outDoublesBuffer =
new double[ blockSizePixels ];
559 unsigned int blockXIndex = 0;
560 unsigned int blockOffset = 0;
563 if( enableProgress ) progressPtr->setTotalSteps( yBlocksNmb * xBlocksNmb );
565 for(
unsigned int blockYIndex = 0 ; blockYIndex < yBlocksNmb ;
568 for( blockXIndex = 0 ; blockXIndex < xBlocksNmb ;
571 inRasterBand.
read( blockXIndex, blockYIndex, inputBuffer );
574 blockSizePixels, inDoublesBuffer );
576 for( blockOffset = 0 ; blockOffset < blockSizePixels ; ++blockOffset )
578 (this->*remapFuncPtr)( inDoublesBuffer[blockOffset],
580 outDoublesBuffer[blockOffset] = std::max( outRangeMin, std::min(
581 outRangeMax, outValue ) );
585 outputVectorDataType, outputBuffer );
587 outRasterBand.
write( blockXIndex, blockYIndex, outputBuffer );
591 progressPtr->pulse();
592 if( ! progressPtr->isActive() )
return false;
597 delete[] inputBuffer;
598 delete[] outputBuffer;
599 delete[] inDoublesBuffer;
600 delete[] outDoublesBuffer;
607 if( enableProgress ) progressPtr->setTotalSteps( linesNumber );
609 unsigned int col = 0;
610 double inputValue = 0;
611 double outputValue = 0;
613 for(
unsigned int line = 0 ; line < linesNumber ; ++line )
615 for( col = 0 ; col < columnsNumber ; ++col )
617 inRasterBand.
getValue( col, line, inputValue );
618 (this->*remapFuncPtr)( inputValue, outputValue );
619 outRasterBand.
setValue( col, line, std::max( outRangeMin, std::min(
620 outRangeMax, outputValue ) ) );
625 progressPtr->pulse();
626 if( ! progressPtr->isActive() )
return false;
bool m_isInitialized
Tells if this instance is initialized.
te::rst::Raster * m_outRasterPtr
A pointer to a valid initiated raster instance where the result must be written, leave NULL to create...
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
A raster band description.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
int m_nblocksx
The number of blocks in x.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
int m_nblocksy
The number of blocks in y.
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.
const OutputParameters & operator=(const OutputParameters ¶ms)
virtual void read(int x, int y, void *buffer) const =0
It reads a data block to the specified buffer.
AbstractParameters * clone() const
Create a clone copy of this instance.
This class implements an iterator to "navigate" over a single band (const).
static ConstBandIterator begin(const Band *b)
Returns an iterator referring to the first value of the band.
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.
double m_offSetGainRemap_offset
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
#define TERP_LOG_AND_THROW(message)
Logs a error message and throws.
std::vector< unsigned int > m_outRasterBands
Bands to be processed from the output raster.
Calculate the standard deviation value.
BandProperty * getProperty()
Returns the band property.
SummaryTypes
Types for the BandSummary.
int m_blkw
Block width (pixels).
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
virtual Raster * getRaster() const =0
Returns the associated raster.
Contrast::InputParameters m_inputParameters
Contrast input execution parameters.
virtual void write(int x, int y, void *buffer)=0
It writes a data block from the specified buffer.
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
void Convert2DoublesVector(void *inputVector, const int inputVectorDataType, unsigned int inputVectorSize, double *outputVector)
Convert vector elements.
A raster band description.
Grid * getGrid()
It returns the raster grid.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
std::auto_ptr< te::rst::Raster > m_createdOutRasterPtr
A pointer to the created output raster instance, or an empty pointer empty if the result must be writ...
Abstract parameters base interface.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
#define TERP_LOG_AND_RETURN_FALSE(message)
Logs a warning message will and return false.
bool execHistogramEqualizationContrast()
Execute the histogram equalization contrast following the internal parameters.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
double m_offSetGainRemap_gain
static Raster * make()
It creates and returns an empty raster with default raster driver.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
int getType() const
It returns the data type of the elements in the band.
void(Contrast::* RemapFuncPtrT)(const double &inValue, double &outValue)
Type definition for a remapping function pointer.
int m_blkh
Block height (pixels).
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
void offSetGainRemap(const double &inValue, double &outValue)
Remap on gray level using an offset (Contrast::m_offSetGainRemap_offset) and a gain value (Contrast::...
Contrast::OutputParameters * m_outputParametersPtr
Contrast input execution parameters.
A rectified grid is the spatial support for raster data.
Contrast output parameters.
std::map< std::string, std::string > m_createdOutRasterInfo
The necessary information to create the raster (as described in te::raster::RasterFactory), leave empty if the result must be written to the raster pointed m_outRasterPtr.
Calculate the mean value.
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
Calculate the histogram for the real part.
bool execSetMeanAndStdContrast()
Execute the histogram equalization contrast following the internal parameters.
bool execLinearContrast()
Execute a linear contrast following the internal parameters.
void ConvertDoublesVector(double *inputVector, unsigned int inputVectorSize, const int outputVectorDataType, void *outputVector)
Convert a doubles vector.
bool remapBandLevels(const te::rst::Band &inRasterBand, te::rst::Band &outRasterBand, RemapFuncPtrT remapFuncPtr, const bool enableProgress)
Band gray levels remap using a remap function.
static ConstBandIterator end(const Band *b)
Returns an iterator referring to after the end of the iterator.