Isis 3 Programmer Reference
ControlPointV0002.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "ControlPointV0002.h"
10 
11 #include <QString>
12 
13 #include "ControlPointV0001.h"
14 #include "IException.h"
15 #include "Pvl.h"
16 #include "PvlContainer.h"
17 
18 using namespace std;
19 
20 namespace Isis {
21 
28  ControlPointV0002::ControlPointV0002(
31  : m_pointData(pointData), m_logData(logData) {
32 
33  }
34 
35 
42  : m_pointData(new ControlNetFileProtoV0001_PBControlPoint),
43  m_logData(new ControlNetLogDataProtoV0001_Point) {
44 
45  // Copy over strings, doubles, and bools
46  copy(pointObject, "PointId",
47  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_id);
48  copy(pointObject, "ChooserName",
49  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_choosername);
50  copy(pointObject, "DateTime",
51  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_datetime);
52  copy(pointObject, "AprioriXYZSourceFile",
53  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_apriorisurfpointsourcefile);
54  copy(pointObject, "AprioriRadiusSourceFile",
55  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_aprioriradiussourcefile);
56  copy(pointObject, "JigsawRejected",
57  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_jigsawrejected);
58  copy(pointObject, "EditLock",
59  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_editlock);
60  copy(pointObject, "Ignore",
61  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_ignore);
62  copy(pointObject, "AprioriX",
63  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_apriorix);
64  copy(pointObject, "AprioriY",
65  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_aprioriy);
66  copy(pointObject, "AprioriZ",
67  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_aprioriz);
68  copy(pointObject, "AdjustedX",
69  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_adjustedx);
70  copy(pointObject, "AdjustedY",
71  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_adjustedy);
72  copy(pointObject, "AdjustedZ",
73  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_adjustedz);
74  copy(pointObject, "LatitudeConstrained",
75  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_latitudeconstrained);
76  copy(pointObject, "LongitudeConstrained",
77  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_longitudeconstrained);
78  copy(pointObject, "RadiusConstrained",
79  m_pointData, &ControlNetFileProtoV0001_PBControlPoint::set_radiusconstrained);
80 
81  // Copy enumerated values
82 
83  if (pointObject["PointType"][0] == "Ground") {
84  m_pointData->set_type(ControlNetFileProtoV0001_PBControlPoint::Ground);
85  }
86  else if (pointObject["PointType"][0] == "Tie") {
87  m_pointData->set_type(ControlNetFileProtoV0001_PBControlPoint::Tie);
88  }
89  else {
90  QString msg = "Invalid ControlPoint type [" + pointObject["PointType"][0] + "].";
91  throw IException(IException::User, msg, _FILEINFO_);
92  }
93 
94  if (pointObject.hasKeyword("AprioriXYZSource")) {
95  QString source = pointObject["AprioriXYZSource"][0];
96 
97  if (source == "None") {
98  m_pointData->set_apriorisurfpointsource(ControlNetFileProtoV0001_PBControlPoint::None);
99  }
100  else if (source == "User") {
101  m_pointData->set_apriorisurfpointsource(ControlNetFileProtoV0001_PBControlPoint::User);
102  }
103  else if (source == "AverageOfMeasures") {
104  m_pointData->set_apriorisurfpointsource(
105  ControlNetFileProtoV0001_PBControlPoint::AverageOfMeasures);
106  }
107  else if (source == "Reference") {
108  m_pointData->set_apriorisurfpointsource(
109  ControlNetFileProtoV0001_PBControlPoint::Reference);
110  }
111  else if (source == "Basemap") {
112  m_pointData->set_apriorisurfpointsource(ControlNetFileProtoV0001_PBControlPoint::Basemap);
113  }
114  else if (source == "BundleSolution") {
115  m_pointData->set_apriorisurfpointsource(
116  ControlNetFileProtoV0001_PBControlPoint::BundleSolution);
117  }
118  else {
119  QString msg = "Invalid AprioriXYZSource [" + source + "]";
120  throw IException(IException::User, msg, _FILEINFO_);
121  }
122  }
123 
124  if (pointObject.hasKeyword("AprioriRadiusSource")) {
125  QString source = pointObject["AprioriRadiusSource"][0];
126 
127  if (source == "None") {
128  m_pointData->set_aprioriradiussource(ControlNetFileProtoV0001_PBControlPoint::None);
129  }
130  else if (source == "User") {
131  m_pointData->set_aprioriradiussource(ControlNetFileProtoV0001_PBControlPoint::User);
132  }
133  else if (source == "AverageOfMeasures") {
134  m_pointData->set_aprioriradiussource(
135  ControlNetFileProtoV0001_PBControlPoint::AverageOfMeasures);
136  }
137  else if (source == "Ellipsoid") {
138  m_pointData->set_aprioriradiussource(ControlNetFileProtoV0001_PBControlPoint::Ellipsoid);
139  }
140  else if (source == "DEM") {
141  m_pointData->set_aprioriradiussource(ControlNetFileProtoV0001_PBControlPoint::DEM);
142  }
143  else if (source == "BundleSolution") {
144  m_pointData->set_aprioriradiussource(
145  ControlNetFileProtoV0001_PBControlPoint::BundleSolution);
146  }
147  else {
148  QString msg = "Invalid AprioriRadiusSource, [" + source + "]";
149  throw IException(IException::User, msg, _FILEINFO_);
150  }
151  }
152 
153  // Copy array values
154  if (pointObject.hasKeyword("AprioriCovarianceMatrix")) {
155  PvlKeyword &matrix = pointObject["AprioriCovarianceMatrix"];
156 
157  m_pointData->add_aprioricovar(toDouble(matrix[0]));
158  m_pointData->add_aprioricovar(toDouble(matrix[1]));
159  m_pointData->add_aprioricovar(toDouble(matrix[2]));
160  m_pointData->add_aprioricovar(toDouble(matrix[3]));
161  m_pointData->add_aprioricovar(toDouble(matrix[4]));
162  m_pointData->add_aprioricovar(toDouble(matrix[5]));
163  }
164 
165  if (pointObject.hasKeyword("AdjustedCovarianceMatrix")) {
166  PvlKeyword &matrix = pointObject["AdjustedCovarianceMatrix"];
167 
168  m_pointData->add_adjustedcovar(toDouble(matrix[0]));
169  m_pointData->add_adjustedcovar(toDouble(matrix[1]));
170  m_pointData->add_adjustedcovar(toDouble(matrix[2]));
171  m_pointData->add_adjustedcovar(toDouble(matrix[3]));
172  m_pointData->add_adjustedcovar(toDouble(matrix[4]));
173  m_pointData->add_adjustedcovar(toDouble(matrix[5]));
174  }
175 
176  // Process Measures
177  for (int groupIndex = 0; groupIndex < pointObject.groups(); groupIndex ++) {
178  PvlGroup &group = pointObject.group(groupIndex);
179  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure measure;
180 
181  // Copy strings, booleans, and doubles
182  copy(group, "SerialNumber",
183  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_serialnumber);
184  copy(group, "ChooserName",
185  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_choosername);
186  copy(group, "DateTime",
187  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_datetime);
188  copy(group, "Diameter",
189  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_diameter);
190  copy(group, "EditLock",
191  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_editlock);
192  copy(group, "Ignore",
193  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_ignore);
194  copy(group, "JigsawRejected",
195  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_jigsawrejected);
196  copy(group, "AprioriSample",
197  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_apriorisample);
198  copy(group, "AprioriLine",
199  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_aprioriline);
200  copy(group, "SampleSigma",
201  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_samplesigma);
202  copy(group, "LineSigma",
203  measure, &ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::set_linesigma);
204 
205  // The sample, line, sample residual, and line residual are nested in another structure
206  // inside the measure, so they cannot be copied with the conenience methods.
207  if (group.hasKeyword("Sample")) {
208  double value = toDouble(group["Sample"][0]);
209  measure.mutable_measurement()->set_sample(value);
210  group.deleteKeyword("Sample");
211  }
212  if (group.hasKeyword("Line")) {
213  double value = toDouble(group["Line"][0]);
214  measure.mutable_measurement()->set_line(value);
215  group.deleteKeyword("Line");
216  }
217  if (group.hasKeyword("SampleResidual")) {
218  double value = toDouble(group["SampleResidual"][0]);
219  measure.mutable_measurement()->set_sampleresidual(value);
220  group.deleteKeyword("SampleResidual");
221  }
222  if (group.hasKeyword("LineResidual")) {
223  double value = toDouble(group["LineResidual"][0]);
224  measure.mutable_measurement()->set_lineresidual(value);
225  group.deleteKeyword("LineResidual");
226  }
227  if (group.hasKeyword("Reference")) {
228  if (group["Reference"][0].toLower() == "true") {
229  m_pointData->set_referenceindex(groupIndex);
230  }
231  group.deleteKeyword("Reference");
232  }
233 
234  QString type = group["MeasureType"][0].toLower();
235  if (type == "candidate") {
236  measure.set_type(ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::Candidate);
237  }
238  else if (type == "manual") {
239  measure.set_type(ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::Manual);
240  }
241  else if (type == "registeredpixel") {
242  measure.set_type(
243  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::RegisteredPixel);
244  }
245  else if (type == "registeredsubpixel") {
246  measure.set_type(
247  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::RegisteredSubPixel);
248  }
249  else {
251  "Unknown measure type [" + type + "]",
252  _FILEINFO_);
253  }
254  group.deleteKeyword("MeasureType");
255 
256  // Clean up the remaining keywords
257  // This also removes obsolete log data entries
258  for (int cmKeyIndex = 0; cmKeyIndex < group.keywords(); cmKeyIndex ++) {
259  if (group[cmKeyIndex][0] == ""
260  || group[cmKeyIndex].name() == "ZScore"
261  || group[cmKeyIndex].name() == "ErrorMagnitude") {
262  group.deleteKeyword(cmKeyIndex);
263  }
264  }
265 
266  // Create the log data for the measure
267  ControlNetLogDataProtoV0001_Point_Measure measureLogData;
268 
269  for (int keyIndex = 0; keyIndex < group.keywords(); keyIndex++) {
270  PvlKeyword dataKeyword = group[keyIndex];
271  QString name = dataKeyword.name();
272  int dataType = 0;
273  double value = 0.0;
274 
275  if (name == "Obsolete_Eccentricity") {
276  dataType = 1;
277  }
278  else if (name == "GoodnessOfFit") {
279  dataType = 2;
280  }
281  else if (name == "MinimumPixelZScore") {
282  dataType = 3;
283  }
284  else if (name == "MaximumPixelZScore") {
285  dataType = 4;
286  }
287  else if (name == "PixelShift") {
288  dataType = 5;
289  }
290  else if (name == "WholePixelCorrelation") {
291  dataType = 6;
292  }
293  else if (name == "SubPixelCorrelation") {
294  dataType = 7;
295  }
296  else if (name == "Obsolete_AverageResidual") {
297  dataType = 8;
298  }
299  else {
300  QString msg = "Invalid control measure log data name [" + name + "]";
301  throw IException(IException::Programmer, msg, _FILEINFO_);
302  }
303 
304  try {
305  value = toDouble(dataKeyword[0]);
306  }
307  catch (IException &e) {
308  QString msg = "Invalid control measure log data value [" + dataKeyword[0] + "]";
309  throw IException(e, IException::Io, msg, _FILEINFO_);
310  }
311 
312  ControlNetLogDataProtoV0001_Point_Measure_DataEntry logEntry;
313  logEntry.set_datatype(dataType);
314  logEntry.set_datavalue(value);
315  *measureLogData.add_loggedmeasuredata() = logEntry;
316  }
317 
318  // Store the measure and its log data
319  *m_pointData->add_measures() = measure;
320  *m_logData->add_measures() = measureLogData;
321  }
322 
323  if (!m_pointData->IsInitialized()) {
324  QString msg = "There is missing required information in the control "
325  "points or measures";
326  throw IException(IException::Io, msg, _FILEINFO_);
327  }
328  }
329 
330 
342  : m_pointData(oldPoint.pointData()), m_logData(oldPoint.logData()) {
343 
344  }
345 
346 
354  return m_pointData;
355  }
356 
357 
365  return m_logData;
366  }
367 
368 
384  QString keyName,
386  void (ControlNetFileProtoV0001_PBControlPoint::*setter)(bool)) {
387 
388  if (!container.hasKeyword(keyName)) {
389  return;
390  }
391 
392  QString value = container[keyName][0];
393  container.deleteKeyword(keyName);
394  value = value.toLower();
395 
396  if (value == "true" || value == "yes") {
397  (point.data()->*setter)(true);
398  }
399  }
400 
401 
417  QString keyName,
419  void (ControlNetFileProtoV0001_PBControlPoint::*setter)(double)) {
420 
421  if (!container.hasKeyword(keyName)) {
422  return;
423  }
424 
425  double value = toDouble(container[keyName][0]);
426  container.deleteKeyword(keyName);
427  (point.data()->*setter)(value);
428  }
429 
430 
446  QString keyName,
448  void (ControlNetFileProtoV0001_PBControlPoint::*setter)(const std::string&)) {
449 
450  if (!container.hasKeyword(keyName)) {
451  return;
452  }
453 
454  QString value = container[keyName][0];
455  container.deleteKeyword(keyName);
456  (point.data()->*setter)(value.toLatin1().data());
457  }
458 
459 
475  QString keyName,
476  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure &measure,
477  void (ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::*setter)(bool)) {
478 
479  if (!container.hasKeyword(keyName)) {
480  return;
481  }
482 
483  QString value = container[keyName][0];
484  container.deleteKeyword(keyName);
485  value = value.toLower();
486 
487  if (value == "true" || value == "yes") {
488  (measure.*setter)(true);
489  }
490  }
491 
492 
508  QString keyName,
509  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure &measure,
510  void (ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::*setter)(double)) {
511 
512  if (!container.hasKeyword(keyName)) {
513  return;
514  }
515 
516  double value = toDouble(container[keyName][0]);
517  container.deleteKeyword(keyName);
518  (measure.*setter)(value);
519  }
520 
521 
537  QString keyName,
538  ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure &measure,
539  void (ControlNetFileProtoV0001_PBControlPoint_PBControlMeasure::*setter)
540  (const std::string &)) {
541 
542  if (!container.hasKeyword(keyName)) {
543  return;
544  }
545 
546  QString value = container[keyName][0];
547  container.deleteKeyword(keyName);
548  (measure.*setter)(value.toLatin1().data());
549  }
550 }
Isis::PvlKeyword::name
QString name() const
Returns the keyword name.
Definition: PvlKeyword.h:98
Isis::PvlObject::group
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:452
Isis::IException::Io
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:155
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::ControlPointV0002::copy
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...
Definition: ControlPointV0002.cpp:383
Isis::PvlObject::groups
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:75
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
QSharedPointer< ControlNetFileProtoV0001_PBControlPoint >
Isis::ControlPointV0002::pointData
QSharedPointer< ControlNetFileProtoV0001_PBControlPoint > pointData()
Access the protobuf control point data.
Definition: ControlPointV0002.cpp:353
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::ControlPointV0002::logData
QSharedPointer< ControlNetLogDataProtoV0001_Point > logData()
Access the protobuf log data for the control measures in the point.
Definition: ControlPointV0002.cpp:364
Isis::PvlObject::hasKeyword
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:236
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::ControlPointV0002::m_logData
QSharedPointer< ControlNetLogDataProtoV0001_Point > m_logData
Protobuf container that holds log data for the control measures in the point.
Definition: ControlPointV0002.h:213
Isis::ControlPointV0002::ControlPointV0002
ControlPointV0002()
Default constructor.
Isis::PvlContainer::deleteKeyword
void deleteKeyword(const QString &name)
Remove a specified keyword.
Definition: PvlContainer.cpp:97
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::PvlContainer::keywords
int keywords() const
Returns the number of keywords contained in the PvlContainer.
Definition: PvlContainer.h:86
Isis::PvlContainer
Contains more than one keyword-value pair.
Definition: PvlContainer.h:49
Isis::ControlPointV0002::m_pointData
QSharedPointer< ControlNetFileProtoV0001_PBControlPoint > m_pointData
protobuf container that holds information used to create a control point.
Definition: ControlPointV0002.h:211
Isis::ControlPointV0001
A container for the information stored in a version 1 ControlPoint.
Definition: ControlPointV0001.h:62
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126