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) {
82 QPair<QPointF, QPointF> ControlNetGraphicsItem::pointToScene(ControlPoint *cp)
84 Projection *proj = m_mosaicScene->getProjection();
89 QPointF initialLatLon;
90 QPointF adjustedLatLon;
92 QPair<QPointF, QPointF> rememberedLoc = (*m_pointToScene)[cp];
94 if(!rememberedLoc.second.isNull()) {
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;
109 SurfacePoint adjSurfacePoint(cp->GetAdjustedSurfacePoint());
110 if(adjSurfacePoint.Valid()) {
111 if(proj->SetUniversalGround(adjSurfacePoint.GetLatitude().degrees(),
112 adjSurfacePoint.GetLongitude().degrees())) {
113 adjusted = QPointF(proj->XCoord(), -1 * proj->YCoord());
114 adjustedLatLon = QPointF(adjSurfacePoint.GetLongitude().degrees(),
115 adjSurfacePoint.GetLatitude().degrees());
119 SurfacePoint apriSurfacePoint(cp->GetAprioriSurfacePoint());
120 if(apriSurfacePoint.Valid()) {
121 if(proj->SetUniversalGround(apriSurfacePoint.GetLatitude().degrees(),
122 apriSurfacePoint.GetLongitude().degrees())) {
123 initial = QPointF(proj->XCoord(), -1 * proj->YCoord());
124 initialLatLon = QPointF(apriSurfacePoint.GetLongitude().degrees(),
125 apriSurfacePoint.GetLatitude().degrees());
132 if((!adjusted.isNull() && initial.isNull()) ||
133 (adjusted.isNull() && initial.isNull())) {
135 QString sn = cp->GetReferenceSN();
136 QString filename = snToFileName(sn);
138 if(filename.size() > 0) {
139 if((*m_cubeToGroundMap)[filename] == NULL) {
140 Cube cube(FileName(filename).expanded(),
"r");
141 UniversalGroundMap *groundMap =
new UniversalGroundMap(cube);
142 (*m_cubeToGroundMap)[filename] = groundMap;
145 if((*m_cubeToGroundMap)[filename]->SetImage(
146 cp->GetRefMeasure()->GetSample(),
147 cp->GetRefMeasure()->GetLine())) {
148 double lat = (*m_cubeToGroundMap)[filename]->UniversalLatitude();
149 double lon = (*m_cubeToGroundMap)[filename]->UniversalLongitude();
151 if(proj->SetUniversalGround(lat, lon)) {
152 initial = QPointF(proj->XCoord(), -1 * proj->YCoord());
153 initialLatLon = QPointF(lon, lat);
158 catch(IException &) {
163 QPair<QPointF, QPointF> result;
164 QPair<QPointF, QPointF> latLonResult;
165 if(!adjusted.isNull() && adjusted != initial) {
166 result.second = adjusted;
167 result.first = initial;
168 latLonResult.second = adjustedLatLon;
169 latLonResult.first = initialLatLon;
172 result.second = initial;
173 latLonResult.second = initialLatLon;
176 (*m_pointToScene)[cp] = latLonResult;
182 QString ControlNetGraphicsItem::snToFileName(QString sn) {
185 if(m_serialNumbers && m_serialNumbers->
size()) {
187 result = m_serialNumbers->
fileName(sn);
189 catch(IException &) {
204 bool colorByMeasureCount,
int maxMeasureCount,
205 bool colorByJigsawError,
double maxResidualMagnitude) {
209 visible, colorByMeasureCount, maxMeasureCount, colorByJigsawError, maxResidualMagnitude);
222 foreach(child, children) {
224 child->scene()->removeItem(child);
233 if(m_serialNumbers) {
234 delete m_serialNumbers;
239 QStringList cubeFiles(m_mosaicScene->cubeFileNames());
242 foreach(filename, cubeFiles) {
244 m_serialNumbers->
add(filename);
251 p->
setText(
"Calculating CP Locations");
252 p->setRange(0, numCp - 1);
256 for(
int cpIndex = 0; cpIndex < numCp; cpIndex ++) {
260 QPair<QPointF, QPointF> scenePoints = pointToScene(cp);
263 cp, m_serialNumbers, m_mosaicScene,
this);
265 p->setValue(cpIndex);
268 p->setVisible(
false);