Isis 3 Programmer Reference
ControlPointV0002.cpp
1 #include "ControlPointV0002.h"
2 
3 #include <QString>
4 
5 #include "ControlPointV0001.h"
6 #include "IException.h"
7 #include "Pvl.h"
8 #include "PvlContainer.h"
9 
10 using namespace std;
11 
12 namespace Isis {
13 
20  ControlPointV0002::ControlPointV0002(
23  : m_pointData(pointData), m_logData(logData) {
24 
25  }
26 
27 
34  : m_pointData(new ControlNetFileProtoV0001_PBControlPoint),
35  m_logData(new ControlNetLogDataProtoV0001_Point) {
36 
37  // Copy over strings, doubles, and bools
38  copy(pointObject, "PointId",
39  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_id);
40  copy(pointObject, "ChooserName",
41  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_choosername);
42  copy(pointObject, "DateTime",
43  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_datetime);
44  copy(pointObject, "AprioriXYZSourceFile",
45  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_apriorisurfpointsourcefile);
46  copy(pointObject, "AprioriRadiusSourceFile",
47  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_aprioriradiussourcefile);
48  copy(pointObject, "JigsawRejected",
49  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_jigsawrejected);
50  copy(pointObject, "EditLock",
51  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_editlock);
52  copy(pointObject, "Ignore",
53  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_ignore);
54  copy(pointObject, "AprioriX",
55  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_apriorix);
56  copy(pointObject, "AprioriY",
57  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_aprioriy);
58  copy(pointObject, "AprioriZ",
59  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_aprioriz);
60  copy(pointObject, "AdjustedX",
61  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_adjustedx);
62  copy(pointObject, "AdjustedY",
63  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_adjustedy);
64  copy(pointObject, "AdjustedZ",
65  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_adjustedz);
66  copy(pointObject, "LatitudeConstrained",
67  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_latitudeconstrained);
68  copy(pointObject, "LongitudeConstrained",
69  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_longitudeconstrained);
70  copy(pointObject, "RadiusConstrained",
71  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_radiusconstrained);
72 
73  // Copy enumerated values
74 
75  if (pointObject["PointType"][0] == "Ground") {
76  m_pointData->set_type(ControlNetFileProtoV0001_PBControlPoint::Ground);
77  }
78  else if (pointObject["PointType"][0] == "Tie") {
79  m_pointData->set_type(ControlNetFileProtoV0001_PBControlPoint::Tie);
80  }
81  else {
82  QString msg = "Invalid ControlPoint type [" + pointObject["PointType"][0] + "].";
84  }
85 
86  if (pointObject.hasKeyword("AprioriXYZSource")) {
87  QString source = pointObject["AprioriXYZSource"][0];
88 
89  if (source == "None") {
90  m_pointData->set_apriorisurfpointsource(ControlNetFileProtoV0001_PBControlPoint::None);
91  }
92  else if (source == "User") {
93  m_pointData->set_apriorisurfpointsource(ControlNetFileProtoV0001_PBControlPoint::User);
94  }
95  else if (source == "AverageOfMeasures") {
96  m_pointData->set_apriorisurfpointsource(
97  ControlNetFileProtoV0001_PBControlPoint::AverageOfMeasures);
98  }
99  else if (source == "Reference") {
100  m_pointData->set_apriorisurfpointsource(
101  ControlNetFileProtoV0001_PBControlPoint::Reference);
102  }
103  else if (source == "Basemap") {
104  m_pointData->set_apriorisurfpointsource(ControlNetFileProtoV0001_PBControlPoint::Basemap);
105  }
106  else if (source == "BundleSolution") {
107  m_pointData->set_apriorisurfpointsource(
108  ControlNetFileProtoV0001_PBControlPoint::BundleSolution);
109  }
110  else {
111  QString msg = "Invalid AprioriXYZSource [" + source + "]";
113  }
114  }
115 
116  if (pointObject.hasKeyword("AprioriRadiusSource")) {
117  QString source = pointObject["AprioriRadiusSource"][0];
118 
119  if (source == "None") {
120  m_pointData->set_aprioriradiussource(ControlNetFileProtoV0001_PBControlPoint::None);
121  }
122  else if (source == "User") {
123  m_pointData->set_aprioriradiussource(ControlNetFileProtoV0001_PBControlPoint::User);
124  }
125  else if (source == "AverageOfMeasures") {
126  m_pointData->set_aprioriradiussource(
127  ControlNetFileProtoV0001_PBControlPoint::AverageOfMeasures);
128  }
129  else if (source == "Ellipsoid") {
130  m_pointData->set_aprioriradiussource(ControlNetFileProtoV0001_PBControlPoint::Ellipsoid);
131  }
132  else if (source == "DEM") {
133  m_pointData->set_aprioriradiussource(ControlNetFileProtoV0001_PBControlPoint::DEM);
134  }
135  else if (source == "BundleSolution") {
136  m_pointData->set_aprioriradiussource(
137  ControlNetFileProtoV0001_PBControlPoint::BundleSolution);
138  }
139  else {
140  QString msg = "Invalid AprioriRadiusSource, [" + source + "]";
142  }
143  }
144 
145  // Copy array values
146  if (pointObject.hasKeyword("AprioriCovarianceMatrix")) {
147  PvlKeyword &matrix = pointObject["AprioriCovarianceMatrix"];
148 
149  m_pointData->add_aprioricovar(toDouble(matrix[0]));
150  m_pointData->add_aprioricovar(toDouble(matrix[1]));
151  m_pointData->add_aprioricovar(toDouble(matrix[2]));
152  m_pointData->add_aprioricovar(toDouble(matrix[3]));
153  m_pointData->add_aprioricovar(toDouble(matrix[4]));
154  m_pointData->add_aprioricovar(toDouble(matrix[5]));
155  }
156 
157  if (pointObject.hasKeyword("AdjustedCovarianceMatrix")) {
158  PvlKeyword &matrix = pointObject["AdjustedCovarianceMatrix"];
159 
160  m_pointData->add_adjustedcovar(toDouble(matrix[0]));
161  m_pointData->add_adjustedcovar(toDouble(matrix[1]));
162  m_pointData->add_adjustedcovar(toDouble(matrix[2]));
163  m_pointData->add_adjustedcovar(toDouble(matrix[3]));
164  m_pointData->add_adjustedcovar(toDouble(matrix[4]));
165  m_pointData->add_adjustedcovar(toDouble(matrix[5]));
166  }
167 
168  // Process Measures
169  for (int groupIndex = 0; groupIndex < pointObject.groups(); groupIndex ++) {
170  PvlGroup &group = pointObject.group(groupIndex);
171  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure measure;
172 
173  // Copy strings, booleans, and doubles
174  copy(group, "SerialNumber",
175  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_serialnumber);
176  copy(group, "ChooserName",
177  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_choosername);
178  copy(group, "DateTime",
179  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_datetime);
180  copy(group, "Diameter",
181  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_diameter);
182  copy(group, "EditLock",
183  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_editlock);
184  copy(group, "Ignore",
185  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_ignore);
186  copy(group, "JigsawRejected",
187  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_jigsawrejected);
188  copy(group, "AprioriSample",
189  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_apriorisample);
190  copy(group, "AprioriLine",
191  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_aprioriline);
192  copy(group, "SampleSigma",
193  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_samplesigma);
194  copy(group, "LineSigma",
195  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_linesigma);
196 
197  // The sample, line, sample residual, and line residual are nested in another structure
198  // inside the measure, so they cannot be copied with the conenience methods.
199  if (group.hasKeyword("Sample")) {
200  double value = toDouble(group["Sample"][0]);
201  measure.mutable_measurement()->set_sample(value);
202  group.deleteKeyword("Sample");
203  }
204  if (group.hasKeyword("Line")) {
205  double value = toDouble(group["Line"][0]);
206  measure.mutable_measurement()->set_line(value);
207  group.deleteKeyword("Line");
208  }
209  if (group.hasKeyword("SampleResidual")) {
210  double value = toDouble(group["SampleResidual"][0]);
211  measure.mutable_measurement()->set_sampleresidual(value);
212  group.deleteKeyword("SampleResidual");
213  }
214  if (group.hasKeyword("LineResidual")) {
215  double value = toDouble(group["LineResidual"][0]);
216  measure.mutable_measurement()->set_lineresidual(value);
217  group.deleteKeyword("LineResidual");
218  }
219  if (group.hasKeyword("Reference")) {
220  if (group["Reference"][0].toLower() == "true") {
221  m_pointData->set_referenceindex(groupIndex);
222  }
223  group.deleteKeyword("Reference");
224  }
225 
226  QString type = group["MeasureType"][0].toLower();
227  if (type == "candidate") {
228  measure.set_type(ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::Candidate);
229  }
230  else if (type == "manual") {
231  measure.set_type(ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::Manual);
232  }
233  else if (type == "registeredpixel") {
234  measure.set_type(
235  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::RegisteredPixel);
236  }
237  else if (type == "registeredsubpixel") {
238  measure.set_type(
239  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::RegisteredSubPixel);
240  }
241  else {
243  "Unknown measure type [" + type + "]",
244  _FILEINFO_);
245  }
246  group.deleteKeyword("MeasureType");
247 
248  // Clean up the remaining keywords
249  // This also removes obsolete log data entries
250  for (int cmKeyIndex = 0; cmKeyIndex < group.keywords(); cmKeyIndex ++) {
251  if (group[cmKeyIndex][0] == ""
252  || group[cmKeyIndex].name() == "ZScore"
253  || group[cmKeyIndex].name() == "ErrorMagnitude") {
254  group.deleteKeyword(cmKeyIndex);
255  }
256  }
257 
258  // Create the log data for the measure
259  ControlNetLogDataProtoV0001_Point_Measure measureLogData;
260 
261  for (int keyIndex = 0; keyIndex < group.keywords(); keyIndex++) {
262  PvlKeyword dataKeyword = group[keyIndex];
263  QString name = dataKeyword.name();
264  int dataType = 0;
265  double value = 0.0;
266 
267  if (name == "Obsolete_Eccentricity") {
268  dataType = 1;
269  }
270  else if (name == "GoodnessOfFit") {
271  dataType = 2;
272  }
273  else if (name == "MinimumPixelZScore") {
274  dataType = 3;
275  }
276  else if (name == "MaximumPixelZScore") {
277  dataType = 4;
278  }
279  else if (name == "PixelShift") {
280  dataType = 5;
281  }
282  else if (name == "WholePixelCorrelation") {
283  dataType = 6;
284  }
285  else if (name == "SubPixelCorrelation") {
286  dataType = 7;
287  }
288  else if (name == "Obsolete_AverageResidual") {
289  dataType = 8;
290  }
291  else {
292  QString msg = "Invalid control measure log data name [" + name + "]";
294  }
295 
296  try {
297  value = toDouble(dataKeyword[0]);
298  }
299  catch (IException &e) {
300  QString msg = "Invalid control measure log data value [" + dataKeyword[0] + "]";
301  throw IException(e, IException::Io, msg, _FILEINFO_);
302  }
303 
304  ControlNetLogDataProtoV0001_Point_Measure_DataEntry logEntry;
305  logEntry.set_datatype(dataType);
306  logEntry.set_datavalue(value);
307  *measureLogData.add_loggedmeasuredata() = logEntry;
308  }
309 
310  // Store the measure and its log data
311  *m_pointData->add_measures() = measure;
312  *m_logData->add_measures() = measureLogData;
313  }
314 
315  if (!m_pointData->IsInitialized()) {
316  QString msg = "There is missing required information in the control "
317  "points or measures";
318  throw IException(IException::Io, msg, _FILEINFO_);
319  }
320  }
321 
322 
334  : m_pointData(oldPoint.pointData()), m_logData(oldPoint.logData()) {
335 
336  }
337 
338 
346  return m_pointData;
347  }
348 
349 
357  return m_logData;
358  }
359 
360 
376  QString keyName,
378  void (ControlNetFileProtoV0001_PBControlPoint::*setter)(bool)) {
379 
380  if (!container.hasKeyword(keyName)) {
381  return;
382  }
383 
384  QString value = container[keyName][0];
385  container.deleteKeyword(keyName);
386  value = value.toLower();
387 
388  if (value == "true" || value == "yes") {
389  (point.data()->*setter)(true);
390  }
391  }
392 
393 
409  QString keyName,
411  void (ControlNetFileProtoV0001_PBControlPoint::*setter)(double)) {
412 
413  if (!container.hasKeyword(keyName)) {
414  return;
415  }
416 
417  double value = toDouble(container[keyName][0]);
418  container.deleteKeyword(keyName);
419  (point.data()->*setter)(value);
420  }
421 
422 
438  QString keyName,
440  void (ControlNetFileProtoV0001_PBControlPoint::*setter)(const std::string&)) {
441 
442  if (!container.hasKeyword(keyName)) {
443  return;
444  }
445 
446  QString value = container[keyName][0];
447  container.deleteKeyword(keyName);
448  (point.data()->*setter)(value.toLatin1().data());
449  }
450 
451 
467  QString keyName,
468  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure &measure,
469  void (ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::*setter)(bool)) {
470 
471  if (!container.hasKeyword(keyName)) {
472  return;
473  }
474 
475  QString value = container[keyName][0];
476  container.deleteKeyword(keyName);
477  value = value.toLower();
478 
479  if (value == "true" || value == "yes") {
480  (measure.*setter)(true);
481  }
482  }
483 
484 
500  QString keyName,
501  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure &measure,
502  void (ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::*setter)(double)) {
503 
504  if (!container.hasKeyword(keyName)) {
505  return;
506  }
507 
508  double value = toDouble(container[keyName][0]);
509  container.deleteKeyword(keyName);
510  (measure.*setter)(value);
511  }
512 
513 
529  QString keyName,
530  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure &measure,
531  void (ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::*setter)
532  (const std::string &)) {
533 
534  if (!container.hasKeyword(keyName)) {
535  return;
536  }
537 
538  QString value = container[keyName][0];
539  container.deleteKeyword(keyName);
540  (measure.*setter)(value.toLatin1().data());
541  }
542 }
int keywords() const
Returns the number of keywords contained in the PvlContainer.
Definition: PvlContainer.h:100
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Contains more than one keyword-value pair.
Definition: PvlContainer.h:63
void copy(PvlContainer &container, QString keyName, QSharedPointer< ControlNetFileProtoV0001_PBControlPoint > point, void(ControlNetFileProtoV0001_PBControlPoint::*setter)(bool))
This convenience method takes a boolean value from a PvlKeyword and copies it into a version 1 protob...
Namespace for the standard library.
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:171
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
Definition: PvlObject.cpp:207
QString name() const
Returns the container name.
Definition: PvlContainer.h:77
QSharedPointer< ControlNetFileProtoV0001_PBControlPoint > pointData()
Access the protobuf control point data.
QSharedPointer< ControlNetLogDataProtoV0001_Point > logData()
Access the protobuf log data for the control measures in the point.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
A single keyword-value pair.
Definition: PvlKeyword.h:98
ControlPointV0002()
Default constructor.
A container for the information stored in a version 1 ControlPoint.
QSharedPointer< ControlNetFileProtoV0001_PBControlPoint > m_pointData
protobuf container that holds information used to create a control point.
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:423
QSharedPointer< ControlNetLogDataProtoV0001_Point > m_logData
Protobuf container that holds log data for the control measures in the point.
QString name() const
Returns the keyword name.
Definition: PvlKeyword.h:114
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:87
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
void deleteKeyword(const QString &name)
Remove a specified keyword.