Isis 3 Programmer Reference
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 
Cube display widget for certain Isis MDI applications.
double meters() const
Get the distance in meters.
Definition: Distance.cpp:97
ViewportBuffer * grayBuffer()
Returns the gray viewport buffer (Will be NULL if in RGB mode.)
Definition: CubeViewport.h:421
int cubeLines() const
Return the number of lines in the cube.
Reads and stores visible DN values.
void displayWarning(std::string &pStr, const std::string &pExStr)
Display the Warning icon in case of an exception, sent from the tool where the exception occured...
Definition: TrackTool.cpp:97
void resetWarning(void)
When the dialog "OK" button is clicked or when the mouse is released on some other area or tool the W...
ViewportBuffer * redBuffer()
Returns the red viewport buffer (Will be NULL if in Gray mode.)
Definition: CubeViewport.h:431
ProjectionType projectionType() const
Returns an enum value for the projection type.
Definition: Projection.cpp:213
bool isGray() const
Definition: CubeViewport.h:199
double UniversalLatitude() const
Returns the planetocentric latitude, in degrees, at the surface intersection point in the body fixed ...
Definition: Sensor.cpp:225
WarningWidget * mWarningWidget
Warning Widget.
Definition: TrackTool.h:75
Base class for Map TProjections.
Definition: TProjection.h:182
void viewWarningWidgetIcon(std::string &pStr, const std::string &pExStr)
View Warning icon when there is an exception.
const std::vector< double > & getLine(int line)
Retrieves a line from the buffer.
QLabel * p_sampLabel
Sample label.
Definition: TrackTool.h:67
QLabel * p_lonLabel
Lon label.
Definition: TrackTool.h:70
void clearLabels()
Clears the labels.
Definition: TrackTool.cpp:325
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
QRect bufferXYRect()
Returns a rect, in screen pixels, of the area this buffer covers.
QLabel * p_bluLabel
Blue label.
Definition: TrackTool.h:74
virtual void mouseMove(QPoint p)
Updates the labels anytime the mouse moves.
Definition: TrackTool.cpp:116
Distance LocalRadius() const
Returns the local radius at the intersection point.
Definition: Sensor.cpp:282
QLabel * p_grnLabel
Green label.
Definition: TrackTool.h:73
bool SetImage(const double sample, const double line)
Sets the sample/line values of the image to get the lat/lon values.
Definition: Camera.cpp:170
QLabel * p_redLabel
Red label.
Definition: TrackTool.h:72
Camera * camera() const
Definition: CubeViewport.h:358
QStatusBar * p_sbar
Status bar.
Definition: TrackTool.h:66
QLabel * p_latLabel
Lat label.
Definition: TrackTool.h:69
void locateCursor()
Finds the cursor position.
Definition: TrackTool.cpp:341
Target * target() const
Returns a pointer to the target object.
Definition: Spice.cpp:1290
double Longitude() const
This returns a longitude with correct longitude direction and domain as specified in the label object...
QLabel * p_lineLabel
Line label.
Definition: TrackTool.h:68
virtual void mouseLeave()
Clears the labels if the mouse leaves the application.
Definition: TrackTool.cpp:131
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:884
ShapeModel * shape() const
Return the shape.
Definition: Target.cpp:615
double UniversalLongitude() const
Returns the positive east, 0-360 domain longitude, in degrees, at the surface intersection point in t...
Definition: Sensor.cpp:248
bool working()
This tests if queued actions exist in the viewport buffer.
Displays the NoWarning icon as default and the Warning icon in case of exception and also pops up a a...
Definition: WarningWidget.h:51
double RingRadius() const
This returns a radius.
int cubeSamples() const
Return the number of samples in the cube.
bool SetWorld(const double x, const double y)
This method is used to set a world coordinate.
Definition: Projection.cpp:512
ViewportBuffer * blueBuffer()
Returns the blue viewport buffer (Will be NULL if in Gray mode.)
Definition: CubeViewport.h:451
QString name() const
Gets the shape name.
Definition: ShapeModel.cpp:537
Base class for Map Projections of plane shapes.
void addConnections(MdiCubeViewport *cvp)
Adds the connections to the given viewport.
Definition: TrackTool.cpp:358
void updateLabels(QPoint p)
Updates the tracking labels.
Definition: TrackTool.cpp:142
double Latitude() const
This returns a latitude with correct latitude type as specified in the label object.
QString PixelToString(double d)
Takes a double pixel value and returns the name of the pixel type as a string.
Definition: SpecialPixel.h:386
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Projection * projection() const
Definition: CubeViewport.h:353
Base class for the Qisis tools.
Definition: Tool.h:81
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition: Tool.h:211
void activate(bool)
Activates the tool.
Definition: Tool.cpp:131
double RingLongitude() const
This returns a ring longitude with correct ring longitude direction and domain as specified in the la...
void resetStatusWarning(void)
Resets the warning status on the status bar to default.
Definition: TrackTool.cpp:104
ViewportBuffer * greenBuffer()
Returns the green viewport buffer (Will be NULL if in Gray mode.)
Definition: CubeViewport.h:441
void viewportToCube(int x, int y, double &sample, double &line) const
Turns a viewport into a cube.
void removeConnections(MdiCubeViewport *cvp)
Removes the connections from the given viewport.
Definition: TrackTool.cpp:370
ProjectionType
This enum defines the subclasses of Projection supported in Isis.
Definition: Projection.h:182
TrackTool(QStatusBar *parent)
TrackTool constructor.
Definition: TrackTool.cpp:26
These projections are used to map triaxial and irregular-shaped bodies.
Definition: Projection.h:182
QLabel * p_grayLabel
Gray label.
Definition: TrackTool.h:71