Isis 3.0 Programmer Reference
Back | Home
ControlNetVersioner.cpp
1 #include "ControlNetVersioner.h"
2 
3 #include <string>
4 
5 #include <QDebug>
6 
7 #include "ControlNetFile.h"
8 #include "ControlNetFileV0001.h"
9 #include "ControlNetFileV0002.h"
10 #include "ControlNetFileV0002.pb.h"
11 #include "ControlMeasureLogData.h"
12 #include "Distance.h"
13 #include "FileName.h"
14 #include "IException.h"
15 #include "IString.h"
16 #include "Latitude.h"
17 #include "Longitude.h"
18 #include "NaifStatus.h"
19 #include "Progress.h"
20 #include "Pvl.h"
21 #include "PvlGroup.h"
22 #include "PvlKeyword.h"
23 #include "PvlObject.h"
24 #include "SurfacePoint.h"
25 #include "Target.h"
26 
27 using namespace std;
28 
29 namespace Isis {
30 
40  LatestControlNetFile *ControlNetVersioner::Read(const FileName &networkFileName) {
41 
42  try {
43  Pvl network(networkFileName.expanded());
44 
45  if (network.hasObject("ProtoBuffer")) {
46  return ReadBinaryNetwork(network, networkFileName);
47  }
48  else if (network.hasObject("ControlNetwork")) {
49  return ReadPvlNetwork(network);
50  }
51  else {
52  IString msg = "Could not determine the control network file type";
53  throw IException(IException::Io, msg, _FILEINFO_);
54  }
55  }
56  catch (IException &e) {
57  IString msg = "Reading the control network [" + networkFileName.name()
58  + "] failed";
59  throw IException(e, IException::Io, msg, _FILEINFO_);
60  }
61  }
62 
63 
72  void ControlNetVersioner::Write(const FileName &file,
73  const LatestControlNetFile &fileData, bool pvl) {
74 
75  if (pvl) {
76  fileData.toPvl().write(file.expanded());
77  }
78  else {
79  fileData.Write(file);
80  }
81  }
82 
83 
100  LatestControlNetFile *ControlNetVersioner::ReadPvlNetwork(Pvl pvl) {
101 
102  PvlObject &network = pvl.findObject("ControlNetwork");
103 
104  if (!network.hasKeyword("Version"))
105  network += PvlKeyword("Version", "1");
106 
107  int version = toInt(network["Version"][0]);
108 
109  while (version != LATEST_PVL_VERSION) {
110  int previousVersion = version;
111 
112  switch (version) {
113  case 1:
114  ConvertVersion1ToVersion2(network);
115  break;
116 
117  case 2:
118  ConvertVersion2ToVersion3(network);
119  break;
120 
121  case 3:
122  ConvertVersion3ToVersion4(network);
123  break;
124 
125  default:
126  IString msg = "The Pvl file version [" + IString(version) + "] is not"
127  " supported";
128  throw IException(IException::Unknown, msg, _FILEINFO_);
129  }
130 
131  version = toInt(network["Version"][0]);
132 
133  if (version == previousVersion) {
134  IString msg = "Cannot update from version [" + IString(version) + "] "
135  "to any other version";
136  throw IException(IException::Programmer, msg, _FILEINFO_);
137  }
138  }
139 
140  return LatestPvlToBinary(network);
141  }
142 
143 
156  LatestControlNetFile *ControlNetVersioner::LatestPvlToBinary(PvlObject &network) {
157 
159 
160  ControlNetFileHeaderV0002 &header = latest->GetNetworkHeader();
161 
162  header.set_networkid(network.findKeyword("NetworkId")[0].toLatin1().data());
163  header.set_targetname(network.findKeyword("TargetName")[0].toLatin1().data());
164  header.set_created(network.findKeyword("Created")[0].toLatin1().data());
165  header.set_lastmodified(network.findKeyword("LastModified")[0].toLatin1().data());
166  header.set_description(network.findKeyword("Description")[0].toLatin1().data());
167  header.set_username(network.findKeyword("UserName")[0].toLatin1().data());
168  header.add_pointmessagesizes(0); // Just to pass the "IsInitialized" test
169 
170  if (!header.IsInitialized()) {
171  IString msg = "There is missing required information in the network "
172  "header";
173  throw IException(IException::Io, msg, _FILEINFO_);
174  }
175 
177 
178  for (int objectIndex = 0; objectIndex < network.objects(); objectIndex ++) {
180  PvlObject &object = network.object(objectIndex);
181 
182  Copy(object, "PointId",
183  point, &ControlPointFileEntryV0002::set_id);
184  Copy(object, "ChooserName",
185  point, &ControlPointFileEntryV0002::set_choosername);
186  Copy(object, "DateTime",
187  point, &ControlPointFileEntryV0002::set_datetime);
188  Copy(object, "AprioriXYZSourceFile",
189  point, &ControlPointFileEntryV0002::set_apriorisurfpointsourcefile);
190  Copy(object, "AprioriRadiusSourceFile",
191  point, &ControlPointFileEntryV0002::set_aprioriradiussourcefile);
192  Copy(object, "JigsawRejected",
193  point, &ControlPointFileEntryV0002::set_jigsawrejected);
194  Copy(object, "EditLock",
195  point, &ControlPointFileEntryV0002::set_editlock);
196  Copy(object, "Ignore",
197  point, &ControlPointFileEntryV0002::set_ignore);
198  Copy(object, "AprioriX",
199  point, &ControlPointFileEntryV0002::set_apriorix);
200  Copy(object, "AprioriY",
201  point, &ControlPointFileEntryV0002::set_aprioriy);
202  Copy(object, "AprioriZ",
203  point, &ControlPointFileEntryV0002::set_aprioriz);
204  Copy(object, "AdjustedX",
205  point, &ControlPointFileEntryV0002::set_adjustedx);
206  Copy(object, "AdjustedY",
207  point, &ControlPointFileEntryV0002::set_adjustedy);
208  Copy(object, "AdjustedZ",
209  point, &ControlPointFileEntryV0002::set_adjustedz);
210  Copy(object, "LatitudeConstrained",
211  point, &ControlPointFileEntryV0002::set_latitudeconstrained);
212  Copy(object, "LongitudeConstrained",
213  point, &ControlPointFileEntryV0002::set_longitudeconstrained);
214  Copy(object, "RadiusConstrained",
215  point, &ControlPointFileEntryV0002::set_radiusconstrained);
216 
217  if (object["PointType"][0] == "Fixed")
218  point.set_type(ControlPointFileEntryV0002::Fixed);
219  else if (object["PointType"][0] == "Constrained")
220  point.set_type(ControlPointFileEntryV0002::Constrained);
221  else
222  point.set_type(ControlPointFileEntryV0002::Free);
223 
224  if (object.hasKeyword("AprioriXYZSource")) {
225  IString source = object["AprioriXYZSource"][0];
226 
227  if (source == "None") {
228  point.set_apriorisurfpointsource(ControlPointFileEntryV0002::None);
229  }
230  else if (source == "User") {
231  point.set_apriorisurfpointsource(ControlPointFileEntryV0002::User);
232  }
233  else if (source == "AverageOfMeasures") {
234  point.set_apriorisurfpointsource(
235  ControlPointFileEntryV0002::AverageOfMeasures);
236  }
237  else if (source == "Reference") {
238  point.set_apriorisurfpointsource(
239  ControlPointFileEntryV0002::Reference);
240  }
241  else if (source == "Basemap") {
242  point.set_apriorisurfpointsource(
243  ControlPointFileEntryV0002::Basemap);
244  }
245  else if (source == "BundleSolution") {
246  point.set_apriorisurfpointsource(
247  ControlPointFileEntryV0002::BundleSolution);
248  }
249  else {
250  IString msg = "Invalid AprioriXYZSource [" + source + "]";
251  throw IException(IException::User, msg, _FILEINFO_);
252  }
253  }
254 
255  if (object.hasKeyword("AprioriRadiusSource")) {
256  IString source = object["AprioriRadiusSource"][0];
257 
258  if (source == "None") {
259  point.set_aprioriradiussource(ControlPointFileEntryV0002::None);
260  }
261  else if (source == "User") {
262  point.set_aprioriradiussource(ControlPointFileEntryV0002::User);
263  }
264  else if (source == "AverageOfMeasures") {
265  point.set_aprioriradiussource(ControlPointFileEntryV0002::AverageOfMeasures);
266  }
267  else if (source == "Ellipsoid") {
268  point.set_aprioriradiussource(ControlPointFileEntryV0002::Ellipsoid);
269  }
270  else if (source == "DEM") {
271  point.set_aprioriradiussource(ControlPointFileEntryV0002::DEM);
272  }
273  else if (source == "BundleSolution") {
274  point.set_aprioriradiussource(ControlPointFileEntryV0002::BundleSolution);
275  }
276  else {
277  std::string msg = "Invalid AprioriRadiusSource, [" + source + "]";
278  throw IException(IException::User, msg, _FILEINFO_);
279  }
280  }
281 
282  if (object.hasKeyword("AprioriCovarianceMatrix")) {
283  PvlKeyword &matrix = object["AprioriCovarianceMatrix"];
284 
285  point.add_aprioricovar(toDouble(matrix[0]));
286  point.add_aprioricovar(toDouble(matrix[1]));
287  point.add_aprioricovar(toDouble(matrix[2]));
288  point.add_aprioricovar(toDouble(matrix[3]));
289  point.add_aprioricovar(toDouble(matrix[4]));
290  point.add_aprioricovar(toDouble(matrix[5]));
291  }
292 
293  if (object.hasKeyword("AdjustedCovarianceMatrix")) {
294  PvlKeyword &matrix = object["AdjustedCovarianceMatrix"];
295 
296  point.add_adjustedcovar(toDouble(matrix[0]));
297  point.add_adjustedcovar(toDouble(matrix[1]));
298  point.add_adjustedcovar(toDouble(matrix[2]));
299  point.add_adjustedcovar(toDouble(matrix[3]));
300  point.add_adjustedcovar(toDouble(matrix[4]));
301  point.add_adjustedcovar(toDouble(matrix[5]));
302  }
303 
304  // Process Measures
305  for (int groupIndex = 0; groupIndex < object.groups(); groupIndex ++) {
306  PvlGroup &group = object.group(groupIndex);
308 
309  Copy(group, "SerialNumber",
310  measure, &ControlPointFileEntryV0002::Measure::set_serialnumber);
311  Copy(group, "ChooserName",
312  measure, &ControlPointFileEntryV0002::Measure::set_choosername);
313  Copy(group, "Sample",
314  measure, &ControlPointFileEntryV0002::Measure::set_sample);
315  Copy(group, "Line",
316  measure, &ControlPointFileEntryV0002::Measure::set_line);
317  Copy(group, "SampleResidual",
318  measure, &ControlPointFileEntryV0002::Measure::set_sampleresidual);
319  Copy(group, "LineResidual",
320  measure, &ControlPointFileEntryV0002::Measure::set_lineresidual);
321  Copy(group, "DateTime",
322  measure, &ControlPointFileEntryV0002::Measure::set_datetime);
323  Copy(group, "Diameter",
324  measure, &ControlPointFileEntryV0002::Measure::set_diameter);
325  Copy(group, "EditLock",
326  measure, &ControlPointFileEntryV0002::Measure::set_editlock);
327  Copy(group, "Ignore",
328  measure, &ControlPointFileEntryV0002::Measure::set_ignore);
329  Copy(group, "JigsawRejected",
330  measure, &ControlPointFileEntryV0002::Measure::set_jigsawrejected);
331  Copy(group, "AprioriSample",
332  measure, &ControlPointFileEntryV0002::Measure::set_apriorisample);
333  Copy(group, "AprioriLine",
334  measure, &ControlPointFileEntryV0002::Measure::set_aprioriline);
335  Copy(group, "SampleSigma",
336  measure, &ControlPointFileEntryV0002::Measure::set_samplesigma);
337  Copy(group, "LineSigma",
338  measure, &ControlPointFileEntryV0002::Measure::set_linesigma);
339 
340  if (group.hasKeyword("Reference")) {
341  if (group["Reference"][0].toLower() == "true")
342  point.set_referenceindex(groupIndex);
343 
344  group.deleteKeyword("Reference");
345  }
346 
347  QString type = group["MeasureType"][0].toLower();
348  if (type == "candidate")
349  measure.set_type(ControlPointFileEntryV0002::Measure::Candidate);
350  else if (type == "manual")
351  measure.set_type(ControlPointFileEntryV0002::Measure::Manual);
352  else if (type == "registeredpixel")
353  measure.set_type(ControlPointFileEntryV0002::Measure::RegisteredPixel);
354  else if (type == "registeredsubpixel")
355  measure.set_type(ControlPointFileEntryV0002::Measure::RegisteredSubPixel);
356  else
357  throw IException(IException::Io,
358  "Unknown measure type [" + type + "]",
359  _FILEINFO_);
360  group.deleteKeyword("MeasureType");
361 
362  for (int key = 0; key < group.keywords(); key++) {
363  ControlMeasureLogData interpreter(group[key]);
364  if (!interpreter.IsValid()) {
365  IString msg = "Unhandled or duplicate keywords in control measure ["
366  + group[key].name() + "]";
367  throw IException(IException::Programmer, msg, _FILEINFO_);
368  }
369  else {
370  *measure.add_log() = interpreter.ToProtocolBuffer();
371  }
372  }
373 
374  *point.add_measures() = measure;
375  }
376 
377  if (!point.IsInitialized()) {
378  IString msg = "There is missing required information in the control "
379  "points or measures";
380  throw IException(IException::Io, msg, _FILEINFO_);
381  }
382 
383  points.append(point);
384  }
385 
386  return latest;
387  }
388 
389 
398  LatestControlNetFile *ControlNetVersioner::ReadBinaryNetwork(const Pvl &header,
399  const FileName &filename) {
400 
401  // Find the binary cnet version by any means necessary
402  int version = 1;
403 
404  const PvlObject &protoBuf = header.findObject("ProtoBuffer");
405  const PvlGroup &netInfo = protoBuf.findGroup("ControlNetworkInfo");
406 
407  if (netInfo.hasKeyword("Version"))
408  version = toInt(netInfo["Version"][0]);
409 
410  // Okay, let's instantiate the correct ControlNetFile for this version
411  ControlNetFile *cnetFile;
412  switch (version) {
413  case 1:
414  cnetFile = new ControlNetFileV0001;
415  break;
416 
417  case 2:
418  cnetFile = new ControlNetFileV0002;
419  break;
420 
421  default:
422  IString msg = "The binary file version [" + IString(version) + "] is "
423  "not supported";
424  throw IException(IException::Io, msg, _FILEINFO_);
425  }
426 
427  // Now read and update as necessary
428  cnetFile->Read(header, filename);
429 
430  if (version != LATEST_BINARY_VERSION) {
431  Pvl pvl(cnetFile->toPvl());
432 
433  delete cnetFile;
434  cnetFile = NULL;
435 
436  return ReadPvlNetwork(pvl);
437  }
438  else {
439  return (LatestControlNetFile *)cnetFile;
440  }
441  }
442 
443 
461  void ControlNetVersioner::ConvertVersion1ToVersion2(PvlObject &network) {
462 
463  network["Version"] = "2";
464 
465  // Really... Projection::TargetRadii should be making this call
466  NaifStatus::CheckErrors();
467 
468  if (QString(network["TargetName"]).startsWith("MRO/")) {
469  network["TargetName"] = "Mars";
470  }
471 
472  PvlGroup radii;
473  try {
474  radii = Target::radiiGroup(network["TargetName"][0]);
475  }
476  catch (IException &e) {
477  try {
478  NaifStatus::CheckErrors();
479  }
480  catch (IException &) {
481  }
482 
483  QString msg = "Unable to get convert ControlNet Version 1 to Version 2.";
484  throw IException(e, IException::Io, msg, _FILEINFO_);
485  }
486 
487  Distance equatorialRadius(radii["EquatorialRadius"], Distance::Meters);
488  Distance polarRadius(radii["PolarRadius"], Distance::Meters);
489 
490  for (int cpIndex = 0; cpIndex < network.objects(); cpIndex ++) {
491  PvlObject &cp = network.object(cpIndex);
492 
493  if (cp.hasKeyword("Held") && cp["Held"][0] == "True")
494  cp["PointType"] = "Ground";
495 
496  if (cp.hasKeyword("AprioriLatLonSource"))
497  cp["AprioriLatLonSource"].setName("AprioriXYZSource");
498 
499  if (cp.hasKeyword("AprioriLatLonSourceFile"))
500  cp["AprioriLatLonSourceFile"].setName("AprioriXYZSourceFile");
501 
502  if (cp.hasKeyword("AprioriLatitude")) {
503  SurfacePoint apriori(
504  Latitude(toDouble(cp["AprioriLatitude"][0]), Angle::Degrees),
505  Longitude(toDouble(cp["AprioriLongitude"][0]), Angle::Degrees),
506  Distance(toDouble(cp["AprioriRadius"][0]), Distance::Meters));
507 
508  cp += PvlKeyword("AprioriX", toString(apriori.GetX().meters()), "meters");
509  cp += PvlKeyword("AprioriY", toString(apriori.GetY().meters()), "meters");
510  cp += PvlKeyword("AprioriZ", toString(apriori.GetZ().meters()), "meters");
511  }
512 
513  if (cp.hasKeyword("Latitude")) {
514  SurfacePoint adjusted(
515  Latitude(toDouble(cp["Latitude"][0]), Angle::Degrees),
516  Longitude(toDouble(cp["Longitude"][0]), Angle::Degrees),
517  Distance(toDouble(cp["Radius"][0]), Distance::Meters));
518 
519  cp += PvlKeyword("AdjustedX", toString(adjusted.GetX().meters()), "meters");
520  cp += PvlKeyword("AdjustedY", toString(adjusted.GetY().meters()), "meters");
521  cp += PvlKeyword("AdjustedZ", toString(adjusted.GetZ().meters()), "meters");
522 
523  if (!cp.hasKeyword("AprioriLatitude")) {
524  cp += PvlKeyword("AprioriX", toString(adjusted.GetX().meters()), "meters");
525  cp += PvlKeyword("AprioriY", toString(adjusted.GetY().meters()), "meters");
526  cp += PvlKeyword("AprioriZ", toString(adjusted.GetZ().meters()), "meters");
527  }
528  }
529 
530  if (cp.hasKeyword("X"))
531  cp["X"].setName("AdjustedX");
532 
533  if (cp.hasKeyword("Y"))
534  cp["Y"].setName("AdjustedY");
535 
536  if (cp.hasKeyword("Z"))
537  cp["Z"].setName("AdjustedZ");
538 
539  if (cp.hasKeyword("AprioriSigmaLatitude") ||
540  cp.hasKeyword("AprioriSigmaLongitude") ||
541  cp.hasKeyword("AprioriSigmaRadius")) {
542  double sigmaLat = 10000.0;
543  double sigmaLon = 10000.0;
544  double sigmaRad = 10000.0;
545 
546  if (cp.hasKeyword("AprioriSigmaLatitude")) {
547  if (toDouble(cp["AprioriSigmaLatitude"][0]) > 0 &&
548  toDouble(cp["AprioriSigmaLatitude"][0]) < sigmaLat)
549  sigmaLat = cp["AprioriSigmaLatitude"];
550 
551  cp += PvlKeyword("LatitudeConstrained", "True");
552  }
553 
554  if (cp.hasKeyword("AprioriSigmaLongitude")) {
555  if (toDouble(cp["AprioriSigmaLongitude"][0]) > 0 &&
556  toDouble(cp["AprioriSigmaLongitude"][0]) < sigmaLon)
557  sigmaLon = cp["AprioriSigmaLongitude"];
558 
559  cp += PvlKeyword("LongitudeConstrained", "True");
560  }
561 
562  if (cp.hasKeyword("AprioriSigmaRadius")) {
563  if (toDouble(cp["AprioriSigmaRadius"][0]) > 0 &&
564  toDouble(cp["AprioriSigmaRadius"][0]) < sigmaRad)
565  sigmaRad = cp["AprioriSigmaRadius"];
566 
567  cp += PvlKeyword("RadiusConstrained", "True");
568  }
569 
570  SurfacePoint tmp;
571  tmp.SetRadii(equatorialRadius, equatorialRadius, polarRadius);
572  tmp.SetRectangular(
573  Displacement(cp["AprioriX"], Displacement::Meters),
574  Displacement(cp["AprioriY"], Displacement::Meters),
575  Displacement(cp["AprioriZ"], Displacement::Meters));
577  Distance(sigmaLat, Distance::Meters),
578  Distance(sigmaLon, Distance::Meters),
579  Distance(sigmaRad, Distance::Meters));
580 
581  PvlKeyword aprioriCovarMatrix("AprioriCovarianceMatrix");
582  aprioriCovarMatrix += toString(tmp.GetRectangularMatrix()(0, 0));
583  aprioriCovarMatrix += toString(tmp.GetRectangularMatrix()(0, 1));
584  aprioriCovarMatrix += toString(tmp.GetRectangularMatrix()(0, 2));
585  aprioriCovarMatrix += toString(tmp.GetRectangularMatrix()(1, 1));
586  aprioriCovarMatrix += toString(tmp.GetRectangularMatrix()(1, 2));
587  aprioriCovarMatrix += toString(tmp.GetRectangularMatrix()(2, 2));
588 
589  cp += aprioriCovarMatrix;
590  }
591 
592  if (cp.hasKeyword("AdjustedSigmaLatitude") ||
593  cp.hasKeyword("AdjustedSigmaLongitude") ||
594  cp.hasKeyword("AdjustedSigmaRadius")) {
595  double sigmaLat = 10000.0;
596  double sigmaLon = 10000.0;
597  double sigmaRad = 10000.0;
598 
599  if (cp.hasKeyword("AdjustedSigmaLatitude")) {
600  if (toDouble(cp["AdjustedSigmaLatitude"][0]) > 0 &&
601  toDouble(cp["AdjustedSigmaLatitude"][0]) < sigmaLat)
602  sigmaLat = cp["AdjustedSigmaLatitude"];
603  }
604 
605  if (cp.hasKeyword("AdjustedSigmaLongitude")) {
606  if (toDouble(cp["AdjustedSigmaLongitude"][0]) > 0 &&
607  toDouble(cp["AdjustedSigmaLongitude"][0]) < sigmaLon)
608  sigmaLon = cp["AdjustedSigmaLongitude"];
609  }
610 
611  if (cp.hasKeyword("AdjustedSigmaRadius")) {
612  if (toDouble(cp["AdjustedSigmaRadius"][0]) > 0 &&
613  toDouble(cp["AdjustedSigmaRadius"][0]) < sigmaRad)
614  sigmaRad = cp["AdjustedSigmaRadius"];
615  }
616 
617  SurfacePoint tmp;
618  tmp.SetRadii(equatorialRadius, equatorialRadius, polarRadius);
619  tmp.SetRectangular(Displacement(cp["AdjustedX"], Displacement::Meters),
620  Displacement(cp["AdjustedY"], Displacement::Meters),
621  Displacement(cp["AdjustedZ"], Displacement::Meters));
622  tmp.SetSphericalSigmasDistance(Distance(sigmaLat, Distance::Meters),
623  Distance(sigmaLon, Distance::Meters),
624  Distance(sigmaRad, Distance::Meters));
625 
626  PvlKeyword adjustedCovarMatrix("AdjustedCovarianceMatrix");
627  adjustedCovarMatrix += toString(tmp.GetRectangularMatrix()(0, 0));
628  adjustedCovarMatrix += toString(tmp.GetRectangularMatrix()(0, 1));
629  adjustedCovarMatrix += toString(tmp.GetRectangularMatrix()(0, 2));
630  adjustedCovarMatrix += toString(tmp.GetRectangularMatrix()(1, 1));
631  adjustedCovarMatrix += toString(tmp.GetRectangularMatrix()(1, 2));
632  adjustedCovarMatrix += toString(tmp.GetRectangularMatrix()(2, 2));
633 
634  cp += adjustedCovarMatrix;
635  }
636 
637  if (cp.hasKeyword("ApostCovarianceMatrix"))
638  cp["ApostCovarianceMatrix"].setName("AdjustedCovarianceMatrix");
639 
640  if (!cp.hasKeyword("LatitudeConstrained")) {
641  if (cp.hasKeyword("AprioriCovarianceMatrix"))
642  cp += PvlKeyword("LatitudeConstrained", "True");
643  else
644  cp += PvlKeyword("LatitudeConstrained", "False");
645  }
646 
647  if (!cp.hasKeyword("LongitudeConstrained")) {
648  if (cp.hasKeyword("AprioriCovarianceMatrix"))
649  cp += PvlKeyword("LongitudeConstrained", "True");
650  else
651  cp += PvlKeyword("LongitudeConstrained", "False");
652  }
653 
654  if (!cp.hasKeyword("RadiusConstrained")) {
655  if (cp.hasKeyword("AprioriCovarianceMatrix"))
656  cp += PvlKeyword("RadiusConstrained", "True");
657  else
658  cp += PvlKeyword("RadiusConstrained", "False");
659  }
660 
661  // Delete anything that has no value...
662  for (int cpKeyIndex = 0; cpKeyIndex < cp.keywords(); cpKeyIndex ++) {
663  if (cp[cpKeyIndex][0] == "") {
664  cp.deleteKeyword(cpKeyIndex);
665  }
666  }
667 
668  for (int cmIndex = 0; cmIndex < cp.groups(); cmIndex ++) {
669  PvlGroup &cm = cp.group(cmIndex);
670 
671  // Estimated => Candidate
672  if (cm.hasKeyword("MeasureType")) {
673  QString type = cm["MeasureType"][0].toLower();
674 
675  if (type == "estimated" || type == "unmeasured") {
676  if (type == "unmeasured") {
677  bool hasSampleLine = false;
678 
679  try {
680  toDouble(cm["Sample"][0]);
681  toDouble(cm["Line"][0]);
682  hasSampleLine = true;
683  }
684  catch (...) {
685  }
686 
687  if (!hasSampleLine) {
688  cm.addKeyword(PvlKeyword("Sample", "0.0"), PvlContainer::Replace);
689  cm.addKeyword(PvlKeyword("Line", "0.0"), PvlContainer::Replace);
690  cm.addKeyword(PvlKeyword("Ignore", toString(true)), PvlContainer::Replace);
691  }
692  }
693 
694  cm["MeasureType"] = "Candidate";
695  }
696  else if (type == "automatic" ||
697  type == "validatedmanual" ||
698  type == "automaticpixel") {
699  cm["MeasureType"] = "RegisteredPixel";
700  }
701  else if (type == "validatedautomatic" || type == "automaticsubpixel") {
702  cm["MeasureType"] = "RegisteredSubPixel";
703  }
704  }
705 
706  if (cm.hasKeyword("ErrorSample"))
707  cm["ErrorSample"].setName("SampleResidual");
708 
709  if (cm.hasKeyword("ErrorLine"))
710  cm["ErrorLine"].setName("LineResidual");
711 
712  // Delete some extraneous values we once printed
713  if (cm.hasKeyword("SampleResidual") &&
714  toDouble(cm["SampleResidual"][0]) == 0.0)
715  cm.deleteKeyword("SampleResidual");
716 
717  if (cm.hasKeyword("LineResidual") &&
718  toDouble(cm["LineResidual"][0]) == 0.0)
719  cm.deleteKeyword("LineResidual");
720 
721  if (cm.hasKeyword("Diameter") &&
722  toDouble(cm["Diameter"][0]) == 0.0)
723  cm.deleteKeyword("Diameter");
724 
725  if (cm.hasKeyword("ErrorMagnitude"))
726  cm.deleteKeyword("ErrorMagnitude");
727 
728  if (cm.hasKeyword("ZScore"))
729  cm.deleteKeyword("ZScore");
730 
731  // Delete anything that has no value...
732  for (int cmKeyIndex = 0; cmKeyIndex < cm.keywords(); cmKeyIndex ++) {
733  if (cm[cmKeyIndex][0] == "") {
734  cm.deleteKeyword(cmKeyIndex);
735  }
736  }
737  }
738  }
739  }
740 
741 
749  void ControlNetVersioner::ConvertVersion2ToVersion3(PvlObject &network) {
750 
751  network["Version"] = "3";
752 
753  for (int cpIndex = 0; cpIndex < network.objects(); cpIndex ++) {
754  PvlObject &cp = network.object(cpIndex);
755 
756  if (cp.hasKeyword("AprioriCovarianceMatrix") ||
757  cp.hasKeyword("AdjustedCovarianceMatrix"))
758  cp["PointType"] = "Constrained";
759  }
760  }
761 
762 
770  void ControlNetVersioner::ConvertVersion3ToVersion4(PvlObject &network) {
771 
772  network["Version"] = "4";
773 
774  for (int cpIndex = 0; cpIndex < network.objects(); cpIndex ++) {
775  PvlObject &cp = network.object(cpIndex);
776 
777  if (cp["PointType"][0] == "Ground") cp["PointType"] = "Fixed";
778  if (cp["PointType"][0] == "Tie") cp["PointType"] = "Free";
779  }
780  }
781 
782 
796  void ControlNetVersioner::Copy(PvlContainer &container,
797  QString keyName,
799  void (ControlPointFileEntryV0002::*setter)(bool)) {
800 
801  if (!container.hasKeyword(keyName))
802  return;
803 
804  QString value = container[keyName][0];
805  container.deleteKeyword(keyName);
806  value = value.toLower();
807 
808  if (value == "true" || value == "yes")
809  (point.*setter)(true);
810  }
811 
812 
826  void ControlNetVersioner::Copy(PvlContainer &container,
827  QString keyName,
829  void (ControlPointFileEntryV0002::*setter)(double)) {
830 
831  if (!container.hasKeyword(keyName))
832  return;
833 
834  double value = toDouble(container[keyName][0]);
835  container.deleteKeyword(keyName);
836  (point.*setter)(value);
837  }
838 
839 
853  void ControlNetVersioner::Copy(PvlContainer &container,
854  QString keyName,
856  void (ControlPointFileEntryV0002::*setter)(const std::string&)) {
857 
858  if (!container.hasKeyword(keyName))
859  return;
860 
861  IString value = container[keyName][0];
862  container.deleteKeyword(keyName);
863  (point.*setter)(value);
864  }
865 
866 
880  void ControlNetVersioner::Copy(PvlContainer &container,
881  QString keyName,
883  void (ControlPointFileEntryV0002::Measure::*setter)(bool)) {
884 
885  if (!container.hasKeyword(keyName))
886  return;
887 
888  QString value = container[keyName][0];
889  container.deleteKeyword(keyName);
890  value = value.toLower();
891 
892  if (value == "true" || value == "yes")
893  (measure.*setter)(true);
894  }
895 
896 
910  void ControlNetVersioner::Copy(PvlContainer &container,
911  QString keyName,
913  void (ControlPointFileEntryV0002::Measure::*setter)(double)) {
914 
915  if (!container.hasKeyword(keyName))
916  return;
917 
918  double value = toDouble(container[keyName][0]);
919  container.deleteKeyword(keyName);
920  (measure.*setter)(value);
921  }
922 
923 
937  void ControlNetVersioner::Copy(PvlContainer &container,
938  QString keyName,
941  (const std::string &)) {
942 
943  if (!container.hasKeyword(keyName))
944  return;
945 
946  IString value = container[keyName][0];
947  container.deleteKeyword(keyName);
948  (measure.*set)(value);
949  }
950 }
This class defines a body-fixed surface point.
Definition: SurfacePoint.h:86
PvlObject & object(const int index)
Return the object at the specified index.
Definition: PvlObject.cpp:460
Handle Binary Control Network Files version 1.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
Contains more than one keyword-value pair.
Definition: PvlContainer.h:64
File name manipulation and expansion.
Definition: FileName.h:111
double meters() const
Get the displacement in meters.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
virtual Pvl toPvl() const
Converts binary control net version 2 to pvl version 3.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
Definition: PvlContainer.h:101
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
Statistical and similar ControlMeasure associated information.
This class is designed to encapsulate the concept of a Latitude.
Definition: Latitude.h:59
ControlNetFileHeaderV0002 & GetNetworkHeader()
Get the control network level information - things like NetworkID, TargetName, etc...
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
Generic Binary Control Net File Representation.
Distance measurement, usually in meters.
Definition: Distance.h:47
ControlPointFileEntryV0002_Measure_MeasureLogData ToProtocolBuffer() const
This converts the log data to a protocol buffer object.
void SetRadii(const Distance &majorRadius, const Distance &minorRadius, const Distance &polarRadius)
Reset the radii of the surface body of the surface point.
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
This class is designed to encapsulate the concept of a Longitude.
Definition: Longitude.h:52
QList< ControlPointFileEntryV0002 > & GetNetworkPoints()
Get the control point data along with the log data.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Definition: PvlObject.cpp:148
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
int objects() const
Returns the number of objects.
Definition: PvlObject.h:231
A single keyword-value pair.
Definition: PvlKeyword.h:98
virtual void Read(const Pvl &header, const FileName &file)=0
This reads the binary file into memory.
Container for cube-like labels.
Definition: Pvl.h:135
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
bool IsValid() const
This tests if the log data is complete and valid.
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:87
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:423
virtual void Write(const FileName &file) const
This writes the binary file that is in memory to disk.
Displacement is a signed length, usually in meters.
Definition: Displacement.h:43
Isis exception class.
Definition: IException.h:99
Adds specific functionality to C++ strings.
Definition: IString.h:179
Handle Binary Control Network Files version 2.
void SetSphericalSigmasDistance(const Distance &latSigma, const Distance &lonSigma, const Distance &radiusSigma)
Set the spherical sigmas (in meters) into the spherical variance/covariance matrix.
void write(const QString &file)
Opens and writes PVL information to a file and handles the end of line sequence.
Definition: Pvl.cpp:116
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
QString name() const
Returns the container name.
Definition: PvlContainer.h:78
virtual Pvl toPvl() const =0
Convert the binary representation to Pvl (any pvl version).
void SetRectangular(const Displacement &x, const Displacement &y, const Displacement &z, const Distance &xSigma=Distance(), const Distance &ySigma=Distance(), const Distance &zSigma=Distance())
Set surface point in rectangular body-fixed coordinates wtih optional sigmas.
void deleteKeyword(const QString &name)
Remove a specified keyword.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:16:38