14#include "Calculator.h"
15#include "InfixToPostfix.h"
16#include "IException.h"
17#include "SpecialPixel.h"
119 return a > b ? 1.0 : 0.0;
132 return a < b ? 1.0 : 0.0;
145 return a == b ? 1.0 : 0.0;
158 return a >= b ? 1.0 : 0.0;
171 return a <= b ? 1.0 : 0.0;
184 return a != b ? 1.0 : 0.0;
231 return (a > 0) ? (int)(a + 0.5) : (int)(a - 0.5);
283 if (std::isnan(a))
return (a);
284 if (std::isnan(b))
return (b);
285 return (a > b) ? a : b;
297 if (std::isnan(a))
return (a);
298 if (std::isnan(b))
return (b);
299 return (a < b) ? a : b;
308 QVector<double> result =
Pop();
318 QVector<double> y =
Pop();
319 QVector<double> x =
Pop();
320 QVector<double> result;
331 QVector<double> y =
Pop();
332 QVector<double> x =
Pop();
333 QVector<double> result;
343 QVector<double> y =
Pop();
344 QVector<double> x =
Pop();
345 QVector<double> result;
355 QVector<double> y =
Pop();
356 QVector<double> x =
Pop();
357 QVector<double> result;
367 QVector<double> y =
Pop();
368 QVector<double> x =
Pop();
369 QVector<double> result;
383 QVector<double> exponent =
Pop();
384 QVector<double> x =
Pop();
385 QVector<double> result;
387 PerformOperation(result, x.begin(), x.end(), exponent.begin(), exponent.end(), pow);
398 QVector<double> result =
Pop();
408 QVector<double> result =
Pop();
420 QVector<double> result =
Pop();
430 QVector<double> result =
Pop();
442 QVector<double> y =
Pop();
444 IString msg =
"When trying to do a left shift calculation, a non-scalar "
445 "shift value was encountered. Shifting requires scalars.";
449 QVector<double> x =
Pop();
451 if ((
int)y[0] > (
int)x.size()) {
452 IString msg =
"When trying to do a left shift calculation, a shift "
453 "value greater than the data size was encountered. "
454 "Shifting by this value would erase all of the data.";
458 QVector<double> result;
459 int shift = (int)y[0];
460 result.resize(x.size());
462 for (
int i = 0; i < result.size(); i++) {
463 if (i + shift < x.size() && i + shift >= 0)
464 result[i] = x[i+shift];
466 result[i] = sqrt(-1.0);
481 QVector<double> y =
Pop();
483 IString msg =
"When trying to do a right shift calculation, a non-scalar "
484 "shift value was encountered. Shifting requires scalars.";
488 QVector<double> x =
Pop();
490 if ((
int)y[0] > (
int)x.size()) {
491 IString msg =
"When trying to do a right shift calculation, a shift "
492 "value greater than the data size was encountered. "
493 "Shifting by this value would erase all of the data.";
497 QVector<double> result;
498 int shift = (int)y[0];
499 result.resize(x.size());
501 for (
int i = 0; i < (int)result.size(); i++) {
502 if (i - shift < (
int)x.size() && i - shift >= 0) {
503 result[i] = x[i-shift];
506 result[i] = sqrt(-1.0);
519 QVector<double> result =
Pop();
521 double minVal = result[0];
522 for (
int i = 0; i < result.size(); i++) {
524 minVal = min(minVal, result[i]);
529 result.push_back(minVal);
538 QVector<double> result =
Pop();
540 double maxVal = result[0];
541 for (
int i = 0; i < result.size(); i++) {
543 maxVal = max(maxVal, result[i]);
548 result.push_back(maxVal);
558 QVector<double> x =
Pop();
559 QVector<double> y =
Pop();
560 QVector<double> result;
573 QVector<double> x =
Pop();
574 QVector<double> y =
Pop();
575 QVector<double> result;
588 QVector<double> y =
Pop();
589 QVector<double> x =
Pop();
590 QVector<double> result;
603 QVector<double> y =
Pop();
604 QVector<double> x =
Pop();
605 QVector<double> result;
618 QVector<double> y =
Pop();
619 QVector<double> x =
Pop();
620 QVector<double> result;
633 QVector<double> y =
Pop();
634 QVector<double> x =
Pop();
635 QVector<double> result;
648 QVector<double> y =
Pop();
649 QVector<double> x =
Pop();
650 QVector<double> result;
663 QVector<double> y =
Pop();
664 QVector<double> x =
Pop();
665 QVector<double> result;
680 QVector<double> y =
Pop();
681 QVector<double> x =
Pop();
682 QVector<double> result;
694 QVector<double> y =
Pop();
695 QVector<double> x =
Pop();
696 QVector<double> result;
708 QVector<double> result =
Pop();
718 QVector<double> result =
Pop();
728 QVector<double> result =
Pop();
738 QVector<double> result =
Pop();
748 QVector<double> result =
Pop();
758 QVector<double> result =
Pop();
768 QVector<double> result =
Pop();
778 QVector<double> result =
Pop();
788 QVector<double> result =
Pop();
798 QVector<double> result =
Pop();
808 QVector<double> result =
Pop();
818 QVector<double> result =
Pop();
828 QVector<double> y =
Pop();
829 QVector<double> x =
Pop();
830 QVector<double> result;
841 QVector<double> result =
Pop();
851 QVector<double> result =
Pop();
861 QVector<double> result =
Pop();
906 QVector<double> b(buff.size());
908 for (
int i = 0; i < buff.size(); i++) {
953 IString msg =
"Math calculator stack is empty, cannot perform any "
961 for (
int i = 0; i < (int)top.size(); i++) {
962 if (std::isnan(top[i])) {
966 else if (top[i] > DBL_MAX) {
970 else if (top[i] < -DBL_MAX) {
995 for (
int i = 0; i < (int)top.size(); i++) {
996 temp += QString::number(top[i]);
1003 temp.replace(QRegExp(
"-nan"),
"nan");
1004 std::cout<<temp<<std::endl;
1040 double operation(
double)) {
1041 results.resize(arg1End - arg1Start);
1043 for (
int pos = 0; pos < results.size(); pos++) {
1044 results[pos] = operation(*arg1Start);
1071 double operation(
double,
double)) {
1072 if (arg1End - arg1Start != 1 && arg2End - arg2Start != 1 &&
1073 arg1End - arg1Start != arg2End - arg2Start) {
1074 IString msg =
"The stack based calculator cannot operate on vectors "
1075 "of differing sizes.";
1079 int iSize = max(arg1End - arg1Start, arg2End - arg2Start);
1080 results.resize(iSize);
1082 for (
int pos = 0; pos < results.size(); pos++) {
1083 results[pos] = operation(*arg1Start, *arg2Start);
1085 if (arg1Start + 1 != arg1End) arg1Start++;
1086 if (arg2Start + 1 != arg2End) arg2Start++;
Buffer for reading and writing cube data.
void LessThan()
Pop two elements off the stack and compare them to see where one is less than the other,...
void PrintTop()
Print the vector at the top of the stack.
void Cosecant()
Pops one element and push the cosecant.
void Arctangent2()
Pops two elements and push the arctangent.
void Modulus()
Pops two elements, mods them, then pushes the result on the stack.
void Tangent()
Pops one element and push the tangent.
int StackSize()
Returns the current stack size.
void Arctangent()
Pops one element and push the arctangent.
void SineH()
Pops one element and push the hyperbolic sine.
void Divide()
Pops two, divides them, then pushes the quotient 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 othe...
void TangentH()
Pops one element and push the hyperbolic tangent.
void Push(double scalar)
Push a scalar onto the stack.
void Cotangent()
Pops one element and push the cotangent.
void ArctangentH()
Pops one element and push the inverse hyperbolic tangent.
Calculator()
The code that performs math operations is designed to call a function and use the result.
void Add()
Pops two elements, adds them, then pushes the sum on the stack.
void Multiply()
Pops two elements, multiplies them, then pushes the product on the stack.
void ArcsineH()
Pops one element and push the inverse hyperbolic sine.
QStack< QVector< double > > * p_valStack
The current stack of arguments.
void Negative()
Pops an element, negates it, then pushes the result.
virtual ~Calculator()
Virtual Constructor.
void RightShift()
Pop the top element, then perform a right shift with zero fill.
void Or()
Pop two elements, OR them, then push the result on the stack.
void Sine()
Pops one element and push the sine.
virtual void Clear()
Clear out the stack.
void PerformOperation(QVector< double > &results, QVector< double >::iterator arg1Start, QVector< double >::iterator arg1End, double operation(double))
Performs the mathematical operations on each argument.
void Arcsine()
Pops one element and push the arcsine.
void LeftShift()
Pop the top element, then perform a left shift with zero fill.
void LessThanOrEqual()
Pop two elements off the stack and compare them to see where one is less than or equal to the other,...
void NotEqual()
Pop two elements off the stack and compare them to see where one is not equal to the other,...
void GreaterThan()
Pop two elements off the stack and compare them to see where one is greater than the other,...
void Arccosine()
Pops one element and push the arccosine.
void Log10()
Pop an element, compute its base 10 log, then push the result on the stack.
void MaximumLine()
Pop one element, then push the maximum on the stack.
void MaximumPixel()
Pop two elements, then push the maximum on a pixel by pixel basis back on the stack.
void Secant()
Pops one element and push the secant.
void MinimumLine()
Pop one element, then push the minimum on the stack.
void Log()
Pop an element, compute its log, then push the result on the stack.
void Subtract()
Pops two elements, subtracts them, then pushes the difference on the stack.
void Equal()
Pop two elements off the stack and compare them to see where one is equal to the other,...
QVector< double > Pop(bool keepSpecials=false)
Pop an element off the stack.
void AbsoluteValue()
Pop an element, compute its absolute value, then push the result on the stack.
void MinimumPixel()
Pop two elements, then push the minimum on a pixel by pixel basis back on the stack.
void Exponent()
Pops two elements, computes the power then pushes the result on the stack The exponent has to be a sc...
void ArccosineH()
Pops one element and push the inverse hyperbolic cosine.
void And()
Pop two elements, AND them, then push the result on the stack.
void SquareRoot()
Pop an element, compute its square root, then push the root on the stack.
void Cosine()
Pops one element and push the cosine.
bool Empty()
Check if the stack is empty.
void CosineH()
Pops one element and push the hyperbolic cosine.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ Programmer
This error is for when a programmer made an API call that was illegal.
Adds specific functionality to C++ strings.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
double SecantOperator(double a)
Returns the secant of the input a.
const double Hrs
Value for an Isis High Representation Saturation pixel.
double AddOperator(double a, double b)
Returns the result of additing a with b.
double CosecantOperator(double a)
Returns the cosecant of the input a.
double ModulusOperator(double a, double b)
Returns the modulus of a by b.
bool IsLrsPixel(const double d)
Returns if the input pixel is low representation saturation.
double MultiplyOperator(double a, double b)
Returns the result of a multiplied by b.
bool IsNullPixel(const double d)
Returns if the input pixel is null.
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
double GreaterThanOrEqualOperator(double a, double b)
Returns 1.0 if a is greater than or equal to b.
double DivideOperator(double a, double b)
Returns the result of dividing a by b.
double NotEqualOperator(double a, double b)
Returns 1.0 is a is not equal to b.
double EqualOperator(double a, double b)
Returns 1.0 if a is equal ot b.
double SubtractOperator(double a, double b)
Returns the result of subtracting b from a.
double CotangentOperator(double a)
Returns the cotangent of the input a.
double BitwiseOrOperator(double a, double b)
Returns the result of a bitwise OR across a and b.
const double Null
Value for an Isis Null pixel.
bool IsHisPixel(const double d)
Returns if the input pixel is high instrument saturation.
const double Lrs
Value for an Isis Low Representation Saturation pixel.
double BitwiseAndOperator(double a, double b)
Returns the result of a bitwise AND accross a and b.
double NegateOperator(double a)
Returns the nagative of the input parameter.
double LessThanOperator(double a, double b)
Returns 1.0 if a is less than b.
double LessThanOrEqualOperator(double a, double b)
Returns 1.0 if a is less than or eqaul to b.
bool IsSpecial(const double d)
Returns if the input pixel is special.
double MinimumOperator(double a, double b)
Returns the min of a and b.
double GreaterThanOperator(double a, double b)
Returns 1.0 if a is greater than b.
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
double MaximumOperator(double a, double b)
Returns the max of a and b.
int Round(double a)
Returns the result of rounding the input a to the closest integer.
Namespace for the standard library.