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