USGS

Isis 3.0 Application Source Code Reference

Home

cnet2mat.cpp

Go to the documentation of this file.
00001 #include "Isis.h"
00002 
00003 #include <map>
00004 #include <iomanip>
00005 #include <sstream>
00006 
00007 #include "Pvl.h"
00008 #include "TextFile.h"
00009 #include "FileList.h"
00010 #include "SerialNumberList.h"
00011 #include "ControlNet.h"
00012 #include "iException.h"
00013 
00014 using namespace std;
00015 using namespace Isis;
00016 
00017 void IsisMain() {
00018 
00019   std::map <int,string> fscMap;
00020   std::map <string,int> snMap;
00021 
00022   UserInterface &ui = Application::GetUserInterface();
00023 
00024   FileList list2(ui.GetFilename("LIST2"));
00025 
00026   SerialNumberList snl(ui.GetFilename("LIST3"));
00027   for (unsigned int f=0; f<list2.size(); f++) {
00028     iString currFile (list2[f]);
00029     Pvl lab (currFile);
00030     PvlObject qube (lab.FindObject("QUBE"));
00031     string fsc;
00032     if (qube.HasKeyword("IMAGE_NUMBER")) {
00033       fsc = qube.FindKeyword("IMAGE_NUMBER")[0];
00034     }
00035     else if (qube.HasKeyword("IMAGE_ID")) {
00036       fsc = qube.FindKeyword("IMAGE_ID")[0];
00037     }
00038     else {
00039       string msg = "Unable to find keyword [\"IMAGE_NUMBER\" or \"IMAGE_ID\"] in file [";
00040       msg += fsc + "]";
00041       throw Isis::iException::Message(Isis::iException::User,msg,_FILEINFO_);
00042     }
00043     iString sn (snl.SerialNumber(f));
00044     fscMap.insert(std::pair<int,string>(f,fsc));
00045     snMap.insert(std::pair<string,int>(sn,f));
00046   }
00047 
00048   ControlNet cnet(ui.GetFilename("CONTROL"));
00049 
00050   int mpTotal = 0;
00051 
00052   for (int i=0; i<cnet.Size(); i++) {
00053     mpTotal += cnet[i].Size();
00054   }
00055 
00056   TextFile mpFile(ui.GetFilename("MATCH"),"Overwrite","");
00057 
00058   ostringstream str;
00059   iString textLine;
00060 
00061   textLine = "Matchpoint total =    ";
00062   textLine += iString(mpTotal);
00063   mpFile.PutLine(textLine);
00064   str.clear();
00065   str.str("");
00066   str.width(40);
00067   str.setf(ios::left);
00068   str << "Point ID";
00069   textLine = str.str();
00070 
00071   str.clear();
00072   str.str("");
00073   str.width(7);
00074   str.setf(ios::left);
00075   str << "FSC";
00076   textLine += str.str();
00077 
00078   str.clear();
00079   str.str("");
00080   str.width(8);
00081   str.setf(ios::left);
00082   str << "LINE";
00083   textLine += str.str();
00084 
00085   str.clear();
00086   str.str("");
00087   str.width(5);
00088   str.setf(ios::left);
00089   str << "SAMP";
00090   textLine += str.str();
00091 
00092 
00093   str.clear();
00094   str.str("");
00095   str.width(14);
00096   str.setf(ios::left);
00097   str << "CLASS";
00098   textLine += str.str();
00099 
00100   str.clear();
00101   str.str("");
00102   str.width(8);
00103   str.setf(ios::left);
00104   str << "DIAMETER";
00105   textLine += str.str();
00106 
00107   mpFile.PutLine(textLine);
00108 
00109   // Loop for each point in the control network
00110   for (int i=0; i<cnet.Size(); i++){
00111 
00112     // Loop for each measure in the control point
00113     for (int m=0; m<cnet[i].Size(); m++) {
00114       ostringstream formatter;
00115       ControlMeasure currMeas = cnet[i][m];
00116 
00117       //Set Point ID
00118       formatter.clear();
00119       formatter.str("");
00120       formatter.width(30);
00121       formatter.setf(ios::left);
00122       formatter << cnet[i].Id() << " ";
00123       textLine = formatter.str();
00124 
00125       //Set FSC
00126       formatter.clear();
00127       formatter.str("");
00128       formatter.width(12);
00129       formatter.setf(ios::right);
00130       string sn = currMeas.CubeSerialNumber();
00131       string fsc = fscMap[snMap[sn]];
00132       formatter << fsc << " ";
00133       textLine += formatter.str();
00134 
00135       //Set Line
00136       formatter.clear();
00137       formatter.str("");
00138       formatter.width(7);
00139       formatter.setf(ios::right);
00140       formatter.setf(ios::fixed);
00141       formatter.precision(2);
00142       formatter << currMeas.Line() << " ";
00143       textLine += formatter.str();
00144 
00145       //Set Sample
00146       formatter.clear();
00147       formatter.str("");
00148       formatter.width(7);
00149       formatter.setf(ios::right);
00150       formatter.setf(ios::fixed);
00151       formatter.precision(2);
00152       formatter << currMeas.Sample() << "   ";
00153       textLine += formatter.str();
00154 
00155       //Set Class
00156       string ptClass;
00157       ControlMeasure::MeasureType mType = currMeas.Type();
00158       if (mType == ControlMeasure::Unmeasured) {
00159         ptClass = "U   ";
00160       }
00161       else if (mType == ControlMeasure::ValidatedManual) {
00162         ptClass = "M   ";
00163       }
00164       else if (mType == ControlMeasure::ValidatedAutomatic) {
00165         ptClass = "S   ";
00166       }
00167       else {
00168         ptClass = "U   ";
00169       }
00170       if (currMeas.IsReference()) {
00171         ptClass = "T   ";
00172       }
00173       textLine += ptClass;
00174 
00175       //Set Diameter
00176       formatter.clear();
00177       formatter.str("");
00178       formatter.width(16);
00179       formatter.setf(ios::right);
00180       iString diam;
00181       if (currMeas.Diameter() == Isis::Null) {
00182         diam = 0.0;
00183       }
00184       else {
00185         diam = currMeas.Diameter();
00186       }
00187       formatter << diam;
00188       textLine += formatter.str();
00189 
00190       mpFile.PutLine(textLine);
00191     }
00192   }
00193 }