|
Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 #include <cstdio> 00003 #include <cmath> 00004 #include <string> 00005 00006 #include "Constants.h" 00007 #include "UserInterface.h" 00008 #include "CubeAttribute.h" 00009 #include "Filename.h" 00010 #include "iException.h" 00011 #include "Progress.h" 00012 #include "Pvl.h" 00013 #include "Process.h" 00014 #include "iTime.h" 00015 #include "iString.h" 00016 #include "SerialNumber.h" 00017 #include "OriginalLabel.h" 00018 #include "SpecialPixel.h" 00019 #include "Statistics.h" 00020 #include "LineManager.h" 00021 #include "CamTools.h" 00022 00023 using namespace std; 00024 using namespace Isis; 00025 00026 void IsisMain () 00027 { 00028 const string caminfo_program = "caminfo"; 00029 const string caminfo_version = "2.2"; 00030 const string caminfo_revision = "$Revision: 1.19 $"; 00031 string caminfo_runtime = iTime::CurrentGMT(); 00032 00033 Process p; 00034 // Grab the file to import 00035 UserInterface &ui = Application::GetUserInterface(); 00036 string from = ui.GetAsString("FROM"); 00037 Filename in = ui.GetFilename("FROM"); 00038 bool doCamstat = ui.GetBoolean("CAMSTATS"); 00039 00040 Pvl pout; 00041 // if true then run spiceinit, xml default is FALSE 00042 //spiceinit will use system kernels 00043 if (ui.GetBoolean("SPICE")) { 00044 string parameters = "FROM=" + in.Expanded(); 00045 Isis::iApp->Exec("spiceinit",parameters); 00046 } 00047 00048 Cube *icube = p.SetInputCube("FROM"); 00049 00050 // get some common things like #line, #samples, bands. 00051 PvlObject params("Caminfo"); 00052 PvlObject common("Parameters"); 00053 common += PvlKeyword("Program", caminfo_program); 00054 common += PvlKeyword("Version", caminfo_version); 00055 common += PvlKeyword("IsisVersion", version); 00056 common += PvlKeyword("RunDate", caminfo_runtime); 00057 common += PvlKeyword("IsisId",SerialNumber::Compose(*icube)); 00058 common += PvlKeyword("From",icube->Filename()); 00059 common += PvlKeyword("Lines",icube->Lines()); 00060 common += PvlKeyword("Samples",icube->Samples()); 00061 common += PvlKeyword("Bands",icube->Bands()); 00062 params.AddObject(common); 00063 00064 // Run camstats on the entire image (all bands) 00065 // another camstats will be run for each band and output 00066 // for each band. 00067 Pvl camPvl; // This becomes useful if there is only one band, which is 00068 // frequent! Used below if single band image. 00069 if (doCamstat) { 00070 int linc = ui.GetInteger("LINC"); 00071 int sinc = ui.GetInteger("SINC"); 00072 Filename tempCamPvl; 00073 tempCamPvl.Temporary(in.Basename()+"_", "pvl"); 00074 string pvlOut = tempCamPvl.Expanded(); 00075 PvlObject pcband("Camstats"); 00076 //set up camstats run and execute 00077 string parameters = "FROM=" + from + 00078 " TO=" + pvlOut + 00079 " LINC=" + iString(linc) + 00080 " SINC=" + iString(sinc); 00081 00082 Isis::iApp->Exec("camstats",parameters); 00083 //out put to common object of the PVL 00084 camPvl.Read(pvlOut); 00085 remove(pvlOut.c_str()); 00086 00087 PvlGroup cg = camPvl.FindGroup("Latitude",Pvl::Traverse); 00088 pcband += ValidateKey("MinimumLatitude",cg["latitudeminimum"]); 00089 pcband += ValidateKey("MaximumLatitude",cg["latitudemaximum"]); 00090 cg = camPvl.FindGroup("Longitude",Pvl::Traverse); 00091 pcband += ValidateKey("MinimumLongitude",cg["longitudeminimum"]); 00092 pcband += ValidateKey("MaximumLongitude",cg["longitudemaximum"]); 00093 cg = camPvl.FindGroup("Resolution",Pvl::Traverse); 00094 pcband += ValidateKey("MinimumResolution",cg["resolutionminimum"]); 00095 pcband += ValidateKey("MaximumResolution",cg["resolutionmaximum"]); 00096 cg = camPvl.FindGroup("PhaseAngle",Pvl::Traverse); 00097 pcband += ValidateKey("MinimumPhase",cg["phaseminimum"]); 00098 pcband += ValidateKey("MaximumPhase",cg["phasemaximum"]); 00099 cg = camPvl.FindGroup("EmissionAngle",Pvl::Traverse); 00100 pcband += ValidateKey("MinimumEmission",cg["emissionminimum"]); 00101 pcband += ValidateKey("MaximumEmission",cg["emissionmaximum"]); 00102 cg = camPvl.FindGroup("IncidenceAngle",Pvl::Traverse); 00103 pcband += ValidateKey("MinimumIncidence",cg["incidenceminimum"]); 00104 pcband += ValidateKey("MaximumIncidence",cg["incidencemaximum"]); 00105 cg = camPvl.FindGroup("LocalSolarTime",Pvl::Traverse); 00106 pcband += ValidateKey("LocalTimeMinimum",cg["localsolartimeMinimum"]); 00107 pcband += ValidateKey("LocalTimeMaximum",cg["localsolartimeMaximum"]); 00108 params.AddObject(pcband); 00109 } 00110 00111 00112 // Add the input ISIS label if requested 00113 if ( ui.GetBoolean("ISISLABEL") ) { 00114 Pvl label = *(icube->Label()); 00115 label.SetName("IsisLabel"); 00116 params.AddObject(label); 00117 } 00118 00119 // write out the orginal label blob 00120 if (ui.GetBoolean("ORIGINALLABEL")) { 00121 OriginalLabel orig; 00122 icube->Read(orig); 00123 Pvl p = orig.ReturnLabels(); 00124 p.SetName("OriginalLabel"); 00125 params.AddObject(p); 00126 } 00127 00128 00129 // Compute statistics for entire cube 00130 if ( ui.GetBoolean("STATISTICS") ) { 00131 LineManager iline(*icube); 00132 Statistics stats; 00133 Progress progress; 00134 progress.SetText("Statistics..."); 00135 progress.SetMaximumSteps(icube->Lines()*icube->Bands()); 00136 progress.CheckStatus(); 00137 iline.SetLine(1); 00138 for ( ; !iline.end() ; iline.next()) { 00139 icube->Read(iline); 00140 stats.AddData(iline.DoubleBuffer(), iline.size()); 00141 progress.CheckStatus(); 00142 } 00143 00144 // Compute stats of entire cube 00145 double nPixels = stats.TotalPixels(); 00146 double nullpercent = (stats.NullPixels()/(nPixels))*100; 00147 double hispercent = (stats.HisPixels()/(nPixels))*100; 00148 double hrspercent = (stats.HrsPixels()/(nPixels))*100; 00149 double lispercent = (stats.LisPixels()/(nPixels))*100; 00150 double lrspercent = (stats.LrsPixels()/(nPixels))*100; 00151 //statitics keyword output for band 00152 00153 PvlObject sgroup("Statistics"); 00154 sgroup += ValidateKey("MeanValue",stats.Average()); 00155 sgroup += ValidateKey("StandardDeviation",stats.StandardDeviation()); 00156 sgroup += ValidateKey("MinimumValue",stats.Minimum()); 00157 sgroup += ValidateKey("MaximumValue",stats.Maximum()); 00158 sgroup += PvlKeyword("PercentHIS",hispercent); 00159 sgroup += PvlKeyword("PercentHRS",hrspercent); 00160 sgroup += PvlKeyword("PercentLIS",lispercent); 00161 sgroup += PvlKeyword("PercentLRS",lrspercent); 00162 sgroup += PvlKeyword("PercentNull",nullpercent); 00163 sgroup += PvlKeyword("TotalPixels",stats.TotalPixels()); 00164 00165 params.AddObject(sgroup); 00166 } 00167 00168 Camera *cam = icube->Camera(); 00169 00170 // for geometry, stats, camstats, or polygon get the info for each band 00171 BandGeometry bandGeom; 00172 bool doGeometry = ui.GetBoolean("GEOMETRY"); 00173 bool doPolygon = ui.GetBoolean("POLYGON"); 00174 if (doGeometry || doPolygon) { 00175 int pixinc = ui.GetInteger("PIXINC"); 00176 if (pixinc <= 0) pixinc = 100; 00177 bandGeom.setPixInc(pixinc); 00178 bandGeom.setMaxIncidence(ui.GetDouble("MAXINCIDENCE")); 00179 bandGeom.setMaxEmission(ui.GetDouble("MAXEMISSION")); 00180 bandGeom.collect(*cam, *icube, doGeometry, doPolygon); 00181 00182 00183 // Check if the user requires valid image center geometry 00184 if (ui.GetBoolean("VCAMERA") && (!bandGeom.hasCenterGeometry())) { 00185 string msg = "Image center does not project in camera model"; 00186 throw iException::Message(iException::Camera,msg,_FILEINFO_); 00187 } 00188 00189 // Write geometry data if requested 00190 if (doGeometry) { 00191 PvlObject ggroup("Geometry"); 00192 bandGeom.generateGeometryKeys(ggroup); 00193 params.AddObject(ggroup); 00194 } 00195 00196 // Write polygon group if requested 00197 if (doPolygon) { 00198 PvlObject ggroup("Polygon"); 00199 bandGeom.generatePolygonKeys(ggroup); 00200 params.AddObject(ggroup); 00201 } 00202 } 00203 00204 // Output the result 00205 string outFile = ui.GetFilename("TO"); 00206 pout.AddObject(params); 00207 pout.Write(outFile); 00208 } 00209 00210