|
Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 #include "ProcessByLine.h" 00003 #include "SpecialPixel.h" 00004 #include "LineManager.h" 00005 #include "Filename.h" 00006 #include "iException.h" 00007 #include "Table.h" 00008 00009 using namespace std; 00010 using namespace Isis; 00011 00012 // Globals and prototypes 00013 Cube cube; 00014 LineManager *in; 00015 00016 Table hifix("HiRISE Ancillary"); 00017 Table calfix("HiRISE Calibration Ancillary"); 00018 Table calimg("HiRISE Calibration Image"); 00019 00020 bool flip; 00021 void glob (Buffer &out); 00022 00023 void IsisMain() { 00024 ProcessByLine p; 00025 00026 // Initialize the output size 00027 int samples = 0; 00028 int lines = 0; 00029 int bands = 0; 00030 00031 // Open the input cube 00032 UserInterface &ui = Application::GetUserInterface(); 00033 string from = ui.GetFilename("FROM"); 00034 cube.Open(from); 00035 00036 samples = cube.Samples(); 00037 lines = cube.Lines(); 00038 bands = cube.Bands(); 00039 00040 // Get a cube packet to the input file 00041 Cube *icube = p.SetInputCube("FROM"); 00042 00043 // Get the cube prefix and suffix table 00044 icube->Read(hifix); 00045 00046 // Get the calibration prefix and suffix table 00047 icube->Read(calfix); 00048 00049 // Get the calibration image table 00050 icube->Read(calimg); 00051 00052 // Add the number of buffer pixels and dark pixels to the ouput NS 00053 samples += hifix[0]["BufferPixels"].Size() + hifix[0]["DarkPixels"].Size(); 00054 00055 // Add the number of lines in the calibration image to the output NL 00056 lines += calimg.Records(); 00057 00058 // Decide if the calibration and observation data should be flipped. 00059 flip = false; 00060 PvlGroup &ins = icube->GetGroup("Instrument"); 00061 int chan = ins["ChannelNumber"]; 00062 00063 iString flipChan = ui.GetString("FLIP"); 00064 if (flipChan.UpCase() != "NONE") { 00065 if (flipChan.ToInteger() == chan) flip = true; 00066 } 00067 00068 // Allocate the output file and make sure things get propogated nicely 00069 p.PropagateTables(false); 00070 p.SetOutputCube ("TO",samples,lines,bands); 00071 p.ClearInputCubes(); 00072 00073 // Create a buffer for reading the input cube 00074 in = new LineManager(cube); 00075 00076 // Crop the input cube 00077 p.StartProcess(glob); 00078 00079 // Cleanup 00080 p.EndProcess(); 00081 delete in; 00082 cube.Close(); 00083 } 00084 00085 // Line processing routine 00086 void glob (Buffer &out) { 00087 double int2ToDouble (int value); 00088 00089 // Transfer the calibration buffer, image, and dark pixels 00090 if (out.Line() <= calimg.Records()) { 00091 int outPos = 0; 00092 00093 // Buffer pixels 00094 vector<int> buf = calfix[out.Line()-1]["BufferPixels"]; 00095 for (int i=0; i<(int)buf.size(); i++) { 00096 out[outPos++] = int2ToDouble(buf[i]); 00097 } 00098 00099 // Main calibration pixels 00100 vector<int> cal = calimg[out.Line()-1]["Calibration"]; 00101 if (flip) { 00102 for (int i=(int)cal.size()-1; i>=0; i--) { 00103 out[outPos++] = int2ToDouble(cal[i]); 00104 } 00105 } 00106 else { 00107 for (int i=0; i<(int)cal.size(); i++) { 00108 out[outPos++] = int2ToDouble(cal[i]); 00109 } 00110 } 00111 00112 // Dark pixels 00113 vector<int> dark = calfix[out.Line()-1]["DarkPixels"]; 00114 for (int i=0; i<(int)dark.size(); i++) { 00115 out[outPos++] = int2ToDouble(dark[i]); 00116 } 00117 00118 } // End calibration if 00119 00120 // We are done with the calibration lines so now 00121 // transfer the image buffer, observation, and dark pixels 00122 else { 00123 int outPos = 0; 00124 00125 // Buffer pixels 00126 vector<int> buf = hifix[out.Line()-calimg.Records()-1]["BufferPixels"]; 00127 for (int i=0; i<(int)buf.size(); i++) { 00128 out[outPos++] = int2ToDouble(buf[i]); 00129 } 00130 00131 // Main observation pixels 00132 in->SetLine(out.Line()-calimg.Records(), 1); 00133 cube.Read(*in); 00134 00135 if (flip) { 00136 for (int i=in->size()-1; i>=0; i--) { 00137 out[outPos++] = (*in)[i]; 00138 } 00139 } 00140 else { 00141 for (int i=0; i<in->size(); i++) { 00142 out[outPos++] = (*in)[i]; 00143 } 00144 } 00145 00146 // Dark pixels 00147 vector<int> dark = hifix[out.Line()-calimg.Records()-1]["DarkPixels"]; 00148 for (int i=0; i<(int)dark.size(); i++) { 00149 out[outPos++] = int2ToDouble(dark[i]); 00150 } 00151 00152 } // End main image else 00153 } // End function 00154 00155 double int2ToDouble (int value) { 00156 if (value == NULL2) return NULL8; 00157 else if (value == LOW_REPR_SAT2) return LOW_REPR_SAT8; 00158 else if (value == LOW_INSTR_SAT2) return LOW_INSTR_SAT8; 00159 else if (value == HIGH_INSTR_SAT2) return HIGH_INSTR_SAT8; 00160 else if (value == HIGH_REPR_SAT2) return HIGH_REPR_SAT8; 00161 else return value; 00162 00163 } 00164