Isis 3 Programmer Reference
LinearStretchType.cpp
1#include "LinearStretchType.h"
2
3#include <QVBoxLayout>
4#include <QLayout>
5#include <QLineEdit>
6#include <QLabel>
7#include <QTableWidget>
8
9#include "CubeViewport.h"
10#include "HistogramWidget.h"
11#include "Statistics.h"
12#include "Stretch.h"
13#include "CubeStretch.h"
14
15namespace Isis {
25 const Stretch &stretch,
26 const QString &name, const QColor &color)
27 : StretchType(hist, stretch, name, color) {
28 p_startSlider = NULL;
29 p_endSlider = NULL;
30 p_startEdit = NULL;
31 p_endEdit = NULL;
32 p_sliderOverride = false;
33 p_editOverride = false;
34
35 QWidget *sliderWidget = new QWidget();
36 QGridLayout *sliderLayout = new QGridLayout();
37 sliderLayout->setColumnStretch(1, 10);
38
39 QLabel *minHistLabel = new QLabel("Min DN");
40 p_startSlider = new QSlider(Qt::Horizontal);
41 p_startSlider->setTickPosition(QSlider::NoTicks);
42 p_startSlider->setMinimum(0);
43 p_startSlider->setMaximum(1000);
44 p_startSlider->setPageStep(50);
45 connect(p_startSlider, SIGNAL(valueChanged(int)),
46 this, SLOT(startSliderMoved(int)));
47 p_startEdit = new QLineEdit();
48 p_startEdit->setMaximumWidth(75);
49 connect(p_startEdit, SIGNAL(textChanged(const QString &)),
50 this, SLOT(startEditChanged(const QString &)));
51 sliderLayout->addWidget(minHistLabel, 0, 0);
52 sliderLayout->addWidget(p_startSlider, 0, 1);
53 sliderLayout->addWidget(p_startEdit, 0, 2);
54
55 QLabel *maxHistLabel = new QLabel("Max DN");
56 p_endSlider = new QSlider(Qt::Horizontal);
57 p_endSlider->setTickPosition(QSlider::NoTicks);
58 p_endSlider->setMinimum(0);
59 p_endSlider->setMaximum(1000);
60 p_endSlider->setValue(1000);
61 p_endSlider->setPageStep(50);
62 connect(p_endSlider, SIGNAL(valueChanged(int)),
63 this, SLOT(endSliderMoved(int)));
64 p_endEdit = new QLineEdit();
65 p_endEdit->setMaximumWidth(75);
66 connect(p_endEdit, SIGNAL(textChanged(const QString &)),
67 this, SLOT(endEditChanged(const QString &)));
68 sliderLayout->addWidget(maxHistLabel, 1, 0);
69 sliderLayout->addWidget(p_endSlider, 1, 1);
70 sliderLayout->addWidget(p_endEdit, 1, 2);
71
72 sliderWidget->setLayout(sliderLayout);
73 p_mainLayout->addWidget(sliderWidget, 1, 0);
74
75 setLayout(p_mainLayout);
76
77 setStretch(stretch);
78 }
79
80
86
87
100 Stretch interpretted;
101
102 if(newStretch.Pairs() >= 2) {
103 double inMin = newStretch.Input(0);
104 double inMax = newStretch.Input(1);
105
106 if(inMax < inMin) {
107 double tmp = inMax;
108 inMax = inMin;
109 inMin = tmp;
110 }
111
112 interpretted.AddPair(inMin, 0);
113 interpretted.AddPair(inMax, 255);
114 }
115 else {
116 double inMin = p_cubeHist->BestMinimum();
117 double inMax = p_cubeHist->BestMaximum();
118
119 if(inMin >= inMax) {
120 inMin -= p_cubeHist->BinSize();
121 inMax += p_cubeHist->BinSize();
122 }
123
124 // Handles case where the histogram bin size=0
125 if (inMin == inMax) {
126 inMin -= 1.0;
127 inMax += 1.0;
128 }
129
130 interpretted.AddPair(inMin, 0);
131 interpretted.AddPair(inMax, 255);
132 }
133
134 bool changed = (interpretted.Text() != p_stretch->Text());
135
136 p_editOverride = true;
137
138 if(changed) {
139 p_stretch->CopyPairs(interpretted);
140 p_startEdit->setText(QString::number(p_stretch->Input(0)));
141 p_endEdit->setText(QString::number(p_stretch->Input(1)));
142 }
143
144 // regardless of it all, slider positions could need changed...
145 startEditChanged(QString());
146 endEditChanged(QString());
147 p_editOverride = false;
148
149 if(changed) {
150 emit stretchChanged();
151 }
152 }
153
154
161 return;
162
163 if(p_startSlider->value() >= p_endSlider->value()) {
164 p_startSlider->setValue(p_endSlider->value() - 1);
165 return;
166 }
167
168 double value = p_cubeHist->Minimum();
169 value += p_startSlider->value() *
170 (p_cubeHist->Maximum() - p_cubeHist->Minimum()) / 1000.0;
171 p_startEdit->setText(QString::number(value));
172 }
173
174
180 double value = p_startEdit->text().toDouble();
181
182 if(value >= p_endEdit->text().toDouble()) {
183 return;
184 }
185
186 double percentage = value - p_cubeHist->Minimum();
187 percentage /= (p_cubeHist->Maximum() - p_cubeHist->Minimum());
188 int valuePos = (int)(percentage * 1000.0);
189
190 p_sliderOverride = true;
191 p_startSlider->setValue(valuePos);
192 p_sliderOverride = false;
193
194 if(p_editOverride) return;
195
196 Stretch newStretch;
197 newStretch.AddPair(value, 0);
198 newStretch.AddPair(p_stretch->Input(1), 255);
199
200 if(newStretch.Text() != p_stretch->Text()) {
201 p_stretch->CopyPairs(newStretch);
202 emit stretchChanged();
203 }
204 }
205
206
213 return;
214
215 if(p_endSlider->value() <= p_startSlider->value()) {
216 p_endSlider->setValue(p_startSlider->value() + 1);
217 return;
218 }
219
220 double value = p_cubeHist->Minimum();
221 value += p_endSlider->value() *
222 (p_cubeHist->Maximum() - p_cubeHist->Minimum()) / 1000.0;
223 p_endEdit->setText(QString::number(value));
224 }
225
226
231 void LinearStretchType::endEditChanged(const QString &) {
232 double value = p_endEdit->text().toDouble();
233
234 if(value <= p_startEdit->text().toDouble()) {
235 return;
236 }
237
238 double percentage = value - p_cubeHist->Minimum();
239 percentage /= (p_cubeHist->Maximum() - p_cubeHist->Minimum());
240 int valuePos = (int)(percentage * 1000.0);
241
242 p_sliderOverride = true;
243 p_endSlider->setValue(valuePos);
244 p_sliderOverride = false;
245
246 if(p_editOverride) return;
247
248 Stretch newStretch;
249 newStretch.AddPair(p_stretch->Input(0), 0);
250 newStretch.AddPair(value, 255);
251
252 if(newStretch.Text() != p_stretch->Text()) {
253 p_stretch->CopyPairs(newStretch);
254 emit stretchChanged();
255 }
256 }
257
258
265 CubeStretch cubeStretch(*p_stretch, "Linear");
266 return cubeStretch;
267 }
268}
Stores stretch information for a cube.
Definition CubeStretch.h:27
Container of a cube histogram.
Definition Histogram.h:74
double BinSize() const
Returns the size of an individual bin.
bool p_editOverride
This is used to let the edits be changed without updating the stretch.
virtual CubeStretch getStretch()
Returns the CubeStretch for this LinearStretch.
void startSliderMoved(int)
This is called when the start point slider moves.
virtual void setStretch(Stretch)
Given an arbitrary stretch, this will re-interpret it, as best as possible, into a linear stretch.
QLineEdit * p_startEdit
Line start pt edit.
void endEditChanged(const QString &)
A new end point was typed in.
QLineEdit * p_endEdit
Line end pt edit.
void endSliderMoved(int)
This is called when the end point slider moves.
void startEditChanged(const QString &)
A new start point was typed in.
LinearStretchType(const Histogram &, const Stretch &, const QString &name, const QColor &color)
This constructs a linear stretch type.
QSlider * p_endSlider
Line end pt slider.
QSlider * p_startSlider
Line start pt slider.
bool p_sliderOverride
This is used to let the edits be changed to where sliders cant go.
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
double BestMinimum(const double percent=99.5) const
This method returns the better of the absolute minimum or the Chebyshev minimum.
double BestMaximum(const double percent=99.5) const
This method returns the better of the absolute maximum or the Chebyshev maximum.
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
Pixel value mapper.
Definition Stretch.h:58
void CopyPairs(const Stretch &other)
Copies the stretch pairs from another Stretch object, but maintains special pixel values.
Definition Stretch.cpp:392
void AddPair(const double input, const double output)
Adds a stretch pair to the list of pairs.
Definition Stretch.cpp:48
double Input(const int index) const
Returns the value of the input side of the stretch pair at the specified index.
Definition Stretch.cpp:287
QString Text() const
Converts stretch pair to a string.
Definition Stretch.cpp:268
This is the base class for advanced stretches.
Definition StretchType.h:39
Stretch * p_stretch
Current stretch pairs stored here.
Definition StretchType.h:71
Histogram * p_cubeHist
Visible area histogram.
Definition StretchType.h:68
QGridLayout * p_mainLayout
Main layout.
Definition StretchType.h:67
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