|
Isis 3.0 Application Source Code Reference |
Home |
00001 /** 00002 * @file 00003 * $Revision: 1.8 $ 00004 * $Date: 2010/04/08 15:28:20 $ 00005 * 00006 * Unless noted otherwise, the portions of Isis written by the USGS are public 00007 * domain. See individual third-party library and package descriptions for 00008 * intellectual property information,user agreements, and related information. 00009 * 00010 * Although Isis has been used by the USGS, no warranty, expressed or implied, 00011 * is made by the USGS as to the accuracy and functioning of such software 00012 * and related material nor shall the fact of distribution constitute any such 00013 * warranty, and no responsibility is assumed by the USGS in connection 00014 * therewith. 00015 * 00016 * For additional information, launch 00017 * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html in a browser or see 00018 * the Privacy & Disclaimers page on the Isis website, 00019 * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on 00020 * http://www.usgs.gov/privacy.html. 00021 */ 00022 00023 #include "Isis.h" 00024 00025 #include <string> 00026 00027 #include "IString.h" 00028 #include "CubeCalculator.h" 00029 #include "CubeInfixToPostfix.h" 00030 #include "FileList.h" 00031 #include "FileName.h" 00032 #include "ProcessByLine.h" 00033 00034 00035 using namespace std; 00036 using namespace Isis; 00037 00038 Isis::CubeCalculator c; 00039 00040 // Prototypes 00041 void Evaluate(vector<Buffer *> &input, vector<Buffer *> &output); 00042 00043 void IsisMain() { 00044 UserInterface &ui = Application::GetUserInterface(); 00045 ProcessByLine p; 00046 QVector<Cube *> cubes; 00047 Cube *outCube; 00048 00049 if(ui.GetString("MODE") == "CUBES") { 00050 // Require atleast one file to be specified 00051 cubes.push_back(p.SetInputCube("F1", Isis::AllMatchOrOne)); 00052 if(ui.WasEntered("F2")) cubes.push_back(p.SetInputCube("F2", Isis::AllMatchOrOne)); 00053 if(ui.WasEntered("F3")) cubes.push_back(p.SetInputCube("F3", Isis::AllMatchOrOne)); 00054 if(ui.WasEntered("F4")) cubes.push_back(p.SetInputCube("F4", Isis::AllMatchOrOne)); 00055 if(ui.WasEntered("F5")) cubes.push_back(p.SetInputCube("F5", Isis::AllMatchOrOne)); 00056 outCube = p.SetOutputCube("TO"); 00057 } 00058 else if(ui.GetString("MODE") == "LIST") { 00059 FileList list(ui.GetFileName("FROMLIST")); 00060 00061 // Run through file list and set its entries as input cubes 00062 for(int i = 0; i < list.size(); i++) { 00063 CubeAttributeInput att(list[i].toString()); 00064 cubes.push_back(p.SetInputCube(list[i].toString(), att, Isis::AllMatchOrOne)); 00065 } 00066 outCube = p.SetOutputCube("TO"); 00067 } 00068 else { 00069 int lines = ui.GetInteger("LINES"); 00070 int samples = ui.GetInteger("SAMPLES"); 00071 int bands = ui.GetInteger("BANDS"); 00072 outCube = p.SetOutputCube("TO", samples, lines, bands); 00073 } 00074 00075 CubeInfixToPostfix infixToPostfix; 00076 c.prepareCalculations(infixToPostfix.convert(ui.GetString("EQUATION")), cubes, outCube); 00077 p.StartProcess(Evaluate); 00078 p.EndProcess(); 00079 } 00080 00081 /** 00082 * Take in the input buffer, apply the user-defined equation to 00083 * it, then write the results to the output buffer 00084 * 00085 * @param input The input buffer vector 00086 * @param output The output buffer 00087 */ 00088 void Evaluate(vector<Buffer *> &input, vector<Buffer *> &output) { 00089 Buffer &outBuffer = *output[0]; 00090 00091 QVector<Buffer *> inputCopy; 00092 00093 for(int i = 0; i < (int)input.size(); i++) { 00094 inputCopy.push_back(input[i]); 00095 } 00096 00097 QVector<double> results = c.runCalculations(inputCopy, 00098 outBuffer.Line(), outBuffer.Band()); 00099 00100 // If final result is a scalar, set all pixels to that value. 00101 if(results.size() == 1) { 00102 for(int i = 0; i < (int)outBuffer.size(); i++) { 00103 outBuffer[i] = results[0]; 00104 } 00105 } 00106 // Final result is a valid vector, write to output buffer 00107 else { 00108 for(int i = 0; i < (int)results.size(); i++) { 00109 outBuffer[i] = results[i]; 00110 } 00111 } 00112 00113 }