Isis 3 Programmer Reference
SpecialPixelTool.cpp
1 #include "SpecialPixelTool.h"
2 
3 #include <QCheckBox>
4 #include <QColorDialog>
5 #include <QDialog>
6 #include <QHBoxLayout>
7 #include <QLabel>
8 #include <QMenu>
9 #include <QPainter>
10 #include <QPalette>
11 #include <QPixmap>
12 #include <QPushButton>
13 #include <QToolBar>
14 #include <QToolButton>
15 #include <QVBoxLayout>
16 
17 #include "FileName.h"
18 #include "MainWindow.h"
19 #include "MdiCubeViewport.h"
20 #include "Stretch.h"
21 #include "Workspace.h"
22 
23 namespace Isis {
31  // Create the SpecialPixel window
32  p_parent = parent;
33 
34  p_dialog = new QDialog(parent);
35  p_dialog->setWindowTitle("Special Pixel Tool");
36  p_dialog->setSizeGripEnabled(true);
38  p_spWindow->setMinimumSize(492, 492);
39  p_spWindow->installEventFilter(this);
40 
41  QWidget *buttons = new QWidget(p_dialog);
42  QWidget *colors = new QWidget(p_dialog);
43  QWidget *labels = new QWidget(p_dialog);
44  QWidget *defaults = new QWidget(p_dialog);
45  QWidget *main = new QWidget(p_dialog);
46 
47  QVBoxLayout *layout = new QVBoxLayout();
48  layout->addWidget(defaults, 0);
49  layout->addWidget(main, 0);
50  layout->addWidget(buttons, 0);
51  p_dialog->setLayout(layout);
52 
53  QPushButton *ok = new QPushButton("Ok", buttons);
54  ok->setShortcut(Qt::Key_Enter);
55  connect(ok, SIGNAL(released()), this, SLOT(apply()));
56  connect(ok, SIGNAL(released()), p_dialog, SLOT(hide()));
57 
58  QPushButton *apply = new QPushButton("Apply", buttons);
59  connect(apply, SIGNAL(released()), this, SLOT(apply()));
60 
61  QPushButton *cancel = new QPushButton("Cancel", buttons);
62  connect(cancel, SIGNAL(released()), p_dialog, SLOT(hide()));
63 
64  QPushButton *defaultBlackWhite = new QPushButton("Default B&W", defaults);
65  connect(defaultBlackWhite, SIGNAL(released()), this, SLOT(defaultBW()));
66 
67  QPushButton *defaultColor = new QPushButton("Default Color", defaults);
68  connect(defaultColor, SIGNAL(released()), this, SLOT(defaultColor()));
69 
70  QHBoxLayout *hlayout = new QHBoxLayout();
71  hlayout->addWidget(ok);
72  hlayout->addWidget(apply);
73  hlayout->addWidget(cancel);
74  // hlayout->addStretch(1);
75  buttons->setLayout(hlayout);
76 
77  QHBoxLayout *h2layout = new QHBoxLayout();
78  h2layout->addWidget(defaultBlackWhite);
79  h2layout->addWidget(defaultColor);
80  defaults->setLayout(h2layout);
81 
82  p_nullColor = new QToolButton(p_dialog);
83  connect(p_nullColor, SIGNAL(released()), this, SLOT(setNullColor()));
84  QSize *size = new QSize(25, 25);
85  QLabel *nullLabel = new QLabel("Null");
86  p_nullColor->setFixedSize(*size);
87 
88  p_lisColor = new QToolButton(p_dialog);
89  connect(p_lisColor, SIGNAL(released()), this, SLOT(setLisColor()));
90  QLabel *lisLabel = new QLabel("Low Instrument Saturation");
91  p_lisColor->setFixedSize(*size);
92 
93  p_lrsColor = new QToolButton(p_dialog);
94  connect(p_lrsColor, SIGNAL(released()), this, SLOT(setLrsColor()));
95  QLabel *lrsLabel = new QLabel("Low Representation Saturation");
96  p_lrsColor->setFixedSize(*size);
97 
98  p_ldsColor = new QToolButton(p_dialog);
99  connect(p_ldsColor, SIGNAL(released()), this, SLOT(setLdsColor()));
100  QLabel *ldsLabel = new QLabel("Low Display Saturation");
101  p_ldsColor->setFixedSize(*size);
102 
103  p_hisColor = new QToolButton(p_dialog);
104  connect(p_hisColor, SIGNAL(released()), this, SLOT(setHisColor()));
105  QLabel *hisLabel = new QLabel("High Instrument Saturation");
106  p_hisColor->setFixedSize(*size);
107 
108  p_hrsColor = new QToolButton(p_dialog);
109  connect(p_hrsColor, SIGNAL(released()), this, SLOT(setHrsColor()));
110  QLabel *hrsLabel = new QLabel("High Representation Saturation");
111  p_hrsColor->setFixedSize(*size);
112 
113  p_hdsColor = new QToolButton(p_dialog);
114  connect(p_hdsColor, SIGNAL(released()), this, SLOT(setHdsColor()));
115  QLabel *hdsLabel = new QLabel("High Display Saturation");
116  p_hdsColor->setFixedSize(*size);
117 
118  p_bgColor = new QToolButton(p_dialog);
119  connect(p_bgColor, SIGNAL(released()), this, SLOT(setBgColor()));
120  QLabel *bgLabel = new QLabel("Background");
121  p_bgColor->setFixedSize(*size);
122 
123  connect(this, SIGNAL(setDefaultColors()), this, SLOT(defaultBW()));
124  emit setDefaultColors();
125 
126  QVBoxLayout *vlayout = new QVBoxLayout();
127  vlayout->addWidget(nullLabel);
128  vlayout->addWidget(lisLabel);
129  vlayout->addWidget(hisLabel);
130  vlayout->addWidget(lrsLabel);
131  vlayout->addWidget(hrsLabel);
132  vlayout->addWidget(ldsLabel);
133  vlayout->addWidget(hdsLabel);
134  vlayout->addWidget(bgLabel);
135  labels->setLayout(vlayout);
136 
137  QVBoxLayout *v2layout = new QVBoxLayout();
138  v2layout->addWidget(p_nullColor);
139  v2layout->addWidget(p_lisColor);
140  v2layout->addWidget(p_hisColor);
141  v2layout->addWidget(p_lrsColor);
142  v2layout->addWidget(p_hrsColor);
143  v2layout->addWidget(p_ldsColor);
144  v2layout->addWidget(p_hdsColor);
145  v2layout->addWidget(p_bgColor);
146  colors->setLayout(v2layout);
147 
148  QHBoxLayout *mainlayout = new QHBoxLayout();
149  mainlayout->addWidget(colors);
150  mainlayout->addWidget(labels);
151  main->setLayout(mainlayout);
152 
153  // Create the action to bring up the SpecialPixel window
154  p_action = new QAction(parent);
155  //p_action->setShortcut(Qt::CTRL+Qt::Key_C);
156  p_action->setText("&Special Pixel Tool ...");
157  p_action->setIcon(QPixmap(toolIconDir() + "/colorize.png"));
158  p_action->setToolTip("SpecialPixelTool");
159  QString text =
160  "<b>Function:</b> Opens a window that allows you to chose what color to \
161  display each different type of special pixel \
162  <p><b>Shortcut:</b> Ctrl+C</p>";
163  p_action->setWhatsThis(text);
164  p_action->setEnabled(false);
165  connect(p_action, SIGNAL(triggered()), p_dialog, SLOT(show()));
166 
167  readSettings();
168  }
169 
170 
178  menu->addAction(p_action);
179  }
180 
181 
189  perm->addAction(p_action);
190  }
191 
192 
198  Tool::addTo(ws);
199  connect(ws, SIGNAL(cubeViewportAdded(MdiCubeViewport *)),
200  this, SLOT(apply()));
201  }
202 
203 
209  for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
210  MdiCubeViewport *cvp = (*(cubeViewportList()))[i];
211 
212  // Get the Stretch objects from the cubeViewport
213  Stretch redStretch = cvp->redStretch();
214  Stretch greenStretch = cvp->greenStretch();
215  Stretch blueStretch = cvp->blueStretch();
216 
217  // Apply selected null color
218  QPalette palette = p_nullColor->palette();
219  QColor nullColor = palette.color(QPalette::Button);
220  int r, g, b;
221  nullColor.getRgb(&r, &g, &b);
222  redStretch.SetNull(r);
223  greenStretch.SetNull(g);
224  blueStretch.SetNull(b);
225 
226  // Apply selected lis
227  palette = p_lisColor->palette();
228  QColor lisColor = palette.color(QPalette::Button);
229  lisColor.getRgb(&r, &g, &b);
230  redStretch.SetLis(r);
231  greenStretch.SetLis(g);
232  blueStretch.SetLis(b);
233 
234  // Apply selected lrs
235  palette = p_lrsColor->palette();
236  QColor lrsColor = palette.color(QPalette::Button);
237  lrsColor.getRgb(&r, &g, &b);
238  redStretch.SetLrs(r);
239  greenStretch.SetLrs(g);
240  blueStretch.SetLrs(b);
241 
242  // Apply selected lds
243  palette = p_ldsColor->palette();
244  QColor ldsColor = palette.color(QPalette::Button);
245  ldsColor.getRgb(&r, &g, &b);
246  redStretch.SetMinimum(r);
247  greenStretch.SetMinimum(g);
248  blueStretch.SetMinimum(b);
249 
250  // Apply selected his
251  palette = p_hisColor->palette();
252  QColor hisColor = palette.color(QPalette::Button);
253  hisColor.getRgb(&r, &g, &b);
254  redStretch.SetHis(r);
255  greenStretch.SetHis(g);
256  blueStretch.SetHis(b);
257 
258  // Apply selected hrs
259  palette = p_hrsColor->palette();
260  QColor hrsColor = palette.color(QPalette::Button);
261  hrsColor.getRgb(&r, &g, &b);
262  redStretch.SetHrs(r);
263  greenStretch.SetHrs(g);
264  blueStretch.SetHrs(b);
265 
266  // Apply selected hds
267  palette = p_hdsColor->palette();
268  QColor hdsColor = palette.color(QPalette::Button);
269  hdsColor.getRgb(&r, &g, &b);
270  redStretch.SetMaximum(r);
271  greenStretch.SetMaximum(g);
272  blueStretch.SetMaximum(b);
273 
274  // Apply selected background
275  palette = p_bgColor->palette();
276  QColor bgColor = palette.color(QPalette::Button);
277  bgColor.getRgb(&r, &g, &b);
278 
279  cvp->setBackground(bgColor);
280  cvp->stretchRed(redStretch);
281  cvp->stretchGreen(greenStretch);
282  cvp->stretchBlue(blueStretch);
283 
284  //If any of the defaults changed, make sure to write them
285  if(p_color) {
286  p_nullDefault = nullColor;
287  p_lisDefault = lisColor;
288  p_lrsDefault = lrsColor;
289  p_ldsDefault = ldsColor;
290  p_hisDefault = hisColor;
291  p_hrsDefault = hrsColor;
292  p_hdsDefault = hdsColor;
293  p_bgDefault = bgColor;
294  writeSettings();
295  }
296  }
297  }
298 
299 
306  }
307 
308 
315  }
316 
317 
324  }
325 
326 
333  }
334 
335 
342  }
343 
344 
351  }
352 
353 
360  }
361 
362  void SpecialPixelTool::setBgColor() {
364  }
365 
372  void SpecialPixelTool::setColor(QToolButton *button) {
373  // Let the user pick a color
374  QColor color = QColorDialog::getColor();
375 
376  // Set the color if they didnt cancel out of the window
377  if(color.isValid()) {
378  QPalette *palette = new QPalette();
379  palette->setColor(QPalette::Button, color);
380  button->setPalette(*palette);
381  }
382 
383  }
384 
385 
391  p_color = false;
392  QPalette *palette = new QPalette();
393  palette->setColor(QPalette::Button, Qt::black);
394  p_nullColor->setPalette(*palette);
395  p_lisColor->setPalette(*palette);
396  p_lrsColor->setPalette(*palette);
397  p_ldsColor->setPalette(*palette);
398  p_bgColor->setPalette(*palette);
399 
400  palette->setColor(QPalette::Button, Qt::white);
401  p_hisColor->setPalette(*palette);
402  p_hrsColor->setPalette(*palette);
403  p_hdsColor->setPalette(*palette);
404  }
405 
406 
412  p_color = true;
413  QPalette *palette = new QPalette();
414  palette->setColor(QPalette::Button, p_nullDefault);
415  p_nullColor->setPalette(*palette);
416 
417  palette->setColor(QPalette::Button, p_lisDefault);
418  p_lisColor->setPalette(*palette);
419 
420  palette->setColor(QPalette::Button, p_lrsDefault);
421  p_lrsColor->setPalette(*palette);
422 
423  palette->setColor(QPalette::Button, p_ldsDefault);
424  p_ldsColor->setPalette(*palette);
425 
426  palette->setColor(QPalette::Button, p_hisDefault);
427  p_hisColor->setPalette(*palette);
428 
429  palette->setColor(QPalette::Button, p_hrsDefault);
430  p_hrsColor->setPalette(*palette);
431 
432  palette->setColor(QPalette::Button, p_hdsDefault);
433  p_hdsColor->setPalette(*palette);
434 
435  palette->setColor(QPalette::Button, p_bgDefault);
436  p_bgColor->setPalette(*palette);
437  }
438 
439 
445  if(cubeViewport() == NULL) {
446  p_action->setEnabled(false);
447  }
448  else {
449  p_action->setEnabled(true);
450  }
451  }
452 
453 
460  /*Now read the settings that are specific to this window.*/
461  QString appName = p_parent->windowTitle();
462 
463  /*Now read the settings that are specific to this window.*/
464  QString instanceName = p_dialog->windowTitle();
465 
466  FileName config("$HOME/.Isis/" + appName + "/" + instanceName + ".config");
467  p_settings = new QSettings(config.expanded(), QSettings::NativeFormat);
468 
469  //For each special pixel value, if it exists set it, otherwise set
470  //it to the system defaults.
471 
472  //Default value for Null
473  if(p_settings->value("defaultNull", 1).toInt() == 0) {
474  p_nullDefault = p_settings->value("defaultNull", 1).value<QColor>();
475  }
476  else {
477  p_nullDefault = Qt::blue;
478  }
479 
480  //Default value for Lis
481  if(p_settings->value("defaultLis", 1).toInt() == 0) {
482  p_lisDefault = p_settings->value("defaultLis", 1).value<QColor>();
483  }
484  else {
485  p_lisDefault = Qt::cyan;
486  }
487 
488  //Default value for Lrs
489  if(p_settings->value("defaultLrs", 1).toInt() == 0) {
490  p_lrsDefault = p_settings->value("defaultLrs", 1).value<QColor>();
491  }
492  else {
493  p_lrsDefault = Qt::yellow;
494  }
495 
496  //Default value for Lds
497  if(p_settings->value("defaultLds", 1).toInt() == 0) {
498  p_ldsDefault = p_settings->value("defaultLds", 1).value<QColor>();
499  }
500  else {
501  p_ldsDefault = Qt::black;
502  }
503 
504  //Default value for His
505  if(p_settings->value("defaultHis", 1).toInt() == 0) {
506  p_hisDefault = p_settings->value("defaultHis", 1).value<QColor>();
507  }
508  else {
509  p_hisDefault = Qt::magenta;
510  }
511 
512  //Default value for Hrs
513  if(p_settings->value("defaultHrs", 1).toInt() == 0) {
514  p_hrsDefault = p_settings->value("defaultHrs", 1).value<QColor>();
515  }
516  else {
517  p_hrsDefault = Qt::green;
518  }
519 
520  //Default value for Hds
521  if(p_settings->value("defaultHds", 1).toInt() == 0) {
522  p_hdsDefault = p_settings->value("defaultHds", 1).value<QColor>();
523  }
524  else {
525  p_hdsDefault = Qt::white;
526  }
527 
528  //Default value for Bg
529  if(p_settings->value("defaultBg", 1).toInt() == 0) {
530  p_bgDefault = p_settings->value("defaultBg", 1).value<QColor>();
531  }
532  else {
533  p_bgDefault = Qt::black;
534  }
535  }
536 
537 
544  QString appName = p_parent->windowTitle();
545 
546  /*Now read the settings that are specific to this window.*/
547  QString instanceName = p_dialog->windowTitle();
548 
549  //Write all of the special pixel value colors
550  FileName config("$HOME/.Isis/" + appName + "/" + instanceName + ".config");
551  QSettings settings(config.expanded(), QSettings::NativeFormat);
552  settings.setValue("defaultNull", p_nullDefault);
553  settings.setValue("defaultLis", p_lisDefault);
554  settings.setValue("defaultLrs", p_lrsDefault);
555  settings.setValue("defaultLds", p_ldsDefault);
556  settings.setValue("defaultHis", p_hisDefault);
557  settings.setValue("defaultHrs", p_hrsDefault);
558  settings.setValue("defaultHds", p_hdsDefault);
559  settings.setValue("defaultBg", p_bgDefault);
560  }
561 }
Cube display widget for certain Isis MDI applications.
QColor p_hrsDefault
Color chosen for high representation saturation pixels.
Stretch redStretch() const
Return the red band stretch.
void apply()
Applies the colors picked for the special pixels.
void addToPermanent(QToolBar *perm)
Adds the tool to the permanent tool bar.
QString toolIconDir() const
returns the path to the icon directory.
Definition: Tool.h:127
QToolButton * p_hisColor
High instrument saturation Button.
QColor p_ldsDefault
Color chosen for pixels.
File name manipulation and expansion.
Definition: FileName.h:116
void stretchBlue(const QString &string)
Apply stretch pairs to blue bands.
Stretch greenStretch() const
Return the green band stretch.
QColor p_bgDefault
Color chosen for pixels.
void setHdsColor()
Sets the color for Hds pixels.
void stretchRed(const QString &string)
Apply stretch pairs to red bands.
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition: Tool.cpp:390
void setLisColor()
Sets the color for Lis pixels.
QToolButton * p_ldsColor
Low Button.
void SetLis(const double value)
Sets the mapping for LIS pixels.
Definition: Stretch.h:119
QColor p_lrsDefault
Color chosen for Low representation saturation pixels.
void readSettings()
This method reads in the default special pixel value colors from a config file.
void setNullColor()
Sets the color for null pixels.
void defaultColor()
Reset the default color colors.
QAction * p_action
Special Pixel Tool&#39;s action.
QToolButton * p_lrsColor
Low representation saturation Button.
void writeSettings()
This methods writes the default special pixel values to a config file that will be read by the readSe...
void setLrsColor()
Sets the color for Lrs pixels.
QWidget * p_parent
Parent widget.
QToolButton * p_nullColor
Null Button.
void setHisColor()
Sets the color for His pixels.
void setDefaultColors()
Emitted when the default colors are reset.
QToolButton * p_hrsColor
High representation saturation Button.
QColor p_lisDefault
Color chosen for low instrument saturation pixels.
void defaultBW()
Reset the default black/white colors.
void SetHrs(const double value)
Sets the mapping for HRS pixels.
Definition: Stretch.h:152
void setColor(QToolButton *button)
Gets the selected color from the color dialog.
Pixel value mapper.
Definition: Stretch.h:72
void SetLrs(const double value)
Sets the mapping for LRS pixels.
Definition: Stretch.h:130
int main(int argc, char *argv[])
The programmer supplied main function.
Definition: Isis.h:109
void SetHis(const double value)
Sets the mapping for HIS pixels.
Definition: Stretch.h:141
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
void updateTool()
Updates special pixel tool.
void addTo(ViewportMainWindow *mw)
Adds the tool to the application.
Definition: Tool.cpp:78
QSettings * p_settings
< Settings
QColor p_hdsDefault
Color chosen for pixels.
SpecialPixelTool(QWidget *parent)
SpecialPixelTool constructor.
void addTo(QMenu *menu)
Adds the tool to the given menu.
QToolButton * p_bgColor
Background color Button.
void setHrsColor()
Sets the color for Hrs pixels.
QWidget * p_spWindow
Window widget.
QDialog * p_dialog
Dialog box.
void stretchGreen(const QString &string)
Apply stretch pairs to green bands.
QToolButton * p_lisColor
Low instrument saturation Button.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Base class for the Qisis tools.
Definition: Tool.h:81
void setBackground(QColor color)
Sets the background color.
Definition: CubeViewport.h:383
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition: Tool.h:211
QToolButton * p_hdsColor
High Button.
void setLdsColor()
Sets the color for Lds pixels.
bool p_color
Color Mode?
QColor p_nullDefault
Color chosen for null pixels.
void SetNull(const double value)
Sets the mapping for NULL pixels.
Definition: Stretch.h:108
QColor p_hisDefault
Color chosen for high instrument saturation pixels.
Stretch blueStretch() const
Return the blue band stretch.