Isis 3 Programmer Reference
ControlNetVitals.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "ControlNetVitals.h"
10
11#include <QDateTime>
12#include <QList>
13#include <QPair>
14#include <QVariant>
15
16#include "IException.h"
17#include "IString.h"
18#include "ControlNet.h"
19#include "ControlPoint.h"
20#include "ControlMeasure.h"
21
22namespace Isis {
23
24
33 m_controlNet = cnet;
34
36
37 connect(cnet, SIGNAL(networkModified(ControlNet::ModType)),
39
40 connect(cnet, SIGNAL(newPoint(ControlPoint*)),
41 this, SLOT(addPoint(ControlPoint*)));
42 connect(cnet, SIGNAL(pointModified(ControlPoint *, ControlPoint::ModType, QVariant, QVariant)),
43 this, SLOT(pointModified(ControlPoint *, ControlPoint::ModType, QVariant, QVariant)));
44 connect(cnet, SIGNAL(pointDeleted(ControlPoint*)),
45 this, SLOT(deletePoint(ControlPoint*)));
46
47 connect(cnet, SIGNAL(newMeasure(ControlMeasure*)),
48 this, SLOT(addMeasure(ControlMeasure*)));
49 connect(cnet, SIGNAL(measureModified(ControlMeasure *, ControlMeasure::ModType, QVariant, QVariant)),
50 this, SLOT(measureModified(ControlMeasure *, ControlMeasure::ModType, QVariant, QVariant)));
51 connect(cnet, SIGNAL(measureRemoved(ControlMeasure*)),
52 this, SLOT(deleteMeasure(ControlMeasure*)));
53
54 validate();
55 }
56
57
64
66
67 m_numPoints = 0;
71
74 m_pointTypeCounts.clear();
75
79
80 foreach(ControlPoint* point, m_controlNet->GetPoints()) {
81 addPoint(point);
82 }
83
84 foreach(QString serial, m_controlNet->GetCubeSerials()) {
85 int numValidMeasures = m_controlNet->GetNumberOfValidMeasuresInImage(serial);
86 if ( !m_imageMeasureCounts.contains(numValidMeasures) ) {
87 m_imageMeasureCounts.insert(numValidMeasures, 1);
88 }
89 else {
90 m_imageMeasureCounts[numValidMeasures]++;
91 }
92 }
93 }
94
95
110 void ControlNetVitals::emitHistoryEntry(QString entry, QString id, QVariant oldValue, QVariant newValue) {
111 emit historyEntry(entry, id, oldValue, newValue, QDateTime::currentDateTime().toString());
112 }
113
114
130
131 emitHistoryEntry("Control Point Added", point->GetId(), "", "");
132 m_numPoints++;
133
134 if (point->IsIgnored()) {
136 return;
137 }
138
139 if (point->IsEditLocked()) {
141 }
142
143 m_pointTypeCounts[point->GetType()]++;
144
145 int numValidMeasures = point->GetNumValidMeasures();
146 if ( !m_pointMeasureCounts.contains(numValidMeasures) ) {
147 m_pointMeasureCounts.insert(numValidMeasures, 1);
148 }
149
150 else {
151 m_pointMeasureCounts[numValidMeasures]++;
152 }
153
155 validate();
156 }
157
158
177 QVariant oldValue, QVariant newValue) {
178
179 QString historyEntry;
180
181 switch(type) {
182 case ControlPoint::EditLockModified:
183
184 historyEntry = "Point Edit Lock Modified";
185
186 if (oldValue.toBool()) {
188 }
189
190 if (newValue.toBool()) {
192 }
193
194 emitHistoryEntry( historyEntry, point->GetId(),
195 oldValue, newValue );
196
197 break;
198
199 case ControlPoint::IgnoredModified:
200
201 historyEntry = "Point Ignored Modified";
202
203 if (oldValue.toBool()) {
205 if (point->IsEditLocked()) {
207 }
208 m_pointTypeCounts[point->GetType()]++;
209 int numValidMeasures = point->GetNumValidMeasures();
210 if ( !m_pointMeasureCounts.contains(numValidMeasures) ) {
211 m_pointMeasureCounts.insert(numValidMeasures, 1);
212 }
213 else {
214 m_pointMeasureCounts[numValidMeasures]++;
215 }
216 }
217
218 if (newValue.toBool()) {
220 if (point->IsEditLocked()) {
222 }
223 m_pointTypeCounts[point->GetType()]--;
224 int numValidMeasures = point->GetNumValidMeasures();
225 if ( --m_pointMeasureCounts[numValidMeasures] < 1 ) {
226 m_pointMeasureCounts.remove(numValidMeasures);
227 }
228 }
229
230 emitHistoryEntry( historyEntry, point->GetId(),
231 oldValue, newValue );
232
233 break;
234
235 case ControlPoint::TypeModified:
236
237 historyEntry = "Point Type Modified";
238
239 m_pointTypeCounts[ControlPoint::PointType(oldValue.toInt())]--;
240 m_pointTypeCounts[ControlPoint::PointType(newValue.toInt())]++;
241
242 emitHistoryEntry( historyEntry, point->GetId(),
245
246 break;
247
248 default:
249 // no operation
250 break;
251 }
252
253 validate();
254
255 }
256
257
266 return m_controlNet->GetPoint(id);
267 }
268
269
286
287 emitHistoryEntry("Control Point Deleted", point->GetId(), "", "");
288 m_numPoints--;
289
290 if (point->IsIgnored()) {
292 validate();
293 return;
294 }
295 if (point->IsEditLocked()) {
297 }
298
299 m_pointTypeCounts[point->GetType()]--;
300
301 int numValidMeasures= point->GetNumValidMeasures();
302 if ( --m_pointMeasureCounts[numValidMeasures] < 1 ) {
303 m_pointMeasureCounts.remove(numValidMeasures);
304 }
305
306 validate();
307 }
308
309
328 emitHistoryEntry("Control Measure Added", measure->GetCubeSerialNumber(), "", "");
329
331
332 addMeasureToCounts(measure);
333
334 validate();
335 }
336
337
353 void ControlNetVitals::measureModified(ControlMeasure *measure, ControlMeasure::ModType type, QVariant oldValue, QVariant newValue) {
354
355 QString historyEntry;
356
357 switch (type) {
358 case ControlMeasure::IgnoredModified:
359
360 historyEntry = "Measure Ignored Modified";
361
362 if ( !oldValue.toBool() && newValue.toBool() ) {
363 return removeMeasureFromCounts(measure);
364 }
365 else if ( oldValue.toBool() && !newValue.toBool() ) {
366 return addMeasureToCounts(measure);
367 }
368 break;
369
370 default:
371 // No operation.
372 break;
373 }
374
375 ControlNetVitals::emitHistoryEntry(historyEntry, measure->GetCubeSerialNumber(), "", "");
376 validate();
377 }
378
379
391
392 emitHistoryEntry("Control Measure Deleted", measure->GetCubeSerialNumber(), "", "");
393
395
397
398 validate();
399 }
400
401
408 ControlPoint *point = measure->Parent();
409 if (point) {
410 // By this time, the measure has been added to its parent point, so the
411 // old count is the current count minus one.
412 int numValidMeasures = point->GetNumValidMeasures();
413 if ( --m_pointMeasureCounts[numValidMeasures] < 1 ) {
414 m_pointMeasureCounts.remove(numValidMeasures);
415 }
416 if ( !m_pointMeasureCounts.contains(numValidMeasures + 1) ) {
417 m_pointMeasureCounts.insert(numValidMeasures + 1, 1);
418 }
419 else {
420 m_pointMeasureCounts[numValidMeasures + 1]++;
421 }
422 }
423
424 QString serial = measure->GetCubeSerialNumber();
425 int numValidMeasures = m_controlNet->GetNumberOfValidMeasuresInImage(serial);
426 if ( --m_imageMeasureCounts[numValidMeasures - 1] < 1 ) {
427 m_imageMeasureCounts.remove(numValidMeasures);
428 }
429 if ( !m_imageMeasureCounts.contains(numValidMeasures) ) {
430 m_imageMeasureCounts.insert(numValidMeasures, 1);
431 }
432 else {
433 m_imageMeasureCounts[numValidMeasures]++;
434 }
435 }
436
437
444 ControlPoint *point = measure->Parent();
445 if (point) {
446 // By this time, the measure is still a valid measure in the parent control point.
447 int numValidMeasures = point->GetNumValidMeasures();
448
449 if ( --m_pointMeasureCounts[numValidMeasures] < 1 ) {
450 m_pointMeasureCounts.remove(numValidMeasures);
451 }
452 if ( !m_pointMeasureCounts.contains(numValidMeasures - 1) ) {
453 m_pointMeasureCounts.insert(numValidMeasures - 1, 1);
454 }
455 else {
456 m_pointMeasureCounts[numValidMeasures - 1]++;
457 }
458 }
459
460 QString serial = measure->GetCubeSerialNumber();
461 int numValidMeasures = m_controlNet->GetNumberOfValidMeasuresInImage(serial);
462
463 if ( --m_imageMeasureCounts[numValidMeasures] < 1 ) {
464 m_imageMeasureCounts.remove(numValidMeasures);
465 }
466
467 if ( !m_imageMeasureCounts.contains(numValidMeasures - 1) ) {
468 m_imageMeasureCounts.insert(numValidMeasures - 1, 1);
469 }
470 else {
471 m_imageMeasureCounts[numValidMeasures - 1]++;
472 }
473 }
474
475
488
489 QString historyEntry;
490
491 switch (type) {
492 case ControlNet::Swapped:
493 emitHistoryEntry("Control Net Swapped", m_controlNet->GetNetworkId(), "", "");
495 break;
496 case ControlNet::GraphModified:
497 emitHistoryEntry("Control Net Graph Modified", m_controlNet->GetNetworkId(), "", "");
499 break;
500 default:
501 // No operation.
502 break;
503 }
504 validate();
505 }
506
507
513
514
522 return numIslands() > 1;
523 }
524
525
533 return m_islandList.size();
534 }
535
536
544 const QList< QList<QString> > &ControlNetVitals::getIslands() {
545 return m_islandList;
546 }
547
548
555 return m_numPoints;
556 }
557
558
567
568
577
578
587
588
597
598
607
608
618 int count = 0;
619
621 while (i != m_pointMeasureCounts.constEnd()) {
622 if (i.key() >= num ) {
623 break;
624 }
625 count += i.value();
626 ++i;
627 }
628
629 return count;
630 }
631
632
639 return m_controlNet->GetCubeSerials().size();
640 }
641
642
651
652
662 int count = 0;
663
665 while (i != m_imageMeasureCounts.constEnd()) {
666 if (i.key() >= num ) {
667 break;
668 }
669 count += i.value();
670 ++i;
671 }
672 return count;
673 }
674
675
676 // REFACTOR
686 return 0;
687 }
688
689
697 }
698
699
705 QList<ControlPoint*> ControlNetVitals::getAllPoints() {
706 return m_controlNet->GetPoints();
707 }
708
709
715 QList<ControlPoint*> ControlNetVitals::getIgnoredPoints() {
716 QList<ControlPoint*> ignoredPoints;
717 foreach(ControlPoint* point, m_controlNet->GetPoints()) {
718 if (point->IsIgnored()) ignoredPoints.append(point);
719 }
720 return ignoredPoints;
721 }
722
723
729 QList<ControlPoint*> ControlNetVitals::getLockedPoints() {
730 QList<ControlPoint*> lockedPoints;
731 foreach(ControlPoint* point, m_controlNet->GetPoints()) {
732 if (!point->IsIgnored() && point->IsEditLocked()) lockedPoints.append(point);
733 }
734 return lockedPoints;
735 }
736
737
743 QList<ControlPoint*> ControlNetVitals::getFixedPoints() {
744 QList<ControlPoint*> fixedPoints;
745 foreach(ControlPoint* point, m_controlNet->GetPoints()) {
746 if (!point->IsIgnored() && point->GetType() == ControlPoint::Fixed) fixedPoints.append(point);
747 }
748 return fixedPoints;
749 }
750
751
758 QList<ControlPoint*> constrainedPoints;
759 foreach(ControlPoint* point, m_controlNet->GetPoints()) {
760 if (!point->IsIgnored() && point->GetType() == ControlPoint::Constrained) constrainedPoints.append(point);
761 }
762 return constrainedPoints;
763 }
764
765
771 QList<ControlPoint*> ControlNetVitals::getFreePoints() {
772 QList<ControlPoint*> freePoints;
773 foreach(ControlPoint* point, m_controlNet->GetPoints()) {
774 if (!point->IsIgnored() && point->GetType() == ControlPoint::Free) freePoints.append(point);
775 }
776 return freePoints;
777 }
778
779
789 QList<ControlPoint*> belowThreshold;
790 foreach(ControlPoint* point, m_controlNet->GetPoints()) {
791 if (!point->IsIgnored() && point->GetNumMeasures() < num) belowThreshold.append(point);
792 }
793 return belowThreshold;
794 }
795
796
807 QList<QString> imagesBelowThreshold;
808 foreach(QString serial, m_controlNet->GetCubeSerials()) {
809 if (m_controlNet->GetValidMeasuresInCube(serial).size() < num) {
810 imagesBelowThreshold.append(serial);
811 }
812 }
813 return imagesBelowThreshold;
814 }
815
816
827 QList<QString> list;
828 return list;
829 }
830
831
840 return m_status;
841 }
842
843
856
857
866 return m_controlNet->GetNetworkId();
867 }
868
869
883
884 QString status = "";
885 QString details = "";
886 if (hasIslands()) {
887 status = "Broken!";
888 details = "This network has " + toString(numIslands()) + " islands.";
889 }
890 else {
891
893 status = "Weak!";
894 details += "This network has " + toString(numPointsBelowMeasureThreshold()) + " point(s) with less than 3 measures\n";
895 }
896
898 status = "Weak!";
899 details += "This network has " + toString(numImagesBelowMeasureThreshold()) + " image(s) with less than 3 measures\n";
900 }
901
902 if (numImagesBelowHullTolerance() > 0) {
903 status = "Weak!";
904 details += "This network has " + toString(numImagesBelowHullTolerance()) + " image(s) below the Convex Hull Tolerance of 75%\n";
905 }
906
907 if (status.isEmpty()) {
908 status = "Healthy!";
909 details = "This network is healthy.";
910 }
911 }
912 m_status = status;
913 m_statusDetails = details;
914 emit networkChanged();
915 }
916
917}
a control measurement
ModType
Control Measure Modification Types.
a control network
Definition ControlNet.h:258
int GetNumMeasures() const
Returns the total number of measures for all control points in the network.
QList< QList< QString > > GetSerialConnections() const
This method searches through all the cube serial numbers in the network.
int GetNumberOfValidMeasuresInImage(const QString &serialNumber)
Return the number of measures in image specified by serialNumber.
ModType
Control Point Modification Types.
Definition ControlNet.h:275
QList< ControlPoint * > GetPoints()
Return QList of all the ControlPoints in the network.
QList< QString > GetCubeSerials() const
Use this method to get a complete list of all the cube serial numbers in the network.
QList< ControlMeasure * > GetValidMeasuresInCube(QString serialNumber)
Get all the valid measures pertaining to a given cube serial number.
int m_numPointsIgnored
The number of ignored points in the network.
void addMeasureToCounts(ControlMeasure *measure)
Add a measure to the internal counters.
QList< QString > getCubeSerials()
This method is designed to return all cube serials present in the Control Network.
QList< ControlPoint * > getAllPoints()
This method is designed to return all points in the Control Network.
QList< ControlPoint * > getFixedPoints()
This method is designed to return all fixed points in the Control Network.
void deletePoint(ControlPoint *)
This SLOT is designed to intercept the removePoint() signal emitted by a Control Network whenever a p...
int m_numMeasures
The number of measures in the network.
void addPoint(ControlPoint *)
This SLOT is designed to intercept the newPoint() signal emitted from a ControlNetwork whenever a new...
ControlNet * m_controlNet
The Control Network that the vitals class is observing.
void emitHistoryEntry(QString entry, QString id, QVariant oldValue, QVariant newValue)
This method is designed to be called whenever a modification is made to the network,...
QString getNetworkId()
This method is designed to return networkId of the observed Control Network.
ControlPoint * getPoint(QString id)
This method is designed to return the Control Point with the associated point id from the Control Net...
int numFixedPoints()
This method is designed to return the number of fixed points in the Control Network.
QString getStatus()
This method is designed to return the current status of the network.
QMap< int, int > m_pointMeasureCounts
The measureCount maps track how many points/images have how many measures. For instance,...
void deleteMeasure(ControlMeasure *)
This SLOT is designed to intercept the measureRemoved() signal emitted by a Control Network whenever ...
int numIgnoredPoints()
This method is designed to return the number of ignored points in the Control Network.
QMap< ControlPoint::PointType, int > m_pointTypeCounts
The pointTypeCounts operates in the same fashion as the above two, except that the key would be the C...
int numLockedPoints()
This method is designed to return the number of edit locked points in the Control Network.
virtual ~ControlNetVitals()
De-constructor.
int numPoints()
This method is designed to return the number of points in the Control Network.
ControlNetVitals(ControlNet *net)
Constructs a ControlNetVitals object from a ControlNet.
void validateNetwork(ControlNet::ModType)
This SLOT is designed to intercept the networkModified() signal emitted by a Control Network whenever...
QString getStatusDetails()
This method is designed to return details for the status of the network.
bool hasIslands()
This method is designed to return true if islands exist in the ControlNet Graph and False otherwise.
QList< QString > getImagesBelowHullTolerance(int num=75)
This method is designed to return a QList containing cube serials for all images that fall below a co...
int numImagesBelowMeasureThreshold(int num=3)
This method is designed to return the number of images that fall below a measure threshold.
int numImages()
This method is designed to return the number of images in the Control Network.
const QList< QList< QString > > & getIslands()
This method is designed to return a QList containing each island present in the ControlNet.
void removeMeasureFromCounts(ControlMeasure *measure)
Remove a measure from the internal counters.
QString m_status
The string representing the status of the net. Healthy, Weak, or Broken.
void measureModified(ControlMeasure *, ControlMeasure::ModType, QVariant, QVariant)
This SLOT is designed to intercept the measureModified() signal emitted by a Control Network whenever...
void validate()
This method is designed to evaluate the current vitals of the network to determine if any weaknesses ...
void addMeasure(ControlMeasure *)
This SLOT is designed to intercept the newMeasure() signal emitted by a Control Network whenever a me...
int numFreePoints()
This method is designed to return the number of free points in the Control Network.
int numPointsBelowMeasureThreshold(int num=3)
This method is designed to return the number of points that fall below a measure threshold.
int numImagesBelowHullTolerance(int tolerance=75)
This method is designed to return the number of images that fall below a hull tolerance.
QList< QString > getImagesBelowMeasureThreshold(int num=3)
This method is designed to return a QList containing cube serials for all images that fall below a me...
QList< ControlPoint * > getIgnoredPoints()
This method is designed to return all ignored points in the Control Network.
QList< ControlPoint * > getLockedPoints()
This method is designed to return all edit locked points in the Control Network.
QList< QList< QString > > m_islandList
A QList containing every island in the net. Each island consists of a QList containing All cube seria...
QMap< int, int > m_imageMeasureCounts
The same is true for imageMeasureCounts, except for images.
int m_numPointsLocked
The number of edit locked points in the network.
QList< ControlPoint * > getFreePoints()
This method is designed to return all free points in the Control Network.
QList< ControlPoint * > getConstrainedPoints()
This method is designed to return all constrained points in the Control Network.
void pointModified(ControlPoint *, ControlPoint::ModType, QVariant, QVariant)
This SLOT is designed to receive a signal emitted from the Control Network whenever a modification is...
QList< ControlPoint * > getPointsBelowMeasureThreshold(int num=3)
This method is designed to return all points that fall below a measure threshold.
int numIslands()
This method is designed to return the number of islands that exist in the ControlNet Graph.
QString m_statusDetails
The string providing details into the status of the network.
void initializeVitals()
This will initialize all necessary values and set up the point measure and image measure QMaps approp...
int m_numPoints
The number of points in the network.
int numConstrainedPoints()
This method is designed to return the number of constrained points in the Control Network.
int numMeasures()
This method is designed to return the number of measures in the Control Network.
A single control point.
ModType
Control Point Modification Types.
int GetNumValidMeasures() const
PointType GetType() const
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.
static QString PointTypeToString(PointType type)
Obtain a string representation of a given PointType.
QString GetId() const
Return the Id of the control point.
This is free and unencumbered software released into the public domain.
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