117 return a > b ? 1.0 : 0.0;
130 return a < b ? 1.0 : 0.0;
143 return a == b ? 1.0 : 0.0;
156 return a >= b ? 1.0 : 0.0;
169 return a <= b ? 1.0 : 0.0;
182 return a != b ? 1.0 : 0.0;
229 return (a > 0) ? (int)(a + 0.5) : (int)(a - 0.5);
281 if (isnan(a))
return (a);
282 if (isnan(b))
return (b);
283 return (a > b) ? a : b;
295 if (isnan(a))
return (a);
296 if (isnan(b))
return (b);
297 return (a < b) ? a : b;
302 Calculator::Calculator() {
309 Calculator::~Calculator() {
320 void Calculator::Negative() {
322 PerformOperation(result, result.begin(), result.end(),
NegateOperator);
330 void Calculator::Multiply() {
335 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
MultiplyOperator);
343 void Calculator::Add() {
347 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
AddOperator);
355 void Calculator::Subtract() {
359 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
SubtractOperator);
367 void Calculator::Divide() {
372 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
DivideOperator);
379 void Calculator::Modulus() {
384 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
ModulusOperator);
395 void Calculator::Exponent() {
400 PerformOperation(result, x.begin(), x.end(), exponent.begin(), exponent.end(), pow);
410 void Calculator::SquareRoot() {
412 PerformOperation(result, result.begin(), result.end(), sqrt);
420 void Calculator::AbsoluteValue() {
422 PerformOperation(result, result.begin(), result.end(), fabs);
432 void Calculator::Log() {
434 PerformOperation(result, result.begin(), result.end(), log);
442 void Calculator::Log10() {
444 PerformOperation(result, result.begin(), result.end(), log10);
454 void Calculator::LeftShift() {
457 IString msg =
"When trying to do a left shift calculation, a non-scalar "
458 "shift value was encountered. Shifting requires scalars.";
464 if((
int)y[0] > (
int)x.size()) {
465 IString msg =
"When trying to do a left shift calculation, a shift "
466 "value greater than the data size was encountered. "
467 "Shifting by this value would erase all of the data.";
472 int shift = (int)y[0];
473 result.resize(x.size());
475 for(
int i = 0; i < result.size(); i++) {
476 if(i + shift < x.size() && i + shift >= 0)
477 result[i] = x[i+shift];
479 result[i] = sqrt(-1.0);
493 void Calculator::RightShift() {
496 IString msg =
"When trying to do a right shift calculation, a non-scalar "
497 "shift value was encountered. Shifting requires scalars.";
503 if((
int)y[0] > (
int)x.size()) {
504 IString msg =
"When trying to do a right shift calculation, a shift "
505 "value greater than the data size was encountered. "
506 "Shifting by this value would erase all of the data.";
511 int shift = (int)y[0];
512 result.resize(x.size());
514 for(
int i = 0; i < (int)result.size(); i++) {
515 if(i - shift < (
int)x.size() && i - shift >= 0) {
516 result[i] = x[i-shift];
519 result[i] = sqrt(-1.0);
531 void Calculator::MinimumLine() {
534 double minVal = result[0];
535 for(
int i = 0; i < result.size(); i++) {
537 minVal = min(minVal, result[i]);
542 result.push_back(minVal);
550 void Calculator::MaximumLine() {
553 double maxVal = result[0];
554 for(
int i = 0; i < result.size(); i++) {
556 maxVal = max(maxVal, result[i]);
561 result.push_back(maxVal);
570 void Calculator::MinimumPixel() {
575 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
585 void Calculator::MaximumPixel() {
590 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
600 void Calculator::GreaterThan() {
605 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
615 void Calculator::LessThan() {
620 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
630 void Calculator::Equal() {
635 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
645 void Calculator::GreaterThanOrEqual() {
650 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
660 void Calculator::LessThanOrEqual() {
665 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
675 void Calculator::NotEqual() {
680 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
692 void Calculator::And() {
697 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
706 void Calculator::Or() {
711 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
720 void Calculator::Sine() {
722 PerformOperation(result, result.begin(), result.end(), sin);
730 void Calculator::Cosine() {
732 PerformOperation(result, result.begin(), result.end(), cos);
740 void Calculator::Tangent() {
742 PerformOperation(result, result.begin(), result.end(), tan);
750 void Calculator::Cosecant() {
760 void Calculator::Secant() {
762 PerformOperation(result, result.begin(), result.end(),
SecantOperator);
770 void Calculator::Cotangent() {
780 void Calculator::Arcsine() {
782 PerformOperation(result, result.begin(), result.end(), asin);
790 void Calculator::Arccosine() {
792 PerformOperation(result, result.begin(), result.end(), acos);
800 void Calculator::Arctangent() {
802 PerformOperation(result, result.begin(), result.end(), atan);
810 void Calculator::ArcsineH() {
812 PerformOperation(result, result.begin(), result.end(), asinh);
820 void Calculator::ArccosineH() {
822 PerformOperation(result, result.begin(), result.end(), acosh);
830 void Calculator::ArctangentH() {
832 PerformOperation(result, result.begin(), result.end(), atanh);
840 void Calculator::Arctangent2() {
845 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(), atan2);
853 void Calculator::SineH() {
855 PerformOperation(result, result.begin(), result.end(), sinh);
863 void Calculator::CosineH() {
865 PerformOperation(result, result.begin(), result.end(), cosh);
873 void Calculator::TangentH() {
875 PerformOperation(result, result.begin(), result.end(), tanh);
883 int Calculator::StackSize() {
884 return p_valStack->size();
893 p_valStack->push(vect);
902 void Calculator::Push(
double scalar) {
917 for(
int i = 0; i < buff.
size(); i++) {
961 if(p_valStack->empty()) {
962 IString msg =
"Math calculator stack is empty, cannot perform any "
967 top = p_valStack->top();
970 for(
int i = 0; i < (int)top.size(); i++) {
975 else if(top[i] > DBL_MAX) {
979 else if(top[i] < -DBL_MAX) {
998 void Calculator::PrintTop() {
999 if(p_valStack->empty())
return;
1003 for(
int i = 0; i < (int)top.size(); i++) {
1004 std::cout << top[i] <<
" ";
1006 std::cout <<
"]" << std::endl;
1015 bool Calculator::Empty() {
1016 return p_valStack->empty();
1023 void Calculator::Clear() {
1024 while(!p_valStack->empty()) {
1042 double operation(
double)) {
1043 results.resize(arg1End - arg1Start);
1045 for(
int pos = 0; pos < results.size(); pos++) {
1046 results[pos] = operation(*arg1Start);
1073 double operation(
double,
double)) {
1074 if(arg1End - arg1Start != 1 && arg2End - arg2Start != 1 &&
1075 arg1End - arg1Start != arg2End - arg2Start) {
1076 IString msg =
"The stack based calculator cannot operate on vectors "
1077 "of differing sizes.";
1081 int iSize = max(arg1End - arg1Start, arg2End - arg2Start);
1082 results.resize(iSize);
1084 for(
int pos = 0; pos < results.size(); pos++) {
1085 results[pos] = operation(*arg1Start, *arg2Start);
1087 if(arg1Start + 1 != arg1End) arg1Start++;
1088 if(arg2Start + 1 != arg2End) arg2Start++;
double MinimumOperator(double a, double b)
Returns the min of a and b.
Buffer for reading and writing cube data.
double BitwiseAndOperator(double a, double b)
Returns the result of a bitwise AND accross a and b.
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
double CosecantOperator(double a)
Returns the cosecant of the input a.
double SecantOperator(double a)
Returns the secant of the input a.
const double Null
Value for an Isis Null pixel.
double LessThanOperator(double a, double b)
Returns 1.0 if a is less than b.
bool IsLrsPixel(const double d)
Returns if the input pixel is low representation saturation.
double DivideOperator(double a, double b)
Returns the result of dividing a by b.
bool IsHisPixel(const double d)
Returns if the input pixel is high instrument saturation.
double CotangentOperator(double a)
Returns the cotangent of the input a.
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
double BitwiseOrOperator(double a, double b)
Returns the result of a bitwise OR across a and b.
#define _FILEINFO_
Macro for the filename and line number.
double GreaterThanOrEqualOperator(double a, double b)
Returns 1.0 if a is greater than or equal to b.
double ModulusOperator(double a, double b)
Returns the modulus of a by b.
int Round(double a)
Returns the result of rounding the input a to the closest integer.
bool IsSpecial(const double d)
Returns if the input pixel is special.
double LessThanOrEqualOperator(double a, double b)
Returns 1.0 if a is less than or eqaul to b.
double NegateOperator(double a)
The code that performs math operations is designed to call a function and use the result...
double AddOperator(double a, double b)
Returns the result of additing a with b.
double EqualOperator(double a, double b)
Returns 1.0 if a is equal ot b.
double MultiplyOperator(double a, double b)
Returns the result of a multiplied by b.
double MaximumOperator(double a, double b)
Returns the max of a and b.
int size() const
Returns the total number of pixels in the shape buffer.
Adds specific functionality to C++ strings.
bool IsNullPixel(const double d)
Returns if the input pixel is null.
double NotEqualOperator(double a, double b)
Returns 1.0 is a is not equal to b.
const double Lrs
Value for an Isis Low Representation Saturation pixel.
double SubtractOperator(double a, double b)
Returns the result of subtracting b from a.
double GreaterThanOperator(double a, double b)
Returns 1.0 if a is greater than b.
const double Hrs
Value for an Isis High Representation Saturation pixel.