USGS

Isis 3.0 Object Programmers' Reference

Home

TrackTool.cpp
1 #include "TrackTool.h"
2 
3 #include <QStatusBar>
4 #include <QLabel>
5 #include <QCursor>
6 
7 #include "Camera.h"
8 #include "Distance.h"
9 #include "MdiCubeViewport.h"
10 #include "Projection.h"
11 #include "RingPlaneProjection.h"
12 #include "SpecialPixel.h"
13 #include "Target.h"
14 #include "TProjection.h"
15 #include "ViewportBuffer.h"
16 #include "WarningWidget.h"
17 
18 
19 namespace Isis {
26  TrackTool::TrackTool(QStatusBar *parent) : Tool(parent) {
27  p_sbar = parent;
28 
29  p_sampLabel = new QLabel(p_sbar);
30  p_sampLabel->setText("W 999999");
31  p_sampLabel->setMinimumSize(p_sampLabel->sizeHint());
32  p_sampLabel->setToolTip("Sample Position");
33  p_sbar->addPermanentWidget(p_sampLabel);
34 
35  p_lineLabel = new QLabel(p_sbar);
36  p_lineLabel->setText("W 999999");
37  p_lineLabel->setMinimumSize(p_lineLabel->sizeHint());
38  p_lineLabel->setToolTip("Line Position");
39  p_sbar->addPermanentWidget(p_lineLabel);
40 
41  p_latLabel = new QLabel(p_sbar);
42  p_latLabel->setText("9.999999E-99");
43  p_latLabel->setMinimumSize(p_latLabel->sizeHint());
44  p_latLabel->hide();
45  p_latLabel->setToolTip("Latitude Position");
46  p_sbar->addPermanentWidget(p_latLabel);
47 
48  p_lonLabel = new QLabel(p_sbar);
49  p_lonLabel->setText("9.999999E-99");
50  p_lonLabel->setMinimumSize(p_lonLabel->sizeHint());
51  p_lonLabel->hide();
52  p_lonLabel->setToolTip("Longitude Position");
53  p_sbar->addPermanentWidget(p_lonLabel);
54 
55  p_grayLabel = new QLabel(p_sbar);
56  p_grayLabel->setText("9.999999E-99");
57  p_grayLabel->setMinimumSize(p_grayLabel->sizeHint());
58  p_grayLabel->setToolTip("Gray Pixel Value");
59  p_sbar->addPermanentWidget(p_grayLabel);
60 
61  p_redLabel = new QLabel(p_sbar);
62  p_redLabel->setText("W 9.999999E-99");
63  p_redLabel->setMinimumSize(p_redLabel->sizeHint());
64  p_redLabel->hide();
65  p_redLabel->setToolTip("Red Pixel Value");
66  p_sbar->addPermanentWidget(p_redLabel);
67 
68  p_grnLabel = new QLabel(p_sbar);
69  p_grnLabel->setText("W 9.999999E-99");
70  p_grnLabel->setMinimumSize(p_grnLabel->sizeHint());
71  p_grnLabel->hide();
72  p_grnLabel->setToolTip("Green Pixel Value");
73  p_sbar->addPermanentWidget(p_grnLabel);
74 
75  p_bluLabel = new QLabel(p_sbar);
76  p_bluLabel->setText("W 9.999999E-99");
77  p_bluLabel->setMinimumSize(p_bluLabel->sizeHint());
78  p_bluLabel->hide();
79  p_bluLabel->setToolTip("Blue Pixel Value");
80  p_sbar->addPermanentWidget(p_bluLabel);
81 
83  connect(p_sbar, SIGNAL(messageChanged(const QString &)), mWarningWidget, SLOT(checkMessage()));
84 
85  clearLabels();
86 
87  activate(true);
88  }
89 
97  void TrackTool::displayWarning(std::string &pStr, const std::string &pExStr) {
99  }
100 
105  if(mWarningWidget != NULL) {
107  }
108  }
109 
116  void TrackTool::mouseMove(QPoint p) {
117  MdiCubeViewport *cvp = cubeViewport();
118  if(cvp == NULL) return;
119 
120  if(p.x() >= 0 && p.x() < cvp->width() &&
121  p.y() >= 0 && p.y() < cvp->height()) {
122  updateLabels(p);
123  }
124  }
125 
126 
132  clearLabels();
133  }
134 
135 
142  void TrackTool::updateLabels(QPoint p) {
143  MdiCubeViewport *cvp = cubeViewport();
144 
145  clearLabels();
146 
147  if(cvp == NULL) {
148  return;
149  }
150 
151  double sample, line;
152  cvp->viewportToCube(p.x(), p.y(), sample, line);
153  if((sample < 0.5) || (line < 0.5) ||
154  (sample > cvp->cubeSamples() + 0.5) ||
155  (line > cvp->cubeLines() + 0.5)) {
156  return;
157  }
158 
159  int isamp = (int)(sample + 0.5);
160  QString text;
161  text.setNum(isamp);
162  text = "S " + text;
163  p_sampLabel->setText(text);
164 
165  int iline = (int)(line + 0.5);
166  text.setNum(iline);
167  text = "L " + text;
168  p_lineLabel->setText(text);
169 
170 
171  // Do we have a projection?
172  if(cvp->projection() != NULL) {
173  // Set up for projection types
175  p_latLabel->show();
176  p_lonLabel->show();
177 
178  if(cvp->projection()->SetWorld(sample, line)) {
179  if (projType == Projection::Triaxial) {
180  TProjection *tproj = (TProjection *) cvp->projection();
181  double lat = tproj->Latitude();
182  double lon = tproj->Longitude();
183  p_latLabel->setText(QString("Lat %1").arg(lat));
184  p_lonLabel->setText(QString("Lon %1").arg(lon));
185  }
186  else { // RingPlane TODO write out radius azimuth instead of lat/lon
188  double rad = rproj->RingRadius();
189  double lon = rproj->RingLongitude();
190  //??? p_latLabel->setToolTip("Radius Position");
191  p_latLabel->setText(QString("Rad %1").arg(rad));
192  p_lonLabel->setText(QString("Lon %1").arg(lon));
193  }
194  }
195  else {
196  p_latLabel->setText("Lat N/A");
197  p_lonLabel->setText("Lon N/A");
198  }
199  }
200  // Do we have a camera model?
201  else if(cvp->camera() != NULL) {
202  p_latLabel->show();
203  p_lonLabel->show();
204 
205  if(cvp->camera()->SetImage(sample, line)) {
206  if (cvp->camera()->target()->shape()->name() != "Plane") {
207  double lat = cvp->camera()->UniversalLatitude();
208  double lon = cvp->camera()->UniversalLongitude();
209  p_latLabel->setText(QString("Lat %1").arg(lat));
210  p_lonLabel->setText(QString("Lon %1").arg(lon));
211  }
212  else {
213  double rad = cvp->camera()->LocalRadius().meters();
214  double lon = cvp->camera()->UniversalLongitude();
215  //??? p_latLabel->setToolTip("Radius Position");
216  p_latLabel->setText(QString("Rad %1").arg(rad));
217  p_lonLabel->setText(QString("Lon %1").arg(lon));
218  }
219  }
220  else {
221  p_latLabel->setText("Lat N/A");
222  p_lonLabel->setText("Lon N/A");
223  }
224  }
225 
226  else {
227  p_latLabel->hide();
228  p_lonLabel->hide();
229  }
230 
231  if(cvp->isGray()) {
232  p_grayLabel->show();
233  p_redLabel->hide();
234  p_grnLabel->hide();
235  p_bluLabel->hide();
236 
237  ViewportBuffer *grayBuf = cvp->grayBuffer();
238 
239  if(grayBuf->working()) {
240  p_grayLabel->setText("BUSY");
241  }
242  else {
243  const QRect rect(grayBuf->bufferXYRect());
244 
245  if(p.x() >= rect.left() && p.x() <= rect.right() &&
246  p.y() >= rect.top() && p.y() <= rect.bottom()) {
247  const int bufX = p.x() - rect.left();
248  const int bufY = p.y() - rect.top();
249  QString pixelString = IString(PixelToString(
250  grayBuf->getLine(bufY)[bufX])).ToQt();
251  p_grayLabel->setText(pixelString);
252  }
253  }
254  }
255  else {
256  p_grayLabel->hide();
257  p_redLabel->show();
258  p_grnLabel->show();
259  p_bluLabel->show();
260 
261  ViewportBuffer *redBuf = cvp->redBuffer();
262 
263  if(redBuf->working()) {
264  p_grayLabel->setText("BUSY");
265  }
266  else {
267  const QRect rRect = redBuf->bufferXYRect();
268 
269  if(p.x() >= rRect.left() && p.x() < rRect.right() &&
270  p.y() >= rRect.top() && p.y() < rRect.bottom()) {
271  const int rBufX = p.x() - rRect.left();
272  const int rBufY = p.y() - rRect.top();
273  QString rLab = "R ";
274  rLab += IString(PixelToString(
275  redBuf->getLine(rBufY)[rBufX])).ToQt();
276  p_redLabel->setText(rLab);
277  }
278  }
279 
280  ViewportBuffer *greenBuf = cvp->greenBuffer();
281 
282  if(greenBuf->working()) {
283  p_grayLabel->setText("BUSY");
284  }
285  else {
286  const QRect gRect = greenBuf->bufferXYRect();
287 
288  if(p.x() >= gRect.left() && p.x() < gRect.right() &&
289  p.y() >= gRect.top() && p.y() < gRect.bottom()) {
290  const int gBufX = p.x() - gRect.left();
291  const int gBufY = p.y() - gRect.top();
292  QString gLab = "G ";
293  gLab += IString(PixelToString(
294  greenBuf->getLine(gBufY)[gBufX])).ToQt();
295  p_grnLabel->setText(gLab);
296  }
297  }
298 
299  ViewportBuffer *blueBuf = cvp->blueBuffer();
300 
301  if(blueBuf->working()) {
302  p_grayLabel->setText("BUSY");
303  }
304  else {
305  const QRect bRect = blueBuf->bufferXYRect();
306 
307  if(p.x() >= bRect.left() && p.x() < bRect.right() &&
308  p.y() >= bRect.top() && p.y() < bRect.bottom()) {
309  const int bBufX = p.x() - bRect.left();
310  const int bBufY = p.y() - bRect.top();
311  QString bLab = "B ";
312  bLab += IString(PixelToString(
313  blueBuf->getLine(bBufY)[bBufX])).ToQt();
314  p_bluLabel->setText(bLab);
315  }
316  }
317  }
318  }
319 
320 
326  p_sampLabel->setText("S N/A");
327  p_lineLabel->setText("L N/A");
328  p_latLabel->setText("Lat N/A");
329  p_lonLabel->setText("Lon N/A");
330  p_grayLabel->setText("N/A");
331  p_redLabel->setText("R N/A");
332  p_grnLabel->setText("G N/A");
333  p_bluLabel->setText("B N/A");
334  }
335 
336 
342  if(cubeViewport() == NULL) return;
343  QPoint p = cubeViewport()->viewport()->mapFromGlobal(QCursor::pos());
344  if(p.x() < 0) return;
345  if(p.y() < 0) return;
346  if(p.x() >= cubeViewport()->viewport()->width()) return;
347  if(p.y() >= cubeViewport()->viewport()->height()) return;
348  updateLabels(p);
349  }
350 
351 
359  connect(cubeViewport(), SIGNAL(viewportUpdated()),
360  this, SLOT(locateCursor()));
361  }
362 
363 
371  disconnect(cubeViewport(), SIGNAL(viewportUpdated()),
372  this, SLOT(locateCursor()));
373  }
374 
375 
376  QStatusBar *TrackTool::getStatusBar(void) {
377  return p_sbar;
378  }
379 }
380