Isis 3 Programmer Reference
AdvancedStretchDialog.cpp
1#include "AdvancedStretchDialog.h"
2
3#include <QHBoxLayout>
4#include <QString>
5#include <QPushButton>
6
7#include "CubeViewport.h"
8#include "Stretch.h"
9#include "CubeStretch.h"
10#include "AdvancedStretch.h"
11
12namespace Isis {
19 QDialog(parent) {
20 p_grayStretch = NULL;
21 p_redStretch = NULL;
22 p_grnStretch = NULL;
23 p_bluStretch = NULL;
24 p_enabled = false;
25
26 setWindowTitle("Advanced Stretch Tool");
27
28 QVBoxLayout *layout = new QVBoxLayout();
29
30 setLayout(layout);
31 }
32
33
40
41
53 Histogram &redHist,
54 Stretch &grnStretch, Histogram &grnHist,
55 Stretch &bluStretch, Histogram &bluHist) {
57
58 QHBoxLayout* rgbLayout = new QHBoxLayout();
59
60 p_redStretch = new AdvancedStretch(redHist, redStretch,
61 "Red", QColor(Qt::red));
62 rgbLayout->addWidget(p_redStretch);
63
64 p_grnStretch = new AdvancedStretch(grnHist, grnStretch,
65 "Green", QColor(Qt::green));
66 rgbLayout->addWidget(p_grnStretch);
67
68 p_bluStretch = new AdvancedStretch(bluHist, bluStretch,
69 "Blue", QColor(Qt::blue));
70 rgbLayout->addWidget(p_bluStretch);
71
72 ((QVBoxLayout*)layout())->addLayout(rgbLayout);
73
74 QFrame* line = new QFrame();
75 line->setFrameShape(QFrame::HLine);
76 line->setFrameShadow(QFrame::Sunken);
77 ((QVBoxLayout*)layout())->addWidget(line);
78
79 updateGeometry();
80
81 connect(p_redStretch, SIGNAL(stretchChanged()),
82 this, SIGNAL(stretchChanged()));
83 connect(p_grnStretch, SIGNAL(stretchChanged()),
84 this, SIGNAL(stretchChanged()));
85 connect(p_bluStretch, SIGNAL(stretchChanged()),
86 this, SIGNAL(stretchChanged()));
87
88 // Add buttons for save/load/delete stretch to RGB stretches
89 QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube...");
90 saveToCubeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
91 connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube()));
92
93 QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube...");
94 deleteFromCubeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
95 connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube()));
96
97 QPushButton *loadStretchButton = new QPushButton("Restore Saved Stretch from Cube...");
98 loadStretchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
99 connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch()));
100
101 QHBoxLayout* buttonLayout = new QHBoxLayout();
102
103 buttonLayout->addWidget(saveToCubeButton);
104 buttonLayout->addWidget(deleteFromCubeButton);
105 buttonLayout->addWidget(loadStretchButton);
106 ((QBoxLayout*)layout())->addLayout(buttonLayout);
107 }
108
123 Histogram &redHist,
124 Stretch &grnStretch, Histogram &grnHist,
125 Stretch &bluStretch, Histogram &bluHist)
126 {
127 if(p_redStretch) {
128 p_redStretch->setStretch(redStretch);
129 p_redStretch->setHistogram(redHist);
130 }
131
132 if(p_grnStretch) {
133 p_grnStretch->setStretch(grnStretch);
134 p_grnStretch->setHistogram(grnHist);
135 }
136
137 if(p_bluStretch) {
138 p_bluStretch->setStretch(bluStretch);
139 p_bluStretch->setHistogram(bluHist);
140 }
141 }
142
143
144
152 Histogram &grayHist) {
154
155 p_grayStretch = new AdvancedStretch(grayHist, grayStretch,
156 "Gray", QColor(Qt::gray));
157 layout()->addWidget(p_grayStretch);
158 updateGeometry();
159
160 connect(p_grayStretch, SIGNAL(stretchChanged()),
161 this, SIGNAL(stretchChanged()));
162 connect(p_grayStretch, SIGNAL(saveToCube()),
163 this, SIGNAL(saveToCube()));
164 connect(p_grayStretch, SIGNAL(deleteFromCube()),
165 this, SIGNAL(deleteFromCube()));
166 connect(p_grayStretch, SIGNAL(loadStretch()),
167 this, SIGNAL(loadStretch()));
168 }
169
170
177 if (p_grayStretch) {
179 }
180 else {
181 QString msg = "Gray mode not enabled, cannot restore gray stretch";
182 throw IException(IException::Programmer, msg, _FILEINFO_);
183 }
184 }
185
186
195 if (isRgbMode()) {
196 if (p_redStretch) {
198 }
199
200 if (p_grnStretch) {
202 }
203
204 if (p_bluStretch) {
206 }
207 }
208 else {
209 QString msg = "RGB mode not enabled, cannot restore RGB stretch";
210 throw IException(IException::Programmer, msg, _FILEINFO_);
211 }
212 }
213
214
220 if(p_redStretch) {
221 layout()->removeWidget(p_redStretch);
222 disconnect(p_redStretch, SIGNAL(stretchChanged()),
223 this, SIGNAL(stretchChanged()));
224 delete p_redStretch;
225 p_redStretch = NULL;
226 }
227
228 if(p_grnStretch) {
229 layout()->removeWidget(p_grnStretch);
230 disconnect(p_grnStretch, SIGNAL(stretchChanged()),
231 this, SIGNAL(stretchChanged()));
232 delete p_grnStretch;
233 p_grnStretch = NULL;
234 }
235
236 if(p_bluStretch) {
237 layout()->removeWidget(p_bluStretch);
238 disconnect(p_bluStretch, SIGNAL(stretchChanged()),
239 this, SIGNAL(stretchChanged()));
240 delete p_bluStretch;
241 p_bluStretch = NULL;
242 }
243
244 if(p_grayStretch) {
245 layout()->removeWidget(p_grayStretch);
246 disconnect(p_grayStretch, SIGNAL(stretchChanged()),
247 this, SIGNAL(stretchChanged()));
248 delete p_grayStretch;
249 p_grayStretch = NULL;
250 }
251 }
252
253
261 if(p_grayStretch){
262 p_grayStretch->setStretch(cvp->grayStretch());
263 }
264 if(p_redStretch) {
265 p_redStretch->setStretch(cvp->redStretch());
266 }
267 if(p_grnStretch){
268 p_grnStretch->setStretch(cvp->greenStretch());
269 }
270 if(p_bluStretch){
271 p_bluStretch->setStretch(cvp->blueStretch());
272 }
273 }
274
275
285 const Histogram &grnHist,
286 const Histogram &bluHist) {
287
288 if(p_redStretch){
289 p_redStretch->setHistogram(redHist);
290 }
291 if(p_grnStretch){
292 p_grnStretch->setHistogram(grnHist);
293 }
294 if(p_bluStretch){
295 p_bluStretch->setHistogram(bluHist);
296 }
297 }
298
299
307 if(p_grayStretch)
308 p_grayStretch->setHistogram(grayHist);
309 }
310
311
317 void AdvancedStretchDialog::showEvent(QShowEvent *event) {
318 QDialog::showEvent(event);
319 emit visibilityChanged();
320 }
321
322
328 void AdvancedStretchDialog::hideEvent(QHideEvent *event) {
329 QDialog::hideEvent(event);
330 emit visibilityChanged();
331 }
332
333
343
344
351 if(p_grayStretch) {
352 return p_grayStretch->getStretch();
353 }
354 else {
355 QString msg = "Gray mode not enabled, cannot get gray stretch";
356 throw IException(IException::Programmer, msg, _FILEINFO_);
357 }
358 }
359
360
367 if(p_redStretch) {
368 return p_redStretch->getStretch();
369 }
370 else {
371 QString msg = "RGB mode not enabled, cannot get red stretch";
372 throw IException(IException::Programmer, msg, _FILEINFO_);
373 }
374 }
375
376
383 if(p_grnStretch) {
384 return p_grnStretch->getStretch();
385 }
386 else {
387 QString msg = "RGB mode not enabled, cannot get green stretch";
388 throw IException(IException::Programmer, msg, _FILEINFO_);
389 }
390 }
391
392
399 if(p_bluStretch) {
400 return p_bluStretch->getStretch();
401 }
402 else {
403 QString msg = "RGB mode not enabled, cannot get blue stretch";
404 throw IException(IException::Programmer, msg, _FILEINFO_);
405 }
406 }
407}
AdvancedStretch * p_bluStretch
Blue stretch pane.
CubeStretch getBluStretch()
This returns the advanced stretch's stretch for blue.
void updateHistograms(const Histogram &redHist, const Histogram &grnHist, const Histogram &bluHist)
This calls setHistogram on all of the advanced stretches.
void restoreGrayStretch(CubeStretch stretch)
Restores a saved grayscale stretch from the cube.
void updateForRGBMode(Stretch &redStretch, Histogram &redHist, Stretch &grnStretch, Histogram &grnHist, Stretch &bluStretch, Histogram &bluHist)
Update the stretch and histogram for all the bands for All BandId option.
~AdvancedStretchDialog()
This destroys the advanced stretch dialog.
void updateHistogram(const Histogram &grayHist)
This calls setHistogram on the gray advanced stretches.
void enableRgbMode(Stretch &redStretch, Histogram &redHist, Stretch &grnStretch, Histogram &grnHist, Stretch &bluStretch, Histogram &bluHist)
This displays RGB advanced stretches.
CubeStretch getGrnStretch()
This returns the advanced stretch's stretch for green.
CubeStretch getGrayStretch()
This returns the advanced stretch's stretch for gray.
CubeStretch getRedStretch()
This returns the advanced stretch's stretch for red.
bool isRgbMode() const
Returns true if the dialog is displaying the RGB advanced stretches.
void destroyCurrentStretches()
This cleans up memory from currently displayed advanced stretches.
void hideEvent(QHideEvent *)
This is implemented to send a signal when visibility changes.
void visibilityChanged()
Emitted when this dialog is shown or hidden.
void restoreRgbStretch(CubeStretch red, CubeStretch green, CubeStretch blue)
Restores a saved RGB stretch from the cube.
AdvancedStretch * p_grnStretch
Green stretch pane.
void updateStretch(CubeViewport *)
This calls setStretch on all applicable advanced stretches.
AdvancedStretch * p_grayStretch
Gray stretch pane.
AdvancedStretchDialog(QWidget *parent)
This constructs an advanced stretch.
void showEvent(QShowEvent *)
This is implemented to send a signal when visibility changes.
void enableGrayMode(Stretch &grayStretch, Histogram &grayHist)
This displays a gray advanced stretch.
bool p_enabled
True if advanced stretch should be used.
AdvancedStretch * p_redStretch
Red stretch pane.
void stretchChanged()
Emitted when an advanced stretch has changed.
Advanced Stretch Dialog.
void setStretch(Stretch newStretch)
This is called when the user creates a stretch outside of the advanced stretch.
void setHistogram(const Histogram &newHist)
This is called when the visible area changes, so that the histogram can be updated.
CubeStretch getStretch()
This returns the current stretch type's stretch.
void restoreSavedStretch(CubeStretch newStretch)
Used to restore a saved Stretch from a cube.
Stores stretch information for a cube.
Definition CubeStretch.h:27
Widget to display Isis cubes for qt apps.
Container of a cube histogram.
Definition Histogram.h:74
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Pixel value mapper.
Definition Stretch.h:58
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16