1#include "ControlNetGraphicsItem.h"
7#include <QGraphicsScene>
10#include "ControlMeasure.h"
11#include "ControlNet.h"
12#include "ControlPoint.h"
13#include "ControlPointGraphicsItem.h"
15#include "IException.h"
18#include "MosaicGraphicsView.h"
19#include "MosaicSceneWidget.h"
20#include "ProgressBar.h"
21#include "Projection.h"
23#include "SerialNumberList.h"
24#include "SurfacePoint.h"
25#include "UniversalGroundMap.h"
30 ControlNetGraphicsItem::ControlNetGraphicsItem(ControlNet *controlNet,
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);
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) {
82 QPair<QPointF, QPointF> ControlNetGraphicsItem::pointToScene(ControlPoint *cp) {
83 Projection *proj = m_mosaicScene->getProjection();
88 QPointF initialLatLon;
89 QPointF adjustedLatLon;
91 QPair<QPointF, QPointF> rememberedLoc = (*m_pointToScene)[cp];
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 &) {
167 QPair<QPointF, QPointF> result;
168 QPair<QPointF, QPointF> latLonResult;
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 &) {
224 void ControlNetGraphicsItem::setArrowsVisible(
bool visible,
225 bool colorByMeasureCount,
int maxMeasureCount,
226 bool colorByJigsawError,
double maxResidualMagnitude) {
230 visible, colorByMeasureCount, maxMeasureCount, colorByJigsawError, maxResidualMagnitude);
240 void ControlNetGraphicsItem::buildChildren() {
241 QList<QGraphicsItem *> children = childItems();
243 foreach (child, children) {
245 child->scene()->removeItem(child);
252 const int numCp = m_controlNet->GetNumPoints();
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 ++) {
282 QPair<QPointF, QPointF> scenePoints = pointToScene(cp);
285 cp, m_serialNumbers, m_mosaicScene,
this);
286 p->setValue(cpIndex);
289 p->setVisible(
false);
302 ControlPoint *ControlNetGraphicsItem::findClosestControlPoint(QPointF locationPoint) {
305 QPoint viewPoint = m_mosaicScene->getView()->mapFromScene(locationPoint);
306 cpItem = (
QGraphicsItem *) m_mosaicScene->getView()->itemAt(viewPoint);
The visual display of a single control point.
void setText(QString text)
Set custom text for this progress bar.
Serial Number list generator.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.