Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 #include <iostream> 00003 #include <sstream> 00004 #include <string> 00005 #include "Pvl.h" 00006 #include "Cube.h" 00007 #include "History.h" 00008 #include "Projection.h" 00009 #include "ProjectionFactory.h" 00010 00011 using namespace Isis; 00012 using namespace std; 00013 00014 void IsisMain() { 00015 // Access input parameters (user interface) 00016 UserInterface &ui = Application::GetUserInterface(); 00017 00018 // Open the input cube 00019 Cube cube; 00020 cube.open(ui.GetFilename("FROM"), "rw"); 00021 00022 //Get the map projection file provided by the user 00023 Pvl userMap; 00024 userMap.Read(ui.GetFilename("MAP")); 00025 PvlGroup &mapGrp = userMap.FindGroup("Mapping", Pvl::Traverse); 00026 00027 // Error checking to ensure the map projection file provided contains 00028 // information pertaining to a target, body radius, and longitude direction 00029 if(!mapGrp.HasKeyword("TargetName")) { 00030 string msg = "The given MAP [" + userMap.Name() + 00031 "] does not have the TargetName keyword."; 00032 throw iException::Message(iException::User, msg, _FILEINFO_); 00033 } 00034 else if(!mapGrp.HasKeyword("EquatorialRadius") || 00035 !mapGrp.HasKeyword("PolarRadius")) { 00036 string msg = "The given MAP [" + userMap.Name() + 00037 "] does not have the EquatorialRadius and PolarRadius keywords."; 00038 throw iException::Message(iException::User, msg, _FILEINFO_); 00039 } 00040 else if(!mapGrp.HasKeyword("LongitudeDomain")) { 00041 string msg = "The given MAP [" + userMap.Name() + 00042 "] does not have the LongitudeDomain keyword."; 00043 throw iException::Message(iException::User, msg, _FILEINFO_); 00044 } 00045 00046 00047 // Get user entered option 00048 string option = ui.GetString("COORDINATES"); 00049 00050 double x = 0.0; 00051 double y = 0.0; 00052 Projection * proj = ProjectionFactory::Create(userMap, false); 00053 if(option == "XY") { 00054 x = ui.GetDouble("X"); 00055 y = ui.GetDouble("Y"); 00056 } 00057 else if(option == "LATLON") { 00058 proj->SetGround(ui.GetDouble("LAT"), ui.GetDouble("LON")); 00059 x = proj->XCoord(); 00060 y = proj->YCoord(); 00061 } 00062 else { 00063 string message = "Invalid option [" + option + "] for parameter COORDINATES"; 00064 throw iException::Message(iException::User, message, _FILEINFO_); 00065 } 00066 00067 double res = 0.0; 00068 double scale = 0.0; 00069 00070 if(mapGrp.HasKeyword("PixelResolution")) { 00071 double localRadius = proj->LocalRadius(proj->TrueScaleLatitude()); 00072 res = mapGrp.FindKeyword("PixelResolution"); 00073 scale = (2.0 * Isis::PI * localRadius) / (360.0 * res); 00074 } 00075 else if(mapGrp.HasKeyword("Scale")) { 00076 double localRadius = proj->LocalRadius(proj->TrueScaleLatitude()); 00077 scale = mapGrp.FindKeyword("Scale"); 00078 res = (2.0 * Isis::PI * localRadius) / (360.0 * scale); 00079 } 00080 else { 00081 string msg = "The given MAP[" + userMap.Name() + 00082 "] does not have the PixelResolution or Scale keywords."; 00083 throw iException::Message(iException::User, msg, _FILEINFO_); 00084 } 00085 00086 //Read in line and sample inputs 00087 double line = ui.GetDouble("LINE"); 00088 double samp = ui.GetDouble("SAMPLE"); 00089 x = x - res * (samp - 0.5); 00090 y = y + res * (line - 0.5); 00091 00092 //add origen values to Mapping Group 00093 mapGrp.AddKeyword(PvlKeyword("UpperLeftCornerX", x, "meters"), Pvl::Replace); 00094 mapGrp.AddKeyword(PvlKeyword("UpperLeftCornerY", y, "meters"), Pvl::Replace); 00095 00096 if(!mapGrp.HasKeyword("PixelResolution")) { 00097 mapGrp.AddKeyword(PvlKeyword("PixelResolution", res, "meters")); 00098 } 00099 if(!mapGrp.HasKeyword("Scale")) { 00100 mapGrp.AddKeyword(PvlKeyword("Scale", scale, "pixels/degree")); 00101 } 00102 00103 00104 // Output the mapping group used to the Gui session log 00105 Application::GuiLog(userMap); 00106 // Extract label from cube file 00107 Pvl *label = cube.getLabel(); 00108 PvlObject &o = label->FindObject("IsisCube"); 00109 // Add Mapping Group to input cube 00110 if(o.HasGroup("Mapping")) { 00111 o.DeleteGroup("Mapping"); 00112 } 00113 o.AddGroup(mapGrp); 00114 00115 // keep track of change to labels in history 00116 History hist = History("IsisCube"); 00117 try { 00118 cube.read(hist); 00119 } 00120 catch(iException &e) { 00121 e.Clear(); 00122 } 00123 hist.AddEntry(); 00124 cube.write(hist); 00125 00126 cube.close(); 00127 }