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