USGS

Isis 3.0 Object Programmers' Reference

Home

Isis::Calculator Class Reference
[Math]

#include <Calculator.h>

Inheritance diagram for Isis::Calculator:

Inheritance graph
[legend]
Collaboration diagram for Isis::Calculator:

Collaboration graph
[legend]
List of all members.

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

For internal use only.

History:
2007-06-11 Jeff Anderson - Fixed bug in Push(Buffer) method. NAN was not computed properly.
History:
2007-08-21 Steven Lambright - Moved the infix to postfix conversion into its own class.
History:
2008-01-28 Steven Lambright - Added more support for the power operator
History:
2008-03-28 Steven Lambright - Condensed math methods to just call PerformOperation(...). Converted valarray's to vectors (in order to use iterators)
History:
2008-06-18 Christopher Austin - Added as well as fixed documentation

Definition at line 57 of file Calculator.h.

Public Member Functions

 Calculator ()
 Constructor.
virtual ~Calculator ()
 Virtual Constructor.
void Negative ()
 Pops an element, negates it, then pushes the result.
void Multiply ()
 Pops two elements, multiplies them, then pushes the product on the stack.
void Add ()
 Pops two elements, adds them, then pushes the sum on the stack.
void Subtract ()
 Pops two elements, subtracts them, then pushes the difference on the stack.
void Divide ()
 Pops two, divides them, then pushes the quotient on the stack.
void Modulus ()
 Pops two elements, mods them, then pushes the result on the stack.
void Exponent ()
 Pops two elements, computes the power then pushes the result on the stack The exponent has to be a scalar.
void SquareRoot ()
 Pop an element, compute its square root, then push the root on the stack.
void AbsoluteValue ()
 Pop an element, compute its absolute value, then push the result on the stack.
void Log ()
 Pop an element, compute its log, then push the result on the stack.
void Log10 ()
 Pop an element, compute its base 10 log, then push the result on the stack.
void LeftShift ()
 Pop the top element, then perform a left shift with zero fill.
void RightShift ()
 Pop the top element, then perform a right shift with zero fill.
void Minimum ()
 Pop one element, then push the maximum on the stack.
void Maximum ()
 Pop one element, then push the maximum on the stack.
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.
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.
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.
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.
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.
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.
void And ()
 Pop two elements, AND them, then push the result on the stack.
void Or ()
 Pop two elements, OR them, then push the result on the stack.
void Sine ()
 Pops one element and push the sine.
void Cosine ()
 Pops one element and push the cosine.
void Tangent ()
 Pops one element and push the tangent.
void Secant ()
 Pops one element and push the secant.
void Cosecant ()
 Pops one element and push the cosecant.
void Cotangent ()
 Pops one element and push the cotangent.
void Arcsine ()
 Pops one element and push the arcsine.
void Arccosine ()
 Pops one element and push the arccosine.
void Arctangent ()
 Pops one element and push the arctangent.
void Arctangent2 ()
 Pops two elements and push the arctangent.
void SineH ()
 Pops one element and push the hyperbolic sine.
void CosineH ()
 Pops one element and push the hyperbolic cosine.
void TangentH ()
 Pops one element and push the hyperbolic tangent.
void ArcsineH ()
 Pops one element and push the inverse hyperbolic sine.
void ArccosineH ()
 Pops one element and push the inverse hyperbolic cosine.
void ArctangentH ()
 Pops one element and push the inverse hyperbolic tangent.
void Push (double scalar)
 Push a scalar onto the stack.
void Push (Buffer &buff)
 Push a buffer onto the stack.
void Push (std::vector< double > &vect)
 Push a vector onto the stack.
std::vector< double > Pop (bool keepSpecials=false)
 Pop an element off the stack.
void PrintTop ()
 Print the vector at the top of the stack.
bool Empty ()
 Check if the stack is empty.
virtual void Clear ()
 Clear out the stack.

Protected Member Functions

void PerformOperation (std::vector< double > &results, std::vector< double >::iterator arg1Start, std::vector< double >::iterator arg1End, double operation(double))
 Performs the mathematical operations on each argument.
void PerformOperation (std::vector< double > &results, std::vector< double >::iterator arg1Start, std::vector< double >::iterator arg1End, std::vector< double >::iterator arg2Start, std::vector< 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.
int StackSize ()
 Returns the current stack size.

Private Attributes

std::stack< std::vector< double > > p_valStack
 The current stack of arguments.


Constructor & Destructor Documentation

Isis::Calculator::Calculator (  ) 

Constructor.

Definition at line 235 of file Calculator.cpp.

virtual Isis::Calculator::~Calculator (  )  [inline, virtual]

Virtual Constructor.

Definition at line 61 of file Calculator.h.


Member Function Documentation

void Isis::Calculator::AbsoluteValue (  ) 

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

Definition at line 341 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Add (  ) 

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

Definition at line 264 of file Calculator.cpp.

References Isis::AddOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::And (  ) 

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

Definition at line 565 of file Calculator.cpp.

References Isis::BitwiseAndOperator(), PerformOperation(), Pop(), Push(), x, and y.

void Isis::Calculator::Arccosine (  ) 

Pops one element and push the arccosine.

Definition at line 661 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::ArccosineH (  ) 

Pops one element and push the inverse hyperbolic cosine.

Definition at line 691 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

void Isis::Calculator::Arcsine (  ) 

Pops one element and push the arcsine.

Definition at line 651 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::ArcsineH (  ) 

Pops one element and push the inverse hyperbolic sine.

Definition at line 681 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

void Isis::Calculator::Arctangent (  ) 

Pops one element and push the arctangent.

Definition at line 671 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Arctangent2 (  ) 

Pops two elements and push the arctangent.

Definition at line 711 of file Calculator.cpp.

References p_valStack, PerformOperation(), Pop(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::ArctangentH (  ) 

Pops one element and push the inverse hyperbolic tangent.

Definition at line 701 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

void Isis::Calculator::Clear (  )  [virtual]

Clear out the stack.

Reimplemented in Isis::CubeCalculator.

Definition at line 887 of file Calculator.cpp.

References p_valStack.

Referenced by Isis::CubeCalculator::Clear().

void Isis::Calculator::Cosecant (  ) 

Pops one element and push the cosecant.

Definition at line 621 of file Calculator.cpp.

References Isis::CosecantOperator(), PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Cosine (  ) 

Pops one element and push the cosine.

Definition at line 601 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::CosineH (  ) 

Pops one element and push the hyperbolic cosine.

Definition at line 734 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Cotangent (  ) 

Pops one element and push the cotangent.

Definition at line 641 of file Calculator.cpp.

References Isis::CotangentOperator(), PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Divide (  ) 

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

Definition at line 288 of file Calculator.cpp.

References Isis::DivideOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

bool Isis::Calculator::Empty (  ) 

Check if the stack is empty.

Returns:
bool True if the stack is empty

Definition at line 879 of file Calculator.cpp.

References p_valStack.

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 508 of file Calculator.cpp.

References Isis::EqualOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

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 316 of file Calculator.cpp.

References PerformOperation(), Pop(), Push(), and x.

Referenced by Isis::CubeCalculator::PrepareCalculations().

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 480 of file Calculator.cpp.

References Isis::GreaterThanOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

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 522 of file Calculator.cpp.

References Isis::GreaterThanOrEqualOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::LeftShift (  ) 

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

Exceptions:
Isis::iException::Math 

Definition at line 375 of file Calculator.cpp.

References _FILEINFO_, Isis::iException::Message(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

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 494 of file Calculator.cpp.

References Isis::LessThanOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

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 536 of file Calculator.cpp.

References Isis::LessThanOrEqualOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Log (  ) 

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

Exceptions:
Isis::iException::Math 

Definition at line 353 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Log10 (  ) 

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

Definition at line 363 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Maximum (  ) 

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

Definition at line 463 of file Calculator.cpp.

References Pop(), Push(), and size.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Minimum (  ) 

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

Definition at line 447 of file Calculator.cpp.

References Pop(), Push(), and size.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Modulus (  ) 

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

Definition at line 300 of file Calculator.cpp.

References Isis::ModulusOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Multiply (  ) 

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

Definition at line 251 of file Calculator.cpp.

References Isis::MultiplyOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Negative (  ) 

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

Definition at line 241 of file Calculator.cpp.

References Isis::NegateOperator(), PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

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 550 of file Calculator.cpp.

References Isis::NotEqualOperator(), PerformOperation(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Or (  ) 

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

Definition at line 578 of file Calculator.cpp.

References Isis::BitwiseOrOperator(), PerformOperation(), Pop(), Push(), x, and y.

void Isis::Calculator::PerformOperation ( std::vector< double > &  results,
std::vector< double >::iterator  arg1Start,
std::vector< double >::iterator  arg1End,
std::vector< double >::iterator  arg2Start,
std::vector< double >::iterator  arg2End,
double   operation(double, 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
arg1Start The first of the primary argument to have the operation done on
arg1End One arguement beyond the final primary argument to have the operation done upon
arg2Start The first of the secondaty argument to have the operation done on
arg2End One arguement beyond the final secondary argument to have the operation done upon
operation The operation to be done on all pairs of arguments

Definition at line 932 of file Calculator.cpp.

References _FILEINFO_, Isis::iException::Message(), and pos.

void Isis::Calculator::PerformOperation ( std::vector< double > &  results,
std::vector< double >::iterator  arg1Start,
std::vector< double >::iterator  arg1End,
double   operation(double) 
) [protected]

Performs the mathematical operations on each argument.

Parameters:
results [out] The results of the performed operation
arg1Start The first argument to have the operation done on
arg1End One argument beyond the final argument to have the operation done upon
operation The operation to be done on all arguments

Definition at line 903 of file Calculator.cpp.

References pos.

Referenced by AbsoluteValue(), Add(), And(), Arccosine(), ArccosineH(), Arcsine(), ArcsineH(), Arctangent(), Arctangent2(), ArctangentH(), Cosecant(), Cosine(), CosineH(), Cotangent(), Divide(), Equal(), Exponent(), GreaterThan(), GreaterThanOrEqual(), LessThan(), LessThanOrEqual(), Log(), Log10(), Modulus(), Multiply(), Negative(), NotEqual(), Or(), Secant(), Sine(), SineH(), SquareRoot(), Subtract(), Tangent(), and TangentH().

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

Pop an element off the stack.

Parameters:
keepSpecials If 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 823 of file Calculator.cpp.

References _FILEINFO_, Isis::Hrs, Isis::Lrs, Isis::iException::Message(), Isis::Null, p_valStack, and top.

Referenced by AbsoluteValue(), Add(), And(), Arccosine(), ArccosineH(), Arcsine(), ArcsineH(), Arctangent(), Arctangent2(), ArctangentH(), Cosecant(), Cosine(), CosineH(), Cotangent(), Divide(), Equal(), Exponent(), GreaterThan(), GreaterThanOrEqual(), LeftShift(), LessThan(), LessThanOrEqual(), Log(), Log10(), Maximum(), Minimum(), Modulus(), Multiply(), Negative(), NotEqual(), Or(), RightShift(), Isis::CubeCalculator::RunCalculations(), Secant(), Sine(), SineH(), SquareRoot(), Subtract(), Tangent(), and TangentH().

void Isis::Calculator::PrintTop (  ) 

Print the vector at the top of the stack.

Definition at line 862 of file Calculator.cpp.

References p_valStack, and top.

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

Push a vector onto the stack.

Parameters:
vect The vector that will be pushed on the stack

Definition at line 758 of file Calculator.cpp.

References p_valStack.

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

Push a buffer onto the stack.

Parameters:
buff The buffer that will be pushed on the stack

Definition at line 780 of file Calculator.cpp.

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

void Isis::Calculator::Push ( double  scalar  ) 

Push a scalar onto the stack.

Parameters:
scalar The scalar that will be pushed on the stack

Definition at line 768 of file Calculator.cpp.

Referenced by AbsoluteValue(), Add(), And(), Arccosine(), ArccosineH(), Arcsine(), ArcsineH(), Arctangent(), ArctangentH(), Cosecant(), Cosine(), CosineH(), Cotangent(), Divide(), Equal(), Exponent(), GreaterThan(), GreaterThanOrEqual(), LeftShift(), LessThan(), LessThanOrEqual(), Log(), Log10(), Maximum(), Minimum(), Modulus(), Multiply(), Negative(), NotEqual(), Or(), RightShift(), Isis::CubeCalculator::RunCalculations(), Secant(), Sine(), SineH(), SquareRoot(), Subtract(), Tangent(), and TangentH().

void Isis::Calculator::RightShift (  ) 

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

Exceptions:
Isis::iException::Math 

Definition at line 411 of file Calculator.cpp.

References _FILEINFO_, Isis::iException::Message(), Pop(), Push(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Secant (  ) 

Pops one element and push the secant.

Definition at line 631 of file Calculator.cpp.

References PerformOperation(), Pop(), Push(), and Isis::SecantOperator().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Sine (  ) 

Pops one element and push the sine.

Definition at line 591 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::SineH (  ) 

Pops one element and push the hyperbolic sine.

Definition at line 724 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

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 331 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

int Isis::Calculator::StackSize (  )  [inline, protected]

Returns the current stack size.

Definition at line 129 of file Calculator.h.

References p_valStack.

Referenced by Isis::CubeCalculator::RunCalculations().

void Isis::Calculator::Subtract (  ) 

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

Definition at line 276 of file Calculator.cpp.

References PerformOperation(), Pop(), Push(), Isis::SubtractOperator(), x, and y.

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::Tangent (  ) 

Pops one element and push the tangent.

Definition at line 611 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().

void Isis::Calculator::TangentH (  ) 

Pops one element and push the hyperbolic tangent.

Definition at line 744 of file Calculator.cpp.

References PerformOperation(), Pop(), and Push().

Referenced by Isis::CubeCalculator::PrepareCalculations().


Member Data Documentation

std::stack<std::vector<double> > Isis::Calculator::p_valStack [private]

The current stack of arguments.

Definition at line 133 of file Calculator.h.

Referenced by Arctangent2(), Clear(), Empty(), Pop(), PrintTop(), Push(), and StackSize().


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