|
Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 00003 #include "CameraPointInfo.h" 00004 #include "ControlMeasure.h" 00005 #include "ControlNet.h" 00006 #include "ControlPoint.h" 00007 #include "iException.h" 00008 #include "iString.h" 00009 #include "Progress.h" 00010 #include "PvlGroup.h" 00011 #include "PvlKeyword.h" 00012 #include "PvlObject.h" 00013 #include "SerialNumberList.h" 00014 #include "TextFile.h" 00015 #include "UserInterface.h" 00016 00017 #include <QString> 00018 #include <QVector> 00019 00020 #include <string> 00021 00022 using namespace std; 00023 using namespace Isis; 00024 00025 void Write(PvlGroup * point, ControlMeasure & cm); 00026 00027 // Allows for column names to be written on the first pass 00028 bool isFirst; 00029 bool append; 00030 00031 TextFile * txt = NULL; 00032 00033 // For control measure related data and labels 00034 QString measureInfo; 00035 QString measureLabels; 00036 00037 void IsisMain() { 00038 isFirst = true; 00039 append = false; 00040 measureInfo = ""; 00041 measureLabels = ""; 00042 00043 Progress prog; 00044 00045 // Get user entered information 00046 UserInterface &ui = Application::GetUserInterface(); 00047 ControlNet cnet(ui.GetFilename("CNET")); 00048 SerialNumberList serials(ui.GetFilename("FROMLIST")); 00049 append = ui.GetBoolean("APPEND"); 00050 00051 if (cnet.Size() == 0) { 00052 string msg = "Your control network must contain at least one point"; 00053 throw iException::Message(iException::User, msg, _FILEINFO_); 00054 } 00055 00056 prog.SetMaximumSteps(cnet.Size()); 00057 00058 // If append is true, output will be appended or a new file created 00059 if (append) { 00060 txt = new TextFile(ui.GetFilename("TO"), "append"); 00061 } 00062 // Without append, if the files exists it will be overwritten 00063 else { 00064 txt = new TextFile(ui.GetFilename("TO"), "overwrite"); 00065 } 00066 00067 PvlGroup * grp = NULL; 00068 CameraPointInfo camPoint; 00069 00070 // Loop through all points in controlnet 00071 for (int i = 0; i < cnet.Size(); i++) { 00072 ControlPoint & cpoint = cnet[i]; 00073 00074 if (isFirst && !append) { 00075 measureLabels += "ControlPointId,"; 00076 measureLabels += "PointType,"; 00077 measureLabels += "Ignored,"; 00078 measureLabels += "Held,"; 00079 measureLabels += "Invalid,"; 00080 measureLabels += "UniversalLatitude,"; 00081 measureLabels += "UniversalLongitude,"; 00082 measureLabels += "Radius,"; 00083 } 00084 00085 // Always add data 00086 measureInfo.clear(); 00087 measureInfo += QString(cpoint.Id().c_str()) + ","; 00088 measureInfo += QString(cpoint.PointTypeToString(cpoint.Type()).c_str()) + ","; 00089 measureInfo += iString(cpoint.Ignore()).ToQt() + ","; 00090 measureInfo += iString(cpoint.Held()).ToQt() + ","; 00091 measureInfo += iString(cpoint.Invalid()).ToQt() + ","; 00092 measureInfo += iString(cpoint.UniversalLatitude()).ToQt() + ","; 00093 measureInfo += iString(cpoint.UniversalLongitude()).ToQt() + ","; 00094 measureInfo += iString(cpoint.Radius()).ToQt() + ","; 00095 00096 // Loop through all measures in controlpoint 00097 for (int j = 0; j < cpoint.Size(); j++) { 00098 00099 ControlMeasure & cmeasure = cpoint[j]; 00100 00101 // Set and then get CameraPointInfo information 00102 camPoint.SetCube(serials.Filename(cmeasure.CubeSerialNumber())); 00103 00104 grp = camPoint.SetImage(cmeasure.Sample(), cmeasure.Line()); 00105 00106 Write(grp, cmeasure); 00107 delete grp; 00108 grp = NULL; 00109 } 00110 00111 // Making progress! 00112 prog.CheckStatus(); 00113 } 00114 00115 // All done, clean up 00116 prog.CheckStatus(); 00117 delete txt; 00118 txt = NULL; 00119 } 00120 00121 // Write each PvlGroup out to file 00122 void Write(PvlGroup * point, ControlMeasure & cm) { 00123 00124 // QStrings are used QString here because of ControlMeasure returning 00125 // QStrings. There is some monkey motion involving ingesting doubles, 00126 // this is necessary as iString will accept doubles but QString won't. 00127 00128 QString output = ""; 00129 QVector < QString > dataNames; 00130 00131 // If its first and not appending, write the column labels 00132 if (isFirst && !append) { 00133 // point information 00134 for (int i = 0; i < point->Keywords(); i++) { 00135 if ((*point)[i].Size() == 3) { 00136 output += "X,"; 00137 output += "Y,"; 00138 output += "Z,"; 00139 } 00140 else { 00141 output += QString((*point)[i].Name().c_str()) + ","; 00142 } 00143 } 00144 00145 // control measure information 00146 dataNames = cm.GetMeasureDataNames(); 00147 for (int i = 0; i < dataNames.size(); i++) { 00148 output += dataNames[i] + ","; 00149 } 00150 isFirst = false; 00151 measureLabels += output; 00152 txt->PutLine(measureLabels.toStdString()); 00153 } 00154 output.clear(); 00155 measureLabels.clear(); 00156 00157 // Write out date values 00158 // point information 00159 for (int i = 0; i < point->Keywords(); i++) { 00160 if ((*point)[i].Size() == 3) { 00161 output += QString((*point)[i][0]) + ","; 00162 output += QString((*point)[i][1]) + ","; 00163 output += QString((*point)[i][2]) + ","; 00164 } 00165 else { 00166 output += QString((*point)[i][0]); 00167 if (i < point->Keywords()) { 00168 output += ","; 00169 } 00170 } 00171 } 00172 00173 dataNames = cm.GetMeasureDataNames(); 00174 for (int i = 0; i < dataNames.size(); i++) { 00175 output += iString(cm.GetMeasureData(dataNames[i])).ToQt() + ","; 00176 } 00177 00178 // Meseaure info comes first 00179 QString pri = ""; 00180 pri += measureInfo; 00181 pri += output; 00182 00183 txt->PutLine(pri.toStdString()); 00184 00185 output.clear(); 00186 pri.clear(); 00187 }