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 
12 namespace 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 
39  }
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){
263  }
264  if(p_redStretch) {
266  }
267  if(p_grnStretch){
269  }
270  if(p_bluStretch){
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 
341  return (p_redStretch && p_grnStretch && p_bluStretch);
342  }
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 }
Isis::AdvancedStretch
Advanced Stretch Dialog.
Definition: AdvancedStretch.h:32
Isis::AdvancedStretchDialog::isRgbMode
bool isRgbMode() const
Returns true if the dialog is displaying the RGB advanced stretches.
Definition: AdvancedStretchDialog.cpp:340
Isis::AdvancedStretchDialog::restoreRgbStretch
void restoreRgbStretch(CubeStretch red, CubeStretch green, CubeStretch blue)
Restores a saved RGB stretch from the cube.
Definition: AdvancedStretchDialog.cpp:194
QWidget
Isis::AdvancedStretchDialog::updateHistogram
void updateHistogram(const Histogram &grayHist)
This calls setHistogram on the gray advanced stretches.
Definition: AdvancedStretchDialog.cpp:306
Isis::AdvancedStretchDialog::hideEvent
void hideEvent(QHideEvent *)
This is implemented to send a signal when visibility changes.
Definition: AdvancedStretchDialog.cpp:328
Isis::AdvancedStretchDialog::getGrayStretch
CubeStretch getGrayStretch()
This returns the advanced stretch's stretch for gray.
Definition: AdvancedStretchDialog.cpp:350
Isis::AdvancedStretchDialog::updateStretch
void updateStretch(CubeViewport *)
This calls setStretch on all applicable advanced stretches.
Definition: AdvancedStretchDialog.cpp:260
Isis::Stretch
Pixel value mapper.
Definition: Stretch.h:58
Isis::AdvancedStretch::getStretch
CubeStretch getStretch()
This returns the current stretch type's stretch.
Definition: AdvancedStretch.cpp:102
Isis::AdvancedStretch::setHistogram
void setHistogram(const Histogram &newHist)
This is called when the visible area changes, so that the histogram can be updated.
Definition: AdvancedStretch.cpp:158
Isis::AdvancedStretch::restoreSavedStretch
void restoreSavedStretch(CubeStretch newStretch)
Used to restore a saved Stretch from a cube.
Definition: AdvancedStretch.cpp:129
Isis::AdvancedStretchDialog::visibilityChanged
void visibilityChanged()
Emitted when this dialog is shown or hidden.
Isis::CubeStretch
Stores stretch information for a cube.
Definition: CubeStretch.h:27
Isis::CubeViewport::greenStretch
CubeStretch greenStretch() const
Return the green band stretch.
Definition: CubeViewport.cpp:1674
Isis::AdvancedStretchDialog::p_grnStretch
AdvancedStretch * p_grnStretch
Green stretch pane.
Definition: AdvancedStretchDialog.h:101
Isis::CubeViewport::redStretch
CubeStretch redStretch() const
Return the red band stretch.
Definition: CubeViewport.cpp:1668
Isis::AdvancedStretchDialog::stretchChanged
void stretchChanged()
Emitted when an advanced stretch has changed.
Isis::AdvancedStretchDialog::getBluStretch
CubeStretch getBluStretch()
This returns the advanced stretch's stretch for blue.
Definition: AdvancedStretchDialog.cpp:398
Isis::AdvancedStretchDialog::restoreGrayStretch
void restoreGrayStretch(CubeStretch stretch)
Restores a saved grayscale stretch from the cube.
Definition: AdvancedStretchDialog.cpp:176
Isis::CubeViewport::blueStretch
CubeStretch blueStretch() const
Return the blue band stretch.
Definition: CubeViewport.cpp:1680
Isis::AdvancedStretchDialog::updateHistograms
void updateHistograms(const Histogram &redHist, const Histogram &grnHist, const Histogram &bluHist)
This calls setHistogram on all of the advanced stretches.
Definition: AdvancedStretchDialog.cpp:284
Isis::AdvancedStretchDialog::p_enabled
bool p_enabled
True if advanced stretch should be used.
Definition: AdvancedStretchDialog.h:98
Isis::CubeViewport::grayStretch
CubeStretch grayStretch() const
Return the gray band stretch.
Definition: CubeViewport.cpp:1662
Isis::AdvancedStretchDialog::p_bluStretch
AdvancedStretch * p_bluStretch
Blue stretch pane.
Definition: AdvancedStretchDialog.h:102
Isis::AdvancedStretchDialog::getRedStretch
CubeStretch getRedStretch()
This returns the advanced stretch's stretch for red.
Definition: AdvancedStretchDialog.cpp:366
Isis::AdvancedStretchDialog::p_redStretch
AdvancedStretch * p_redStretch
Red stretch pane.
Definition: AdvancedStretchDialog.h:100
Isis::AdvancedStretchDialog::AdvancedStretchDialog
AdvancedStretchDialog(QWidget *parent)
This constructs an advanced stretch.
Definition: AdvancedStretchDialog.cpp:18
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::CubeViewport
Widget to display Isis cubes for qt apps.
Definition: CubeViewport.h:122
Isis::AdvancedStretchDialog::showEvent
void showEvent(QShowEvent *)
This is implemented to send a signal when visibility changes.
Definition: AdvancedStretchDialog.cpp:317
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::AdvancedStretchDialog::enableGrayMode
void enableGrayMode(Stretch &grayStretch, Histogram &grayHist)
This displays a gray advanced stretch.
Definition: AdvancedStretchDialog.cpp:151
Isis::AdvancedStretchDialog::updateForRGBMode
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.
Definition: AdvancedStretchDialog.cpp:122
Isis::Histogram
Container of a cube histogram.
Definition: Histogram.h:74
Isis::AdvancedStretchDialog::~AdvancedStretchDialog
~AdvancedStretchDialog()
This destroys the advanced stretch dialog.
Definition: AdvancedStretchDialog.cpp:37
QFrame
Isis::AdvancedStretchDialog::p_grayStretch
AdvancedStretch * p_grayStretch
Gray stretch pane.
Definition: AdvancedStretchDialog.h:99
Isis::AdvancedStretch::setStretch
void setStretch(Stretch newStretch)
This is called when the user creates a stretch outside of the advanced stretch.
Definition: AdvancedStretch.cpp:115
QDialog
Isis::AdvancedStretchDialog::getGrnStretch
CubeStretch getGrnStretch()
This returns the advanced stretch's stretch for green.
Definition: AdvancedStretchDialog.cpp:382
Isis::AdvancedStretchDialog::destroyCurrentStretches
void destroyCurrentStretches()
This cleans up memory from currently displayed advanced stretches.
Definition: AdvancedStretchDialog.cpp:219
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::AdvancedStretchDialog::enableRgbMode
void enableRgbMode(Stretch &redStretch, Histogram &redHist, Stretch &grnStretch, Histogram &grnHist, Stretch &bluStretch, Histogram &bluHist)
This displays RGB advanced stretches.
Definition: AdvancedStretchDialog.cpp:52