Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 #include "Blob.h" 00003 #include "Cube.h" 00004 #include "CubeAttribute.h" 00005 #include "LineManager.h" 00006 #include "Progress.h" 00007 #include "SpecialPixel.h" 00008 00009 using namespace Isis; 00010 using namespace std; 00011 00012 void IsisMain() { 00013 UserInterface &ui = Application::GetUserInterface(); 00014 00015 CubeAttributeInput inAtt = ui.GetInputAttribute("FROM"); 00016 Cube icube; 00017 00018 if(inAtt.Bands().size() != 0) { 00019 icube.setVirtualBands(inAtt.Bands()); 00020 } 00021 00022 icube.open(Filename(ui.GetFilename("FROM")).Expanded()); 00023 00024 // Make sure it is a Themis EDR/RDR 00025 Filename inFilename = ui.GetFilename("FROM"); 00026 try { 00027 if(icube.getGroup("Instrument")["InstrumentID"][0] != "THEMIS_VIS") { 00028 string msg = "This program is intended for use on THEMIS VIS images only. ["; 00029 msg += inFilename.Expanded() + "] does not appear to be a THEMIS VIS image."; 00030 throw iException::Message(iException::User, msg, _FILEINFO_); 00031 } 00032 } 00033 catch(iException &e) { 00034 string msg = "This program is intended for use on THEMIS VIS images only. ["; 00035 msg += inFilename.Expanded() + "] does not appear to be a THEMIS VIS image."; 00036 throw iException::Message(iException::User, msg, _FILEINFO_); 00037 } 00038 00039 vector<Cube *> flatcubes; 00040 vector<LineManager *> fcubeMgrs; 00041 int summing = icube.getGroup("Instrument")["SpatialSumming"][0]; 00042 00043 for(int filt = 0; filt < 5; filt++) { 00044 string filePattern = "$odyssey/calibration/flat_filter_"; 00045 filePattern += iString(filt + 1) + "_summing_"; 00046 filePattern += iString(summing) + "_v????.cub"; 00047 Filename flatFile(filePattern); 00048 flatFile.HighestVersion(); 00049 Cube *fcube = new Cube(); 00050 fcube->open(flatFile.Expanded()); 00051 flatcubes.push_back(fcube); 00052 00053 LineManager *fcubeMgr = new LineManager(*fcube); 00054 fcubeMgr->SetLine(1, 1); 00055 fcubeMgrs.push_back(fcubeMgr); 00056 } 00057 00058 Cube ocube; 00059 00060 CubeAttributeOutput outAtt = ui.GetOutputAttribute("TO"); 00061 ocube.setDimensions(icube.getSampleCount(), icube.getLineCount(), icube.getBandCount()); 00062 ocube.setByteOrder(outAtt.ByteOrder()); 00063 ocube.setFormat(outAtt.FileFormat()); 00064 ocube.setLabelsAttached(outAtt.AttachedLabel()); 00065 ocube.setPixelType(outAtt.PixelType()); 00066 00067 ocube.create(Filename(ui.GetFilename("TO")).Expanded()); 00068 00069 LineManager icubeMgr(icube); 00070 vector<int> filter; 00071 00072 PvlKeyword &filtNums = 00073 icube.getLabel()->FindGroup("BandBin", Pvl::Traverse)["FilterNumber"]; 00074 for(int i = 0; i < filtNums.Size(); i++) { 00075 filter.push_back(filtNums[i]); 00076 } 00077 00078 LineManager ocubeMgr(ocube); 00079 ocubeMgr.SetLine(1, 1); 00080 00081 Progress prog; 00082 prog.SetText("Applying Flat-Field Correction"); 00083 prog.SetMaximumSteps(ocube.getLineCount() * ocube.getBandCount()); 00084 prog.CheckStatus(); 00085 00086 do { 00087 icube.read(icubeMgr); 00088 ocube.read(ocubeMgr); 00089 00090 int fcubeIndex = filter[ocubeMgr.Band()-1] - 1; 00091 flatcubes[fcubeIndex]->read((*fcubeMgrs[fcubeIndex])); 00092 00093 for(int i = 0; i < ocubeMgr.size(); i++) { 00094 if(IsSpecial((*fcubeMgrs[fcubeIndex])[i]) || (*fcubeMgrs[fcubeIndex])[i] == 0.0) { 00095 ocubeMgr[i] = Isis::Null; 00096 } 00097 else if(IsSpecial(icubeMgr[i])) { 00098 ocubeMgr[i] = icubeMgr[i]; 00099 } 00100 else { 00101 ocubeMgr[i] = icubeMgr[i] / (*fcubeMgrs[fcubeIndex])[i]; 00102 } 00103 } 00104 00105 ocube.write(ocubeMgr); 00106 00107 icubeMgr++; 00108 ocubeMgr++; 00109 00110 for(int i = 0; i < (int)fcubeMgrs.size(); i++) { 00111 (*fcubeMgrs[i]) ++; 00112 00113 if(fcubeMgrs[i]->end()) { 00114 fcubeMgrs[i]->SetLine(1, 1); 00115 } 00116 } 00117 00118 prog.CheckStatus(); 00119 } 00120 while(!ocubeMgr.end()); 00121 00122 // Propagate labels and objects (in case of spice data) 00123 PvlObject &inCubeObj = icube.getLabel()->FindObject("IsisCube"); 00124 PvlObject &outCubeObj = ocube.getLabel()->FindObject("IsisCube"); 00125 00126 for(int g = 0; g < inCubeObj.Groups(); g++) { 00127 outCubeObj.AddGroup(inCubeObj.Group(g)); 00128 } 00129 00130 for(int o = 0; o < icube.getLabel()->Objects(); o++) { 00131 if(icube.getLabel()->Object(o).IsNamed("Table")) { 00132 Blob t(icube.getLabel()->Object(o)["Name"], 00133 icube.getLabel()->Object(o).Name()); 00134 icube.read(t); 00135 ocube.write(t); 00136 } 00137 } 00138 00139 icube.close(); 00140 ocube.close(); 00141 00142 for(int i = 0; i < (int)flatcubes.size(); i++) { 00143 delete fcubeMgrs[i]; 00144 delete flatcubes[i]; 00145 } 00146 00147 fcubeMgrs.clear(); 00148 flatcubes.clear(); 00149 } 00150