Isis 3 Programmer Reference
ControlNetGraphicsItem.cpp
1 #include "ControlNetGraphicsItem.h"
2 
3 #include <float.h>
4 #include <iostream>
5 
6 #include <QDebug>
7 #include <QGraphicsScene>
8 
9 #include "Cube.h"
10 #include "ControlMeasure.h"
11 #include "ControlNet.h"
12 #include "ControlPoint.h"
13 #include "ControlPointGraphicsItem.h"
14 #include "FileName.h"
15 #include "IException.h"
16 #include "Latitude.h"
17 #include "Longitude.h"
18 #include "MosaicGraphicsView.h"
19 #include "MosaicSceneWidget.h"
20 #include "ProgressBar.h"
21 #include "Projection.h"
22 #include "Pvl.h"
23 #include "SerialNumberList.h"
24 #include "SurfacePoint.h"
25 #include "UniversalGroundMap.h"
26 
27 using namespace std;
28 
29 namespace Isis {
30  ControlNetGraphicsItem::ControlNetGraphicsItem(ControlNet *controlNet,
31  MosaicSceneWidget *mosaicScene) : QGraphicsObject() {
32  m_controlNet = controlNet;
33  m_mosaicScene = mosaicScene;
34  m_pointToScene = new QMap<ControlPoint *, QPair<QPointF, QPointF> >;
35  m_cubeToGroundMap = new QMap<QString, UniversalGroundMap *>;
36  m_serialNumbers = NULL;
37  mosaicScene->getScene()->addItem(this);
38 
39  buildChildren();
40 
41  connect(mosaicScene, SIGNAL(projectionChanged(Projection *)),
42  this, SLOT(buildChildren()));
43  connect(mosaicScene, SIGNAL(cubesChanged()),
44  this, SLOT(buildChildren()));
45 
46  setZValue(DBL_MAX);
47  }
48 
49 
50  ControlNetGraphicsItem::~ControlNetGraphicsItem() {
51  if (m_pointToScene) {
52  delete m_pointToScene;
53  m_pointToScene = NULL;
54  }
55 
56  if (m_cubeToGroundMap) {
57  QMapIterator<QString, UniversalGroundMap *> it(*m_cubeToGroundMap);
58 
59  while(it.hasNext()) {
60  it.next();
61 
62  if (it.value())
63  delete it.value();
64  }
65 
66  delete m_cubeToGroundMap;
67  m_cubeToGroundMap = NULL;
68  }
69  }
70 
71 
72  QRectF ControlNetGraphicsItem::boundingRect() const {
73  return QRectF();
74  }
75 
76 
77  void ControlNetGraphicsItem::paint(QPainter *painter,
78  const QStyleOptionGraphicsItem *style, QWidget * widget) {
79  }
80 
81 
82  QPair<QPointF, QPointF> ControlNetGraphicsItem::pointToScene(ControlPoint *cp) {
83  Projection *proj = m_mosaicScene->getProjection();
84 
85  QPointF initial;
86  QPointF adjusted;
87 
88  QPointF initialLatLon;
89  QPointF adjustedLatLon;
90 
91  QPair<QPointF, QPointF> rememberedLoc = (*m_pointToScene)[cp];
92 
93  if (!rememberedLoc.second.isNull()) {
94 // //qDebug() << "\t\t\tPoint is in list: " << cp->GetId();
95  proj->SetUniversalGround(rememberedLoc.second.y(),
96  rememberedLoc.second.x());
97  adjusted = QPointF(proj->XCoord(), -1 * proj->YCoord());
98  adjustedLatLon = rememberedLoc.second;
99 
100  if (!rememberedLoc.first.isNull()) {
101  proj->SetUniversalGround(rememberedLoc.first.y(),
102  rememberedLoc.first.x());
103  initial = QPointF(proj->XCoord(), -1 * proj->YCoord());
104  initialLatLon = rememberedLoc.first;
105  }
106  }
107  else if (proj) {
108 
109 // //qDebug() << "\t\t\telse if point not in list but proj: " << cp->GetId();
110  SurfacePoint adjSurfacePoint(cp->GetAdjustedSurfacePoint());
111  if (adjSurfacePoint.Valid()) {
112 // //qDebug() << "\t\t\tadj";
113  if (proj->SetUniversalGround(adjSurfacePoint.GetLatitude().degrees(),
114  adjSurfacePoint.GetLongitude().degrees())) {
115  adjusted = QPointF(proj->XCoord(), -1 * proj->YCoord());
116  adjustedLatLon = QPointF(adjSurfacePoint.GetLongitude().degrees(),
117  adjSurfacePoint.GetLatitude().degrees());
118  }
119  }
120 
121  SurfacePoint apriSurfacePoint(cp->GetAprioriSurfacePoint());
122  if (apriSurfacePoint.Valid()) {
123 // //qDebug() << "\t\t\tapriori";
124  if (proj->SetUniversalGround(apriSurfacePoint.GetLatitude().degrees(),
125  apriSurfacePoint.GetLongitude().degrees())) {
126  initial = QPointF(proj->XCoord(), -1 * proj->YCoord());
127  initialLatLon = QPointF(apriSurfacePoint.GetLongitude().degrees(),
128  apriSurfacePoint.GetLatitude().degrees());
129  }
130  }
131 
132  // If we have adjusted and not apriori then find camera
133  // OR if we don't have an adjusted and don't have an initial we still
134  // need an initial
135  if ((!adjusted.isNull() && initial.isNull()) ||
136  (adjusted.isNull() && initial.isNull())) {
137 // //qDebug() << "\t\t\tother if";
138  try {
139  QString sn = cp->GetReferenceSN();
140  QString filename = snToFileName(sn);
141 
142  if (filename.size() > 0) {
143  if ((*m_cubeToGroundMap)[filename] == NULL) {
144  Cube cube(FileName(filename).expanded(), "r");
145  UniversalGroundMap *groundMap = new UniversalGroundMap(cube);
146  (*m_cubeToGroundMap)[filename] = groundMap;
147  }
148 
149  if ((*m_cubeToGroundMap)[filename]->SetImage(
150  cp->GetRefMeasure()->GetSample(),
151  cp->GetRefMeasure()->GetLine())) {
152  double lat = (*m_cubeToGroundMap)[filename]->UniversalLatitude();
153  double lon = (*m_cubeToGroundMap)[filename]->UniversalLongitude();
154 
155  if (proj->SetUniversalGround(lat, lon)) {
156  initial = QPointF(proj->XCoord(), -1 * proj->YCoord());
157  initialLatLon = QPointF(lon, lat);
158  }
159  }
160  }
161  }
162  catch(IException &) {
163  }
164  }
165  }
166 
168  QPair<QPointF, QPointF> latLonResult;
169  if (!adjusted.isNull() && adjusted != initial) {
170 // //qDebug() << "\t\t\tlast if";
171  result.second = adjusted;
172  result.first = initial;
173  latLonResult.second = adjustedLatLon;
174  latLonResult.first = initialLatLon;
175  }
176  else {
177 // //qDebug() << "\t\t\tlast else";
178  result.second = initial;
179  latLonResult.second = initialLatLon;
180  }
181 
182  (*m_pointToScene)[cp] = latLonResult;
183 
184  return result;
185  }
186 
187 
188  void ControlNetGraphicsItem::clearControlPointGraphicsItem(QString pointId) {
189 
190  //qDebug()<<"ControlNetGraphicsItem::clearControlPointGraphicsItem(QString pointId)";
191  // Find control point
192 // ControlPoint *cp = m_controlNet->GetPoint(pointId);
193  m_pointToScene->clear();
194 // QPair<QPointF, QPointF> location = (*m_pointToScene)[cp];
195 // location.first.setX(0.0);
196 // location.first.setY(0.0);
197 // location.second.setX(0.0);;
198 // location.second.setY(0.0);;
199 // (*m_pointToScene)[cp] = location;
200  }
201 
202 
203  QString ControlNetGraphicsItem::snToFileName(QString sn) {
204  QString result;
205 
206  if (m_serialNumbers && m_serialNumbers->size()) {
207  try {
208  result = m_serialNumbers->fileName(sn);
209  }
210  catch(IException &) {
211  }
212  }
213 
214  return result;
215  }
216 
217 
225  bool colorByMeasureCount, int maxMeasureCount,
226  bool colorByJigsawError, double maxResidualMagnitude) {
227 
228  foreach (QGraphicsItem *child, childItems()) {
229  ((ControlPointGraphicsItem *)child)->setArrowVisible(
230  visible, colorByMeasureCount, maxMeasureCount, colorByJigsawError, maxResidualMagnitude);
231  }
232  }
233 
234 
241  QList<QGraphicsItem *> children = childItems();
242  QGraphicsItem *child;
243  foreach (child, children) {
244  if (child->scene())
245  child->scene()->removeItem(child);
246 
247  delete child;
248  child = NULL;
249  }
250 
251  if (m_controlNet) {
252  const int numCp = m_controlNet->GetNumPoints();
253 
254  if (m_serialNumbers) {
255  delete m_serialNumbers;
256  }
257 
258  m_serialNumbers = new SerialNumberList;
259 
260  QStringList cubeFiles(m_mosaicScene->cubeFileNames());
261 
262  QString filename;
263  foreach (filename, cubeFiles) {
264  try {
265  m_serialNumbers->add(filename);
266  }
267  catch(IException &) {
268  }
269  }
270 
271  ProgressBar *p = (ProgressBar *)m_mosaicScene->getProgress();
272  p->setText("Calculating CP Locations");
273  p->setRange(0, numCp - 1);
274  p->setValue(0);
275  p->setVisible(true);
276 
277  for (int cpIndex = 0; cpIndex < numCp; cpIndex ++) {
278  ControlPoint *cp = m_controlNet->GetPoint(cpIndex);
279 
280  // 1st in pair - Initial (apriori), 2nd in pair - Final
281  // Returns apriori x/y in first point, adjusted x/y in 2nd point
282  QPair<QPointF, QPointF> scenePoints = pointToScene(cp);
283 
284  new ControlPointGraphicsItem(scenePoints.second, scenePoints.first,
285  cp, m_serialNumbers, m_mosaicScene, this);
286  p->setValue(cpIndex);
287  }
288 
289  p->setVisible(false);
290  }
291  }
292 
293 
303 
304  QGraphicsItem *cpItem = NULL;
305  QPoint viewPoint = m_mosaicScene->getView()->mapFromScene(locationPoint);
306  cpItem = (QGraphicsItem *) m_mosaicScene->getView()->itemAt(viewPoint);
307 
308  ControlPoint *result = NULL;
309  if (dynamic_cast<ControlPointGraphicsItem *> (cpItem)) {
310  result = ((ControlPointGraphicsItem *)(cpItem))->controlPoint();
311  }
312  return result;
313  }
314 }
Isis::ControlNetGraphicsItem::setArrowsVisible
void setArrowsVisible(bool visible, bool colorByMeasureCount, int measureCount, bool colorByJigsawError, double residualMagnitude)
Enable/disable and configure movement arrows for all CP displays in the network.
Definition: ControlNetGraphicsItem.cpp:224
QWidget
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::ProgressBar
Definition: ProgressBar.h:15
Isis::SerialNumberList::size
int size() const
How many serial number / filename combos are in the list.
Definition: SerialNumberList.cpp:384
Isis::ControlNetGraphicsItem::findClosestControlPoint
ControlPoint * findClosestControlPoint(QPointF locationPoint)
Return the closest control point to the pointLocation.
Definition: ControlNetGraphicsItem.cpp:302
QGraphicsObject
QStringList
Isis::SerialNumberList
Serial Number list generator.
Definition: SerialNumberList.h:64
Isis::ControlPointGraphicsItem
The visual display of a single control point.
Definition: ControlPointGraphicsItem.h:45
Isis::ControlPoint
A single control point.
Definition: ControlPoint.h:354
Isis::ControlNet::GetNumPoints
int GetNumPoints() const
Return the number of control points in the network.
Definition: ControlNet.cpp:1465
Isis::SerialNumberList::add
void add(const QString &filename, bool def2filename=false)
Adds a new filename / serial number pair to the SerialNumberList.
Definition: SerialNumberList.cpp:121
Isis::IException
Isis exception class.
Definition: IException.h:91
std
Namespace for the standard library.
QPair< QPointF, QPointF >
QMap
This is free and unencumbered software released into the public domain.
Definition: CubeIoHandler.h:22
Isis::ProgressBar::setText
void setText(QString text)
Set custom text for this progress bar.
Definition: ProgressBar.cpp:32
Isis::SerialNumberList::fileName
QString fileName(const QString &sn)
Return a filename given a serial number.
Definition: SerialNumberList.cpp:399
Isis::ControlNetGraphicsItem::buildChildren
void buildChildren()
Call this to re-calculate where control points ought to lie.
Definition: ControlNetGraphicsItem.cpp:240
QGraphicsItem
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16