10 #include "AdvancedStretchDialog.h"
16 #include "MainWindow.h"
18 #include "RubberBandTool.h"
23 #include "ViewportMainWindow.h"
48 QPushButton *hiddenButton =
new QPushButton();
49 hiddenButton->setVisible(
false);
50 hiddenButton->setDefault(
true);
65 if (parentMainWindow) {
66 connect(
this, SIGNAL(
warningSignal(std::string &,
const std::string)),
67 parentMainWindow, SLOT(displayWarning(std::string &,
const std::string &)));
94 action->setIcon(QPixmap(
toolIconDir() +
"/stretch_global.png"));
95 action->setToolTip(
"Stretch (S)");
96 action->setShortcut(Qt::Key_S);
98 "<b>Function:</b> Change the stretch range of the cube.\
99 <p><b>Shortcut:</b> S</p> ";
100 action->setWhatsThis(text);
129 QToolButton *butt =
new QToolButton(hbox);
130 butt->setAutoRaise(
true);
131 butt->setIconSize(QSize(22, 22));
132 butt->setIcon(QPixmap(
toolIconDir() +
"/regional_stretch-2.png"));
133 butt->setToolTip(
"Stretch");
135 "<b>Function:</b> Automatically compute min/max stretch using viewed \
136 pixels in the band(s) of the active viewport. That is, only pixels \
137 that are visible in the viewport are used. \
138 If the viewport is in RGB color all three bands will be stretched. \
139 <p><b>Shortcut:</b> Ctrl+R</p> \
140 <p><b>Mouse:</b> Left click \
141 <p><b>Hint:</b> Left click and drag for a local stretch. Uses only \
142 pixels in the red marquee</p>";
143 butt->setWhatsThis(text);
155 "<b>Function:</b> Selecting the color will allow the appropriate \
156 min/max to be seen and/or edited in text fields to the right.";
167 QDoubleValidator *dval =
new QDoubleValidator(hbox);
172 "<b>Function:</b> Shows the current minimum pixel value. Pixel values \
173 below minimum are shown as black. Pixel values above the maximum \
174 are shown as white or the highest intensity of red/green/blue \
175 if in color. Pixel values between the minimum and maximum are stretched \
176 linearly between black and white (or color component). \
177 <p><b>Hint:</b> You can manually edit the minimum but it must be \
178 less than the maximum.";
188 "<b>Function:</b> Shows the current maximum pixel value. Pixel values \
189 below minimum are shown as black. Pixel values above the maximum \
190 are shown as white or the highest intensity of red/green/blue \
191 if in color. Pixel values between the minimum and maximum are stretched \
192 linearly between black and white (or color component). \
193 <p><b>Hint:</b> You can manually edit the maximum but it must be \
194 greater than the minimum";
200 QMenu *copyMenu =
new QMenu();
201 QMenu *globalMenu =
new QMenu();
208 copyAll->setIcon(QPixmap(
toolIconDir() +
"/copy_stretch.png"));
209 copyAll->setText(
"to All Viewports");
212 copyMenu->addAction(copyAll);
219 m_copyButton->setPopupMode(QToolButton::MenuButtonPopup);
224 "<b>Function:</b> Copy the current stretch to all the \
225 active viewports. Or use the drop down menu to copy the current stretch \
226 to all the bands in the active viewport. \
227 <p><b>Hint:</b> Can reset the stretch to an automaticaly computed \
228 stretch by using the 'Reset' stretch button option. </p>";
232 currentView->setText(
"Active Viewport");
233 currentView->setIcon(QPixmap(
toolIconDir() +
"/global_stretch.png"));
234 globalMenu->addAction(currentView);
235 connect(currentView, SIGNAL(triggered(
bool)),
this, SLOT(
stretchGlobal()));
238 globalAll->setText(
"All Viewports");
239 globalMenu->addAction(globalAll);
243 globalBands->setText(
"All Bands");
244 globalMenu->addAction(globalBands);
255 "<b>Function:</b> Reset the stretch to be automatically computed "
256 "using the statisics from the entire image. Use the drop down menu "
257 "to reset the stretch for all the bands in the active viewport or "
258 "to reset the stretch for all the viewports.";
261 QPushButton *advancedButton =
new QPushButton(
"Advanced");
266 "<b>Function:</b> While this button is pressed down, the visible stretch "
267 "will be the automatically computed stretch using the statisics from the "
268 "entire image. The original stretch is restored once you let up on this "
274 QHBoxLayout *layout =
new QHBoxLayout(hbox);
275 layout->setMargin(0);
282 layout->addWidget(advancedButton);
284 layout->addStretch();
285 hbox->setLayout(layout);
361 bluStretch, bluHist);
401 bluStretch, bluHist);
433 if(cvp && cvp->
isGray()) {
474 QRect rect(0, 0, cvp->viewport()->width(), cvp->viewport()->height());
476 if(bandId == (
int)
Gray) {
489 if(bandId == (
int)
Red || bandId == (
int)
All) {
500 if(bandId == (
int)
Green || bandId == (
int)All) {
511 if(bandId == (
int)
Blue || bandId == (
int)All) {
534 if(cvp == NULL)
return;
562 double min = 0, max = 0;
567 min = stretch.
Input(0);
579 min = rstretch.
Input(0);
583 min = gstretch.
Input(0);
587 min = bstretch.
Input(0);
618 if(cvp == NULL)
return;
658 if(cvp == NULL)
return;
692 redStretch.
AddPair(max, 255.0);
696 greenStretch.
AddPair(min, 0.0);
697 greenStretch.
AddPair(max, 255.0);
702 blueStretch.
AddPair(max, 255.0);
736 if(cvp == NULL)
return;
747 if(cvp == NULL)
return;
783 if(cvp == NULL)
return;
793 QRect rect(0, 0, cvp->viewport()->width(), cvp->viewport()->height());
807 if(cvp == NULL)
return;
808 if(!rubberBandTool()->isValid())
return;
810 QRect rubberBandRect = rubberBandTool()->
rectangle();
812 if(rubberBandRect.width() == 0 || rubberBandRect.height() == 0)
return;
858 "Unknown stretch band",
876 if(cvp == NULL)
return;
882 if(s == Qt::RightButton) {
899 rubberBandTool()->
enable(RubberBandTool::RectangleMode);
911 if(cvp == NULL)
return;
963 if(thisViewport == NULL)
return;
1019 if(stretch.
Pairs() == 0) {
1020 stretch.
AddPair(-DBL_MAX, 0.0);
1021 stretch.
AddPair(DBL_MAX, 255.0);
1042 else if(band ==
Green) {
1046 else if(band ==
Blue) {
1056 if(fabs(hist.Percent(0.5) - hist.Percent(99.5)) > DBL_EPSILON) {
1057 stretch.
AddPair(hist.Percent(0.5), 0.0);
1058 stretch.
AddPair(hist.Percent(99.5), 255.0);
1061 stretch.
AddPair(-DBL_MAX, 0.0);
1062 stretch.
AddPair(DBL_MAX, 255.0);
1081 for(
int line = 0; line < cube->
lineCount(); line++) {
1104 "Cannot stretch while the cube is still loading",
1108 QRect dataArea = QRect(buffer->
bufferXYRect().intersected(rect));
1111 for(
int y = dataArea.top();
1112 !dataArea.isNull() && y <= dataArea.bottom();
1116 for(
int x = dataArea.left(); x < dataArea.right(); x++) {
1117 stats.AddData(line[x - buffer->
bufferXYRect().left()]);
1136 double min,
double max) {
1140 for(
int line = 0; line < cube->
lineCount(); line++) {
1177 QRect rect,
double min,
double max) {
1178 QRect dataArea = QRect(buffer->
bufferXYRect().intersected(rect));
1183 for(
int y = dataArea.top(); !dataArea.isNull() && y <= dataArea.bottom(); y++) {
1185 hist.
AddData(&line.front() + (dataArea.left() - buffer->
bufferXYRect().left()), dataArea.width());
1194 std::string msg =
"Insufficient data Min [" + sMin +
"], Max [" + sMax +
"]";
1195 msg +=
" in the stretch area.";