|
Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 #include "Cube.h" 00003 #include "Table.h" 00004 #include "Camera.h" 00005 #include "LineScanCameraRotation.h" 00006 #include "PixelOffset.h" 00007 #include "SpiceRotation.h" 00008 #include "iString.h" 00009 #include "FileList.h" 00010 #include "iException.h" 00011 #include "CameraDetectorMap.h" 00012 00013 using namespace std; 00014 using namespace Isis; 00015 00016 void IsisMain() { 00017 UserInterface &ui = Application::GetUserInterface(); 00018 /*Processing steps 00019 1. Open and read the jitter table, convert the pixel offsets to angles, 00020 and create the polynomials (solve for the coefficients) to use to do 00021 the high pass filter putting the results into a rotation matrix in the jitter class. 00022 2. Apply the jitter correction in the LineScanCameraRotation object of the master cube. 00023 3. Loop through FROMLIST correcting the pointing and writing out the 00024 updated camera pointing from the master cube 00025 */ 00026 00027 int degree = ui.GetInteger("DEGREE"); 00028 00029 // Get the input file list to make sure it is not empty and the master cube is included 00030 FileList list; 00031 list.Read(ui.GetFilename("FROMLIST")); 00032 00033 if (list.size() < 1) { 00034 string msg = "The input list file [" + ui.GetFilename("FROMLIST") + "is empty"; 00035 throw iException::Message(iException::User,msg,_FILEINFO_); 00036 } 00037 00038 int ifile = 0; 00039 // Make sure the master file is included in the input file list 00040 while (ifile < (int) list.size() && Filename(list[ifile]).Expanded() != Filename(ui.GetFilename("MASTER")).Expanded()) { 00041 ifile++; 00042 } 00043 00044 if (ifile >= (int) list.size()) { 00045 string msg = "The master file, [" + Filename(ui.GetFilename("MASTER")).Expanded() + " is not included in " + 00046 "the input list file " + ui.GetFilename("FROMLIST") + "]"; 00047 throw iException::Message(iException::User,msg,_FILEINFO_); 00048 } 00049 00050 bool step2 = false; 00051 PvlGroup gp("AppjitResults"); 00052 00053 //Step 1: Create the jitter rotation 00054 00055 try { 00056 // Open the master cube 00057 Cube cube; 00058 cube.Open(ui.GetFilename("MASTER"),"rw"); 00059 00060 //check for existing polygon, if exists delete it 00061 if (cube.Label()->HasObject("Polygon")){ 00062 cube.Label()->DeleteObject("Polygon"); 00063 } 00064 00065 // Get the camera 00066 Camera *cam = cube.Camera(); 00067 if (cam->DetectorMap()->LineRate() == 0.0) { 00068 string msg = "[" + ui.GetFilename("MASTER") + "] is not a line scan camera image"; 00069 throw iException::Message(Isis::iException::User,msg,_FILEINFO_); 00070 } 00071 00072 // Create the master rotation to be corrected 00073 int frameCode = cam->InstrumentRotation()->Frame(); 00074 cam->SetImage(int(cube.Samples()/2), int(cube.Lines()/2) ); 00075 double tol = cam->PixelResolution(); 00076 00077 if (tol < 0.) { 00078 // Alternative calculation of .01*ground resolution of a pixel 00079 tol = cam->PixelPitch()*cam->SpacecraftAltitude()/cam->FocalLength()/1000./100.; 00080 } 00081 LineScanCameraRotation crot(frameCode, *(cube.Label()), cam->InstrumentRotation()->GetFullCacheTime(), tol ); 00082 crot.SetPolynomialDegree(ui.GetInteger("DEGREE")); 00083 crot.SetAxes(1, 2, 3); 00084 if (ui.WasEntered("PITCHRATE")) crot.ResetPitchRate(ui.GetDouble("PITCHRATE")); 00085 if (ui.WasEntered("YAW")) crot.ResetYaw(ui.GetDouble("YAW")); 00086 crot.SetPolynomial(); 00087 double baseTime = crot.GetBaseTime(); 00088 double timeScale = crot.GetTimeScale(); 00089 double fl = cam->FocalLength(); 00090 double pixpitch = cam->PixelPitch(); 00091 std::vector<double> cacheTime = cam->InstrumentRotation()->GetFullCacheTime(); 00092 00093 // Get the jitter in pixels, compute jitter angles, and fit a polynomial to each angle 00094 PixelOffset jitter(ui.GetFilename("JITTERFILE"), fl, pixpitch, baseTime, timeScale, degree); 00095 jitter.LoadAngles(cacheTime); 00096 jitter.SetPolynomial(); 00097 00098 // Set the jitter and apply to the instrument rotation 00099 crot.SetJitter( &jitter ); 00100 crot.ReloadCache(); 00101 00102 // Pull out the pointing cache as a table and write it 00103 Table cmatrix = crot.Cache("InstrumentPointing"); 00104 cmatrix.Label().AddComment("Corrected using appjit and" + ui.GetFilename("JITTERFILE")); 00105 cube.Write(cmatrix); 00106 00107 // Write out the instrument position table 00108 Isis::PvlGroup kernels = cube.Label()->FindGroup("Kernels",Isis::Pvl::Traverse); 00109 00110 // Write out the "Table" label to the tabled kernels in the kernels group 00111 kernels["InstrumentPointing"] = "Table"; 00112 // kernels["InstrumentPosition"] = "Table"; 00113 cube.PutGroup(kernels); 00114 cube.Close(); 00115 gp += PvlKeyword("StatusMaster",ui.GetFilename("MASTER") + ": camera pointing updated"); 00116 00117 // Apply the dejittered pointing to the rest of the files 00118 step2 = true; 00119 for (int ifile = 0; ifile < (int) list.size(); ifile++) { 00120 if (list[ifile] != ui.GetFilename("MASTER")) { 00121 // Open the cube 00122 cube.Open(list[ifile],"rw"); 00123 //check for existing polygon, if exists delete it 00124 if (cube.Label()->HasObject("Polygon")){ 00125 cube.Label()->DeleteObject("Polygon"); 00126 } 00127 // Get the camera and make sure it is a line scan camera 00128 Camera *cam = cube.Camera(); 00129 if (cam->DetectorMap()->LineRate() == 0.0) { 00130 string msg = "[" + ui.GetFilename("FROM") + "] is not a line scan camera"; 00131 throw iException::Message(Isis::iException::User,msg,_FILEINFO_); 00132 } 00133 // Pull out the pointing cache as a table and write it 00134 cube.Write(cmatrix); 00135 cube.PutGroup(kernels); 00136 cube.Close(); 00137 gp += PvlKeyword("Status" + iString(ifile), list[ifile] + ": camera pointing updated"); 00138 } 00139 } 00140 Application::Log( gp ); 00141 } 00142 catch (iException &e) { 00143 string msg; 00144 if (!step2) { 00145 msg = "Unable to fit pointing for [" + ui.GetFilename("MASTER") + "]"; 00146 } 00147 else { 00148 msg = "Unable to update pointing for nonMaster file(s)"; 00149 } 00150 throw iException::Message(Isis::iException::User,msg,_FILEINFO_); 00151 } 00152 }