Isis 3 Programmer Reference
Isis::Calculator Class Reference

Calculator for arrays. More...

#include <Calculator.h>

Inheritance diagram for Isis::Calculator:
Inheritance graph
Collaboration diagram for Isis::Calculator:
Collaboration graph

Public Member Functions

 Calculator ()
 The code that performs math operations is designed to call a function and use the result. More...
 
virtual ~Calculator ()
 Virtual Constructor. More...
 
void Negative ()
 Pops an element, negates it, then pushes the result. More...
 
void Multiply ()
 Pops two elements, multiplies them, then pushes the product on the stack. More...
 
void Add ()
 Pops two elements, adds them, then pushes the sum on the stack. More...
 
void Subtract ()
 Pops two elements, subtracts them, then pushes the difference on the stack. More...
 
void Divide ()
 Pops two, divides them, then pushes the quotient on the stack. More...
 
void Modulus ()
 Pops two elements, mods them, then pushes the result on the stack. More...
 
void Exponent ()
 Pops two elements, computes the power then pushes the result on the stack The exponent has to be a scalar. More...
 
void SquareRoot ()
 Pop an element, compute its square root, then push the root on the stack. More...
 
void AbsoluteValue ()
 Pop an element, compute its absolute value, then push the result on the stack. More...
 
void Log ()
 Pop an element, compute its log, then push the result on the stack. More...
 
void Log10 ()
 Pop an element, compute its base 10 log, then push the result on the stack. More...
 
void LeftShift ()
 Pop the top element, then perform a left shift with zero fill. More...
 
void RightShift ()
 Pop the top element, then perform a right shift with zero fill. More...
 
void MinimumPixel ()
 Pop two elements, then push the minimum on a pixel by pixel basis back on the stack. More...
 
void MaximumPixel ()
 Pop two elements, then push the maximum on a pixel by pixel basis back on the stack. More...
 
void MinimumLine ()
 Pop one element, then push the minimum on the stack. More...
 
void MaximumLine ()
 Pop one element, then push the maximum on the stack. More...
 
void Minimum2 ()
 Not implemented in Calculator.cpp. More...
 
void Maximum2 ()
 Not implemented in Calculator.cpp. More...
 
void GreaterThan ()
 Pop two elements off the stack and compare them to see where one is greater than the other, then push the results on the stack. More...
 
void LessThan ()
 Pop two elements off the stack and compare them to see where one is less than the other, then push the results on the stack. More...
 
void Equal ()
 Pop two elements off the stack and compare them to see where one is equal to the other, then push the results on the stack. More...
 
void LessThanOrEqual ()
 Pop two elements off the stack and compare them to see where one is less than or equal to the other, then push the results on the stack. More...
 
void GreaterThanOrEqual ()
 Pop two elements off the stack and compare them to see where one is greater than or equal to the other, then push the results on the stack. More...
 
void NotEqual ()
 Pop two elements off the stack and compare them to see where one is not equal to the other, then push the results on the stack. More...
 
void And ()
 Pop two elements, AND them, then push the result on the stack. More...
 
void Or ()
 Pop two elements, OR them, then push the result on the stack. More...
 
void Sine ()
 Pops one element and push the sine. More...
 
void Cosine ()
 Pops one element and push the cosine. More...
 
void Tangent ()
 Pops one element and push the tangent. More...
 
void Secant ()
 Pops one element and push the secant. More...
 
void Cosecant ()
 Pops one element and push the cosecant. More...
 
void Cotangent ()
 Pops one element and push the cotangent. More...
 
void Arcsine ()
 Pops one element and push the arcsine. More...
 
void Arccosine ()
 Pops one element and push the arccosine. More...
 
void Arctangent ()
 Pops one element and push the arctangent. More...
 
void Arctangent2 ()
 Pops two elements and push the arctangent. More...
 
void SineH ()
 Pops one element and push the hyperbolic sine. More...
 
void CosineH ()
 Pops one element and push the hyperbolic cosine. More...
 
void TangentH ()
 Pops one element and push the hyperbolic tangent. More...
 
void ArcsineH ()
 Pops one element and push the inverse hyperbolic sine. More...
 
void ArccosineH ()
 Pops one element and push the inverse hyperbolic cosine. More...
 
void ArctangentH ()
 Pops one element and push the inverse hyperbolic tangent. More...
 
void Push (double scalar)
 Push a scalar onto the stack. More...
 
void Push (Buffer &buff)
 Push a buffer onto the stack. More...
 
void Push (QVector< double > &vect)
 Push a vector onto the stack. More...
 
QVector< double > Pop (bool keepSpecials=false)
 Pop an element off the stack. More...
 
void PrintTop ()
 Print the vector at the top of the stack. More...
 
bool Empty ()
 Check if the stack is empty. More...
 
virtual void Clear ()
 Clear out the stack. More...
 

Protected Member Functions

void PerformOperation (QVector< double > &results, QVector< double >::iterator arg1Start, QVector< double >::iterator arg1End, double operation(double))
 Performs the mathematical operations on each argument. More...
 
void PerformOperation (QVector< double > &results, QVector< double >::iterator arg1Start, QVector< double >::iterator arg1End, QVector< double >::iterator arg2Start, QVector< double >::iterator arg2End, double operation(double, double))
 Performs the mathematical operation on each pair of arguments, or a set of agruments against a single argument. More...
 
int StackSize ()
 Returns the current stack size. More...
 

Private Attributes

QStack< QVector< double > > * p_valStack
 The current stack of arguments. More...
 

Detailed Description

Calculator for arrays.

This class is a RPN calculator on arrays. It uses classic push/pop/operator methods. That is, push array1, push array2, add, pop arrayResult.

Author
2007-04-01 Sean Crosby
History:

2007-06-11 Jeff Anderson - Fixed bug in Push(Buffer) method. NAN was not computed properly.

2007-08-21 Steven Lambright - Moved the infix to postfix conversion into its own class.

2008-01-28 Steven Lambright - Added more support for the power operator

2008-03-28 Steven Lambright - Condensed math methods to just call PerformOperation(...). Converted valarray's to vectors (in order to use iterators).

2008-06-18 Christopher Austin - Added as well as fixed documentation

2010-02-23 Steven Lambright - Added Minimum2, Maximum2 and all min/max operations now ignore special pixels.

2010-04-08 Steven Lambright - Made min, max have proper implementations and vectors are now QVectors.

2017-08-30 Summer Stapleton - Updated documentation. References #4807.

2017-08-30 Tyler Wilson and Ian Humphrey - provided std:: namespace for isnan to fix ambiguity error when using c++11. References #4809.

2018-09-27 Kaitlyn Lee - Fixed the cout in PrintTop() so that -nan is printed as nan. Updated code up to standards. References #5520.

Definition at line 70 of file Calculator.h.

Constructor & Destructor Documentation

◆ Calculator()

Isis::Calculator::Calculator ( )

The code that performs math operations is designed to call a function and use the result.

These helper methods convert standard operators into functions which perform the desired operations. See the implementation of Calculator::Negative for an example.Constructor

Definition at line 47 of file Calculator.cpp.

◆ ~Calculator()

Isis::Calculator::~Calculator ( )
virtual

Virtual Constructor.

Destructor.

Definition at line 54 of file Calculator.cpp.

Member Function Documentation

◆ AbsoluteValue()

void Isis::Calculator::AbsoluteValue ( )

Pop an element, compute its absolute value, then push the result on the stack.

Definition at line 422 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ Add()

void Isis::Calculator::Add ( )

Pops two elements, adds them, then pushes the sum on the stack.

Definition at line 345 of file Calculator.cpp.

References Isis::AddOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ And()

void Isis::Calculator::And ( )

Pop two elements, AND them, then push the result on the stack.

Definition at line 694 of file Calculator.cpp.

References Isis::BitwiseAndOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Arccosine()

void Isis::Calculator::Arccosine ( )

Pops one element and push the arccosine.

Definition at line 792 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ ArccosineH()

void Isis::Calculator::ArccosineH ( )

Pops one element and push the inverse hyperbolic cosine.

Definition at line 822 of file Calculator.cpp.

◆ Arcsine()

void Isis::Calculator::Arcsine ( )

Pops one element and push the arcsine.

Definition at line 782 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ ArcsineH()

void Isis::Calculator::ArcsineH ( )

Pops one element and push the inverse hyperbolic sine.

Definition at line 812 of file Calculator.cpp.

◆ Arctangent()

void Isis::Calculator::Arctangent ( )

Pops one element and push the arctangent.

Definition at line 802 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ Arctangent2()

void Isis::Calculator::Arctangent2 ( )

Pops two elements and push the arctangent.

Definition at line 842 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ ArctangentH()

void Isis::Calculator::ArctangentH ( )

Pops one element and push the inverse hyperbolic tangent.

Definition at line 832 of file Calculator.cpp.

◆ Clear()

void Isis::Calculator::Clear ( )
virtual

Clear out the stack.

Reimplemented in Isis::CubeCalculator.

Definition at line 1036 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::compile(), and Isis::InlineCalculator::popVariables().

◆ Cosecant()

void Isis::Calculator::Cosecant ( )

Pops one element and push the cosecant.

Definition at line 752 of file Calculator.cpp.

References Isis::CosecantOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Cosine()

void Isis::Calculator::Cosine ( )

Pops one element and push the cosine.

Definition at line 732 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ CosineH()

void Isis::Calculator::CosineH ( )

Pops one element and push the hyperbolic cosine.

Definition at line 865 of file Calculator.cpp.

◆ Cotangent()

void Isis::Calculator::Cotangent ( )

Pops one element and push the cotangent.

Definition at line 772 of file Calculator.cpp.

References Isis::CotangentOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Divide()

void Isis::Calculator::Divide ( )

Pops two, divides them, then pushes the quotient on the stack.

Definition at line 369 of file Calculator.cpp.

References Isis::DivideOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Empty()

bool Isis::Calculator::Empty ( )

Check if the stack is empty.

Returns
bool True if the stack is empty

Definition at line 1028 of file Calculator.cpp.

◆ Equal()

void Isis::Calculator::Equal ( )

Pop two elements off the stack and compare them to see where one is equal to the other, then push the results on the stack.

Definition at line 632 of file Calculator.cpp.

References Isis::EqualOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Exponent()

void Isis::Calculator::Exponent ( )

Pops two elements, computes the power then pushes the result on the stack The exponent has to be a scalar.

Exceptions
Isis::iException::Math

Definition at line 397 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ GreaterThan()

void Isis::Calculator::GreaterThan ( )

Pop two elements off the stack and compare them to see where one is greater than the other, then push the results on the stack.

Definition at line 602 of file Calculator.cpp.

References Isis::GreaterThanOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ GreaterThanOrEqual()

void Isis::Calculator::GreaterThanOrEqual ( )

Pop two elements off the stack and compare them to see where one is greater than or equal to the other, then push the results on the stack.

Definition at line 647 of file Calculator.cpp.

References Isis::GreaterThanOrEqualOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ LeftShift()

void Isis::Calculator::LeftShift ( )

Pop the top element, then perform a left shift with zero fill.

Exceptions
Isis::iException::Math

Definition at line 456 of file Calculator.cpp.

References _FILEINFO_.

Referenced by Isis::InlineCalculator::initialize().

◆ LessThan()

void Isis::Calculator::LessThan ( )

Pop two elements off the stack and compare them to see where one is less than the other, then push the results on the stack.

Definition at line 617 of file Calculator.cpp.

References Isis::LessThanOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ LessThanOrEqual()

void Isis::Calculator::LessThanOrEqual ( )

Pop two elements off the stack and compare them to see where one is less than or equal to the other, then push the results on the stack.

Definition at line 662 of file Calculator.cpp.

References Isis::LessThanOrEqualOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Log()

void Isis::Calculator::Log ( )

Pop an element, compute its log, then push the result on the stack.

Exceptions
Isis::iException::Math

Definition at line 434 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ Log10()

void Isis::Calculator::Log10 ( )

Pop an element, compute its base 10 log, then push the result on the stack.

Definition at line 444 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ Maximum2()

void Isis::Calculator::Maximum2 ( )

Not implemented in Calculator.cpp.

◆ MaximumLine()

void Isis::Calculator::MaximumLine ( )

Pop one element, then push the maximum on the stack.

Definition at line 552 of file Calculator.cpp.

References Isis::IsSpecial().

◆ MaximumPixel()

void Isis::Calculator::MaximumPixel ( )

Pop two elements, then push the maximum on a pixel by pixel basis back on the stack.

Definition at line 587 of file Calculator.cpp.

References Isis::MaximumOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Minimum2()

void Isis::Calculator::Minimum2 ( )

Not implemented in Calculator.cpp.

◆ MinimumLine()

void Isis::Calculator::MinimumLine ( )

Pop one element, then push the minimum on the stack.

Definition at line 533 of file Calculator.cpp.

References Isis::IsSpecial().

◆ MinimumPixel()

void Isis::Calculator::MinimumPixel ( )

Pop two elements, then push the minimum on a pixel by pixel basis back on the stack.

Definition at line 572 of file Calculator.cpp.

References Isis::MinimumOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Modulus()

void Isis::Calculator::Modulus ( )

Pops two elements, mods them, then pushes the result on the stack.

Definition at line 381 of file Calculator.cpp.

References Isis::ModulusOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Multiply()

void Isis::Calculator::Multiply ( )

Pops two elements, multiplies them, then pushes the product on the stack.

Definition at line 332 of file Calculator.cpp.

References Isis::MultiplyOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Negative()

void Isis::Calculator::Negative ( )

Pops an element, negates it, then pushes the result.

Definition at line 322 of file Calculator.cpp.

References Isis::NegateOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ NotEqual()

void Isis::Calculator::NotEqual ( )

Pop two elements off the stack and compare them to see where one is not equal to the other, then push the results on the stack.

Definition at line 677 of file Calculator.cpp.

References Isis::NotEqualOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Or()

void Isis::Calculator::Or ( )

Pop two elements, OR them, then push the result on the stack.

Definition at line 708 of file Calculator.cpp.

References Isis::BitwiseOrOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ PerformOperation() [1/2]

void Isis::Calculator::PerformOperation ( QVector< double > &  results,
QVector< double >::iterator  arg1Start,
QVector< double >::iterator  arg1End,
double   operationdouble 
)
protected

Performs the mathematical operations on each argument.

Parameters
results[out] The results of the performed operation
arg1StartThe first argument to have the operation done on
arg1EndOne argument beyond the final argument to have the operation done upon
operationThe operation to be done on all arguments

Definition at line 1052 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::floatModulus().

◆ PerformOperation() [2/2]

void Isis::Calculator::PerformOperation ( QVector< double > &  results,
QVector< double >::iterator  arg1Start,
QVector< double >::iterator  arg1End,
QVector< double >::iterator  arg2Start,
QVector< double >::iterator  arg2End,
double   operationdouble, double 
)
protected

Performs the mathematical operation on each pair of arguments, or a set of agruments against a single argument.

Parameters
results[out] The results of the performed operation
arg1StartThe first of the primary argument to have the operation done on
arg1EndOne arguement beyond the final primary argument to have the operation done upon
arg2StartThe first of the secondaty argument to have the operation done on
arg2EndOne arguement beyond the final secondary argument to have the operation done upon
operationThe operation to be done on all pairs of arguments

Definition at line 1081 of file Calculator.cpp.

References _FILEINFO_.

◆ Pop()

QVector< double > Isis::Calculator::Pop ( bool  keepSpecials = false)

Pop an element off the stack.

Parameters
keepSpecialsIf true, special pixels will be preserved; otherwise, they will be mapped to double values
Returns
The top of the stack, which gets popped

Definition at line 964 of file Calculator.cpp.

References _FILEINFO_, Isis::Hrs, Isis::Lrs, and Isis::Null.

Referenced by Isis::InlineCalculator::degrees(), Isis::InlineCalculator::evaluate(), Isis::InlineCalculator::floatModulus(), Isis::InlineCalculator::logicalAnd(), Isis::InlineCalculator::logicalOr(), and Isis::InlineCalculator::radians().

◆ PrintTop()

void Isis::Calculator::PrintTop ( )

Print the vector at the top of the stack.

Definition at line 1004 of file Calculator.cpp.

◆ Push() [1/3]

◆ Push() [2/3]

void Isis::Calculator::Push ( Buffer buff)

Push a buffer onto the stack.

Parameters
buffThe buffer that will be pushed on the stack

Definition at line 920 of file Calculator.cpp.

References Isis::IsHisPixel(), Isis::IsHrsPixel(), Isis::IsLisPixel(), Isis::IsLrsPixel(), Isis::IsNullPixel(), Isis::IsSpecial(), and Isis::Buffer::size().

◆ Push() [3/3]

void Isis::Calculator::Push ( QVector< double > &  vect)

Push a vector onto the stack.

Parameters
vectThe vector that will be pushed on the stack

Definition at line 898 of file Calculator.cpp.

◆ RightShift()

void Isis::Calculator::RightShift ( )

Pop the top element, then perform a right shift with zero fill.

Exceptions
Isis::iException::Math

Definition at line 495 of file Calculator.cpp.

References _FILEINFO_.

Referenced by Isis::InlineCalculator::initialize().

◆ Secant()

void Isis::Calculator::Secant ( )

Pops one element and push the secant.

Definition at line 762 of file Calculator.cpp.

References Isis::SecantOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Sine()

void Isis::Calculator::Sine ( )

Pops one element and push the sine.

Definition at line 722 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ SineH()

void Isis::Calculator::SineH ( )

Pops one element and push the hyperbolic sine.

Definition at line 855 of file Calculator.cpp.

◆ SquareRoot()

void Isis::Calculator::SquareRoot ( )

Pop an element, compute its square root, then push the root on the stack.

Exceptions
Isis::iException::Math

Definition at line 412 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ StackSize()

int Isis::Calculator::StackSize ( )
protected

Returns the current stack size.

Get the current stack size.

Returns
int Number of arguments in the stack

Definition at line 889 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::evaluate().

◆ Subtract()

void Isis::Calculator::Subtract ( )

Pops two elements, subtracts them, then pushes the difference on the stack.

Definition at line 357 of file Calculator.cpp.

References Isis::SubtractOperator().

Referenced by Isis::InlineCalculator::initialize().

◆ Tangent()

void Isis::Calculator::Tangent ( )

Pops one element and push the tangent.

Definition at line 742 of file Calculator.cpp.

Referenced by Isis::InlineCalculator::initialize().

◆ TangentH()

void Isis::Calculator::TangentH ( )

Pops one element and push the hyperbolic tangent.

Definition at line 875 of file Calculator.cpp.

Member Data Documentation

◆ p_valStack

QStack< QVector<double> >* Isis::Calculator::p_valStack
private

The current stack of arguments.

Definition at line 150 of file Calculator.h.


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