1#include "BinaryStretchType.h"
9#include "CubeViewport.h"
10#include "HistogramWidget.h"
11#include "Statistics.h"
13#include "CubeStretch.h"
26 const QString &name,
const QColor &color)
36 QGridLayout *sliderLayout =
new QGridLayout();
37 sliderLayout->setColumnStretch(1, 10);
39 QLabel *startLabel =
new QLabel(
"Start");
50 connect(
p_startEdit, SIGNAL(textChanged(
const QString &)),
52 sliderLayout->addWidget(startLabel, 0, 0);
56 QLabel *endLabel =
new QLabel(
"End");
68 connect(
p_endEdit, SIGNAL(textChanged(
const QString &)),
70 sliderLayout->addWidget(endLabel, 1, 0);
74 sliderWidget->setLayout(sliderLayout);
105 double switch1 = 0.0;
106 double switch2 = 1.0;
108 if(newStretch.
Pairs() == 2) {
119 switch1 = newStretch.
Input(0);
120 if(switch1 < p_cubeHist->Minimum())
123 interpretted.
AddPair(switch1, 0);
124 interpretted.
AddPair(switch1 + epsilon, 255);
126 switch2 = newStretch.
Input(1);
127 if(switch2 <= switch1 + epsilon)
128 switch2 = switch1 + epsilon + epsilon;
130 interpretted.
AddPair(switch2, 255);
131 interpretted.
AddPair(switch2 + epsilon, 0);
134 if(end <= switch2 + epsilon)
135 end = switch2 + epsilon + epsilon;
140 else if(newStretch.
Pairs() == 4) {
141 if(newStretch.
Output(0) > 127) {
144 switch1 = newStretch.
Input(1);
145 if(switch1 <= p_cubeHist->Minimum())
148 interpretted.
AddPair(switch1, 255);
149 interpretted.
AddPair(switch1 + epsilon, 0);
152 if(end <= switch1 + epsilon)
153 end = switch1 + epsilon + epsilon;
162 switch1 = newStretch.
Input(1);
163 if(switch1 < p_cubeHist->Minimum())
166 interpretted.
AddPair(switch1, 0);
167 interpretted.
AddPair(switch1 + epsilon, 255);
170 if(end <= switch1 + epsilon)
171 end = switch1 + epsilon + epsilon;
174 interpretted.
AddPair(end, 255);
178 else if(newStretch.
Pairs() == 6) {
181 switch1 = newStretch.
Input(1);
182 if(switch1 <= p_cubeHist->Minimum())
185 interpretted.
AddPair(switch1, 0);
186 interpretted.
AddPair(switch1 + epsilon, 255);
189 switch2 = newStretch.
Input(3);
190 if(switch2 <= switch1 + epsilon)
191 switch2 = switch1 + epsilon + epsilon;
193 interpretted.
AddPair(switch2, 255);
194 interpretted.
AddPair(switch2 + epsilon, 0);
197 if(end <= switch2 + epsilon)
198 end = switch2 + epsilon + epsilon;
203 if(!interpretted.
Pairs()) {
215 p_endEdit->setText(QString::number(switch2));
224 emit stretchChanged();
256 if(value >=
p_endEdit->text().toDouble()) {
260 double percentage = value -
p_cubeHist->Minimum();
262 int valuePos = (int)(percentage * 1000.0);
274 emit stretchChanged();
295 p_endEdit->setText(QString::number(value));
304 double value =
p_endEdit->text().toDouble();
306 if(value <= p_startEdit->text().
toDouble()) {
310 double percentage = value -
p_cubeHist->Minimum();
312 int valuePos = (int)(percentage * 1000.0);
324 emit stretchChanged();
349 if(fabs(startPt -
p_cubeHist->Minimum()) < epsilon ||
350 startPt <= p_cubeHist->Minimum()) {
356 newStretch.
AddPair(startPt, 0);
357 newStretch.
AddPair(startPt + epsilon, 255);
361 double endPt =
p_endEdit->text().toDouble();
362 if(endPt <= startPt + epsilon) {
363 endPt = startPt + 2 * epsilon;
366 if(fabs(endPt + epsilon -
p_cubeHist->Maximum()) < epsilon ||
371 newStretch.
AddPair(endPt, 255);
372 newStretch.
AddPair(endPt + epsilon, 0);
BinaryStretchType(const Histogram &, const Stretch &, const QString &name, const QColor &color)
This constructs a binary stretch type.
virtual CubeStretch getStretch()
Gets the CubeStretch for this Binary Stretch.
QSlider * p_endSlider
End point slider.
bool p_sliderOverride
This is used to let the edits be changed to where sliders cant go.
void startEditChanged(const QString &)
A new start point was typed in.
void startSliderMoved(int)
This is called when the start point slider moves.
QLineEdit * p_endEdit
End point edit.
virtual void setStretch(Stretch)
Given an arbitrary stretch, this will re-interpret it, as best as possible, into a binary stretch.
void endSliderMoved(int)
This is called when the end point slider moves.
~BinaryStretchType()
Destroys the binary stretch.
Stretch calculateNewStretch()
This uses the GUI elements to calculate the current binary stretch.
void endEditChanged(const QString &)
A new end point was typed in.
QSlider * p_startSlider
Start point slider.
bool p_editOverride
This is used to let the edits be changed without updating the stretch.
QLineEdit * p_startEdit
Start point edit.
Stores stretch information for a cube.
Container of a cube histogram.
void CopyPairs(const Stretch &other)
Copies the stretch pairs from another Stretch object, but maintains special pixel values.
void AddPair(const double input, const double output)
Adds a stretch pair to the list of pairs.
double Output(const int index) const
Returns the value of the output side of the stretch pair at the specified index.
double Input(const int index) const
Returns the value of the input side of the stretch pair at the specified index.
int Pairs() const
Returns the number of stretch pairs.
QString Text() const
Converts stretch pair to a string.
Stretch * p_stretch
Current stretch pairs stored here.
Histogram * p_cubeHist
Visible area histogram.
StretchType(const Histogram &hist, const Stretch &stretch, const QString &name, const QColor &color)
This constructs a stretch type.
QGridLayout * p_mainLayout
Main layout.
This is free and unencumbered software released into the public domain.
double toDouble(const QString &string)
Global function to convert from a string to a double.