te::rp::ArithmeticOperations Class Reference

Performs arithmetic operation over raster data. More...

#include <ArithmeticOperations.h>

Inheritance diagram for te::rp::ArithmeticOperations:
te::rp::Algorithm

Classes

class  ExecStackElement
 Execution stack element. More...
 
class  InputParameters
 ArithmeticOperations input parameters. More...
 
class  OutputParameters
 ArithmeticOperations output parameters. More...
 

Public Member Functions

 ArithmeticOperations ()
 
bool execute (AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
 Executes the algorithm using the supplied parameters. More...
 
const std::string & getErrorMessage () const
 Return the current error message if there is any. More...
 
bool initialize (const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
 Initialize the algorithm instance making it ready for execution. More...
 
bool isInitialized () const
 Returns true if the algorithm instance is initialized and ready for execution. More...
 
void reset () _NOEXCEPT_OP(false)
 Clear all internal allocated objects and reset the algorithm to its initial state. More...
 
 ~ArithmeticOperations ()
 

Protected Types

typedef void(ArithmeticOperations::* BinOpFuncPtrT) (const double &inputValue1, const double &inputValue2, double &outputValue) const
 Type definition for a operation function pointer. More...
 
typedef std::stack< ExecStackElementExecStackT
 Execution stack type definition. More...
 
typedef void(ArithmeticOperations::* UnaryOpFuncPtrT) (const double &inputValue1, double &outputValue) const
 

Protected Member Functions

void acosUnaryOp (const double &inputValue, double &outputValue) const
 Arc cosine unary operator function. More...
 
void additionBinOp (const double &inputValue1, const double &inputValue2, double &outputValue) const
 Addition binary operator function. More...
 
bool allocResultRaster (const te::rst::Grid &grid, std::unique_ptr< te::rst::Raster > &rasterPtr) const
 Allocate a new RAM memory raster. More...
 
void asinUnaryOp (const double &inputValue, double &outputValue) const
 Arc sine unary operator function. More...
 
void atanUnaryOp (const double &inputValue, double &outputValue) const
 Arc Tangent unary operator function. More...
 
void cosUnaryOp (const double &inputValue, double &outputValue) const
 Cosine unary operator function. More...
 
void divisionBinOp (const double &inputValue1, const double &inputValue2, double &outputValue) const
 Division binary operator function. More...
 
bool execBinaryOperator (const std::string &token, ExecStackT &execStack, bool generateOutput) const
 Execute the given binary operator using the current given execution stack. More...
 
bool execBinaryOperatorRasterXRaster (const te::rst::Raster &inRaster1, const unsigned int band1, const te::rst::Raster &inRaster2, const unsigned int band2, const BinOpFuncPtrT binOptFunctPtr, std::unique_ptr< te::rst::Raster > &outRasterPtr) const
 Execute the given binary operator using the given input rasters. More...
 
bool execBinaryOperatorRasterXReal (const te::rst::Raster &inRaster, const unsigned int bandIdx, const double value, const BinOpFuncPtrT binOptFunctPtr, std::unique_ptr< te::rst::Raster > &outRasterPtr, const bool realNumberIsRigthtTerm) const
 Execute the given binary operator using the given input raster and a real number. More...
 
bool execUnaryOperator (const std::string &token, ExecStackT &execStack, bool generateOutput) const
 Execute the given unary operator using the current given execution stack. More...
 
bool execUnaryOperatorRaster (const te::rst::Raster &inRaster, const unsigned int band, const UnaryOpFuncPtrT unaryOptFunctPtr, std::unique_ptr< te::rst::Raster > &outRasterPtr) const
 Execute the given unary operator using the given input raster. More...
 
bool execUnaryOperatorReal (const double value, const UnaryOpFuncPtrT unaryOptFunctPtr, std::unique_ptr< te::rst::Raster > &outRasterPtr, const bool realNumberIsRigthtTerm) const
 Execute the given unary operator using the given a real number. More...
 
bool executeString (const std::string &aStr, const std::vector< te::rst::Raster * > &inRasters, std::unique_ptr< te::rst::Raster > &outRaster, bool generateOutput, te::common::TaskProgress *const progressPtr) const
 Execute the automata parsing the given input string. More...
 
void exponencialBinOp (const double &inputValue1, const double &inputValue2, double &outputValue) const
 Exponencial binary operator function. More...
 
void getTokensStrs (const std::string &inputStr, std::vector< std::string > &outTokens) const
 Split the input string into a vector of token strings. More...
 
void inFix2PostFix (const std::vector< std::string > &input, std::vector< std::string > &output) const
 Convert the input tokens vector from the infix notation to postfix notation. More...
 
bool isBinaryOperator (const std::string &inputToken) const
 Returns true if the given token is a binary operator. More...
 
bool isOperator (const std::string &inputToken) const
 Returns true if the given token is an operator. More...
 
bool isRasterBandToken (const std::string &token, unsigned int &rasterIdx, unsigned int &bandIdx) const
 Returns true if the given token is a raster data token. More...
 
bool isRealNumberToken (const std::string &token, double &realValue) const
 Returns true if the given token is a real number. More...
 
bool isUnaryOperator (const std::string &inputToken) const
 Returns true if the given token is a unary operator. More...
 
void lnUnaryOp (const double &inputValue, double &outputValue) const
 unary operator function. More...
 
void logUnaryOp (const double &inputValue, double &outputValue) const
 Common logarithm unary operator function. More...
 
void multiplicationBinOp (const double &inputValue1, const double &inputValue2, double &outputValue) const
 Multiplication binary operator function. More...
 
bool op1HasGreaterOrEqualPrecedence (const std::string &operator1, const std::string &operator2) const
 Returns true if operator1 has greater of equal precedence over operator2. More...
 
void printTokens (const std::vector< std::string > &input) const
 Print tokens to stout. More...
 
void setErrorMessage (const std::string &newErrorMessage)
 Set the current error message. More...
 
void sinUnaryOp (const double &inputValue, double &outputValue) const
 Sine unary operator function. More...
 
void sqrtUnaryOp (const double &inputValue, double &outputValue) const
 Square root unary operator function. More...
 
void subtractionBinOp (const double &inputValue1, const double &inputValue2, double &outputValue) const
 Subtraction binary operator function. More...
 
void tanUnaryOp (const double &inputValue, double &outputValue) const
 Tangent unary operator function. More...
 

Protected Attributes

ArithmeticOperations::InputParameters m_inputParameters
 Input execution parameters. More...
 
bool m_isInitialized
 Tells if this instance is initialized. More...
 

Detailed Description

Performs arithmetic operation over raster data.

The expression (arithmetic stringIt) must be formed by a combination of the following elements, separated by spaces:

Operators: +(Sum of Rasters or a raster and a real number), -(Subtraction of Rasters or a raster and a real number), (Multiplication of Rasters or a raster and a real number), /(Division of Rasters or a raster and a real number) ^(Exponential of a raster and a real number) sqrt() (Square root of a raster) sin() (Sine of a raster) asin() (Arc Sine of a raster) cos() (Cosine of a raster) acos() (Arc Cosine of a raster) log() (Common (base-10) logarithm of a raster) tan() (Tangent of a raster) atan() (Arc tangent of a raster) ln() (Natural (base e) logarithm of a raster)

Real Numbers (negative numbers must follow the form "-1.0")

Raster bands: R0:1, R0:1, R1:0, .... (R0:1 is a reference to the first raster - with index 0 - from feeder, second band - with index 1).

Definition at line 79 of file ArithmeticOperations.h.

Member Typedef Documentation

◆ BinOpFuncPtrT

typedef void(ArithmeticOperations::* te::rp::ArithmeticOperations::BinOpFuncPtrT) (const double &inputValue1, const double &inputValue2, double &outputValue) const
protected

Type definition for a operation function pointer.

Definition at line 228 of file ArithmeticOperations.h.

◆ ExecStackT

Execution stack type definition.

Definition at line 223 of file ArithmeticOperations.h.

◆ UnaryOpFuncPtrT

typedef void(ArithmeticOperations::* te::rp::ArithmeticOperations::UnaryOpFuncPtrT) (const double &inputValue1, double &outputValue) const
protected

Definition at line 231 of file ArithmeticOperations.h.

Constructor & Destructor Documentation

◆ ArithmeticOperations()

te::rp::ArithmeticOperations::ArithmeticOperations ( )

◆ ~ArithmeticOperations()

te::rp::ArithmeticOperations::~ArithmeticOperations ( )

Member Function Documentation

◆ acosUnaryOp()

void te::rp::ArithmeticOperations::acosUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

Arc cosine unary operator function.

Definition at line 297 of file ArithmeticOperations.h.

◆ additionBinOp()

void te::rp::ArithmeticOperations::additionBinOp ( const double &  inputValue1,
const double &  inputValue2,
double &  outputValue 
) const
inlineprotected

Addition binary operator function.

Definition at line 240 of file ArithmeticOperations.h.

◆ allocResultRaster()

bool te::rp::ArithmeticOperations::allocResultRaster ( const te::rst::Grid grid,
std::unique_ptr< te::rst::Raster > &  rasterPtr 
) const
protected

Allocate a new RAM memory raster.

Parameters
gridThe output raster grid.
rasterPtrThe output raster pointer.
Returns
Returns true if OK, false on errors.

◆ asinUnaryOp()

void te::rp::ArithmeticOperations::asinUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

Arc sine unary operator function.

Definition at line 285 of file ArithmeticOperations.h.

◆ atanUnaryOp()

void te::rp::ArithmeticOperations::atanUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

Arc Tangent unary operator function.

Definition at line 315 of file ArithmeticOperations.h.

◆ cosUnaryOp()

void te::rp::ArithmeticOperations::cosUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

Cosine unary operator function.

Definition at line 291 of file ArithmeticOperations.h.

◆ divisionBinOp()

void te::rp::ArithmeticOperations::divisionBinOp ( const double &  inputValue1,
const double &  inputValue2,
double &  outputValue 
) const
inlineprotected

Division binary operator function.

Definition at line 258 of file ArithmeticOperations.h.

◆ execBinaryOperator()

bool te::rp::ArithmeticOperations::execBinaryOperator ( const std::string &  token,
ExecStackT execStack,
bool  generateOutput 
) const
protected

Execute the given binary operator using the current given execution stack.

Parameters
tokenOperator token.
execStackExecution stack.
generateOutputif true the execution will generate valid output data, if false only dummy stack elements will be generated.
Returns
true if OK, false on errors..

◆ execBinaryOperatorRasterXRaster()

bool te::rp::ArithmeticOperations::execBinaryOperatorRasterXRaster ( const te::rst::Raster inRaster1,
const unsigned int  band1,
const te::rst::Raster inRaster2,
const unsigned int  band2,
const BinOpFuncPtrT  binOptFunctPtr,
std::unique_ptr< te::rst::Raster > &  outRasterPtr 
) const
protected

Execute the given binary operator using the given input rasters.

Parameters
inRaster1Input raster 1.
band1Input raster 1 band.
inRaster2Input raster 2.
band2Input raster 2 band.
binOptFunctPtrThe binary operation function pointer.
outRasterPtrThe generated output raster.
Returns
true if OK, false on errors..

◆ execBinaryOperatorRasterXReal()

bool te::rp::ArithmeticOperations::execBinaryOperatorRasterXReal ( const te::rst::Raster inRaster,
const unsigned int  bandIdx,
const double  value,
const BinOpFuncPtrT  binOptFunctPtr,
std::unique_ptr< te::rst::Raster > &  outRasterPtr,
const bool  realNumberIsRigthtTerm 
) const
protected

Execute the given binary operator using the given input raster and a real number.

Parameters
inRasterInput raster.
bandIdxInput raster band.
binOptFunctPtrThe binary operation function pointer.
outRasterPtrThe generated output raster.
realNumberIsRigthtTermtrue if the real number is the right term.
Returns
true if OK, false on errors..

◆ execUnaryOperator()

bool te::rp::ArithmeticOperations::execUnaryOperator ( const std::string &  token,
ExecStackT execStack,
bool  generateOutput 
) const
protected

Execute the given unary operator using the current given execution stack.

Parameters
tokenOperator token.
execStackExecution stack.
generateOutputif true the execution will generate valid output data, if false only dummy stack elements will be generated.
Returns
true if OK, false on errors..

◆ execUnaryOperatorRaster()

bool te::rp::ArithmeticOperations::execUnaryOperatorRaster ( const te::rst::Raster inRaster,
const unsigned int  band,
const UnaryOpFuncPtrT  unaryOptFunctPtr,
std::unique_ptr< te::rst::Raster > &  outRasterPtr 
) const
protected

Execute the given unary operator using the given input raster.

Parameters
inRasterInput raster.
band1Input raster band.
unaryOptFunctPtrThe unary operation function pointer.
outRasterPtrThe generated output raster.
Returns
true if OK, false on errors..

◆ execUnaryOperatorReal()

bool te::rp::ArithmeticOperations::execUnaryOperatorReal ( const double  value,
const UnaryOpFuncPtrT  unaryOptFunctPtr,
std::unique_ptr< te::rst::Raster > &  outRasterPtr,
const bool  realNumberIsRigthtTerm 
) const
protected

Execute the given unary operator using the given a real number.

Parameters
unaryOptFunctPtrThe unary operation function pointer.
outRasterPtrThe generated output raster.
realNumberIsRigthtTermtrue if the real number is the right term.
Returns
true if OK, false on errors..

◆ execute()

bool te::rp::ArithmeticOperations::execute ( AlgorithmOutputParameters outputParams)
virtual

Executes the algorithm using the supplied parameters.

Parameters
outputParamsOutput parameters.
Returns
true if OK, false on errors.
Note
A return error string can be obtained via Algorithm::getErrorMessage()

Implements te::rp::Algorithm.

◆ executeString()

bool te::rp::ArithmeticOperations::executeString ( const std::string &  aStr,
const std::vector< te::rst::Raster * > &  inRasters,
std::unique_ptr< te::rst::Raster > &  outRaster,
bool  generateOutput,
te::common::TaskProgress *const  progressPtr 
) const
protected

Execute the automata parsing the given input string.

Parameters
aStrThe input arithmetic expression string.
inRastersInput rasters pointers.
outRasterOutput raster pointer (pre-initiated).
generateOutputIf true, the output raster data will be generated, if false only the automata execution will be performed..
progressPtrA pointer to a progress interface to be pulsed on each operation or a null pointer.

◆ exponencialBinOp()

void te::rp::ArithmeticOperations::exponencialBinOp ( const double &  inputValue1,
const double &  inputValue2,
double &  outputValue 
) const
inlineprotected

Exponencial binary operator function.

Definition at line 267 of file ArithmeticOperations.h.

◆ getErrorMessage()

const std::string& te::rp::Algorithm::getErrorMessage ( ) const
inherited

Return the current error message if there is any.

Returns
Return the current error message if there is any.

◆ getTokensStrs()

void te::rp::ArithmeticOperations::getTokensStrs ( const std::string &  inputStr,
std::vector< std::string > &  outTokens 
) const
protected

Split the input string into a vector of token strings.

Parameters
inputStrThe input string.
outTokensThe generated output tokens vector.

◆ inFix2PostFix()

void te::rp::ArithmeticOperations::inFix2PostFix ( const std::vector< std::string > &  input,
std::vector< std::string > &  output 
) const
protected

Convert the input tokens vector from the infix notation to postfix notation.

Parameters
inputThe input tokens vector.
outputThe output tokens vector.

◆ initialize()

bool te::rp::ArithmeticOperations::initialize ( const AlgorithmInputParameters inputParams)
virtual

Initialize the algorithm instance making it ready for execution.

Parameters
inputParamsInput parameters.
Returns
true if OK, false on errors.
Note
A return error string can be obtained via Algorithm::getErrorMessage()

Implements te::rp::Algorithm.

◆ isBinaryOperator()

bool te::rp::ArithmeticOperations::isBinaryOperator ( const std::string &  inputToken) const
protected

Returns true if the given token is a binary operator.

Parameters
inputTokenInput token.
Returns
Returns true if the given token is a binary operator.

◆ isInitialized()

bool te::rp::ArithmeticOperations::isInitialized ( ) const
virtual

Returns true if the algorithm instance is initialized and ready for execution.

Returns
true if the algorithm instance is initialized and ready for execution.

Implements te::rp::Algorithm.

◆ isOperator()

bool te::rp::ArithmeticOperations::isOperator ( const std::string &  inputToken) const
protected

Returns true if the given token is an operator.

Parameters
inputTokenInput token.
Returns
Returns true if the given token is an operator.

◆ isRasterBandToken()

bool te::rp::ArithmeticOperations::isRasterBandToken ( const std::string &  token,
unsigned int &  rasterIdx,
unsigned int &  bandIdx 
) const
protected

Returns true if the given token is a raster data token.

Parameters
tokenInput token.
rasterIdxThe output converted raster index value.
bandIdxThe output converted band index value.
Returns
Returns true if the given token is a raster data token.

◆ isRealNumberToken()

bool te::rp::ArithmeticOperations::isRealNumberToken ( const std::string &  token,
double &  realValue 
) const
protected

Returns true if the given token is a real number.

Parameters
tokenInput token.
realValueThe output converted value.
Returns
Returns true if the given token is a real number.

◆ isUnaryOperator()

bool te::rp::ArithmeticOperations::isUnaryOperator ( const std::string &  inputToken) const
protected

Returns true if the given token is a unary operator.

Parameters
inputTokenInput token.
Returns
Returns true if the given token is a unary operator.

◆ lnUnaryOp()

void te::rp::ArithmeticOperations::lnUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

unary operator function.

Definition at line 321 of file ArithmeticOperations.h.

◆ logUnaryOp()

void te::rp::ArithmeticOperations::logUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

Common logarithm unary operator function.

Definition at line 303 of file ArithmeticOperations.h.

◆ multiplicationBinOp()

void te::rp::ArithmeticOperations::multiplicationBinOp ( const double &  inputValue1,
const double &  inputValue2,
double &  outputValue 
) const
inlineprotected

Multiplication binary operator function.

Definition at line 252 of file ArithmeticOperations.h.

◆ op1HasGreaterOrEqualPrecedence()

bool te::rp::ArithmeticOperations::op1HasGreaterOrEqualPrecedence ( const std::string &  operator1,
const std::string &  operator2 
) const
protected

Returns true if operator1 has greater of equal precedence over operator2.

Parameters
operator1Operator1 input token.
operator2Operator2 input token.
Returns
Returns true if operator1 has greater of equal precedence over operator2.

◆ printTokens()

void te::rp::ArithmeticOperations::printTokens ( const std::vector< std::string > &  input) const
protected

Print tokens to stout.

Parameters
inputThe input tokens vector.

◆ reset()

void te::rp::ArithmeticOperations::reset ( )
virtual

Clear all internal allocated objects and reset the algorithm to its initial state.

Reimplemented from te::rp::Algorithm.

◆ setErrorMessage()

void te::rp::Algorithm::setErrorMessage ( const std::string &  newErrorMessage)
protectedinherited

Set the current error message.

Parameters
newErrorMessageNew error message;

◆ sinUnaryOp()

void te::rp::ArithmeticOperations::sinUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

Sine unary operator function.

Definition at line 279 of file ArithmeticOperations.h.

◆ sqrtUnaryOp()

void te::rp::ArithmeticOperations::sqrtUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

Square root unary operator function.

Definition at line 273 of file ArithmeticOperations.h.

◆ subtractionBinOp()

void te::rp::ArithmeticOperations::subtractionBinOp ( const double &  inputValue1,
const double &  inputValue2,
double &  outputValue 
) const
inlineprotected

Subtraction binary operator function.

Definition at line 246 of file ArithmeticOperations.h.

◆ tanUnaryOp()

void te::rp::ArithmeticOperations::tanUnaryOp ( const double &  inputValue,
double &  outputValue 
) const
inlineprotected

Tangent unary operator function.

Definition at line 309 of file ArithmeticOperations.h.

Member Data Documentation

◆ m_inputParameters

ArithmeticOperations::InputParameters te::rp::ArithmeticOperations::m_inputParameters
protected

Input execution parameters.

Definition at line 233 of file ArithmeticOperations.h.

◆ m_isInitialized

bool te::rp::ArithmeticOperations::m_isInitialized
protected

Tells if this instance is initialized.

Definition at line 235 of file ArithmeticOperations.h.


The documentation for this class was generated from the following file: