Isis 3 Programmer Reference
SpectralPlotWindow.cpp
1 #include "IsisDebug.h"
2 
3 #include "SpectralPlotWindow.h"
4 
5 #include <QAction>
6 #include <QMenu>
7 #include <QMenuBar>
8 #include <QString>
9 
10 #include "Cube.h"
11 #include "MdiCubeViewport.h"
12 #include "Pvl.h"
13 #include "PvlGroup.h"
14 #include "PvlObject.h"
15 
16 
17 using namespace std;
18 
19 namespace Isis {
27  SpectralPlotWindow::SpectralPlotWindow(PlotCurve::Units xUnits,
28  QWidget *parent) : PlotWindow("Spectral Plot", xUnits,
29  PlotCurve::CubeDN, parent) {
30  nullify();
31 
32  m_showHideBandMarkers = new QAction("Show Band Markers", this);
33  m_showHideBandMarkers->setCheckable(true);
34  m_showHideBandMarkers->setChecked(true);
35  connect(m_showHideBandMarkers, SIGNAL(toggled(bool)),
36  this, SLOT(setBandMarkersVisible(bool)));
37 
38  m_grayBandLine = createMarker(Qt::white);
39  m_redBandLine = createMarker(Qt::red);
40  m_greenBandLine = createMarker(Qt::green);
41  m_blueBandLine = createMarker(Qt::blue);
42 
44 
45  foreach (QAction *menuAction, menuBar()->actions()) {
46  if (menuAction->text() == "&Options") {
47  QMenu *optsMenu = qobject_cast<QMenu *>(menuAction->parentWidget());
48 
49  optsMenu->addAction(m_showHideBandMarkers);
50  }
51  }
52  }
53 
54 
55  SpectralPlotWindow::~SpectralPlotWindow() {
56  nullify();
57  }
58 
59 
64  m_cvp = NULL;
65  m_grayBandLine = NULL;
66  m_redBandLine = NULL;
67  m_greenBandLine = NULL;
68  m_blueBandLine = NULL;
69  m_showHideBandMarkers = NULL;
70  }
71 
72 
80  QwtPlotMarker *SpectralPlotWindow::createMarker(QColor color) {
81  QPen markerPen(color);
82  markerPen.setWidth(1);
83 
84  QwtPlotMarker *newMarker = new QwtPlotMarker;
85  newMarker->setLineStyle(QwtPlotMarker::LineStyle(2));
86  newMarker->setLinePen(markerPen);
87  newMarker->attach(plot());
88  newMarker->setVisible(false);
89 
90  return newMarker;
91  }
92 
93 
100  if (m_cvp) {
101  int redBand = 0, greenBand = 0, blueBand = 0, grayBand = 0;
102 
103  Cube *cube = m_cvp->cube();
104  Pvl &pvl = *cube->label();
105  PvlKeyword wavelengths;
106 
107  if (pvl.findObject("IsisCube").hasGroup("BandBin")) {
108  PvlGroup &bandBin = pvl.findObject("IsisCube").findGroup("BandBin");
109  if (bandBin.hasKeyword("Center")) {
110  wavelengths = bandBin.findKeyword("Center");
111  }
112  }
113 
114  if (m_cvp->isColor()) {
115  redBand = m_cvp->redBand();
116  greenBand = m_cvp->greenBand();
117  blueBand = m_cvp->blueBand();
118  }
119  else {
120  grayBand = m_cvp->grayBand();
121  }
122 
123  /*This is were we need to set the x value to the band number.*/
124  if (grayBand > 0) {
126  m_grayBandLine->setXValue(toDouble(wavelengths[grayBand-1]));
127  }
128  else {
129  m_grayBandLine->setXValue(grayBand);
130  }
131 
132  if (m_markersVisible)
133  m_grayBandLine->show();
134  }
135  else {
136  m_grayBandLine->hide();
137  }
138 
139  if (redBand > 0) {
141  m_redBandLine->setXValue(toDouble(wavelengths[redBand-1]));
142  }
143  else {
144  m_redBandLine->setXValue(redBand);
145  }
146 
147  if (m_markersVisible)
148  m_redBandLine->show();
149  }
150  else {
151  m_redBandLine->hide();
152  }
153  if (greenBand > 0) {
155  m_greenBandLine->setXValue(toDouble(wavelengths[greenBand-1]));
156  }
157  else {
158  m_greenBandLine->setXValue(greenBand);
159  }
160 
161  if (m_markersVisible)
162  m_greenBandLine->show();
163  }
164  else {
165  m_greenBandLine->hide();
166  }
167 
168  if (blueBand > 0) {
170  m_blueBandLine->setXValue(toDouble(wavelengths[blueBand-1]));
171  }
172  else {
173  m_blueBandLine->setXValue(blueBand);
174  }
175 
176  if (m_markersVisible)
177  m_blueBandLine->show();
178  }
179  else {
180  m_blueBandLine->hide();
181  }
182 
183  plot()->replot();
184  }
185  }
186 
187 
195  m_cvp = cvp;
196 
197  }
198 
199 
206  m_markersVisible = visible;
207 
208  m_blueBandLine->setVisible(m_markersVisible);
209  m_redBandLine->setVisible(m_markersVisible);
210  m_greenBandLine->setVisible(m_markersVisible);
211  m_grayBandLine->setVisible(m_markersVisible);
212 
213  replot();
214  }
215 
216 
224  setViewport(activeViewport);
225  drawBandMarkers();
226  }
227 
228 
236  return m_markersVisible;
237  }
238 }
239 
Cube display widget for certain Isis MDI applications.
QAction * m_showHideBandMarkers
This action toggles band marker visibility.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Cube * cube() const
Definition: CubeViewport.h:348
void update(MdiCubeViewport *activeViewport)
This window can show markers for the currently visible bands.
int greenBand() const
Definition: CubeViewport.h:214
QwtPlotMarker * createMarker(QColor color)
This is a helper method to create new band markers with the same line style and a custom color...
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
QwtPlotMarker * m_grayBandLine
The band marker for the gray band.
Namespace for the standard library.
int blueBand() const
Definition: CubeViewport.h:219
bool isColor() const
Definition: CubeViewport.h:194
void setBandMarkersVisible(bool visible)
The data is a wavelength.
Definition: PlotCurve.h:92
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
QwtPlotMarker * m_redBandLine
The band marker for the red band.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
int grayBand() const
Definition: CubeViewport.h:204
QwtPlotMarker * m_blueBandLine
The band marker for the blue band.
A single keyword-value pair.
Definition: PvlKeyword.h:98
PlotCurve::Units xAxisUnits() const
This is the data-type of the curves&#39; x data in this plot window.
Definition: PlotWindow.cpp:266
Container for cube-like labels.
Definition: Pvl.h:135
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
void drawBandMarkers()
This method actually draws in the vertical band line(s) on the plot area.
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition: Cube.cpp:1346
bool m_markersVisible
True if the visibile state of the active markers should be true.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
MdiCubeViewport * m_cvp
The viewport to be used as a reference for band markers.
void nullify()
This initializes the class member data to NULL.
void replot()
Reset the scale of the plot, replot it and emit plot changed.
int redBand() const
Definition: CubeViewport.h:209
QwtPlotMarker * m_greenBandLine
The band marker for the green band.
QwtPlot * plot()
Get the plot encapsulated by this PlotWindow.
void setViewport(MdiCubeViewport *cvp)
This class needs to know which viewport the user is looking at so it can appropriately draw in the ba...
Units
These are all the possible units for the x or y data in a plot curve.
Definition: PlotCurve.h:54
IO Handler for Isis Cubes.
Definition: Cube.h:170