7#include "CubeCalculator.h"
15#include "Statistics.h"
31 m_methods =
new QVector<void (Calculator:: *)(void)>();
82 delete (*m_cubeStats)[i];
83 (*m_cubeStats)[i] = NULL;
95 delete (*m_cameraBuffers)[i];
96 (*m_cameraBuffers)[i] = NULL;
123 for (
int currentCalculation = 0; currentCalculation <
m_calculations->size();
124 currentCalculation++) {
126 void (
Calculator::*aMethod)() = (*m_methods)[methodIndex];
131 DataValue &data = (*m_dataDefinitions)[dataIndex];
142 QVector<double> samples;
227 string msg =
"Too many operands in the equation.";
250 QVector<Cube *> &inCubes,
265 if (isdigit(token[0]) || token[0] ==
'.') {
272 else if (token[0] ==
'f') {
274 int file = tok.ToInteger() - 1;
275 if (file < 0 || file >= (
int)inCubes.size()) {
276 QString msg =
"Invalid file number [" + tok.ToQt() +
"]";
283 else if (token ==
"band") {
287 else if (token ==
"line") {
291 else if (token ==
"sample") {
296 else if (token ==
"+") {
301 else if (token ==
"-") {
306 else if (token ==
"*") {
311 else if (token ==
"/") {
316 else if (token ==
"%") {
321 else if (token ==
"^") {
326 else if (token ==
"--") {
331 else if (token ==
"neg") {
336 else if (token ==
"<<") {
341 else if (token ==
">>") {
346 else if (token ==
"linemax") {
351 else if (token ==
"max") {
356 else if (token ==
"linemin") {
361 else if (token ==
"min") {
366 else if (token ==
"abs") {
371 else if (token ==
"sqrt") {
376 else if (token ==
"log" || token ==
"ln") {
381 else if (token ==
"log10") {
386 else if (token ==
"pi") {
394 else if (token ==
"e") {
401 else if (token ==
"rads") {
410 else if (token ==
"degs") {
419 else if (token ==
"sin") {
424 else if (token ==
"cos") {
429 else if (token ==
"tan") {
434 else if (token ==
"sec") {
439 else if (token ==
"csc") {
444 else if (token ==
"cot") {
449 else if (token ==
"asin") {
454 else if (token ==
"acos") {
459 else if (token ==
"atan") {
464 else if (token ==
"atan2") {
469 else if (token ==
"sinh") {
474 else if (token ==
"cosh") {
479 else if (token ==
"tanh") {
484 else if (token ==
"<") {
489 else if (token ==
">") {
494 else if (token ==
"<=") {
499 else if (token ==
">=") {
504 else if (token ==
"==") {
509 else if (token ==
"!=") {
514 else if (token ==
"cubemax") {
525 else if (token ==
"cubemin") {
536 else if (token ==
"cubeavg") {
547 else if (token ==
"cubestd") {
558 else if (token ==
"inac") {
560 (*m_cameraBuffers)[cubeIndex]->enableInacBuffer();
567 else if (token ==
"emac") {
569 (*m_cameraBuffers)[cubeIndex]->enableEmacBuffer();
576 else if (token ==
"phac") {
578 (*m_cameraBuffers)[cubeIndex]->enablePhacBuffer();
585 else if (token ==
"ina") {
587 (*m_cameraBuffers)[cubeIndex]->enableInaBuffer();
594 else if (token ==
"ema") {
596 (*m_cameraBuffers)[cubeIndex]->enableEmaBuffer();
603 else if (token ==
"pha") {
605 (*m_cameraBuffers)[cubeIndex]->enablePhaBuffer();
612 else if (token ==
"inal") {
614 (*m_cameraBuffers)[cubeIndex]->enableInalBuffer();
621 else if (token ==
"emal") {
623 (*m_cameraBuffers)[cubeIndex]->enableEmalBuffer();
630 else if (token ==
"phal") {
632 (*m_cameraBuffers)[cubeIndex]->enablePhalBuffer();
639 else if (token ==
"lat") {
641 (*m_cameraBuffers)[cubeIndex]->enableLatBuffer();
648 else if (token ==
"lon") {
650 (*m_cameraBuffers)[cubeIndex]->enableLonBuffer();
657 else if (token ==
"res") {
659 (*m_cameraBuffers)[cubeIndex]->enableResBuffer();
666 else if (token ==
"radius") {
668 (*m_cameraBuffers)[cubeIndex]->enableRadiusBuffer();
675 else if (token ==
"") {
679 string msg =
"Unidentified operator [";
701 string msg =
"Not sure which file to get statistics from";
706 string msg =
"This function must not contain calculations,";
707 msg +=
" only input cubes may be specified.";
717 string msg =
"This function must not contain constants,";
718 msg +=
" only input cubes may be specified.";
722 int cubeStatsIndex = lastData.cubeIndex();
735 (*m_cubeStats)[cubeStatsIndex] = inCubes[cubeStatsIndex]->statistics();
738 return cubeStatsIndex;
761 string msg =
"Not sure which file to get cameras from";
766 string msg =
"This function must not contain calculations,";
767 msg +=
" only input cubes may be specified.";
777 string msg =
"This function must not contain constants,";
778 msg +=
" only input cubes may be specified.";
782 int cubeIndex = lastData.cubeIndex();
801 cam = inCubes[cubeIndex]->camera();
803 string msg =
"This function requires a camera and the input cube does";
804 msg +=
" not have one. You may need to run spiceinit";
809 string msg =
"This function requires a camera and the input cube does";
810 msg +=
" not have one. You may need to run spiceinit";
814 (*m_cubeCameras)[cubeIndex] = cam;
1065 QVector<double> *CameraBuffers::phaBuffer(
int currentLine,
int ns,
int currentBand) {
1066 loadBuffers(currentLine, ns, currentBand);
1071 QVector<double> *CameraBuffers::inaBuffer(
int currentLine,
int ns,
int currentBand) {
1072 loadBuffers(currentLine, ns, currentBand);
1077 QVector<double> *CameraBuffers::emaBuffer(
int currentLine,
int ns,
int currentBand) {
1078 loadBuffers(currentLine, ns, currentBand);
1083 QVector<double> *CameraBuffers::latBuffer(
int currentLine,
int ns,
int currentBand) {
1084 loadBuffers(currentLine, ns, currentBand);
1089 QVector<double> *CameraBuffers::lonBuffer(
int currentLine,
int ns,
int currentBand) {
1090 loadBuffers(currentLine, ns, currentBand);
1095 QVector<double> *CameraBuffers::resBuffer(
int currentLine,
int ns,
int currentBand) {
1096 loadBuffers(currentLine, ns, currentBand);
1101 QVector<double> *CameraBuffers::radiusBuffer(
int currentLine,
int ns,
int currentBand) {
1102 loadBuffers(currentLine,ns,currentBand);
1107 QVector<double> *CameraBuffers::phalBuffer(
int currentLine,
int ns,
int currentBand) {
1108 loadBuffers(currentLine, ns, currentBand);
1113 QVector<double> *CameraBuffers::inalBuffer(
int currentLine,
int ns,
int currentBand) {
1114 loadBuffers(currentLine, ns, currentBand);
1119 QVector<double> *CameraBuffers::emalBuffer(
int currentLine,
int ns,
int currentBand) {
1120 loadBuffers(currentLine, ns, currentBand);
1125 QVector<double> *CameraBuffers::phacBuffer(
int currentLine,
int ns,
int currentBand) {
1126 loadBuffers(currentLine, ns, currentBand);
1131 QVector<double> *CameraBuffers::inacBuffer(
int currentLine,
int ns,
int currentBand) {
1132 loadBuffers(currentLine, ns, currentBand);
1137 QVector<double> *CameraBuffers::emacBuffer(
int currentLine,
int ns,
int currentBand) {
1138 loadBuffers(currentLine, ns, currentBand);
1143 void CameraBuffers::loadBuffers(
int currentLine,
int ns,
int currentBand) {
1186 QString msg =
"Unable to compute illumination angles at image center for operator ["
1193 for (
int i = 0; i < ns; i++) {
1204 Angle phal, inal, emal;
Functor for reduce using average functionality.
void LessThan()
Pop two elements off the stack and compare them to see where one is less than the other,...
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 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 Negative()
Pops an element, negates it, then pushes the result.
void RightShift()
Pop the top element, then perform a right shift with zero fill.
void Sine()
Pops one element and push the sine.
virtual void Clear()
Clear out the stack.
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 SquareRoot()
Pop an element, compute its square root, then push the root on the stack.
void Cosine()
Pops one element and push the cosine.
void CosineH()
Pops one element and push the hyperbolic cosine.
This class is used to manage buffers for calculating camera related information, such as angles,...
QVector< double > * m_phacBuffer
Center phase angle buffer.
void enableLonBuffer()
Enables the longitude buffer for use.
void enableLatBuffer()
Enables the latitude buffer for use.
void enablePhalBuffer()
Enables the local phase angle buffer for use.
void enableResBuffer()
Enables the resolution buffer for use.
void enablePhaBuffer()
Enables the phase angle buffer for use.
void enableRadiusBuffer()
Enables the radius buffer for use.
CameraBuffers(Camera *camera)
Constructs a CameraBuffers object.
QVector< double > * m_inaBuffer
Incidence angle buffer.
QVector< double > * m_inalBuffer
Local incidence angle buffer.
QVector< double > * m_emacBuffer
Center emission angle buffer.
QVector< double > * m_emalBuffer
Local emission angle buffer.
void enableInalBuffer()
Enables the local incidence angle buffer for use.
int m_lastLine
The number of the last line loaded into the enabled camera buffers.
QVector< double > * m_inacBuffer
Center incidence angle buffer.
QVector< double > * m_phaBuffer
Phase angle buffer.
void enableInaBuffer()
Enables the incidence angle buffer for use.
void enableEmalBuffer()
Enables the local emission angle buffer for use.
Camera * m_camera
Camera to obtain camera-related information from.
QVector< double > * m_latBuffer
Latitude buffer.
QVector< double > * m_emaBuffer
Emission angle buffer.
QVector< double > * m_phalBuffer
Local phase angle buffer.
QVector< double > * m_radiusBuffer
Radius buffer.
~CameraBuffers()
Destroys the CameraBuffers.
void enableEmacBuffer()
Enables the center emission angle buffer for use.
void enableInacBuffer()
Enables the center incidence angle buffer for use.
void enableEmaBuffer()
Enables the emission angle buffer for use.
QVector< double > * m_resBuffer
Resolution buffer.
QVector< double > * m_lonBuffer
Longitude buffer.
void enablePhacBuffer()
Enables the center phase angle buffer for use.
int Lines() const
Returns the number of lines in the image.
virtual double PixelResolution()
Returns the pixel resolution at the current position in meters/pixel.
virtual bool SetImage(const double sample, const double line)
Sets the sample/line values of the image to get the lat/lon values.
void LocalPhotometricAngles(Angle &phase, Angle &incidence, Angle &emission, bool &success)
Calculates LOCAL photometric angles using the DEM (not ellipsoid).
int Samples() const
Returns the number of samples in the image.
virtual void SetBand(const int band)
Virtual method that sets the band number.
int lastPushToCubeCameras(QVector< Cube * > &inCubes)
Creates internal camera for the last pushed cube data.
int m_outputSamples
Number of samples in the output cube.
void addMethodCall(void(Calculator::*method)(void))
This is a conveinience method for PrepareCalculations(...).
~CubeCalculator()
Destroys the CubeCalculator object.
int lastPushToCubeStats(QVector< Cube * > &inCubes)
Creates statistics internally for the last cube data pushed to the data definitions.
CubeCalculator()
Constructs a CubeCalculator.
QVector< Camera * > * m_cubeCameras
Stores the cameras for the input cubes.
@ CallNextMethod
The calculation requires calling one of the methods.
@ PushNextData
The calculation requires input data.
QVector< void(Calculator::*)(void)> * m_methods
This stores the addresses to the methods RunCalculations(...) will call.
void Clear()
This method completely resets the calculator.
QVector< double > runCalculations(QVector< Buffer * > &cubeData, int line, int band)
This method will execute the calculations built up when PrepareCalculations was called.
QVector< Calculations > * m_calculations
This is what RunCalculations(...) will loop over.
QVector< CameraBuffers * > * m_cameraBuffers
Stores the camera buffers that are enabled for camera related calculations.
void prepareCalculations(QString equation, QVector< Cube * > &inCubes, Cube *outCube)
This method builds a list of actions to perform based on the postfix expression.
QVector< DataValue > * m_dataDefinitions
This defines what kind of data RunCalculations(...) will push onto the calculator.
QVector< Statistics * > * m_cubeStats
Stores the cube statistics for the input cubes.
IO Handler for Isis Cubes.
This class is used to define what kind of data is being pushed onto the cube calculator.
int cubeIndex()
Accesses the cube index of the DataValue.
double constant()
Accesses the constant value of the DataValue.
DataValue()
Constructs a default DataValue.
int m_cubeIndex
The index of the associated cube.
double m_constantValue
Stored constant value.
DataValueType
This is used to tell what kind of data to push onto the RPN calculator.
@ InaData
Incidence camera data.
@ PhacData
Center phase camera data.
@ EmalData
Local emission camera data.
@ PhaData
Phase camera data.
@ InalData
Local incidence camera data.
@ EmaData
Emission camera data.
@ LatData
Latitude camera data.
@ Sample
Current sample number.
@ Band
Current band number.
@ ResData
Pixel resolution camera data.
@ Constant
A single constant value.
@ InacData
Center incidence camera data.
@ PhalData
Local phase camera data.
@ Line
Current line number.
@ LonData
Longitude camera data.
@ CubeData
A brick of cube data.
@ EmacData
Center emission camera data.
DataValueType m_type
Type of data stored.
DataValueType type()
Accesses the type of the DataValue.
double meters() const
Get the distance in meters.
@ Unknown
A type of error that cannot be classified as any of the other error types.
Adds specific functionality to C++ strings.
IString Token(const IString &separator)
Returns the first token in the IString.
virtual double UniversalLatitude() const
Returns the planetocentric latitude, in degrees, at the surface intersection point in the body fixed ...
virtual double PhaseAngle() const
Returns the phase angle in degrees.
virtual double IncidenceAngle() const
Returns the incidence angle in degrees.
virtual double UniversalLongitude() const
Returns the positive east, 0-360 domain longitude, in degrees, at the surface intersection point in t...
Distance LocalRadius() const
Returns the local radius at the intersection point.
virtual double EmissionAngle() const
Returns the emission angle in degrees.
const double E
Sets some basic constants for use in ISIS programming.
This is free and unencumbered software released into the public domain.
const double PI
The mathematical constant PI.
Namespace for the standard library.