Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 #include "ProcessByLine.h" 00003 #include "SpecialPixel.h" 00004 #include "iException.h" 00005 00006 using namespace std; 00007 using namespace Isis; 00008 00009 void add (vector<Buffer *> &in, 00010 vector<Buffer *> &out); 00011 void sub (vector<Buffer *> &in, 00012 vector<Buffer *> &out); 00013 void mult (vector<Buffer *> &in, 00014 vector<Buffer *> &out); 00015 void div (vector<Buffer *> &in, 00016 vector<Buffer *> &out); 00017 void unary (Buffer &in, Buffer &out); 00018 00019 double a,b,c,d,e; 00020 00021 void IsisMain() { 00022 // We will be processing by line 00023 ProcessByLine p; 00024 00025 // Setup the input and output files 00026 UserInterface &ui = Application::GetUserInterface(); 00027 // Setup the input and output cubes 00028 p.SetInputCube("FROM1"); 00029 if (ui.WasEntered ("FROM2")) p.SetInputCube("FROM2"); 00030 p.SetOutputCube ("TO"); 00031 00032 // Get the coefficients 00033 a = ui.GetDouble ("A"); 00034 b = ui.GetDouble ("B"); 00035 c = ui.GetDouble ("C"); 00036 d = ui.GetDouble ("D"); 00037 e = ui.GetDouble ("E"); 00038 00039 // Start the processing based on the operator 00040 string op = ui.GetString ("OPERATOR"); 00041 if (op == "ADD" ) p.StartProcess(add); 00042 if (op == "SUBTRACT") p.StartProcess(sub); 00043 if (op == "MULTIPLY") p.StartProcess(mult); 00044 if (op == "DIVIDE") p.StartProcess(div); 00045 if (op == "UNARY") p.StartProcess(unary); 00046 00047 // Cleanup 00048 p.EndProcess(); 00049 } 00050 00051 // Add routine 00052 void add (vector<Buffer *> &in, vector<Buffer *> &out) { 00053 Buffer &inp1 = *in[0]; 00054 Buffer &inp2 = *in[1]; 00055 Buffer &outp = *out[0]; 00056 00057 // Loop for each pixel in the line. 00058 for (int i=0; i<inp1.size(); i++) { 00059 if (IsSpecial(inp1[i])) { 00060 outp[i] = inp1[i]; 00061 } 00062 else if (IsSpecial(inp2[i])) { 00063 outp[i] = NULL8; 00064 } 00065 else { 00066 outp[i] = ((inp1[i] - d) * a) + ((inp2[i] - e) * b) + c; 00067 } 00068 } 00069 } 00070 00071 // Sub routine 00072 void sub (vector<Buffer *> &in, vector<Buffer *> &out) { 00073 Buffer &inp1 = *in[0]; 00074 Buffer &inp2 = *in[1]; 00075 Buffer &outp = *out[0]; 00076 00077 // Loop for each pixel in the line. 00078 for (int i=0; i<inp1.size(); i++) { 00079 if (IsSpecial(inp1[i])) { 00080 outp[i] = inp1[i]; 00081 } 00082 else if (IsSpecial(inp2[i])) { 00083 outp[i] = NULL8; 00084 } 00085 else { 00086 outp[i] = ((inp1[i] - d) * a) - ((inp2[i] - e) * b) + c; 00087 } 00088 } 00089 } 00090 00091 // Sub routine 00092 void mult (vector<Buffer *> &in, vector<Buffer *> &out) { 00093 Buffer &inp1 = *in[0]; 00094 Buffer &inp2 = *in[1]; 00095 Buffer &outp = *out[0]; 00096 00097 // Loop for each pixel in the line. 00098 for (int i=0; i<inp1.size(); i++) { 00099 if (IsSpecial (inp1[i])) { 00100 outp[i] = inp1[i]; 00101 } 00102 else if (IsSpecial (inp2[i])) { 00103 outp[i] = NULL8; 00104 } 00105 else { 00106 outp[i] = ((inp1[i] - d) * a) * ((inp2[i] - e) * b) + c; 00107 } 00108 } 00109 } 00110 00111 // Div routine 00112 void div (vector<Buffer *> &in, vector<Buffer *> &out) { 00113 Buffer &inp1 = *in[0]; 00114 Buffer &inp2 = *in[1]; 00115 Buffer &outp = *out[0]; 00116 00117 // Loop for each pixel in the line. 00118 for (int i=0; i<inp1.size(); i++) { 00119 if (IsSpecial (inp1[i])) { 00120 outp[i] = inp1[i]; 00121 } 00122 else if (IsSpecial (inp2[i])) { 00123 outp[i] = NULL8; 00124 } 00125 else { 00126 if ((inp2[i] - e) * b == 0.0) { 00127 outp[i] = NULL8; 00128 } 00129 else { 00130 outp[i] = ((inp1[i] - d) * a) / ((inp2[i] - e) * b) + c; 00131 } 00132 } 00133 } 00134 } 00135 00136 // Unary routine 00137 void unary (Buffer &in, Buffer &out) { 00138 // Loop for each pixel in the line. 00139 for (int i=0; i<in.size(); i++) { 00140 if (IsSpecial (in[i])) { 00141 out[i] = in[i]; 00142 } 00143 else { 00144 out[i] = in[i] * a + c; 00145 } 00146 } 00147 }