Isis 3 Programmer Reference
ControlNetVersioner.cpp
1 #include "ControlNetVersioner.h"
2 
3 #include <boost/numeric/ublas/symmetric.hpp>
4 #include <boost/numeric/ublas/io.hpp>
5 
6 #include <QDebug>
7 #include <QString>
8 
9 #include "ControlNetFileHeaderV0002.pb.h"
10 #include "ControlNetFileHeaderV0005.pb.h"
11 #include "ControlNetLogDataProtoV0001.pb.h"
12 #include "ControlPointFileEntryV0002.pb.h"
13 
14 #include "ControlMeasure.h"
15 #include "ControlNet.h"
16 #include "ControlMeasureLogData.h"
17 #include "Distance.h"
18 #include "EndianSwapper.h"
19 #include "FileName.h"
20 #include "IException.h"
21 #include "Latitude.h"
22 #include "LinearAlgebra.h"
23 #include "Longitude.h"
24 #include "NaifStatus.h"
25 #include "Progress.h"
26 #include "Pvl.h"
27 #include "PvlGroup.h"
28 #include "PvlKeyword.h"
29 #include "PvlObject.h"
30 #include "SpecialPixel.h"
31 #include "SurfacePoint.h"
32 #include "Target.h"
33 
34 
35 #include <google/protobuf/io/zero_copy_stream_impl.h>
36 #include <google/protobuf/io/zero_copy_stream.h>
37 #include <google/protobuf/io/coded_stream.h>
38 
39 using boost::numeric::ublas::symmetric_matrix;
40 using boost::numeric::ublas::upper;
41 using namespace google::protobuf::io;
42 using namespace std;
43 
44 namespace Isis {
45 
53  ControlNetVersioner::ControlNetVersioner(ControlNet *net)
54  : m_ownsPoints(false) {
55  // Populate the internal list of points.
56  m_points.append( net->GetPoints() );
57 
58  ControlNetHeaderV0001 header;
59 
60  header.networkID = net->GetNetworkId();
61  header.targetName = net->GetTarget();
62  header.created = net->CreatedDate();
63  header.lastModified = net->GetLastModified();
64  header.description = net->Description();
65  header.userName = net->GetUserName();
66  createHeader(header);
67  }
68 
69 
81  : m_ownsPoints(true) {
82  read(netFile, progress);
83  }
84 
85 
91  if ( m_ownsPoints ) {
92  while ( !m_points.isEmpty() ) {
93  ControlPoint *unusedPoint = m_points.takeFirst();
94  delete unusedPoint;
95  unusedPoint = NULL;
96  }
97  }
98  }
99 
100 
106  QString ControlNetVersioner::netId() const {
107  return m_header.networkID;
108  }
109 
110 
117  return m_header.targetName;
118  }
119 
120 
127  return m_header.created;
128  }
129 
130 
137  return m_header.lastModified;
138  }
139 
140 
147  return m_header.description;
148  }
149 
150 
157  return m_header.userName;
158  }
159 
160 
167  return m_points.size();
168  }
169 
170 
180  ControlPoint *point = NULL;
181  if ( !m_points.isEmpty() ) {
182  point = m_points.takeFirst();
183  }
184 
185  return point;
186  }
187 
188 
195  Pvl pvl;
196  pvl.addObject(PvlObject("ControlNetwork"));
197  PvlObject &network = pvl.findObject("ControlNetwork");
198 
199  network += PvlKeyword("NetworkId", m_header.networkID);
200  network += PvlKeyword("TargetName", m_header.targetName);
201  network += PvlKeyword("UserName", m_header.userName);
202  network += PvlKeyword("Created", m_header.created);
203  network += PvlKeyword("LastModified", m_header.lastModified);
204  network += PvlKeyword("Description", m_header.description);
205 
206  // This is the Pvl version we're converting to
207  network += PvlKeyword("Version", "5");
208 
209  foreach (ControlPoint *controlPoint, m_points) {
210  PvlObject pvlPoint("ControlPoint");
211 
212  if ( controlPoint->GetType() == ControlPoint::Fixed ) {
213  pvlPoint += PvlKeyword("PointType", "Fixed");
214  }
215 
216  else if ( controlPoint->GetType() == ControlPoint::Constrained ) {
217  pvlPoint += PvlKeyword("PointType", "Constrained");
218  }
219 
220  else {
221  pvlPoint += PvlKeyword("PointType", "Free");
222  }
223 
224  if ( controlPoint->GetId().isEmpty() ) {
225  QString msg = "Unable to write control net to PVL file. "
226  "Invalid control point has no point ID value.";
228  }
229  else {
230  pvlPoint += PvlKeyword("PointId", controlPoint->GetId());
231  }
232  if ( QString::compare(controlPoint->GetChooserName(), "Null", Qt::CaseInsensitive) != 0 ) {
233  pvlPoint += PvlKeyword("ChooserName", controlPoint->GetChooserName());
234  }
235  if ( QString::compare(controlPoint->GetDateTime(), "Null", Qt::CaseInsensitive) != 0 ) {
236  pvlPoint += PvlKeyword("DateTime", controlPoint->GetDateTime());
237  }
238  if ( controlPoint->IsEditLocked() ) {
239  pvlPoint += PvlKeyword("EditLock", "True");
240  }
241  if ( controlPoint->IsIgnored() ) {
242  pvlPoint += PvlKeyword("Ignore", "True");
243  }
244 
245  switch ( controlPoint->GetAprioriSurfacePointSource() ) {
246  case ControlPoint::SurfacePointSource::None:
247  break;
248  case ControlPoint::SurfacePointSource::User:
249  pvlPoint += PvlKeyword("AprioriXYZSource", "User");
250  break;
251  case ControlPoint::SurfacePointSource::AverageOfMeasures:
252  pvlPoint += PvlKeyword("AprioriXYZSource", "AverageOfMeasures");
253  break;
254  case ControlPoint::SurfacePointSource::Reference:
255  pvlPoint += PvlKeyword("AprioriXYZSource", "Reference");
256  break;
257  case ControlPoint::SurfacePointSource::Basemap:
258  pvlPoint += PvlKeyword("AprioriXYZSource", "Basemap");
259  break;
260  case ControlPoint::SurfacePointSource::BundleSolution:
261  pvlPoint += PvlKeyword("AprioriXYZSource", "BundleSolution");
262  break;
263  }
264 
265  if ( controlPoint->HasAprioriSurfacePointSourceFile() ) {
266  pvlPoint += PvlKeyword("AprioriXYZSourceFile",
267  controlPoint->GetAprioriSurfacePointSourceFile());
268  }
269 
270  switch ( controlPoint->GetAprioriRadiusSource() ) {
271  case ControlPoint::RadiusSource::None:
272  break;
273  case ControlPoint::RadiusSource::User:
274  pvlPoint += PvlKeyword("AprioriRadiusSource", "User");
275  break;
276  case ControlPoint::RadiusSource::AverageOfMeasures:
277  pvlPoint += PvlKeyword("AprioriRadiusSource", "AverageOfMeasures");
278  break;
279  case ControlPoint::RadiusSource::BundleSolution:
280  pvlPoint += PvlKeyword("AprioriRadiusSource", "BundleSolution");
281  break;
282  case ControlPoint::RadiusSource::Ellipsoid:
283  pvlPoint += PvlKeyword("AprioriRadiusSource", "Ellipsoid");
284  break;
285  case ControlPoint::RadiusSource::DEM:
286  pvlPoint += PvlKeyword("AprioriRadiusSource", "DEM");
287  break;
288  }
289 
290  if ( controlPoint->HasAprioriRadiusSourceFile() ) {
291  pvlPoint += PvlKeyword("AprioriRadiusSourceFile",
292  controlPoint->GetAprioriRadiusSourceFile());
293  }
294 
295  // add surface point x/y/z, convert to lat,lon,radius and output as comment
296  SurfacePoint aprioriSurfacePoint = controlPoint->GetAprioriSurfacePoint();
297  if ( aprioriSurfacePoint.Valid() ) {
298  PvlKeyword aprioriX("AprioriX", toString(aprioriSurfacePoint.GetX().meters()), "meters");
299  PvlKeyword aprioriY("AprioriY", toString(aprioriSurfacePoint.GetY().meters()), "meters");
300  PvlKeyword aprioriZ("AprioriZ", toString(aprioriSurfacePoint.GetZ().meters()), "meters");
301 
302  aprioriX.addComment("AprioriLatitude = "
303  + toString(aprioriSurfacePoint.GetLatitude().degrees())
304  + " <degrees>");
305  aprioriY.addComment("AprioriLongitude = "
306  + toString(aprioriSurfacePoint.GetLongitude().degrees())
307  + " <degrees>");
308 
309  aprioriZ.addComment("AprioriRadius = "
310  + toString(aprioriSurfacePoint.GetLocalRadius().meters())
311  + " <meters>");
312 
313  pvlPoint += aprioriX;
314  pvlPoint += aprioriY;
315  pvlPoint += aprioriZ;
316 
317  symmetric_matrix<double, upper> aprioriCovarianceMatrix =
318  aprioriSurfacePoint.GetRectangularMatrix();
319 
320  if ( aprioriCovarianceMatrix.size1() > 0 ) {
321 
322  // Matrix units are meters squared
323  PvlKeyword matrix("AprioriCovarianceMatrix");
324  matrix += toString(aprioriCovarianceMatrix(0, 0));
325  matrix += toString(aprioriCovarianceMatrix(0, 1));
326  matrix += toString(aprioriCovarianceMatrix(0, 2));
327  matrix += toString(aprioriCovarianceMatrix(1, 1));
328  matrix += toString(aprioriCovarianceMatrix(1, 2));
329  matrix += toString(aprioriCovarianceMatrix(2, 2));
330 
331  // *** TODO *** What do we do in the case of bundled in rectangular coordinates?
332  // For now we do nothing.
333  if ( aprioriSurfacePoint.GetLatSigmaDistance().meters() != Isis::Null
334  && aprioriSurfacePoint.GetLonSigmaDistance().meters() != Isis::Null
335  && aprioriSurfacePoint.GetLocalRadiusSigma().meters() != Isis::Null ) {
336 
337  QString sigmas = "AprioriLatitudeSigma = "
338  + toString(aprioriSurfacePoint.GetLatSigmaDistance().meters())
339  + " <meters> AprioriLongitudeSigma = "
340  + toString(aprioriSurfacePoint.GetLonSigmaDistance().meters())
341  + " <meters> AprioriRadiusSigma = "
342  + toString(aprioriSurfacePoint.GetLocalRadiusSigma().meters())
343  + " <meters>";
344  matrix.addComment(sigmas);
345  }
346 
347  // If the covariance matrix has a value, add it to the PVL point.
348  if ( aprioriCovarianceMatrix(0, 0) != 0.0
349  || aprioriCovarianceMatrix(0, 1) != 0.0
350  || aprioriCovarianceMatrix(0, 2) != 0.0
351  || aprioriCovarianceMatrix(1, 1) != 0.0
352  || aprioriCovarianceMatrix(1, 2) != 0.0
353  || aprioriCovarianceMatrix(2, 2) != 0.0 ) {
354 
355  pvlPoint += matrix;
356  }
357  }
358  }
359 
360  // Deal with the generalization here. *** TODO ***
361  // Once we have a coordinate type in the header, we should specify the correct coordinate
362  if ( controlPoint->IsCoord1Constrained() ) {
363  pvlPoint += PvlKeyword("LatitudeConstrained", "True");
364  }
365 
366  if ( controlPoint->IsCoord2Constrained() ) {
367  pvlPoint += PvlKeyword("LongitudeConstrained", "True");
368  }
369 
370  if ( controlPoint->IsCoord2Constrained() ) {
371  pvlPoint += PvlKeyword("RadiusConstrained", "True");
372  }
373 
374  // adj surface point, convert to lat,lon,radius and output as comment
375  SurfacePoint adjustedSurfacePoint = controlPoint->GetAdjustedSurfacePoint();
376  if ( adjustedSurfacePoint.Valid() ) {
377  PvlKeyword adjustedX("AdjustedX",
378  toString(adjustedSurfacePoint.GetX().meters()), "meters");
379  PvlKeyword adjustedY("AdjustedY",
380  toString(adjustedSurfacePoint.GetY().meters()), "meters");
381  PvlKeyword adjustedZ("AdjustedZ",
382  toString(adjustedSurfacePoint.GetZ().meters()), "meters");
383 
384  adjustedX.addComment("AdjustedLatitude = "
385  + toString(adjustedSurfacePoint.GetLatitude().degrees())
386  + " <degrees>");
387  adjustedY.addComment("AdjustedLongitude = "
388  + toString(adjustedSurfacePoint.GetLongitude().degrees())
389  + " <degrees>");
390  adjustedZ.addComment("AdjustedRadius = "
391  + toString(adjustedSurfacePoint.GetLocalRadius().meters())
392  + " <meters>");
393 
394  pvlPoint += adjustedX;
395  pvlPoint += adjustedY;
396  pvlPoint += adjustedZ;
397 
398  symmetric_matrix<double, upper> adjustedCovarianceMatrix =
399  adjustedSurfacePoint.GetRectangularMatrix();
400 
401  if ( adjustedCovarianceMatrix.size1() > 0 ) {
402 
403  PvlKeyword matrix("AdjustedCovarianceMatrix");
404  matrix += toString(adjustedCovarianceMatrix(0, 0));
405  matrix += toString(adjustedCovarianceMatrix(0, 1));
406  matrix += toString(adjustedCovarianceMatrix(0, 2));
407  matrix += toString(adjustedCovarianceMatrix(1, 1));
408  matrix += toString(adjustedCovarianceMatrix(1, 2));
409  matrix += toString(adjustedCovarianceMatrix(2, 2));
410 
411  if ( adjustedSurfacePoint.GetLatSigmaDistance().meters() != Isis::Null
412  && adjustedSurfacePoint.GetLonSigmaDistance().meters() != Isis::Null
413  && adjustedSurfacePoint.GetLocalRadiusSigma().meters() != Isis::Null ) {
414 
415  QString sigmas = "AdjustedLatitudeSigma = "
416  + toString(adjustedSurfacePoint.GetLatSigmaDistance().meters())
417  + " <meters> AdjustedLongitudeSigma = "
418  + toString(adjustedSurfacePoint.GetLonSigmaDistance().meters())
419  + " <meters> AdjustedRadiusSigma = "
420  + toString(adjustedSurfacePoint.GetLocalRadiusSigma().meters())
421  + " <meters>";
422 
423  matrix.addComment(sigmas);
424  }
425  // If the covariance matrix has a value, add it to the PVL point.
426  if ( adjustedCovarianceMatrix(0, 0) != 0.0
427  || adjustedCovarianceMatrix(0, 1) != 0.0
428  || adjustedCovarianceMatrix(0, 2) != 0.0
429  || adjustedCovarianceMatrix(1, 1) != 0.0
430  || adjustedCovarianceMatrix(1, 2) != 0.0
431  || adjustedCovarianceMatrix(2, 2) != 0.0 ) {
432 
433  pvlPoint += matrix;
434  }
435  }
436  }
437 
438  for (int j = 0; j < controlPoint->GetNumMeasures(); j++) {
439  PvlGroup pvlMeasure("ControlMeasure");
440  const ControlMeasure &controlMeasure = *controlPoint->GetMeasure(j);
441  pvlMeasure += PvlKeyword("SerialNumber", controlMeasure.GetCubeSerialNumber());
442 
443  switch ( controlMeasure.GetType() ) {
445  pvlMeasure += PvlKeyword("MeasureType", "Candidate");
446  break;
448  pvlMeasure += PvlKeyword("MeasureType", "Manual");
449  break;
451  pvlMeasure += PvlKeyword("MeasureType", "RegisteredPixel");
452  break;
454  pvlMeasure += PvlKeyword("MeasureType", "RegisteredSubPixel");
455  break;
456  }
457 
458  if (QString::compare(controlMeasure.GetChooserName(), "Null", Qt::CaseInsensitive) != 0) {
459  pvlMeasure += PvlKeyword("ChooserName", controlMeasure.GetChooserName());
460  }
461  if (QString::compare(controlMeasure.GetDateTime(), "Null", Qt::CaseInsensitive) != 0) {
462  pvlMeasure += PvlKeyword("DateTime", controlMeasure.GetDateTime());
463  }
464  if ( controlMeasure.IsEditLocked() ) {
465  pvlMeasure += PvlKeyword("EditLock", "True");
466  }
467 
468  if ( controlMeasure.IsIgnored() ) {
469  pvlMeasure += PvlKeyword("Ignore", "True");
470  }
471 
472  if ( controlMeasure.GetSample() != Isis::Null) {
473  pvlMeasure += PvlKeyword("Sample", toString(controlMeasure.GetSample()));
474 
475  }
476 
477  if ( controlMeasure.GetLine() != Isis::Null ) {
478  pvlMeasure += PvlKeyword("Line", toString(controlMeasure.GetLine()));
479  }
480 
481  if ( controlMeasure.GetDiameter() != Isis::Null
482  && controlMeasure.GetDiameter() != 0. ) {
483  pvlMeasure += PvlKeyword("Diameter", toString(controlMeasure.GetDiameter()));
484  }
485 
486  if ( controlMeasure.GetAprioriSample() != Isis::Null ) {
487  pvlMeasure += PvlKeyword("AprioriSample", toString(controlMeasure.GetAprioriSample()));
488  }
489 
490  if ( controlMeasure.GetAprioriLine() != Isis::Null ) {
491  pvlMeasure += PvlKeyword("AprioriLine", toString(controlMeasure.GetAprioriLine()));
492  }
493 
494  if ( controlMeasure.GetSampleSigma() != Isis::Null ) {
495  pvlMeasure += PvlKeyword("SampleSigma", toString(controlMeasure.GetSampleSigma()),
496  "pixels");
497  }
498 
499  if ( controlMeasure.GetLineSigma() != Isis::Null ) {
500  pvlMeasure += PvlKeyword("LineSigma", toString(controlMeasure.GetLineSigma()),
501  "pixels");
502  }
503 
504  if ( controlMeasure.GetSampleResidual() != Isis::Null ) {
505  pvlMeasure += PvlKeyword("SampleResidual",
506  toString(controlMeasure.GetSampleResidual()),
507  "pixels");
508  }
509 
510  if ( controlMeasure.GetLineResidual() != Isis::Null ) {
511  pvlMeasure += PvlKeyword("LineResidual", toString(controlMeasure.GetLineResidual()),
512  "pixels");
513  }
514 
515  if ( controlMeasure.IsRejected() ) {
516  pvlMeasure += PvlKeyword("JigsawRejected", toString(controlMeasure.IsRejected()));
517  }
518 
519  foreach (ControlMeasureLogData log, controlMeasure.GetLogDataEntries()) {
520  pvlMeasure += log.ToKeyword();
521  }
522 
523  if ( controlPoint->HasRefMeasure()
524  && controlPoint->IndexOfRefMeasure() == j
525  && controlPoint->IsReferenceExplicit() ) {
526  pvlMeasure += PvlKeyword("Reference", "True");
527  }
528  pvlPoint.addGroup(pvlMeasure);
529  }
530  network.addObject(pvlPoint);
531  }
532  return pvl;
533  }
534 
535 
543  void ControlNetVersioner::read(const FileName netFile, Progress *progress) {
544  try {
545 
546  const Pvl &network(netFile.expanded());
547 
548  if ( network.hasObject("ProtoBuffer") ) {
549  readProtobuf(network, netFile, progress);
550  }
551  else if ( network.hasObject("ControlNetwork") ) {
552  readPvl(network, progress);
553  }
554  else {
555  QString msg = "Could not determine the control network file type";
556  throw IException(IException::Io, msg, _FILEINFO_);
557  }
558  }
559  catch (IException &e) {
560  QString msg = "Reading the control network [" + netFile.name()
561  + "] failed";
562  throw IException(e, IException::Io, msg, _FILEINFO_);
563  }
564  }
565 
566 
574  void ControlNetVersioner::readPvl(const Pvl &network, Progress *progress) {
575  const PvlObject &controlNetwork = network.findObject("ControlNetwork");
576 
577  int version = 1;
578 
579  if ( controlNetwork.hasKeyword("Version") ) {
580  version = toInt(controlNetwork["Version"][0]);
581  }
582 
583  switch ( version ) {
584  case 1:
585  readPvlV0001(controlNetwork, progress);
586  break;
587  case 2:
588  readPvlV0002(controlNetwork, progress);
589  break;
590  case 3:
591  readPvlV0003(controlNetwork, progress);
592  break;
593  case 4:
594  readPvlV0004(controlNetwork, progress);
595  break;
596  case 5:
597  readPvlV0005(controlNetwork, progress);
598  break;
599  default:
600  QString msg = "The Pvl file version [" + toString(version)
601  + "] is not supported";
603  }
604  }
605 
606 
613  void ControlNetVersioner::readPvlV0001(const PvlObject &network, Progress *progress) {
614  // initialize the header
615  ControlNetHeaderV0001 header;
616 
617  try {
618  header.networkID = network.findKeyword("NetworkId")[0];
619  header.targetName = network.findKeyword("TargetName")[0];
620  header.created = network.findKeyword("Created")[0];
621  header.lastModified = network.findKeyword("LastModified")[0];
622  header.description = network.findKeyword("Description")[0];
623  header.userName = network.findKeyword("UserName")[0];
624  createHeader(header);
625  }
626  catch (IException &e) {
627  QString msg = "Missing required header information.";
628  throw IException(e, IException::Io, msg, _FILEINFO_);
629  }
630 
631  if (progress) {
632  progress->SetText("Reading Control Points...");
633  progress->SetMaximumSteps(network.objects());
634  progress->CheckStatus();
635  }
636 
637  // initialize the control points
638  for (int objectIndex = 0; objectIndex < network.objects(); objectIndex ++) {
639  try {
640 
641  PvlObject pointObject = network.object(objectIndex);
642  ControlPointV0001 point(pointObject, m_header.targetName);
643 
644  m_points.append( createPoint(point) );
645 
646  if (progress) {
647  progress->CheckStatus();
648  }
649 
650  }
651  catch (IException &e) {
652  QString msg = "Failed to initialize control point at index ["
653  + toString(objectIndex) + "].";
654  throw IException(e, IException::Io, msg, _FILEINFO_);
655  }
656  }
657  }
658 
659 
666  void ControlNetVersioner::readPvlV0002(const PvlObject &network, Progress *progress) {
667  // initialize the header
668  try {
669  ControlNetHeaderV0002 header;
670  header.networkID = network.findKeyword("NetworkId")[0];
671  header.targetName = network.findKeyword("TargetName")[0];
672  header.created = network.findKeyword("Created")[0];
673  header.lastModified = network.findKeyword("LastModified")[0];
674  header.description = network.findKeyword("Description")[0];
675  header.userName = network.findKeyword("UserName")[0];
676  createHeader(header);
677  }
678  catch (IException &e) {
679  QString msg = "Missing required header information.";
680  throw IException(e, IException::Io, msg, _FILEINFO_);
681  }
682 
683  if (progress) {
684  progress->SetText("Reading Control Points...");
685  progress->SetMaximumSteps(network.objects());
686  progress->CheckStatus();
687  }
688 
689  // initialize the control points
690  for (int objectIndex = 0; objectIndex < network.objects(); objectIndex ++) {
691  try {
692  PvlObject pointObject = network.object(objectIndex);
693  ControlPointV0002 point(pointObject);
694 
695  m_points.append( createPoint(point) );
696 
697  if (progress) {
698  progress->CheckStatus();
699  }
700 
701  }
702  catch (IException &e) {
703  QString msg = "Failed to initialize control point at index ["
704  + toString(objectIndex) + "].";
705  throw IException(e, IException::Io, msg, _FILEINFO_);
706  }
707  }
708  }
709 
710 
717  void ControlNetVersioner::readPvlV0003(const PvlObject &network, Progress *progress) {
718  // initialize the header
719  try {
720  ControlNetHeaderV0003 header;
721  header.networkID = network.findKeyword("NetworkId")[0];
722  header.targetName = network.findKeyword("TargetName")[0];
723  header.created = network.findKeyword("Created")[0];
724  header.lastModified = network.findKeyword("LastModified")[0];
725  header.description = network.findKeyword("Description")[0];
726  header.userName = network.findKeyword("UserName")[0];
727  createHeader(header);
728  }
729  catch (IException &e) {
730  QString msg = "Missing required header information.";
731  throw IException(e, IException::Io, msg, _FILEINFO_);
732  }
733 
734  if (progress) {
735  progress->SetText("Reading Control Points...");
736  progress->SetMaximumSteps(network.objects());
737  progress->CheckStatus();
738  }
739 
740  // initialize the control points
741  for (int objectIndex = 0; objectIndex < network.objects(); objectIndex ++) {
742  try {
743  PvlObject pointObject = network.object(objectIndex);
744  ControlPointV0003 point(pointObject);
745  m_points.append( createPoint(point) );
746 
747  if (progress) {
748  progress->CheckStatus();
749  }
750 
751  }
752  catch (IException &e) {
753  QString msg = "Failed to initialize control point at index ["
754  + toString(objectIndex) + "].";
755  throw IException(e, IException::Io, msg, _FILEINFO_);
756  }
757  }
758  }
759 
760 
767  void ControlNetVersioner::readPvlV0004(const PvlObject &network, Progress *progress) {
768  // initialize the header
769  try {
770  ControlNetHeaderV0004 header;
771  header.networkID = network.findKeyword("NetworkId")[0];
772  header.targetName = network.findKeyword("TargetName")[0];
773  header.created = network.findKeyword("Created")[0];
774  header.lastModified = network.findKeyword("LastModified")[0];
775  header.description = network.findKeyword("Description")[0];
776  header.userName = network.findKeyword("UserName")[0];
777  createHeader(header);
778  }
779  catch (IException &e) {
780  QString msg = "Missing required header information.";
781  throw IException(e, IException::Io, msg, _FILEINFO_);
782  }
783 
784  if (progress) {
785  progress->SetText("Reading Control Points...");
786  progress->SetMaximumSteps(network.objects());
787  progress->CheckStatus();
788  }
789 
790  // initialize the control points
791  for (int objectIndex = 0; objectIndex < network.objects(); objectIndex ++) {
792  try {
793  PvlObject pointObject = network.object(objectIndex);
794  ControlPointV0004 point(pointObject);
795  m_points.append( createPoint(point) );
796 
797  if (progress) {
798  progress->CheckStatus();
799  }
800  }
801  catch (IException &e) {
802  QString msg = "Failed to initialize control point at index ["
803  + toString(objectIndex) + "].";
804  throw IException(e, IException::Io, msg, _FILEINFO_);
805  }
806  }
807  }
808 
809 
816  void ControlNetVersioner::readPvlV0005(const PvlObject &network, Progress *progress) {
817  // initialize the header
818  try {
819  ControlNetHeaderV0005 header;
820  header.networkID = network.findKeyword("NetworkId")[0];
821  header.targetName = network.findKeyword("TargetName")[0];
822  header.created = network.findKeyword("Created")[0];
823  header.lastModified = network.findKeyword("LastModified")[0];
824  header.description = network.findKeyword("Description")[0];
825  header.userName = network.findKeyword("UserName")[0];
826  createHeader(header);
827  }
828  catch (IException &e) {
829  QString msg = "Missing required header information.";
830  throw IException(e, IException::Io, msg, _FILEINFO_);
831  }
832 
833  if (progress) {
834  progress->SetText("Reading Control Points...");
835  progress->SetMaximumSteps(network.objects());
836  progress->CheckStatus();
837  }
838 
839  // initialize the control points
840  for (int objectIndex = 0; objectIndex < network.objects(); objectIndex ++) {
841  try {
842  PvlObject pointObject = network.object(objectIndex);
843  ControlPointV0005 point(pointObject);
844  m_points.append( createPoint(point) );
845 
846  if (progress) {
847  progress->CheckStatus();
848  }
849  }
850  catch (IException &e) {
851  QString msg = "Failed to initialize control point at index ["
852  + toString(objectIndex) + "].";
853  throw IException(e, IException::Io, msg, _FILEINFO_);
854  }
855  }
856  }
857 
858 
868  const FileName netFile,
869  Progress *progress) {
870  int version = 1;
871 
872  const PvlObject &protoBuf = header.findObject("ProtoBuffer");
873  const PvlGroup &netInfo = protoBuf.findGroup("ControlNetworkInfo");
874 
875  if ( netInfo.hasKeyword("Version") ) {
876  version = toInt(netInfo["Version"][0]);
877  }
878  switch ( version ) {
879  case 1:
880  readProtobufV0001(header, netFile, progress);
881  break;
882  case 2:
883  readProtobufV0002(header, netFile, progress);
884  break;
885  case 5:
886  readProtobufV0005(header, netFile, progress);
887  break;
888  default:
889  QString msg = "The Protobuf file version [" + toString(version)
890  + "] is not supported";
891  throw IException(IException::Io, msg, _FILEINFO_);
892  }
893  }
894 
895 
905  const FileName netFile,
906  Progress *progress) {
907  const PvlObject &protoBufferInfo = header.findObject("ProtoBuffer");
908  const PvlObject &protoBufferCore = protoBufferInfo.findObject("Core");
909 
910  BigInt coreStartPos = protoBufferCore["StartByte"];
911  BigInt coreLength = protoBufferCore["Bytes"];
912 
913  fstream input(netFile.expanded().toLatin1().data(), ios::in | ios::binary);
914  if ( !input.is_open() ) {
915  QString msg = "Failed to open protobuf file [" + netFile.name() + "].";
917  }
918 
919  input.seekg(coreStartPos, ios::beg);
920  IstreamInputStream inStream(&input);
921  CodedInputStream codedInStream(&inStream);
922  codedInStream.PushLimit(coreLength);
923  // max 512MB, warn at 400MB
924  codedInStream.SetTotalBytesLimit(1024 * 1024 * 512, 1024 * 1024 * 400);
925 
926  // Now stream the rest of the input into the google protocol buffer.
927  ControlNetFileProtoV0001 protoNet;
928  try {
929  if ( !protoNet.ParseFromCodedStream(&codedInStream) ) {
930  QString msg = "Failed to read input PB file [" + netFile.name() + "].";
932  }
933  }
934  catch (IException &e) {
935  QString msg = "Cannot parse binary protobuf file";
936  throw IException(e, IException::User, msg, _FILEINFO_);
937  }
938  catch (...) {
939  QString msg = "Cannot parse binary PB file";
941  }
942 
943  const PvlObject &logDataInfo = protoBufferInfo.findObject("LogData");
944  BigInt logStartPos = logDataInfo["StartByte"];
945  BigInt logLength = logDataInfo["Bytes"];
946 
947  input.clear();
948  input.seekg(logStartPos, ios::beg);
949  IstreamInputStream logInStream(&input);
950  CodedInputStream codedLogInStream(&logInStream);
951  codedLogInStream.PushLimit(logLength);
952  // max 512MB, warn at 400MB
953  codedLogInStream.SetTotalBytesLimit(1024 * 1024 * 512, 1024 * 1024 * 400);
954 
955  // Now stream the rest of the input into the google protocol buffer.
956  ControlNetLogDataProtoV0001 protoLogData;
957  try {
958  if ( !protoLogData.ParseFromCodedStream(&codedLogInStream) ) {
959  QString msg = "Failed to read log data in protobuf file [" + netFile.name() + "].";
961  }
962  }
963  catch (...) {
964  QString msg = "Cannot parse binary protobuf file's log data";
966  }
967 
968  // Create the header
969  try {
970  ControlNetHeaderV0002 header;
971  header.networkID = protoNet.networkid().c_str();
972  if ( protoNet.has_targetname() ) {
973  header.targetName = protoNet.targetname().c_str();
974  }
975  else {
976  header.targetName = "";
977  }
978  header.created = protoNet.created().c_str();
979  header.lastModified = protoNet.lastmodified().c_str();
980  header.description = protoNet.description().c_str();
981  header.userName = protoNet.username().c_str();
982  createHeader(header);
983  }
984  catch (IException &e) {
985  QString msg = "Failed to parse the header from the protobuf control network file.";
986  throw IException(e, IException::User, msg, _FILEINFO_);
987  }
988 
989  if (progress) {
990  progress->SetText("Reading Control Points...");
991  progress->SetMaximumSteps( protoNet.points_size() );
992  progress->CheckStatus();
993  }
994 
995  // Create the control points
996  for (int i = 0; i < protoNet.points_size(); i++) {
997  try {
999  protoPoint(new ControlNetFileProtoV0001_PBControlPoint(protoNet.points(i)));
1001  protoPointLogData(new ControlNetLogDataProtoV0001_Point(protoLogData.points(i)));
1002  ControlPointV0002 point(protoPoint, protoPointLogData);
1003  m_points.append( createPoint(point) );
1004 
1005  if (progress) {
1006  progress->CheckStatus();
1007  }
1008 
1009  }
1010  catch (IException &e) {
1011  QString msg = "Failed to convert version 1 protobuf control point at index ["
1012  + toString(i) + "] into a ControlPoint.";
1013  throw IException(e, IException::User, msg, _FILEINFO_);
1014  }
1015  }
1016  }
1017 
1018 
1028  const FileName netFile,
1029  Progress *progress) {
1030  // read the header protobuf object
1031  const PvlObject &protoBufferInfo = header.findObject("ProtoBuffer");
1032  const PvlObject &protoBufferCore = protoBufferInfo.findObject("Core");
1033 
1034  BigInt headerStartPos = protoBufferCore["HeaderStartByte"];
1035  BigInt headerLength = protoBufferCore["HeaderBytes"];
1036 
1037  fstream input(netFile.expanded().toLatin1().data(), ios::in | ios::binary);
1038  if ( !input.is_open() ) {
1039  QString msg = "Failed to open control network file" + netFile.name();
1041  }
1042 
1043  input.seekg(headerStartPos, ios::beg);
1044  streampos filePos = input.tellg();
1045 
1046  ControlNetFileHeaderV0002 protoHeader;
1047  try {
1048  IstreamInputStream headerInStream(&input);
1049  CodedInputStream headerCodedInStream(&headerInStream);
1050  // max 512MB, warn at 400MB
1051  headerCodedInStream.SetTotalBytesLimit(1024 * 1024 * 512,
1052  1024 * 1024 * 400);
1053  CodedInputStream::Limit oldLimit = headerCodedInStream.PushLimit(headerLength);
1054  if ( !protoHeader.ParseFromCodedStream(&headerCodedInStream) ) {
1055  QString msg = "Failed to parse protobuf header from input control net file ["
1056  + netFile.name() + "]";
1057  throw IException(IException::Io, msg, _FILEINFO_);
1058  }
1059  headerCodedInStream.PopLimit(oldLimit);
1060  filePos += headerLength;
1061  }
1062  catch (...) {
1063  QString msg = "An error occured while reading the protobuf control network header.";
1064  throw IException(IException::Io, msg, _FILEINFO_);
1065  }
1066 
1067  // initialize the header from the protobuf header
1068  try {
1069  ControlNetHeaderV0004 header;
1070  header.networkID = protoHeader.networkid().c_str();
1071  if ( protoHeader.has_targetname() ) {
1072  header.targetName = protoHeader.targetname().c_str();
1073  }
1074  else {
1075  header.targetName = "";
1076  }
1077  header.created = protoHeader.created().c_str();
1078  header.lastModified = protoHeader.lastmodified().c_str();
1079  header.description = protoHeader.description().c_str();
1080  header.userName = protoHeader.username().c_str();
1081  createHeader(header);
1082  }
1083  catch (IException &e) {
1084  QString msg = "Missing required header information.";
1085  throw IException(e, IException::Io, msg, _FILEINFO_);
1086  }
1087 
1088  // read each protobuf control point and then initialize it
1089  // For some reason, reading the header causes the input stream to fail so reopen the file
1090  input.close();
1091  input.open(netFile.expanded().toLatin1().data(), ios::in | ios::binary);
1092  input.seekg(filePos, ios::beg);
1093  IstreamInputStream pointInStream(&input);
1094  int numPoints = protoHeader.pointmessagesizes_size();
1095 
1096  if (progress) {
1097  progress->SetText("Reading Control Points...");
1098  progress->SetMaximumSteps(numPoints);
1099  progress->CheckStatus();
1100  }
1101 
1102  for (int pointIndex = 0; pointIndex < numPoints; pointIndex ++) {
1103  QSharedPointer<ControlPointFileEntryV0002> newPoint(new ControlPointFileEntryV0002);
1104 
1105  try {
1106  CodedInputStream pointCodedInStream(&pointInStream);
1107  pointCodedInStream.SetTotalBytesLimit(1024 * 1024 * 512,
1108  1024 * 1024 * 400);
1109  int pointSize = protoHeader.pointmessagesizes(pointIndex);
1110  CodedInputStream::Limit oldPointLimit = pointCodedInStream.PushLimit(pointSize);
1111  newPoint->ParseFromCodedStream(&pointCodedInStream);
1112  pointCodedInStream.PopLimit(oldPointLimit);
1113  }
1114  catch (...) {
1115  QString msg = "Failed to read protobuf version 2 control point at index ["
1116  + toString(pointIndex) + "].";
1117  throw IException(IException::Io, msg, _FILEINFO_);
1118  }
1119 
1120  try {
1121  ControlPointV0004 point(newPoint);
1122  m_points.append( createPoint(point) );
1123 
1124  if (progress) {
1125  progress->CheckStatus();
1126  }
1127 
1128  }
1129  catch (IException &e) {
1130  QString msg = "Failed to convert protobuf version 2 control point at index ["
1131  + toString(pointIndex) + "] into a ControlPoint.";
1132  throw IException(e, IException::Io, msg, _FILEINFO_);
1133  }
1134  }
1135  }
1136 
1137 
1147  const FileName netFile,
1148  Progress *progress) {
1149 
1150  // read the header protobuf object
1151  const PvlObject &protoBufferInfo = header.findObject("ProtoBuffer");
1152  const PvlObject &protoBufferCore = protoBufferInfo.findObject("Core");
1153 
1154  BigInt headerStartPos = protoBufferCore["HeaderStartByte"];
1155  BigInt headerLength = protoBufferCore["HeaderBytes"];
1156  BigInt pointsLength = protoBufferCore["PointsBytes"];
1157 
1158  fstream input(netFile.expanded().toLatin1().data(), ios::in | ios::binary);
1159  if ( !input.is_open() ) {
1160  QString msg = "Failed to open control network file" + netFile.name();
1162  }
1163 
1164  input.seekg(headerStartPos, ios::beg);
1165 
1166  streampos filePos = input.tellg();
1167 
1168  ControlNetFileHeaderV0005 protoHeader;
1169  try {
1170 
1171  IstreamInputStream headerInStream(&input);
1172  CodedInputStream headerCodedInStream(&headerInStream);
1173 
1174  // max 512MB, warn at 400MB
1175  headerCodedInStream.SetTotalBytesLimit(1024 * 1024 * 512,
1176  1024 * 1024 * 400);
1177 
1178  CodedInputStream::Limit oldLimit = headerCodedInStream.PushLimit(headerLength);
1179 
1180  if ( !protoHeader.ParseFromCodedStream(&headerCodedInStream) ) {
1181  QString msg = "Failed to parse protobuf header from input control net file ["
1182  + netFile.name() + "]";
1183  throw IException(IException::Io, msg, _FILEINFO_);
1184  }
1185 
1186  headerCodedInStream.PopLimit(oldLimit);
1187 
1188  filePos += headerLength;
1189  }
1190  catch (...) {
1191  QString msg = "An error occured while reading the protobuf control network header.";
1192  throw IException(IException::Io, msg, _FILEINFO_);
1193  }
1194  // initialize the header from the protobuf header
1195  try {
1196  ControlNetHeaderV0005 header;
1197  header.networkID = protoHeader.networkid().c_str();
1198  if ( protoHeader.has_targetname() ) {
1199  header.targetName = protoHeader.targetname().c_str();
1200  }
1201  else {
1202  header.targetName = "";
1203  }
1204  header.created = protoHeader.created().c_str();
1205  header.lastModified = protoHeader.lastmodified().c_str();
1206  header.description = protoHeader.description().c_str();
1207  header.userName = protoHeader.username().c_str();
1208  createHeader(header);
1209  }
1210  catch (IException &e) {
1211  QString msg = "Missing required header information.";
1212  throw IException(e, IException::Io, msg, _FILEINFO_);
1213  }
1214 
1215  // read each protobuf control point and then initialize it
1216  // For some reason, reading the header causes the input stream to fail so reopen the file
1217  input.close();
1218  input.open(netFile.expanded().toLatin1().data(), ios::in | ios::binary);
1219  input.seekg(filePos, ios::beg);
1220 
1221  IstreamInputStream pointInStream(&input);
1222 
1223  BigInt numberOfPoints = 0;
1224 
1225  if ( protoBufferInfo.hasGroup("ControlNetworkInfo") ) {
1226  const PvlGroup &networkInfo = protoBufferInfo.findGroup("ControlNetworkInfo");
1227 
1228  if ( networkInfo.hasKeyword("NumberOfPoints") ) {
1229  try {
1230  numberOfPoints = networkInfo["NumberOfPoints"];
1231  }
1232  catch (...) {
1233  numberOfPoints = 0;
1234  }
1235  }
1236  }
1237 
1238  if (progress && numberOfPoints != 0) {
1239  progress->SetText("Reading Control Points...");
1240  progress->SetMaximumSteps(numberOfPoints);
1241  progress->CheckStatus();
1242  }
1243 
1244  Isis::EndianSwapper lsb("LSB");
1245  int pointIndex = -1;
1246  while (pointInStream.ByteCount() < pointsLength) {
1247  pointIndex += 1;
1248  QSharedPointer<ControlPointFileEntryV0002> newPoint(new ControlPointFileEntryV0002);
1249 
1250  try {
1251 
1252  CodedInputStream pointCodedInStream(&pointInStream);
1253  pointCodedInStream.SetTotalBytesLimit(1024 * 1024 * 512,
1254  1024 * 1024 * 400);
1255 
1256  uint32_t size;
1257  pointCodedInStream.ReadRaw(reinterpret_cast<char *>(&size), sizeof(size));
1258 
1259  size = lsb.Uint32_t(&size);
1260 
1261  CodedInputStream::Limit oldPointLimit = pointCodedInStream.PushLimit(size);
1262  newPoint->ParseFromCodedStream(&pointCodedInStream);
1263  pointCodedInStream.PopLimit(oldPointLimit);
1264  }
1265  catch (...) {
1266  QString msg = "Failed to read protobuf version 2 control point at index ["
1267  + toString(pointIndex) + "].";
1268  throw IException(IException::Io, msg, _FILEINFO_);
1269  }
1270 
1271  try {
1272  ControlPointV0005 point(newPoint);
1273  m_points.append( createPoint(point) );
1274 
1275  if (progress && numberOfPoints != 0) {
1276  progress->CheckStatus();
1277  }
1278 
1279  }
1280  catch (IException &e) {
1281  QString msg = "Failed to convert protobuf version 2 control point at index ["
1282  + toString(pointIndex) + "] into a ControlPoint.";
1283  throw IException(e, IException::Io, msg, _FILEINFO_);
1284  }
1285  }
1286  }
1287 
1288 
1301  ControlPointV0002 newPoint(point);
1302  return createPoint(newPoint);
1303  }
1304 
1305 
1318 
1319  ControlPointV0003 newPoint(point);
1320  return createPoint(newPoint);
1321 
1322  }
1323 
1324 
1337 
1338  ControlPointFileEntryV0002 protoPoint = point.pointData();
1339  ControlPoint *controlPoint = new ControlPoint;
1340 
1341  // ID is required, no need for if-statement here
1342  controlPoint->SetId(QString(protoPoint.id().c_str()));
1343 
1344  if ( protoPoint.has_choosername() ) {
1345  controlPoint->SetChooserName(protoPoint.choosername().c_str());
1346  }
1347 
1348  // point type is required, no need for if statement here
1349  ControlPoint::PointType pointType;
1350  switch ( protoPoint.type() ) {
1351  case ControlPointFileEntryV0002_PointType_obsolete_Tie:
1352  case ControlPointFileEntryV0002_PointType_Free:
1353  pointType = ControlPoint::Free;
1354  break;
1355  case ControlPointFileEntryV0002_PointType_Constrained:
1356  pointType = ControlPoint::Constrained;
1357  break;
1358  case ControlPointFileEntryV0002_PointType_obsolete_Ground:
1359  case ControlPointFileEntryV0002_PointType_Fixed:
1360  pointType = ControlPoint::Fixed;
1361  break;
1362  default:
1363  QString msg = "Unable to create ControlPoint [" + toString(protoPoint.id().c_str())
1364  + "] from file. Type enumeration [" + toString((int)(protoPoint.type()))
1365  + "] is invalid.";
1367  break;
1368  }
1369  controlPoint->SetType(pointType);
1370 
1371  if ( protoPoint.has_ignore() ) {
1372  controlPoint->SetIgnored(protoPoint.ignore());
1373  }
1374  if ( protoPoint.has_jigsawrejected() ) {
1375  controlPoint->SetRejected(protoPoint.jigsawrejected());
1376  }
1377 
1378  // setting apriori radius information
1379  if ( protoPoint.has_aprioriradiussource() ) {
1380 
1381  switch ( protoPoint.aprioriradiussource() ) {
1382  case ControlPointFileEntryV0002_AprioriSource_None:
1383  controlPoint->SetAprioriRadiusSource(ControlPoint::RadiusSource::None);
1384  break;
1385  case ControlPointFileEntryV0002_AprioriSource_User:
1386  controlPoint->SetAprioriRadiusSource(ControlPoint::RadiusSource::User);
1387  break;
1388  case ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures:
1389  controlPoint->SetAprioriRadiusSource(ControlPoint::RadiusSource::AverageOfMeasures);
1390  break;
1391  case ControlPointFileEntryV0002_AprioriSource_Ellipsoid:
1392  controlPoint->SetAprioriRadiusSource(ControlPoint::RadiusSource::Ellipsoid);
1393  break;
1394  case ControlPointFileEntryV0002_AprioriSource_DEM:
1395  controlPoint->SetAprioriRadiusSource(ControlPoint::RadiusSource::DEM);
1396  break;
1397  case ControlPointFileEntryV0002_AprioriSource_BundleSolution:
1398  controlPoint->SetAprioriRadiusSource(ControlPoint::RadiusSource::BundleSolution);
1399  break;
1400 
1401  default:
1402  QString msg = "Unknown control point apriori radius source.";
1403  throw IException(IException::User, msg, _FILEINFO_);
1404  break;
1405  }
1406  }
1407 
1408  if ( protoPoint.has_aprioriradiussourcefile() ) {
1409  controlPoint->SetAprioriRadiusSourceFile(protoPoint.aprioriradiussourcefile().c_str());
1410  }
1411 
1412  // setting apriori surf pt information
1413  if ( protoPoint.has_apriorisurfpointsource() ) {
1414  switch ( protoPoint.apriorisurfpointsource() ) {
1415  case ControlPointFileEntryV0002_AprioriSource_None:
1416  controlPoint->SetAprioriSurfacePointSource(ControlPoint::SurfacePointSource::None);
1417  break;
1418 
1419  case ControlPointFileEntryV0002_AprioriSource_User:
1420  controlPoint->SetAprioriSurfacePointSource(ControlPoint::SurfacePointSource::User);
1421  break;
1422 
1423  case ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures:
1424  controlPoint->SetAprioriSurfacePointSource(
1425  ControlPoint::SurfacePointSource::AverageOfMeasures);
1426  break;
1427 
1428  case ControlPointFileEntryV0002_AprioriSource_Reference:
1429  controlPoint->SetAprioriSurfacePointSource(ControlPoint::SurfacePointSource::Reference);
1430  break;
1431 
1432  case ControlPointFileEntryV0002_AprioriSource_Basemap:
1433  controlPoint->SetAprioriSurfacePointSource(ControlPoint::SurfacePointSource::Basemap);
1434  break;
1435 
1436  case ControlPointFileEntryV0002_AprioriSource_BundleSolution:
1437  controlPoint->SetAprioriSurfacePointSource(
1438  ControlPoint::SurfacePointSource::BundleSolution);
1439  break;
1440 
1441  default:
1442  QString msg = "Unknown control point aprioir surface point source.";
1443  throw IException(IException::User, msg, _FILEINFO_);
1444  break;
1445  }
1446  }
1447 
1448  if ( protoPoint.has_apriorisurfpointsourcefile() ) {
1449  controlPoint->SetAprioriSurfacePointSourceFile(
1450  protoPoint.apriorisurfpointsourcefile().c_str());
1451  }
1452 
1453  if ( protoPoint.has_apriorix()
1454  && protoPoint.has_aprioriy()
1455  && protoPoint.has_aprioriz() ) {
1456 
1457  SurfacePoint aprioriSurfacePoint(Displacement(protoPoint.apriorix(), Displacement::Meters),
1458  Displacement(protoPoint.aprioriy(), Displacement::Meters),
1459  Displacement(protoPoint.aprioriz(), Displacement::Meters));
1460 
1461  if ( protoPoint.aprioricovar_size() > 0 ) {
1462  symmetric_matrix<double, upper> aprioriCovarianceMatrix;
1463  aprioriCovarianceMatrix.resize(3);
1464  aprioriCovarianceMatrix.clear();
1465  aprioriCovarianceMatrix(0, 0) = protoPoint.aprioricovar(0);
1466  aprioriCovarianceMatrix(0, 1) = protoPoint.aprioricovar(1);
1467  aprioriCovarianceMatrix(0, 2) = protoPoint.aprioricovar(2);
1468  aprioriCovarianceMatrix(1, 1) = protoPoint.aprioricovar(3);
1469  aprioriCovarianceMatrix(1, 2) = protoPoint.aprioricovar(4);
1470  aprioriCovarianceMatrix(2, 2) = protoPoint.aprioricovar(5);
1471  aprioriSurfacePoint.SetRectangularMatrix(aprioriCovarianceMatrix);
1472  // note: setting lat/lon/rad constrained happens when we call SetAprioriSurfacePoint()
1473  }
1474 
1475  controlPoint->SetAprioriSurfacePoint(aprioriSurfacePoint);
1476  }
1477 
1478  // setting adj surf pt information
1479  if ( protoPoint.has_adjustedx()
1480  && protoPoint.has_adjustedy()
1481  && protoPoint.has_adjustedz() ) {
1482 
1483  SurfacePoint adjustedSurfacePoint(Displacement(protoPoint.adjustedx(),Displacement::Meters),
1484  Displacement(protoPoint.adjustedy(),Displacement::Meters),
1485  Displacement(protoPoint.adjustedz(),Displacement::Meters));
1486 
1487  if ( protoPoint.adjustedcovar_size() > 0 ) {
1488  symmetric_matrix<double, upper> adjustedCovarianceMatrix;
1489  adjustedCovarianceMatrix.resize(3);
1490  adjustedCovarianceMatrix.clear();
1491  adjustedCovarianceMatrix(0, 0) = protoPoint.adjustedcovar(0);
1492  adjustedCovarianceMatrix(0, 1) = protoPoint.adjustedcovar(1);
1493  adjustedCovarianceMatrix(0, 2) = protoPoint.adjustedcovar(2);
1494  adjustedCovarianceMatrix(1, 1) = protoPoint.adjustedcovar(3);
1495  adjustedCovarianceMatrix(1, 2) = protoPoint.adjustedcovar(4);
1496  adjustedCovarianceMatrix(2, 2) = protoPoint.adjustedcovar(5);
1497  adjustedSurfacePoint.SetRectangularMatrix(adjustedCovarianceMatrix);
1498  }
1499 
1500  controlPoint->SetAdjustedSurfacePoint(adjustedSurfacePoint);
1501  }
1502 
1503  SurfacePoint aprioriSurfacePoint = controlPoint->GetAprioriSurfacePoint();
1504  SurfacePoint adjustedSurfacePoint = controlPoint->GetAdjustedSurfacePoint();
1505  controlPoint->SetAdjustedSurfacePoint(adjustedSurfacePoint);
1506  controlPoint->SetAprioriSurfacePoint(aprioriSurfacePoint);
1507 
1508  // adding measure information
1509  for (int m = 0 ; m < protoPoint.measures_size(); m++) {
1510  controlPoint->Add( createMeasure( protoPoint.measures(m) ) );
1511  }
1512 
1513  if ( protoPoint.has_referenceindex() ) {
1514  controlPoint->SetRefMeasure(protoPoint.referenceindex());
1515  }
1516 
1517  // Set DateTime after calling all setters that clear DateTime value
1518  if ( protoPoint.has_datetime() ) {
1519  controlPoint->SetDateTime(protoPoint.datetime().c_str());
1520  }
1521  // Set edit lock last
1522  if ( protoPoint.has_editlock() ) {
1523  controlPoint->SetEditLock(protoPoint.editlock());
1524  }
1525 
1526  return controlPoint;
1527 
1528  }
1529 
1530 
1540  const ControlPointFileEntryV0002_Measure &measure) {
1541 
1542  ControlMeasure *newMeasure = new ControlMeasure;
1543 
1544  // serial number is required, no need for if-statement
1545  newMeasure->SetCubeSerialNumber(QString(measure.serialnumber().c_str()));
1546 
1547  // measure type is required, no need for if-statement
1548  ControlMeasure::MeasureType measureType;
1549  switch ( measure.type() ) {
1550  case ControlPointFileEntryV0002_Measure::Candidate:
1551  measureType = ControlMeasure::Candidate;
1552  break;
1553  case ControlPointFileEntryV0002_Measure::Manual:
1554  measureType = ControlMeasure::Manual;
1555  break;
1556  case ControlPointFileEntryV0002_Measure::RegisteredPixel:
1557  measureType = ControlMeasure::RegisteredPixel;
1558  break;
1559  case ControlPointFileEntryV0002_Measure::RegisteredSubPixel:
1560  measureType = ControlMeasure::RegisteredSubPixel;
1561  break;
1562  default:
1563  QString msg = "Unknown control measure type.";
1564  throw IException(IException::User, msg, _FILEINFO_);
1565  break;
1566  }
1567  newMeasure->SetType(measureType);
1568 
1569  if ( measure.has_jigsawrejected() ) {
1570  newMeasure->SetRejected(measure.jigsawrejected());
1571  }
1572  if ( measure.has_ignore() ) {
1573  newMeasure->SetIgnored(measure.ignore());
1574  }
1575  if ( measure.has_line() ) {
1576  newMeasure->SetCoordinate(measure.sample(), measure.line());
1577  }
1578  if ( measure.has_diameter() ) {
1579  newMeasure->SetDiameter(measure.diameter());
1580  }
1581  if ( measure.has_apriorisample() ) {
1582  newMeasure->SetAprioriSample(measure.apriorisample());
1583  }
1584  if ( measure.has_aprioriline() ) {
1585  newMeasure->SetAprioriLine(measure.aprioriline());
1586  }
1587  if ( measure.has_samplesigma() ) {
1588  newMeasure->SetSampleSigma(measure.samplesigma());
1589  }
1590  if ( measure.has_linesigma() ) {
1591  newMeasure->SetLineSigma(measure.linesigma());
1592  }
1593  if ( measure.has_sampleresidual()
1594  && measure.has_lineresidual() ) {
1595  newMeasure->SetResidual(measure.sampleresidual(), measure.lineresidual());
1596  }
1597 
1598  for (int i = 0; i < measure.log_size(); i++) {
1599 
1600  const ControlPointFileEntryV0002_Measure_MeasureLogData &protoLog = measure.log(i);
1601  ControlMeasureLogData logEntry;
1602  if ( protoLog.has_doubledatatype() ) {
1603  logEntry.SetDataType((ControlMeasureLogData::NumericLogDataType)protoLog.doubledatatype());
1604  }
1605  if ( protoLog.has_doubledatavalue() ) {
1606  logEntry.SetNumericalValue( protoLog.doubledatavalue() );
1607  }
1608  newMeasure->SetLogData(logEntry);
1609  }
1610 
1611  if ( measure.has_choosername() ) {
1612  newMeasure->SetChooserName(QString(measure.choosername().c_str()));
1613  }
1614 
1615  if ( measure.has_datetime() ) {
1616  newMeasure->SetDateTime(QString(measure.datetime().c_str()));
1617  }
1618 
1619  // It is VERY important that the edit lock flag is set last because it prevents
1620  // all of the other mutators from working if true.
1621  if ( measure.has_editlock() ) {
1622  newMeasure->SetEditLock(measure.editlock());
1623  }
1624  return newMeasure;
1625  }
1626 
1627 
1637  m_header = header;
1638 
1639  if ( m_header.targetName.startsWith("MRO/") ) {
1640  m_header.targetName = "Mars";
1641  }
1642  }
1643 
1644 
1652  try {
1653 
1654  const int labelBytes = 65536;
1655  fstream output(netFile.expanded().toLatin1().data(), ios::out | ios::trunc | ios::binary);
1656  char *blankLabel = new char[labelBytes];
1657  memset(blankLabel, 0, labelBytes);
1658  output.write(blankLabel, labelBytes);
1659  delete [] blankLabel;
1660 
1661  int numMeasures = 0;
1662  int numPoints = m_points.size();
1663  foreach (ControlPoint *point, m_points) {
1664  numMeasures += point->GetNumMeasures();
1665  }
1666 
1667  streampos startCoreHeaderPos = output.tellp();
1668 
1669  writeHeader(&output);
1670 
1671  BigInt pointByteTotal = 0;
1672  while ( !m_points.isEmpty() ) {
1673  pointByteTotal += writeFirstPoint(&output);
1674  }
1675 
1676  // Insert header at the beginning of the file once writing is done.
1677  ControlNetFileHeaderV0005 protobufHeader;
1678 
1679  protobufHeader.set_networkid(m_header.networkID.toLatin1().data());
1680  protobufHeader.set_targetname(m_header.targetName.toLatin1().data());
1681  protobufHeader.set_created(m_header.created.toLatin1().data());
1682  protobufHeader.set_lastmodified(m_header.lastModified.toLatin1().data());
1683  protobufHeader.set_description(m_header.description.toLatin1().data());
1684  protobufHeader.set_username(m_header.userName.toLatin1().data());
1685 
1686  streampos coreHeaderSize = protobufHeader.ByteSize();
1687 
1688  Pvl p;
1689 
1690  PvlObject protoObj("ProtoBuffer");
1691 
1692  PvlObject protoCore("Core");
1693  protoCore.addKeyword(PvlKeyword("HeaderStartByte",
1694  toString((BigInt) startCoreHeaderPos)));
1695  protoCore.addKeyword(PvlKeyword("HeaderBytes", toString((BigInt) coreHeaderSize)));
1696 
1697  BigInt pointsStartByte = (BigInt) (startCoreHeaderPos + coreHeaderSize);
1698 
1699  protoCore.addKeyword(PvlKeyword("PointsStartByte", toString(pointsStartByte)));
1700 
1701  protoCore.addKeyword(PvlKeyword("PointsBytes",
1702  toString(pointByteTotal)));
1703  protoObj.addObject(protoCore);
1704 
1705  PvlGroup netInfo("ControlNetworkInfo");
1706  netInfo.addComment("This group is for informational purposes only");
1707  netInfo += PvlKeyword("NetworkId", protobufHeader.networkid().c_str());
1708  netInfo += PvlKeyword("TargetName", protobufHeader.targetname().c_str());
1709  netInfo += PvlKeyword("UserName", protobufHeader.username().c_str());
1710  netInfo += PvlKeyword("Created", protobufHeader.created().c_str());
1711  netInfo += PvlKeyword("LastModified", protobufHeader.lastmodified().c_str());
1712  netInfo += PvlKeyword("Description", protobufHeader.description().c_str());
1713  netInfo += PvlKeyword("NumberOfPoints", toString(numPoints));
1714  netInfo += PvlKeyword("NumberOfMeasures", toString(numMeasures));
1715  netInfo += PvlKeyword("Version", "5");
1716  protoObj.addGroup(netInfo);
1717 
1718  p.addObject(protoObj);
1719 
1720  output.seekp(0, ios::beg);
1721  output << p;
1722  output << '\n';
1723  output.close();
1724 
1725  }
1726  catch (...) {
1727  QString msg = "Can't write control net file";
1728  throw IException(IException::Io, msg, _FILEINFO_);
1729  }
1730  }
1731 
1737  void ControlNetVersioner::writeHeader(fstream *output) {
1738 
1739  // Create the protobuf header using our struct
1740  ControlNetFileHeaderV0005 protobufHeader;
1741 
1742  protobufHeader.set_networkid(m_header.networkID.toLatin1().data());
1743  protobufHeader.set_targetname(m_header.targetName.toLatin1().data());
1744  protobufHeader.set_created(m_header.created.toLatin1().data());
1745  protobufHeader.set_lastmodified(m_header.lastModified.toLatin1().data());
1746  protobufHeader.set_description(m_header.description.toLatin1().data());
1747  protobufHeader.set_username(m_header.userName.toLatin1().data());
1748 
1749  // Write out the header
1750  if ( !protobufHeader.SerializeToOstream(output) ) {
1751  QString msg = "Failed to write output control network file.";
1752  throw IException(IException::Io, msg, _FILEINFO_);
1753  }
1754  }
1755 
1756 
1767 
1768  BigInt startPos = output->tellp();
1769 
1770  ControlPointFileEntryV0002 protoPoint;
1771  ControlPoint *controlPoint = m_points.takeFirst();
1772 
1773  if ( controlPoint->GetId().isEmpty() ) {
1774  QString msg = "Unbable to write first point of control net. "
1775  "Invalid control point has no point ID value.";
1777  }
1778  else {
1779  protoPoint.set_id(controlPoint->GetId().toLatin1().data());
1780  }
1781 
1782  if ( QString::compare(controlPoint->GetChooserName(), "Null", Qt::CaseInsensitive) != 0 ) {
1783  protoPoint.set_choosername(controlPoint->GetChooserName().toLatin1().data());
1784  }
1785  if ( QString::compare(controlPoint->GetDateTime(), "Null", Qt::CaseInsensitive) != 0 ) {
1786  protoPoint.set_datetime(controlPoint->GetDateTime().toLatin1().data());
1787  }
1788  if ( controlPoint->IsEditLocked() ) {
1789  protoPoint.set_editlock(true);
1790  }
1791 
1792  ControlPointFileEntryV0002_PointType pointType;
1793  switch ( controlPoint->GetType() ) {
1794  case ControlPoint::Free:
1795  pointType = ControlPointFileEntryV0002_PointType_Free;
1796  break;
1798  pointType = ControlPointFileEntryV0002_PointType_Constrained;
1799  break;
1800  case ControlPoint::Fixed:
1801  pointType = ControlPointFileEntryV0002_PointType_Fixed;
1802  break;
1803  default:
1804  pointType = ControlPointFileEntryV0002_PointType_Free;
1805  break;
1806  }
1807  protoPoint.set_type(pointType);
1808 
1809  if ( controlPoint->IsIgnored() ) {
1810  protoPoint.set_ignore(true);
1811  }
1812 
1813  if ( controlPoint->IsRejected() ) {
1814  protoPoint.set_jigsawrejected(true);
1815  }
1816 
1817  if ( controlPoint->HasRefMeasure() && controlPoint->IsReferenceExplicit() ) {
1818  protoPoint.set_referenceindex(controlPoint->IndexOfRefMeasure());
1819  }
1820 
1821  if ( controlPoint->HasAprioriSurfacePointSourceFile() ) {
1822  protoPoint.set_apriorisurfpointsourcefile(
1823  controlPoint->GetAprioriSurfacePointSourceFile().toLatin1().data());
1824  }
1825 
1826  // Apriori Surf Point Source ENUM settting
1827  switch ( controlPoint->GetAprioriSurfacePointSource() ) {
1828  case ControlPoint::SurfacePointSource::None:
1829  protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_None);
1830  break;
1831  case ControlPoint::SurfacePointSource::User:
1832  protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_User);
1833  break;
1834  case ControlPoint::SurfacePointSource::AverageOfMeasures:
1835  protoPoint.set_apriorisurfpointsource(
1836  ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures);
1837  break;
1838  case ControlPoint::SurfacePointSource::Reference:
1839  protoPoint.set_apriorisurfpointsource(
1840  ControlPointFileEntryV0002_AprioriSource_Reference);
1841  break;
1842  case ControlPoint::SurfacePointSource::Basemap:
1843  protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_Basemap);
1844  break;
1845  case ControlPoint::SurfacePointSource::BundleSolution:
1846  protoPoint.set_apriorisurfpointsource(
1847  ControlPointFileEntryV0002_AprioriSource_BundleSolution);
1848  break;
1849  default:
1850  protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_None);
1851  break;
1852  }
1853 
1854  // Apriori Radius Point Source ENUM setting
1855  switch ( controlPoint->GetAprioriRadiusSource() ) {
1856  case ControlPoint::RadiusSource::None:
1857  protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_None);
1858  break;
1859  case ControlPoint::RadiusSource::User:
1860  protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_User);
1861  break;
1862  case ControlPoint::RadiusSource::AverageOfMeasures:
1863  protoPoint.set_aprioriradiussource(
1864  ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures);
1865  break;
1866  case ControlPoint::RadiusSource::BundleSolution:
1867  protoPoint.set_aprioriradiussource(
1868  ControlPointFileEntryV0002_AprioriSource_BundleSolution);
1869  break;
1870  case ControlPoint::RadiusSource::Ellipsoid:
1871  protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_Ellipsoid);
1872  break;
1873  case ControlPoint::RadiusSource::DEM:
1874  protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_DEM);
1875  break;
1876  default:
1877  protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_None);
1878  break;
1879  }
1880 
1881  if ( controlPoint->HasAprioriRadiusSourceFile() ) {
1882  protoPoint.set_aprioriradiussourcefile(
1883  controlPoint->GetAprioriRadiusSourceFile().toLatin1().data());
1884  }
1885 
1886  SurfacePoint aprioriSurfacePoint = controlPoint->GetAprioriSurfacePoint();
1887  if ( aprioriSurfacePoint.Valid() ) {
1888  protoPoint.set_apriorix(aprioriSurfacePoint.GetX().meters());
1889  protoPoint.set_aprioriy(aprioriSurfacePoint.GetY().meters());
1890  protoPoint.set_aprioriz(aprioriSurfacePoint.GetZ().meters());
1891 
1892  symmetric_matrix<double, upper> aprioriCovarianceMatrix =
1893  aprioriSurfacePoint.GetRectangularMatrix();
1894  if ( aprioriCovarianceMatrix.size1() > 0 &&
1895  aprioriSurfacePoint.GetLatSigmaDistance().meters() != Isis::Null &&
1896  aprioriSurfacePoint.GetLonSigmaDistance().meters() != Isis::Null &&
1897  aprioriSurfacePoint.GetLocalRadiusSigma().meters() != Isis::Null ) {
1898 
1899  protoPoint.add_aprioricovar(aprioriCovarianceMatrix(0, 0));
1900  protoPoint.add_aprioricovar(aprioriCovarianceMatrix(0, 1));
1901  protoPoint.add_aprioricovar(aprioriCovarianceMatrix(0, 2));
1902  protoPoint.add_aprioricovar(aprioriCovarianceMatrix(1, 1));
1903  protoPoint.add_aprioricovar(aprioriCovarianceMatrix(1, 2));
1904  protoPoint.add_aprioricovar(aprioriCovarianceMatrix(2, 2));
1905  }
1906  }
1907  // this might be redundant... determined by covariance matrix???
1908  // *** TODO *** Address the generalized coordinates and the constraint differences
1909  if ( controlPoint->IsCoord1Constrained() ) {
1910  protoPoint.set_latitudeconstrained(controlPoint->IsCoord1Constrained());
1911  }
1912  if ( controlPoint->IsCoord2Constrained() ) {
1913  protoPoint.set_longitudeconstrained(controlPoint->IsCoord2Constrained());
1914  }
1915  if ( controlPoint->IsCoord3Constrained() ) {
1916  protoPoint.set_radiusconstrained(controlPoint->IsCoord3Constrained());
1917  }
1918 
1919  SurfacePoint adjustedSurfacePoint = controlPoint->GetAdjustedSurfacePoint();
1920  if ( adjustedSurfacePoint.Valid() ) {
1921 
1922  protoPoint.set_adjustedx(adjustedSurfacePoint.GetX().meters());
1923  protoPoint.set_adjustedy(adjustedSurfacePoint.GetY().meters());
1924  protoPoint.set_adjustedz(adjustedSurfacePoint.GetZ().meters());
1925 
1926  symmetric_matrix<double, upper> adjustedCovarianceMatrix =
1927  adjustedSurfacePoint.GetRectangularMatrix();
1928  if ( adjustedCovarianceMatrix.size1() > 0 ) {
1929  protoPoint.add_adjustedcovar(adjustedCovarianceMatrix(0, 0));
1930  protoPoint.add_adjustedcovar(adjustedCovarianceMatrix(0, 1));
1931  protoPoint.add_adjustedcovar(adjustedCovarianceMatrix(0, 2));
1932  protoPoint.add_adjustedcovar(adjustedCovarianceMatrix(1, 1));
1933  protoPoint.add_adjustedcovar(adjustedCovarianceMatrix(1, 2));
1934  protoPoint.add_adjustedcovar(adjustedCovarianceMatrix(2, 2));
1935  }
1936  }
1937 
1938  // Converting Measures
1939  for (int j = 0; j < controlPoint->GetNumMeasures(); j++) {
1940 
1941  const ControlMeasure &controlMeasure = *controlPoint->GetMeasure(j);
1942 
1943  ControlPointFileEntryV0002_Measure protoMeasure;
1944 
1945  protoMeasure.set_serialnumber(controlMeasure.GetCubeSerialNumber().toLatin1().data());
1946 
1947  switch ( controlMeasure.GetType() ) {
1949  protoMeasure.set_type(ControlPointFileEntryV0002_Measure_MeasureType_Candidate);
1950  break;
1951 
1952  case (ControlMeasure::Manual):
1953  protoMeasure.set_type(ControlPointFileEntryV0002_Measure_MeasureType_Manual);
1954  break;
1955 
1957  protoMeasure.set_type(
1958  ControlPointFileEntryV0002_Measure_MeasureType_RegisteredPixel);
1959  break;
1960 
1962  protoMeasure.set_type(
1963  ControlPointFileEntryV0002_Measure_MeasureType_RegisteredSubPixel);
1964  break;
1965  }
1966 
1967  if (QString::compare(controlMeasure.GetChooserName(), "Null", Qt::CaseInsensitive) != 0) {
1968  protoMeasure.set_choosername(controlMeasure.GetChooserName().toLatin1().data());
1969  }
1970 
1971  if (QString::compare(controlMeasure.GetDateTime(), "Null", Qt::CaseInsensitive) != 0) {
1972  protoMeasure.set_datetime(controlMeasure.GetDateTime().toLatin1().data());
1973  }
1974 
1975  if ( controlMeasure.IsEditLocked() ) {
1976  protoMeasure.set_editlock(true);
1977  }
1978 
1979  if ( controlMeasure.IsIgnored() ) {
1980  protoMeasure.set_ignore(true);
1981  }
1982 
1983  if ( controlMeasure.IsRejected() ) {
1984  protoMeasure.set_jigsawrejected(true);
1985  }
1986 
1987  if ( controlMeasure.GetSample() != Isis::Null ) {
1988  protoMeasure.set_sample(controlMeasure.GetSample());
1989  }
1990 
1991  if ( controlMeasure.GetLine() != Isis::Null ) {
1992  protoMeasure.set_line(controlMeasure.GetLine());
1993  }
1994 
1995  if ( controlMeasure.GetDiameter() != Isis::Null ) {
1996  protoMeasure.set_diameter(controlMeasure.GetDiameter());
1997  }
1998 
1999  if ( controlMeasure.GetAprioriSample() != Isis::Null ) {
2000  protoMeasure.set_apriorisample(controlMeasure.GetAprioriSample());
2001  }
2002 
2003  if ( controlMeasure.GetAprioriLine() != Isis::Null ) {
2004  protoMeasure.set_aprioriline(controlMeasure.GetAprioriLine());
2005  }
2006 
2007  if ( controlMeasure.GetSampleSigma() != Isis::Null ) {
2008  protoMeasure.set_samplesigma(controlMeasure.GetSampleSigma());
2009  }
2010 
2011  if ( controlMeasure.GetLineSigma() != Isis::Null ) {
2012  protoMeasure.set_linesigma(controlMeasure.GetLineSigma());
2013  }
2014 
2015  if ( controlMeasure.GetSampleResidual() != Isis::Null ) {
2016  protoMeasure.set_sampleresidual(controlMeasure.GetSampleResidual());
2017  }
2018 
2019  if ( controlMeasure.GetLineResidual() != Isis::Null ) {
2020  protoMeasure.set_lineresidual(controlMeasure.GetLineResidual());
2021  }
2022 
2023  if ( controlMeasure.IsRejected() ) {
2024  protoMeasure.set_jigsawrejected(true);
2025  }
2026 
2027  QVector<ControlMeasureLogData> measureLogs = controlMeasure.GetLogDataEntries();
2028  for (int logEntry = 0; logEntry < measureLogs.size(); logEntry ++) {
2029 
2030  const ControlMeasureLogData &log = measureLogs[logEntry];
2031 
2032  ControlPointFileEntryV0002_Measure_MeasureLogData logData;
2033 
2034  if ( log.IsValid() ) {
2035  logData.set_doubledatatype( (int) log.GetDataType() );
2036  logData.set_doubledatavalue( log.GetNumericalValue() );
2037  }
2038 
2039  *protoMeasure.add_log() = logData;
2040  }
2041 
2042  *protoPoint.add_measures() = protoMeasure;
2043  }
2044 
2045  uint32_t byteSize = protoPoint.ByteSize();
2046 
2047  Isis::EndianSwapper lsb("LSB");
2048  byteSize = lsb.Uint32_t(&byteSize);
2049 
2050  output->write(reinterpret_cast<char *>(&byteSize), sizeof(byteSize));
2051 
2052  if ( !protoPoint.SerializeToOstream(output) ) {
2053  QString err = "Error writing to coded protobuf stream";
2055  }
2056 
2057  // Make sure that if the versioner owns the ControlPoint it is properly cleaned up.
2058  if ( m_ownsPoints ) {
2059  delete controlPoint;
2060  controlPoint = NULL;
2061  }
2062  BigInt currentPos = output->tellp();
2063  BigInt byteCount = currentPos - startPos;
2064 
2065  // return size of message
2066  return byteCount;
2067  }
2068 }
This class defines a body-fixed surface point.
Definition: SurfacePoint.h:148
PvlObject & object(const int index)
Return the object at the specified index.
Definition: PvlObject.cpp:460
Status SetType(MeasureType type)
Set how the coordinate was obtained.
ControlMeasure * createMeasure(const ControlPointFileEntryV0002_Measure &)
Create a pointer to a ControlMeasure from a V0006 file.
long long int BigInt
Big int.
Definition: Constants.h:65
Status SetAprioriSurfacePointSource(SurfacePointSource::Source source)
This updates the source of the surface point.
~ControlNetVersioner()
Destroy a ControlNetVersioner.
QString userName
The name of the user or program that last modified the control network.
double meters() const
Get the distance in meters.
Definition: Distance.cpp:97
PvlKeyword ToKeyword() const
This converts the log data to a PvlKeyword.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:110
bool IsReferenceExplicit() const
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
Definition: Progress.cpp:101
void Add(ControlMeasure *measure)
Add a measurement to the control point, taking ownership of the measure in the process.
NumericLogDataType GetDataType() const
Get the data type associated with this log data.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
(e.g., autoseed, interest) AKA predicted, unmeasured, unverified
QString creationDate() const
Returns the date and time that the network was created.
void clear()
Remove everything from the current PvlObject.
Definition: PvlObject.h:353
A Constrained point is a Control Point whose lat/lon/radius is somewhat established and should not be...
Definition: ControlPoint.h:391
A Fixed point is a Control Point whose lat/lon is well established and should not be changed...
Definition: ControlPoint.h:386
File name manipulation and expansion.
Definition: FileName.h:116
QString targetName
The NAIF name of the target body.
Pvl toPvl()
Generates a Pvl file from the currently stored control points and header.
int objects() const
Returns the number of objects.
Definition: PvlObject.h:231
Status SetAprioriRadiusSourceFile(QString sourceFile)
This updates the filename of the DEM that the apriori radius came from.
QString lastModificationDate() const
Returns the date and time of the last modification to the network.
bool IsCoord3Constrained()
Return bool indicating if 3rd coordinate is Constrained or not.
const ControlMeasure * GetMeasure(QString serialNumber) const
Get a control measure based on its cube&#39;s serial number.
Status SetIgnored(bool newIgnoreStatus)
Set whether to ignore or use control point.
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
NumericLogDataType
Please do not change existing values in this list except the size - it will break backwards compadibi...
QString created
The date and time of the control network&#39;s creation.
QString GetUserName() const
Return the user name.
void writeHeader(std::fstream *output)
This will read the binary protobuffer control network header to an fstream.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:198
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
PointType
These are the valid &#39;types&#39; of point.
Definition: ControlPoint.h:379
Statistical and similar ControlMeasure associated information.
QList< ControlPoint * > m_points
ControlPoints that are read in from a file or ready to be written out to a file.
double meters() const
Get the displacement in meters.
bool HasAprioriSurfacePointSourceFile() const
Checks to see if the surface point source file has been set.
Namespace for the standard library.
void SetNumericalValue(double value)
This updates the value associated with a NumericLogDataType.
QList< ControlPoint *> GetPoints()
Return QList of all the ControlPoints in the network.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:178
Distance GetLatSigmaDistance() const
Return the latitude sigma as a Distance.
void readProtobufV0001(const Pvl &header, const FileName netFile, Progress *progress=NULL)
Read a protobuf version 1 control network and prepare the data to be converted into a control network...
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
Definition: PvlObject.h:222
Status SetChooserName(QString name)
Set the point&#39;s chooser name.
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.
Distance GetLonSigmaDistance() const
Return the longitude sigma in meters.
Registered to whole pixel (e.g.,pointreg)
Registered to sub-pixel (e.g., pointreg)
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
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
Status SetEditLock(bool editLock)
Set the EditLock state.
void readPvlV0001(const PvlObject &network, Progress *progress=NULL)
read a version 1 Pvl control network and convert the data into control points.
The distance is being specified in meters.
Definition: Displacement.h:52
Status SetRejected(bool rejected)
Set "jigsaw" rejected flag for a measure.
QString GetTarget() const
Return the target name.
Latitude GetLatitude() const
Return the body-fixed latitude for the surface point.
void readPvlV0002(const PvlObject &network, Progress *progress=NULL)
read a version 2 Pvl control network and convert the data into control points.
bool HasAprioriRadiusSourceFile() const
Checks to see if the radius source file has been set.
double degrees() const
Get the angle in units of Degrees.
Definition: Angle.h:249
void read(const FileName netFile, Progress *progress=NULL)
Read a control network file and prepare the data to be converted into a control network.
void CheckStatus()
Checks and updates the status.
Definition: Progress.cpp:121
Status SetAdjustedSurfacePoint(SurfacePoint newSurfacePoint)
Set or update the surface point relating to this control 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
void readProtobuf(const Pvl &header, const FileName netFile, Progress *progress=NULL)
Read a protobuf control network and prepare the data to be converted into a control network...
A Free point is a Control Point that identifies common measurements between two or more cubes...
Definition: ControlPoint.h:399
void addObject(const PvlObject &object)
Add a PvlObject.
Definition: PvlObject.h:319
Status SetDiameter(double diameter)
Set the crater diameter at the coordinate.
Versioned container for general information about a control network.
A container for the information stored in a version 3 and 4 ControlPoint.
void readProtobufV0002(const Pvl &header, const FileName netFile, Progress *progress=NULL)
Read a protobuf version 2 control network and prepare the data to be converted into a control network...
Status SetAprioriSurfacePointSourceFile(QString sourceFile)
This updates the filename of where the apriori surface point came from.
void readPvlV0005(const PvlObject &network, Progress *progress=NULL)
read a version 5 Pvl control network and convert the data into control points.
void addComment(QString comment)
Add a comment to the PvlKeyword.
Definition: PvlKeyword.cpp:392
void SetRectangularMatrix(const boost::numeric::ublas::symmetric_matrix< double, boost::numeric::ublas::upper > &covar, SurfacePoint::CoordUnits units=SurfacePoint::Meters)
Set rectangular covariance matrix and store in units of km**2.
bool IsValid() const
This tests if the log data is complete and valid.
Program progress reporter.
Definition: Progress.h:58
QString Description() const
Return the description of the network.
Status SetResidual(double sampResidual, double lineResidual)
Set the BundleAdjust Residual of the coordinate.
int writeFirstPoint(std::fstream *output)
This will write the first control point to a file stream.
QString description() const
Returns the network&#39;s description.
a control network
Definition: ControlNet.h:271
Hand Measured (e.g., qnet)
QString GetId() const
Return the Id of the control point.
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
Definition: Progress.cpp:77
void readProtobufV0005(const Pvl &header, const FileName netFile, Progress *progress=NULL)
Read a protobuf version 5 control network and prepare the data to be converted into a control network...
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
Status SetDateTime(QString newDateTime)
Set the point&#39;s last modified time.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
bool IsCoord2Constrained()
Return bool indicating if 2nd coordinate is Constrained or not.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Status SetRefMeasure(ControlMeasure *cm)
Set the point&#39;s reference measure.
void SetLogData(ControlMeasureLogData)
This adds or updates the log data information associated with data&#39;s type.
QString description
The text description of the control network.
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
Status SetAprioriSurfacePoint(SurfacePoint aprioriSP)
This updates the apriori surface point.
A single keyword-value pair.
Definition: PvlKeyword.h:98
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:134
bool IsCoord1Constrained()
Return bool indicating if 1st coordinate is Constrained or not.
Byte swapper.
Definition: EndianSwapper.h:55
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
A single control point.
Definition: ControlPoint.h:369
void readPvlV0003(const PvlObject &network, Progress *progress=NULL)
read a version 3 Pvl control network and convert the data into control points.
void readPvlV0004(const PvlObject &network, Progress *progress=NULL)
read a version 4 Pvl control network and convert the data into control points.
QString networkID
The ID/Name of the control network.
Container for cube-like labels.
Definition: Pvl.h:135
QString GetChooserName() const
Return the chooser name.
MeasureType
Control network measurement types.
Status SetRejected(bool rejected)
Set the jigsawRejected state.
Status SetType(PointType newType)
Updates the control point&#39;s type.
QString targetName() const
Returns the target for the network.
Status SetId(QString id)
Sets the Id of the control point.
void SetDataType(NumericLogDataType newDataType)
This changes the type of this log data.
A container for the information stored in a version 1 ControlPoint.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
QString CreatedDate() const
Return the Created Date.
void write(FileName netFile)
This will write a control net file object to disk.
ControlPoint * takeFirstPoint()
Returns the first point stored in the versioner&#39;s internal list.
ControlNetHeaderV0005 m_header
Header containing information about the whole network.
Longitude GetLongitude() const
Return the body-fixed longitude for the surface point.
bool HasRefMeasure() const
Checks to see if a reference measure is set.
QString GetDateTime() const
Return the date/time the coordinate was last changed.
QVector< ControlMeasureLogData > GetLogDataEntries() const
Return all of the log data for the measure.
int IndexOfRefMeasure() const
Displacement is a signed length, usually in meters.
Definition: Displacement.h:43
QString netId() const
Returns the ID for the network.
Isis exception class.
Definition: IException.h:107
Status SetChooserName()
Set chooser name to a user who last changed the coordinate.
ControlNetVersioner()
Default constructor. Intentially un-implemented.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
bool IsEditLocked() const
Return value for p_editLock or implicit lock on reference measure.
a control measurement
Status SetCubeSerialNumber(QString newSerialNumber)
Set cube serial number.
Status SetCoordinate(double sample, double line)
Set the coordinate of the measurement.
bool m_ownsPoints
Flag if the versioner owns the control points stored in it.
Status SetDateTime()
Date Time - Creation Time.
double GetNumericalValue() const
Get the value associated with this log data.
PointType GetType() const
QString lastModified
The date and time of the control network&#39;s last modification.
Distance GetLocalRadius() const
Return the radius of the surface point.
ControlPoint * createPoint(ControlPointV0001 &point)
Create a pointer to a latest version ControlPoint from an object in a V0001 control net file...
QString userName() const
Returns the name of the last person or program to modify the network.
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
uint32_t Uint32_t(void *buf)
Swaps a 32bit unsigned integer.
A container for the information stored in a version 2 ControlPoint.
Status SetAprioriRadiusSource(RadiusSource::Source source)
This updates the source of the radius of the apriori surface point.
void readPvl(const Pvl &network, Progress *progress=NULL)
Read a Pvl control network and prepare the data to be converted into a control network.
double GetDiameter() const
Return the diameter of the crater in pixels (0 implies no crater)
void createHeader(const ControlNetHeaderV0001 header)
Create the internal header from a V0001 header.
const ControlPointFileEntryV0002 & pointData()
Access the protobuf control point data.
QString GetCubeSerialNumber() const
Return the serial number of the cube containing the coordinate.
QString GetLastModified() const
Return the last modified date.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
int numPoints() const
Returns the number of points that have been read in or are ready to write out.