1 #include "ControlNetGraphicsItem.h"
7 #include <QGraphicsScene>
13 #include "ControlPointGraphicsItem.h"
18 #include "MosaicGraphicsView.h"
19 #include "MosaicSceneWidget.h"
20 #include "ProgressBar.h"
30 ControlNetGraphicsItem::ControlNetGraphicsItem(ControlNet *controlNet,
32 m_controlNet = controlNet;
33 m_mosaicScene = mosaicScene;
36 m_serialNumbers = NULL;
37 mosaicScene->getScene()->addItem(
this);
41 connect(mosaicScene, SIGNAL(projectionChanged(Projection *)),
42 this, SLOT(buildChildren()));
43 connect(mosaicScene, SIGNAL(cubesChanged()),
44 this, SLOT(buildChildren()));
50 ControlNetGraphicsItem::~ControlNetGraphicsItem() {
52 delete m_pointToScene;
53 m_pointToScene = NULL;
56 if (m_cubeToGroundMap) {
57 QMapIterator<QString, UniversalGroundMap *> it(*m_cubeToGroundMap);
66 delete m_cubeToGroundMap;
67 m_cubeToGroundMap = NULL;
72 QRectF ControlNetGraphicsItem::boundingRect()
const {
77 void ControlNetGraphicsItem::paint(QPainter *painter,
78 const QStyleOptionGraphicsItem *style,
QWidget * widget) {
83 Projection *proj = m_mosaicScene->getProjection();
88 QPointF initialLatLon;
89 QPointF adjustedLatLon;
93 if (!rememberedLoc.second.isNull()) {
95 proj->SetUniversalGround(rememberedLoc.second.y(),
96 rememberedLoc.second.x());
97 adjusted = QPointF(proj->XCoord(), -1 * proj->YCoord());
98 adjustedLatLon = rememberedLoc.second;
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;
110 SurfacePoint adjSurfacePoint(cp->GetAdjustedSurfacePoint());
111 if (adjSurfacePoint.Valid()) {
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());
121 SurfacePoint apriSurfacePoint(cp->GetAprioriSurfacePoint());
122 if (apriSurfacePoint.Valid()) {
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());
135 if ((!adjusted.isNull() && initial.isNull()) ||
136 (adjusted.isNull() && initial.isNull())) {
139 QString sn = cp->GetReferenceSN();
140 QString filename = snToFileName(sn);
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;
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();
155 if (proj->SetUniversalGround(lat, lon)) {
156 initial = QPointF(proj->XCoord(), -1 * proj->YCoord());
157 initialLatLon = QPointF(lon, lat);
162 catch(IException &) {
169 if (!adjusted.isNull() && adjusted != initial) {
171 result.second = adjusted;
172 result.first = initial;
173 latLonResult.second = adjustedLatLon;
174 latLonResult.first = initialLatLon;
178 result.second = initial;
179 latLonResult.second = initialLatLon;
182 (*m_pointToScene)[cp] = latLonResult;
188 void ControlNetGraphicsItem::clearControlPointGraphicsItem(QString pointId) {
193 m_pointToScene->clear();
203 QString ControlNetGraphicsItem::snToFileName(QString sn) {
206 if (m_serialNumbers && m_serialNumbers->
size()) {
208 result = m_serialNumbers->
fileName(sn);
210 catch(IException &) {
225 bool colorByMeasureCount,
int maxMeasureCount,
226 bool colorByJigsawError,
double maxResidualMagnitude) {
230 visible, colorByMeasureCount, maxMeasureCount, colorByJigsawError, maxResidualMagnitude);
243 foreach (child, children) {
245 child->scene()->removeItem(child);
254 if (m_serialNumbers) {
255 delete m_serialNumbers;
260 QStringList cubeFiles(m_mosaicScene->cubeFileNames());
263 foreach (filename, cubeFiles) {
265 m_serialNumbers->
add(filename);
272 p->
setText(
"Calculating CP Locations");
273 p->setRange(0, numCp - 1);
277 for (
int cpIndex = 0; cpIndex < numCp; cpIndex ++) {
285 cp, m_serialNumbers, m_mosaicScene,
this);
286 p->setValue(cpIndex);
289 p->setVisible(
false);
301 ControlPoint *ControlNetGraphicsItem::findClosestControlPoint() {
305 (cpItem->controlPoint()->
GetType() >= 0 && cpItem->controlPoint()->
GetType() <= 2) ) {
306 return cpItem->controlPoint();
314 void ControlNetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
316 ControlPointGraphicsItem *cpItem = (ControlPointGraphicsItem *) m_mosaicScene->getScene()->focusItem();
PointType GetType() const
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.
void add(const QString &filename, bool def2filename=false)
Adds a new filename / serial number pair to the SerialNumberList.
int size() const
How many serial number / filename combos are in the list.
int GetNumPoints() const
Return the number of control points in the network.
QString fileName(const QString &sn)
Return a filename given a serial number.
void setText(QString text)
Set custom text for this progress bar.
The visual display of a single control point.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
QProgressBar with customizable text.
Serial Number list generator.
void buildChildren()
Call this to re-calculate where control points ought to lie.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.