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 
14 namespace Isis {
24  const Stretch &stretch,
25  const QString &name, const QColor &color)
26  : StretchType(hist, stretch, name, color) {
27  p_startSlider = NULL;
28  p_endSlider = NULL;
29  p_startEdit = NULL;
30  p_endEdit = NULL;
31  p_sliderOverride = false;
32  p_editOverride = false;
33 
34  QWidget *sliderWidget = new QWidget();
35  QGridLayout *sliderLayout = new QGridLayout();
36  sliderLayout->setColumnStretch(1, 10);
37 
38  QLabel *minHistLabel = new QLabel("Min DN");
39  p_startSlider = new QSlider(Qt::Horizontal);
40  p_startSlider->setTickPosition(QSlider::NoTicks);
41  p_startSlider->setMinimum(0);
42  p_startSlider->setMaximum(1000);
43  p_startSlider->setPageStep(50);
44  connect(p_startSlider, SIGNAL(valueChanged(int)),
45  this, SLOT(startSliderMoved(int)));
46  p_startEdit = new QLineEdit();
47  p_startEdit->setMaximumWidth(75);
48  connect(p_startEdit, SIGNAL(textChanged(const QString &)),
49  this, SLOT(startEditChanged(const QString &)));
50  sliderLayout->addWidget(minHistLabel, 0, 0);
51  sliderLayout->addWidget(p_startSlider, 0, 1);
52  sliderLayout->addWidget(p_startEdit, 0, 2);
53 
54  QLabel *maxHistLabel = new QLabel("Max DN");
55  p_endSlider = new QSlider(Qt::Horizontal);
56  p_endSlider->setTickPosition(QSlider::NoTicks);
57  p_endSlider->setMinimum(0);
58  p_endSlider->setMaximum(1000);
59  p_endSlider->setValue(1000);
60  p_endSlider->setPageStep(50);
61  connect(p_endSlider, SIGNAL(valueChanged(int)),
62  this, SLOT(endSliderMoved(int)));
63  p_endEdit = new QLineEdit();
64  p_endEdit->setMaximumWidth(75);
65  connect(p_endEdit, SIGNAL(textChanged(const QString &)),
66  this, SLOT(endEditChanged(const QString &)));
67  sliderLayout->addWidget(maxHistLabel, 1, 0);
68  sliderLayout->addWidget(p_endSlider, 1, 1);
69  sliderLayout->addWidget(p_endEdit, 1, 2);
70 
71  sliderWidget->setLayout(sliderLayout);
72  p_mainLayout->addWidget(sliderWidget, 1, 0);
73 
74  setLayout(p_mainLayout);
75 
76  setStretch(stretch);
77  }
78 
79 
84  }
85 
86 
99  Stretch interpretted;
100 
101  if(newStretch.Pairs() >= 2) {
102  double inMin = newStretch.Input(0);
103  double inMax = newStretch.Input(1);
104 
105  if(inMax < inMin) {
106  double tmp = inMax;
107  inMax = inMin;
108  inMin = tmp;
109  }
110 
111  interpretted.AddPair(inMin, 0);
112  interpretted.AddPair(inMax, 255);
113  }
114  else {
115  double inMin = p_cubeHist->BestMinimum();
116  double inMax = p_cubeHist->BestMaximum();
117 
118  if(inMin >= inMax) {
119  inMin -= p_cubeHist->BinSize();
120  inMax += p_cubeHist->BinSize();
121  }
122 
123  interpretted.AddPair(inMin, 0);
124  interpretted.AddPair(inMax, 255);
125  }
126 
127  bool changed = (interpretted.Text() != p_stretch->Text());
128 
129  p_editOverride = true;
130 
131  if(changed) {
132  p_stretch->CopyPairs(interpretted);
133  p_startEdit->setText(QString::number(p_stretch->Input(0)));
134  p_endEdit->setText(QString::number(p_stretch->Input(1)));
135  }
136 
137  // regardless of it all, slider positions could need changed...
138  startEditChanged(QString());
139  endEditChanged(QString());
140  p_editOverride = false;
141 
142  if(changed) {
143  emit stretchChanged();
144  }
145  }
146 
147 
153  if(p_sliderOverride)
154  return;
155 
156  if(p_startSlider->value() >= p_endSlider->value()) {
157  p_startSlider->setValue(p_endSlider->value() - 1);
158  return;
159  }
160 
161  double value = p_cubeHist->Minimum();
162  value += p_startSlider->value() *
163  (p_cubeHist->Maximum() - p_cubeHist->Minimum()) / 1000.0;
164  p_startEdit->setText(QString::number(value));
165  }
166 
167 
172  void LinearStretchType::startEditChanged(const QString &) {
173  double value = p_startEdit->text().toDouble();
174 
175  if(value >= p_endEdit->text().toDouble()) {
176  return;
177  }
178 
179  double percentage = value - p_cubeHist->Minimum();
180  percentage /= (p_cubeHist->Maximum() - p_cubeHist->Minimum());
181  int valuePos = (int)(percentage * 1000.0);
182 
183  p_sliderOverride = true;
184  p_startSlider->setValue(valuePos);
185  p_sliderOverride = false;
186 
187  if(p_editOverride) return;
188 
189  Stretch newStretch;
190  newStretch.AddPair(value, 0);
191  newStretch.AddPair(p_stretch->Input(1), 255);
192 
193  if(newStretch.Text() != p_stretch->Text()) {
194  p_stretch->CopyPairs(newStretch);
195  emit stretchChanged();
196  }
197  }
198 
199 
205  if(p_sliderOverride)
206  return;
207 
208  if(p_endSlider->value() <= p_startSlider->value()) {
209  p_endSlider->setValue(p_startSlider->value() + 1);
210  return;
211  }
212 
213  double value = p_cubeHist->Minimum();
214  value += p_endSlider->value() *
215  (p_cubeHist->Maximum() - p_cubeHist->Minimum()) / 1000.0;
216  p_endEdit->setText(QString::number(value));
217  }
218 
219 
224  void LinearStretchType::endEditChanged(const QString &) {
225  double value = p_endEdit->text().toDouble();
226 
227  if(value <= p_startEdit->text().toDouble()) {
228  return;
229  }
230 
231  double percentage = value - p_cubeHist->Minimum();
232  percentage /= (p_cubeHist->Maximum() - p_cubeHist->Minimum());
233  int valuePos = (int)(percentage * 1000.0);
234 
235  p_sliderOverride = true;
236  p_endSlider->setValue(valuePos);
237  p_sliderOverride = false;
238 
239  if(p_editOverride) return;
240 
241  Stretch newStretch;
242  newStretch.AddPair(p_stretch->Input(0), 0);
243  newStretch.AddPair(value, 255);
244 
245  if(newStretch.Text() != p_stretch->Text()) {
246  p_stretch->CopyPairs(newStretch);
247  emit stretchChanged();
248  }
249  }
250 
251 
253  return *p_stretch;
254  }
255 }
QSlider * p_endSlider
Line end pt slider.
void startEditChanged(const QString &)
A new start point was typed in.
void endSliderMoved(int)
This is called when the end point slider moves.
double Input(const int index) const
Returns the value of the input side of the stretch pair at the specified index.
Definition: Stretch.cpp:302
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
Definition: Statistics.cpp:395
QLineEdit * p_endEdit
Line end pt edit.
void startSliderMoved(int)
This is called when the start point slider moves.
double BestMaximum(const double percent=99.5) const
This method returns the better of the absolute maximum or the Chebyshev maximum.
Definition: Statistics.cpp:634
virtual Stretch getStretch()
Returns the current stretch object.
void stretchChanged()
Emitted when a new Stretch object is available.
Stretch * p_stretch
Current stretch pairs stored here.
Definition: StretchType.h:70
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
int Pairs() const
Returns the number of stretch pairs.
Definition: Stretch.h:176
bool p_editOverride
This is used to let the edits be changed without updating the stretch.
void endEditChanged(const QString &)
A new end point was typed in.
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
Definition: Statistics.cpp:416
void AddPair(const double input, const double output)
Adds a stretch pair to the list of pairs.
Definition: Stretch.cpp:63
double BestMinimum(const double percent=99.5) const
This method returns the better of the absolute minimum or the Chebyshev minimum.
Definition: Statistics.cpp:611
void CopyPairs(const Stretch &other)
Copies the stretch pairs from another Stretch object, but maintains special pixel values...
Definition: Stretch.cpp:407
Container of a cube histogram.
Definition: Histogram.h:86
Pixel value mapper.
Definition: Stretch.h:72
bool p_sliderOverride
This is used to let the edits be changed to where sliders cant go.
QString Text() const
Converts stretch pair to a string.
Definition: Stretch.cpp:283
double BinSize() const
Returns the size of an individual bin.
Definition: Histogram.cpp:691
QLineEdit * p_startEdit
Line start pt edit.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
This is the base class for advanced stretches.
Definition: StretchType.h:38
QSlider * p_startSlider
Line start pt slider.
virtual void setStretch(Stretch)
Given an arbitrary stretch, this will re-interpret it, as best as possible, into a linear stretch...
LinearStretchType(const Histogram &, const Stretch &, const QString &name, const QColor &color)
This constructs a linear stretch type.
Histogram * p_cubeHist
Visible area histogram.
Definition: StretchType.h:67
QGridLayout * p_mainLayout
Main layout.
Definition: StretchType.h:66