Isis 3 Programmer Reference
ControlNetVitals.cpp
1 #include "ControlNetVitals.h"
2 
3 #include <QDateTime>
4 #include <QList>
5 #include <QPair>
6 #include <QVariant>
7 
8 #include "IException.h"
9 #include "IString.h"
10 #include "ControlNet.h"
11 #include "ControlPoint.h"
12 #include "ControlMeasure.h"
13 
14 namespace Isis {
15 
16 
25  m_controlNet = cnet;
26 
28 
29  connect(cnet, SIGNAL(networkModified(ControlNet::ModType)),
31 
32  connect(cnet, SIGNAL(newPoint(ControlPoint*)),
33  this, SLOT(addPoint(ControlPoint*)));
34  connect(cnet, SIGNAL(pointModified(ControlPoint *, ControlPoint::ModType, QVariant, QVariant)),
35  this, SLOT(pointModified(ControlPoint *, ControlPoint::ModType, QVariant, QVariant)));
36  connect(cnet, SIGNAL(pointDeleted(ControlPoint*)),
37  this, SLOT(deletePoint(ControlPoint*)));
38 
39  connect(cnet, SIGNAL(newMeasure(ControlMeasure*)),
40  this, SLOT(addMeasure(ControlMeasure*)));
41  connect(cnet, SIGNAL(measureModified(ControlMeasure *, ControlMeasure::ModType, QVariant, QVariant)),
42  this, SLOT(measureModified(ControlMeasure *, ControlMeasure::ModType, QVariant, QVariant)));
43  connect(cnet, SIGNAL(measureRemoved(ControlMeasure*)),
44  this, SLOT(deleteMeasure(ControlMeasure*)));
45 
46  validate();
47  }
48 
49 
56 
58 
59  m_numPoints = 0;
63 
64  m_pointMeasureCounts.clear();
65  m_imageMeasureCounts.clear();
66  m_pointTypeCounts.clear();
67 
71 
72  foreach(ControlPoint* point, m_controlNet->GetPoints()) {
73  addPoint(point);
74  }
75 
76  foreach(QString serial, m_controlNet->GetCubeSerials()) {
77  int numValidMeasures = m_controlNet->GetNumberOfValidMeasuresInImage(serial);
78  if ( !m_imageMeasureCounts.contains(numValidMeasures) ) {
79  m_imageMeasureCounts.insert(numValidMeasures, 1);
80  }
81  else {
82  m_imageMeasureCounts[numValidMeasures]++;
83  }
84  }
85  }
86 
87 
102  void ControlNetVitals::emitHistoryEntry(QString entry, QString id, QVariant oldValue, QVariant newValue) {
103  emit historyEntry(entry, id, oldValue, newValue, QDateTime::currentDateTime().toString());
104  }
105 
106 
122 
123  emitHistoryEntry("Control Point Added", point->GetId(), "", "");
124  m_numPoints++;
125 
126  if (point->IsIgnored()) {
128  return;
129  }
130 
131  if (point->IsEditLocked()) {
133  }
134 
135  m_pointTypeCounts[point->GetType()]++;
136 
137  int numValidMeasures = point->GetNumValidMeasures();
138  if ( !m_pointMeasureCounts.contains(numValidMeasures) ) {
139  m_pointMeasureCounts.insert(numValidMeasures, 1);
140  }
141 
142  else {
143  m_pointMeasureCounts[numValidMeasures]++;
144  }
145 
147  validate();
148  }
149 
150 
169  QVariant oldValue, QVariant newValue) {
170 
171  QString historyEntry;
172 
173  switch(type) {
174  case ControlPoint::EditLockModified:
175 
176  historyEntry = "Point Edit Lock Modified";
177 
178  if (oldValue.toBool()) {
180  }
181 
182  if (newValue.toBool()) {
184  }
185 
186  emitHistoryEntry( historyEntry, point->GetId(),
187  oldValue, newValue );
188 
189  break;
190 
191  case ControlPoint::IgnoredModified:
192 
193  historyEntry = "Point Ignored Modified";
194 
195  if (oldValue.toBool()) {
197  if (point->IsEditLocked()) {
199  }
200  m_pointTypeCounts[point->GetType()]++;
201  int numValidMeasures = point->GetNumValidMeasures();
202  if ( !m_pointMeasureCounts.contains(numValidMeasures) ) {
203  m_pointMeasureCounts.insert(numValidMeasures, 1);
204  }
205  else {
206  m_pointMeasureCounts[numValidMeasures]++;
207  }
208  }
209 
210  if (newValue.toBool()) {
212  if (point->IsEditLocked()) {
214  }
215  m_pointTypeCounts[point->GetType()]--;
216  int numValidMeasures = point->GetNumValidMeasures();
217  if ( --m_pointMeasureCounts[numValidMeasures] < 1 ) {
218  m_pointMeasureCounts.remove(numValidMeasures);
219  }
220  }
221 
222  emitHistoryEntry( historyEntry, point->GetId(),
223  oldValue, newValue );
224 
225  break;
226 
227  case ControlPoint::TypeModified:
228 
229  historyEntry = "Point Type Modified";
230 
231  m_pointTypeCounts[ControlPoint::PointType(oldValue.toInt())]--;
232  m_pointTypeCounts[ControlPoint::PointType(newValue.toInt())]++;
233 
234  emitHistoryEntry( historyEntry, point->GetId(),
237 
238  break;
239 
240  default:
241  // no operation
242  break;
243  }
244 
245  validate();
246 
247  }
248 
249 
258  return m_controlNet->GetPoint(id);
259  }
260 
261 
278 
279  emitHistoryEntry("Control Point Deleted", point->GetId(), "", "");
280  m_numPoints--;
281 
282  if (point->IsIgnored()) {
284  validate();
285  return;
286  }
287  if (point->IsEditLocked()) {
289  }
290 
291  m_pointTypeCounts[point->GetType()]--;
292 
293  int numValidMeasures= point->GetNumValidMeasures();
294  if ( --m_pointMeasureCounts[numValidMeasures] < 1 ) {
295  m_pointMeasureCounts.remove(numValidMeasures);
296  }
297 
298  validate();
299  }
300 
301 
320  emitHistoryEntry("Control Measure Added", measure->GetCubeSerialNumber(), "", "");
321 
322  m_numMeasures++;
323 
324  addMeasureToCounts(measure);
325 
326  validate();
327  }
328 
329 
345  void ControlNetVitals::measureModified(ControlMeasure *measure, ControlMeasure::ModType type, QVariant oldValue, QVariant newValue) {
346 
347  QString historyEntry;
348 
349  switch (type) {
350  case ControlMeasure::IgnoredModified:
351 
352  historyEntry = "Measure Ignored Modified";
353 
354  if ( !oldValue.toBool() && newValue.toBool() ) {
355  return removeMeasureFromCounts(measure);
356  }
357  else if ( oldValue.toBool() && !newValue.toBool() ) {
358  return addMeasureToCounts(measure);
359  }
360  break;
361 
362  default:
363  // No operation.
364  break;
365  }
366 
367  ControlNetVitals::emitHistoryEntry(historyEntry, measure->GetCubeSerialNumber(), "", "");
368  validate();
369  }
370 
371 
383 
384  emitHistoryEntry("Control Measure Deleted", measure->GetCubeSerialNumber(), "", "");
385 
386  m_numMeasures--;
387 
388  removeMeasureFromCounts(measure);
389 
390  validate();
391  }
392 
393 
400  ControlPoint *point = measure->Parent();
401  if (point) {
402  // By this time, the measure has been added to its parent point, so the
403  // old count is the current count minus one.
404  int numValidMeasures = point->GetNumValidMeasures();
405  if ( --m_pointMeasureCounts[numValidMeasures] < 1 ) {
406  m_pointMeasureCounts.remove(numValidMeasures);
407  }
408  if ( !m_pointMeasureCounts.contains(numValidMeasures + 1) ) {
409  m_pointMeasureCounts.insert(numValidMeasures + 1, 1);
410  }
411  else {
412  m_pointMeasureCounts[numValidMeasures + 1]++;
413  }
414  }
415 
416  QString serial = measure->GetCubeSerialNumber();
417  int numValidMeasures = m_controlNet->GetNumberOfValidMeasuresInImage(serial);
418  if ( --m_imageMeasureCounts[numValidMeasures - 1] < 1 ) {
419  m_imageMeasureCounts.remove(numValidMeasures);
420  }
421  if ( !m_imageMeasureCounts.contains(numValidMeasures) ) {
422  m_imageMeasureCounts.insert(numValidMeasures, 1);
423  }
424  else {
425  m_imageMeasureCounts[numValidMeasures]++;
426  }
427  }
428 
429 
436  ControlPoint *point = measure->Parent();
437  if (point) {
438  // By this time, the measure is still a valid measure in the parent control point.
439  int numValidMeasures = point->GetNumValidMeasures();
440 
441  if ( --m_pointMeasureCounts[numValidMeasures] < 1 ) {
442  m_pointMeasureCounts.remove(numValidMeasures);
443  }
444  if ( !m_pointMeasureCounts.contains(numValidMeasures - 1) ) {
445  m_pointMeasureCounts.insert(numValidMeasures - 1, 1);
446  }
447  else {
448  m_pointMeasureCounts[numValidMeasures - 1]++;
449  }
450  }
451 
452  QString serial = measure->GetCubeSerialNumber();
453  int numValidMeasures = m_controlNet->GetNumberOfValidMeasuresInImage(serial);
454 
455  if ( --m_imageMeasureCounts[numValidMeasures] < 1 ) {
456  m_imageMeasureCounts.remove(numValidMeasures);
457  }
458 
459  if ( !m_imageMeasureCounts.contains(numValidMeasures - 1) ) {
460  m_imageMeasureCounts.insert(numValidMeasures - 1, 1);
461  }
462  else {
463  m_imageMeasureCounts[numValidMeasures - 1]++;
464  }
465  }
466 
467 
480 
481  QString historyEntry;
482 
483  switch (type) {
484  case ControlNet::Swapped:
485  emitHistoryEntry("Control Net Swapped", m_controlNet->GetNetworkId(), "", "");
487  break;
488  case ControlNet::GraphModified:
489  emitHistoryEntry("Control Net Graph Modified", m_controlNet->GetNetworkId(), "", "");
491  break;
492  default:
493  // No operation.
494  break;
495  }
496  validate();
497  }
498 
499 
504  }
505 
506 
514  return numIslands() > 1;
515  }
516 
517 
525  return m_islandList.size();
526  }
527 
528 
537  return m_islandList;
538  }
539 
540 
547  return m_numPoints;
548  }
549 
550 
557  return m_numPointsIgnored;
558  }
559 
560 
567  return m_numPointsLocked;
568  }
569 
570 
578  }
579 
580 
588  }
589 
590 
598  }
599 
600 
610  int count = 0;
611 
613  while (i != m_pointMeasureCounts.constEnd()) {
614  if (i.key() >= num ) {
615  break;
616  }
617  count += i.value();
618  ++i;
619  }
620 
621  return count;
622  }
623 
624 
631  return m_controlNet->GetCubeSerials().size();
632  }
633 
634 
641  return m_numMeasures;
642  }
643 
644 
654  int count = 0;
655 
657  while (i != m_imageMeasureCounts.constEnd()) {
658  if (i.key() >= num ) {
659  break;
660  }
661  count += i.value();
662  ++i;
663  }
664  return count;
665  }
666 
667 
668  // REFACTOR
678  return 0;
679  }
680 
681 
688  return m_controlNet->GetCubeSerials();
689  }
690 
691 
698  return m_controlNet->GetPoints();
699  }
700 
701 
708  QList<ControlPoint*> ignoredPoints;
709  foreach(ControlPoint* point, m_controlNet->GetPoints()) {
710  if (point->IsIgnored()) ignoredPoints.append(point);
711  }
712  return ignoredPoints;
713  }
714 
715 
722  QList<ControlPoint*> lockedPoints;
723  foreach(ControlPoint* point, m_controlNet->GetPoints()) {
724  if (!point->IsIgnored() && point->IsEditLocked()) lockedPoints.append(point);
725  }
726  return lockedPoints;
727  }
728 
729 
736  QList<ControlPoint*> fixedPoints;
737  foreach(ControlPoint* point, m_controlNet->GetPoints()) {
738  if (!point->IsIgnored() && point->GetType() == ControlPoint::Fixed) fixedPoints.append(point);
739  }
740  return fixedPoints;
741  }
742 
743 
750  QList<ControlPoint*> constrainedPoints;
751  foreach(ControlPoint* point, m_controlNet->GetPoints()) {
752  if (!point->IsIgnored() && point->GetType() == ControlPoint::Constrained) constrainedPoints.append(point);
753  }
754  return constrainedPoints;
755  }
756 
757 
764  QList<ControlPoint*> freePoints;
765  foreach(ControlPoint* point, m_controlNet->GetPoints()) {
766  if (!point->IsIgnored() && point->GetType() == ControlPoint::Free) freePoints.append(point);
767  }
768  return freePoints;
769  }
770 
771 
781  QList<ControlPoint*> belowThreshold;
782  foreach(ControlPoint* point, m_controlNet->GetPoints()) {
783  if (!point->IsIgnored() && point->GetNumMeasures() < num) belowThreshold.append(point);
784  }
785  return belowThreshold;
786  }
787 
788 
799  QList<QString> imagesBelowThreshold;
800  foreach(QString serial, m_controlNet->GetCubeSerials()) {
801  if (m_controlNet->GetValidMeasuresInCube(serial).size() < num) {
802  imagesBelowThreshold.append(serial);
803  }
804  }
805  return imagesBelowThreshold;
806  }
807 
808 
819  QList<QString> list;
820  return list;
821  }
822 
823 
832  return m_status;
833  }
834 
835 
846  return m_statusDetails;
847  }
848 
849 
858  return m_controlNet->GetNetworkId();
859  }
860 
861 
875 
876  QString status = "";
877  QString details = "";
878  if (hasIslands()) {
879  status = "Broken!";
880  details = "This network has " + toString(numIslands()) + " islands.";
881  }
882  else {
883 
884  if (numPointsBelowMeasureThreshold() > 0) {
885  status = "Weak!";
886  details += "This network has " + toString(numPointsBelowMeasureThreshold()) + " point(s) with less than 3 measures\n";
887  }
888 
889  if (numImagesBelowMeasureThreshold() > 0) {
890  status = "Weak!";
891  details += "This network has " + toString(numImagesBelowMeasureThreshold()) + " image(s) with less than 3 measures\n";
892  }
893 
894  if (numImagesBelowHullTolerance() > 0) {
895  status = "Weak!";
896  details += "This network has " + toString(numImagesBelowHullTolerance()) + " image(s) below the Convex Hull Tolerance of 75%\n";
897  }
898 
899  if (status.isEmpty()) {
900  status = "Healthy!";
901  details = "This network is healthy.";
902  }
903  }
904  m_status = status;
905  m_statusDetails = details;
906  emit networkChanged();
907  }
908 
909 }
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...
ControlNet * m_controlNet
The Control Network that the vitals class is observing.
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 * > getLockedPoints()
This method is designed to return all edit locked points in the Control Network.
QList< ControlPoint * > getFreePoints()
This method is designed to return all free points in the Control Network.
int numImagesBelowMeasureThreshold(int num=3)
This method is designed to return the number of images that fall below a measure threshold.
void measureModified(ControlMeasure *, ControlMeasure::ModType, QVariant, QVariant)
This SLOT is designed to intercept the measureModified() signal emitted by a Control Network whenever...
ControlNetVitals(ControlNet *net)
Constructs a ControlNetVitals object from a ControlNet.
A Constrained point is a Control Point whose lat/lon/radius is somewhat established and should not be...
Definition: ControlPoint.h:391
A Fixed point is a Control Point whose lat/lon is well established and should not be changed...
Definition: ControlPoint.h:386
int numIslands()
This method is designed to return the number of islands that exist in the ControlNet Graph...
int m_numPointsIgnored
The number of ignored points in the network.
virtual ~ControlNetVitals()
De-constructor.
QList< ControlPoint * > getPointsBelowMeasureThreshold(int num=3)
This method is designed to return all points that fall below a measure threshold. ...
ModType
Control Measure Modification Types.
QString getStatusDetails()
This method is designed to return details for the status of the network.
QList< ControlPoint * > getAllPoints()
This method is designed to return all points in the Control Network.
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 numPoints()
This method is designed to return the number of points in the Control Network.
QString m_status
The string representing the status of the net. Healthy, Weak, or Broken.
void addPoint(ControlPoint *)
This SLOT is designed to intercept the newPoint() signal emitted from a ControlNetwork whenever a new...
PointType
These are the valid &#39;types&#39; of point.
Definition: ControlPoint.h:379
QList< QList< QString > > GetSerialConnections() const
This method searches through all the cube serial numbers in the network.
Definition: ControlNet.cpp:959
QList< ControlPoint *> GetPoints()
Return QList of all the ControlPoints in the network.
QString getNetworkId()
This method is designed to return networkId of the observed Control Network.
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, or any of it&#39;s control points or measures.
void validateNetwork(ControlNet::ModType)
This SLOT is designed to intercept the networkModified() signal emitted by a Control Network whenever...
bool hasIslands()
This method is designed to return true if islands exist in the ControlNet Graph and False otherwise...
void validate()
This method is designed to evaluate the current vitals of the network to determine if any weaknesses ...
int m_numPointsLocked
The number of edit locked points in the network.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
int GetNumValidMeasures() const
void removeMeasureFromCounts(ControlMeasure *measure)
Remove a measure from the internal counters.
void deleteMeasure(ControlMeasure *)
This SLOT is designed to intercept the measureRemoved() signal emitted by a Control Network whenever ...
const QList< QList< QString > > & getIslands()
This method is designed to return a QList containing each island present in the ControlNet.
A Free point is a Control Point that identifies common measurements between two or more cubes...
Definition: ControlPoint.h:399
QString getStatus()
This method is designed to return the current status of the network.
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.
a control network
Definition: ControlNet.h:271
int m_numMeasures
The number of measures in the network.
QString GetId() const
Return the Id of the control point.
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 numIgnoredPoints()
This method is designed to return the number of ignored points in the Control Network.
QList< ControlPoint * > getIgnoredPoints()
This method is designed to return all ignored points in the Control Network.
int numLockedPoints()
This method is designed to return the number of edit locked points in the Control Network...
QMap< int, int > m_pointMeasureCounts
The measureCount maps track how many points/images have how many measures. For instance, if I wanted to know how many points have 3 measures I would query the m_pointMeasureCounts with a key of 3 and it would return how many points have 3 measures.
int numImages()
This method is designed to return the number of images in the Control Network.
QString m_statusDetails
The string providing details into the status of the network.
int GetNumMeasures() const
Returns the total number of measures for all control points in the network.
void addMeasureToCounts(ControlMeasure *measure)
Add a measure to the internal counters.
QList< QString > GetCubeSerials() const
Use this method to get a complete list of all the cube serial numbers in the network.
A single control point.
Definition: ControlPoint.h:369
void deletePoint(ControlPoint *)
This SLOT is designed to intercept the removePoint() signal emitted by a Control Network whenever a p...
QList< ControlPoint * > getConstrainedPoints()
This method is designed to return all constrained points in the Control Network.
ModType
Control Point Modification Types.
Definition: ControlNet.h:288
void addMeasure(ControlMeasure *)
This SLOT is designed to intercept the newMeasure() signal emitted by a Control Network whenever a me...
QList< ControlPoint * > getFixedPoints()
This method is designed to return all fixed points in the Control Network.
ModType
Control Point Modification Types.
Definition: ControlPoint.h:446
ControlPoint * getPoint(QString id)
This method is designed to return the Control Point with the associated point id from the Control Net...
QMap< int, int > m_imageMeasureCounts
The same is true for imageMeasureCounts, except for images.
void initializeVitals()
This will initialize all necessary values and set up the point measure and image measure QMaps approp...
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
a control measurement
int numConstrainedPoints()
This method is designed to return the number of constrained 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...
int numMeasures()
This method is designed to return the number of measures in the Control Network.
PointType GetType() const
QList< QString > getCubeSerials()
This method is designed to return all cube serials present in the Control Network.
int numFixedPoints()
This method is designed to return the number of fixed points in the Control Network.
static QString PointTypeToString(PointType type)
Obtain a string representation of a given PointType.
QString GetCubeSerialNumber() const
Return the serial number of the cube containing the coordinate.
int GetNumberOfValidMeasuresInImage(const QString &serialNumber)
Return the number of measures in image specified by serialNumber.
int m_numPoints
The number of points in the network.
int numImagesBelowHullTolerance(int tolerance=75)
This method is designed to return the number of images that fall below a hull tolerance.
QList< ControlMeasure *> GetValidMeasuresInCube(QString serialNumber)
Get all the valid measures pertaining to a given cube serial number.