46 Calculator::Calculator() {
54 Calculator::~Calculator() {
134 return a > b ? 1.0 : 0.0;
147 return a < b ? 1.0 : 0.0;
160 return a == b ? 1.0 : 0.0;
173 return a >= b ? 1.0 : 0.0;
186 return a <= b ? 1.0 : 0.0;
199 return a != b ? 1.0 : 0.0;
246 return (a > 0) ? (int)(a + 0.5) : (int)(a - 0.5);
298 if (std::isnan(a))
return (a);
299 if (std::isnan(b))
return (b);
300 return (a > b) ? a : b;
312 if (std::isnan(a))
return (a);
313 if (std::isnan(b))
return (b);
314 return (a < b) ? a : b;
322 void Calculator::Negative() {
324 PerformOperation(result, result.begin(), result.end(),
NegateOperator);
332 void Calculator::Multiply() {
337 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
MultiplyOperator);
345 void Calculator::Add() {
349 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
AddOperator);
357 void Calculator::Subtract() {
361 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
SubtractOperator);
369 void Calculator::Divide() {
374 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
DivideOperator);
381 void Calculator::Modulus() {
386 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
ModulusOperator);
397 void Calculator::Exponent() {
402 PerformOperation(result, x.begin(), x.end(), exponent.begin(), exponent.end(), pow);
412 void Calculator::SquareRoot() {
414 PerformOperation(result, result.begin(), result.end(), sqrt);
422 void Calculator::AbsoluteValue() {
424 PerformOperation(result, result.begin(), result.end(), fabs);
434 void Calculator::Log() {
436 PerformOperation(result, result.begin(), result.end(), log);
444 void Calculator::Log10() {
446 PerformOperation(result, result.begin(), result.end(), log10);
456 void Calculator::LeftShift() {
459 IString msg =
"When trying to do a left shift calculation, a non-scalar " 460 "shift value was encountered. Shifting requires scalars.";
466 if ((
int)y[0] > (
int)x.size()) {
467 IString msg =
"When trying to do a left shift calculation, a shift " 468 "value greater than the data size was encountered. " 469 "Shifting by this value would erase all of the data.";
474 int shift = (int)y[0];
475 result.resize(x.size());
477 for (
int i = 0; i < result.size(); i++) {
478 if (i + shift < x.size() && i + shift >= 0)
479 result[i] = x[i+shift];
481 result[i] = sqrt(-1.0);
495 void Calculator::RightShift() {
498 IString msg =
"When trying to do a right shift calculation, a non-scalar " 499 "shift value was encountered. Shifting requires scalars.";
505 if ((
int)y[0] > (
int)x.size()) {
506 IString msg =
"When trying to do a right shift calculation, a shift " 507 "value greater than the data size was encountered. " 508 "Shifting by this value would erase all of the data.";
513 int shift = (int)y[0];
514 result.resize(x.size());
516 for (
int i = 0; i < (int)result.size(); i++) {
517 if (i - shift < (
int)x.size() && i - shift >= 0) {
518 result[i] = x[i-shift];
521 result[i] = sqrt(-1.0);
533 void Calculator::MinimumLine() {
536 double minVal = result[0];
537 for (
int i = 0; i < result.size(); i++) {
539 minVal = min(minVal, result[i]);
544 result.push_back(minVal);
552 void Calculator::MaximumLine() {
555 double maxVal = result[0];
556 for (
int i = 0; i < result.size(); i++) {
558 maxVal = max(maxVal, result[i]);
563 result.push_back(maxVal);
572 void Calculator::MinimumPixel() {
577 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
587 void Calculator::MaximumPixel() {
592 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
602 void Calculator::GreaterThan() {
607 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
617 void Calculator::LessThan() {
622 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
632 void Calculator::Equal() {
637 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
647 void Calculator::GreaterThanOrEqual() {
652 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
662 void Calculator::LessThanOrEqual() {
667 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
677 void Calculator::NotEqual() {
682 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
694 void Calculator::And() {
699 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
708 void Calculator::Or() {
713 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
722 void Calculator::Sine() {
724 PerformOperation(result, result.begin(), result.end(), sin);
732 void Calculator::Cosine() {
734 PerformOperation(result, result.begin(), result.end(), cos);
742 void Calculator::Tangent() {
744 PerformOperation(result, result.begin(), result.end(), tan);
752 void Calculator::Cosecant() {
762 void Calculator::Secant() {
764 PerformOperation(result, result.begin(), result.end(),
SecantOperator);
772 void Calculator::Cotangent() {
782 void Calculator::Arcsine() {
784 PerformOperation(result, result.begin(), result.end(), asin);
792 void Calculator::Arccosine() {
794 PerformOperation(result, result.begin(), result.end(), acos);
802 void Calculator::Arctangent() {
804 PerformOperation(result, result.begin(), result.end(), atan);
812 void Calculator::ArcsineH() {
814 PerformOperation(result, result.begin(), result.end(), asinh);
822 void Calculator::ArccosineH() {
824 PerformOperation(result, result.begin(), result.end(), acosh);
832 void Calculator::ArctangentH() {
834 PerformOperation(result, result.begin(), result.end(), atanh);
842 void Calculator::Arctangent2() {
847 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(), atan2);
855 void Calculator::SineH() {
857 PerformOperation(result, result.begin(), result.end(), sinh);
865 void Calculator::CosineH() {
867 PerformOperation(result, result.begin(), result.end(), cosh);
875 void Calculator::TangentH() {
877 PerformOperation(result, result.begin(), result.end(), tanh);
889 int Calculator::StackSize() {
890 return p_valStack->size();
899 p_valStack->push(vect);
908 void Calculator::Push(
double scalar) {
923 for (
int i = 0; i < buff.
size(); i++) {
967 if (p_valStack->empty()) {
968 IString msg =
"Math calculator stack is empty, cannot perform any " 973 top = p_valStack->top();
976 for (
int i = 0; i < (int)top.size(); i++) {
977 if (std::isnan(top[i])) {
981 else if (top[i] > DBL_MAX) {
985 else if (top[i] < -DBL_MAX) {
1004 void Calculator::PrintTop() {
1005 if (p_valStack->empty())
return;
1010 for (
int i = 0; i < (int)top.size(); i++) {
1011 temp += QString::number(top[i]);
1018 temp.replace(QRegExp(
"-nan"),
"nan");
1019 std::cout<<temp<<std::endl;
1028 bool Calculator::Empty() {
1029 return p_valStack->empty();
1036 void Calculator::Clear() {
1037 while (!p_valStack->empty()) {
1055 double operation(
double)) {
1056 results.resize(arg1End - arg1Start);
1058 for (
int pos = 0; pos < results.size(); pos++) {
1059 results[pos] = operation(*arg1Start);
1086 double operation(
double,
double)) {
1087 if (arg1End - arg1Start != 1 && arg2End - arg2Start != 1 &&
1088 arg1End - arg1Start != arg2End - arg2Start) {
1089 IString msg =
"The stack based calculator cannot operate on vectors " 1090 "of differing sizes.";
1094 int iSize = max(arg1End - arg1Start, arg2End - arg2Start);
1095 results.resize(iSize);
1097 for (
int pos = 0; pos < results.size(); pos++) {
1098 results[pos] = operation(*arg1Start, *arg2Start);
1100 if (arg1Start + 1 != arg1End) arg1Start++;
1101 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.
Namespace for the standard library.
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.
int size() const
Returns the total number of pixels in the shape buffer.
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)
Returns the nagative of the input parameter.
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.
Adds specific functionality to C++ strings.
Namespace for ISIS/Bullet specific routines.
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.