1#include "StatisticsTool.h"
9#include <QIntValidator>
14#include <QRadioButton>
17#include <QStackedWidget>
22#include "MdiCubeViewport.h"
42 p_dialog->setWindowTitle(
"Statistics");
52 QCheckBox *checkBox =
new QCheckBox(
"Hide Display");
53 connect(checkBox, SIGNAL(toggled(
bool)),
this, SLOT(
hideDisplay(
bool)));
55 QLabel *boxLabel =
new QLabel(
"Box Size:");
62 QHBoxLayout *boxLabelLayout =
new QHBoxLayout;
64 boxLabelLayout->addWidget(checkBox);
65 boxLabelLayout->addStretch(1);
66 boxLabelLayout->addWidget(boxLabel);
69 QSlider *slider =
new QSlider(Qt::Vertical);
70 slider->setRange(2, 18);
71 slider->setSliderPosition(10);
72 slider->setSingleStep(1);
73 slider->setTickInterval(1);
74 slider->setTickPosition(QSlider::TicksBelow);
75 connect(slider, SIGNAL(valueChanged(
int)),
p_visualDisplay, SLOT(setBoxSize(
int)));
79 QGroupBox *displayMode =
new QGroupBox(
"Display Mode");
80 QRadioButton *displayText =
new QRadioButton(
"Show Text");
81 displayText->setToolTip(
"Display the pixels of a region as text");
82 QRadioButton *displayPixels =
new QRadioButton(
"Show Pixel Values");
83 displayPixels->setToolTip(
"Display the pixels of a region");
84 QRadioButton *displayDeviation =
new QRadioButton(
"Show Deviation");
85 displayDeviation->setToolTip(
"Display standard deviation over a region,\n where red denotes a larger deviation");
87 QHBoxLayout *displayModeLayout =
new QHBoxLayout;
88 displayModeLayout->addWidget(displayText);
89 displayModeLayout->addWidget(displayPixels);
90 displayModeLayout->addWidget(displayDeviation);
92 displayMode->setLayout(displayModeLayout);
94 connect(displayText, SIGNAL(toggled(
bool)),
p_visualDisplay, SLOT(showText(
bool)));
95 connect(displayText, SIGNAL(toggled(
bool)), slider, SLOT(setDisabled(
bool)));
96 connect(displayPixels, SIGNAL(toggled(
bool)),
p_visualDisplay, SLOT(showPixels(
bool)));
97 connect(displayDeviation, SIGNAL(toggled(
bool)),
p_visualDisplay, SLOT(showDeviation(
bool)));
99 displayText->setChecked(
true);
101 QHBoxLayout *visualHBoxLayout =
new QHBoxLayout;
103 visualHBoxLayout->addWidget(slider);
105 QVBoxLayout *visualVBoxLayout =
new QVBoxLayout;
106 visualVBoxLayout->addLayout(visualHBoxLayout);
107 visualVBoxLayout->addWidget(displayMode);
111 QGroupBox *statsBox =
new QGroupBox(
"Statistics");
114 p_minLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
120 p_maxLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
126 p_avgLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
132 p_stdevLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
139 labelFont.setPointSize(8);
154 QGridLayout *statsLayout =
new QGridLayout;
155 statsLayout->addWidget(
p_minLabel, 0, 0, 1, 2);
156 statsLayout->addWidget(
p_maxLabel, 1, 0, 1, 2);
157 statsLayout->addWidget(
p_avgLabel, 0, 2, 1, 2);
163 statsBox->setLayout(statsLayout);
165 QVBoxLayout *dialogLayout =
new QVBoxLayout;
166 dialogLayout->addLayout(boxLabelLayout);
168 dialogLayout->addWidget(statsBox);
172 checkBox->setChecked(
true);
184 action->setIcon(QPixmap(
toolIconDir() +
"/statistics.png"));
185 action->setToolTip(
"Statistics");
186 QObject::connect(action, SIGNAL(triggered()),
p_dialog, SLOT(show()));
190 action->setWhatsThis(text);
204 QIntValidator *ival =
new QIntValidator(hbox);
205 ival->setRange(1, 100);
207 QLabel *sampleLabel =
new QLabel(
"Box Samples:");
218 QLabel *lineLabel =
new QLabel(
"Box Lines:");
229 QToolButton *showButton =
new QToolButton();
230 showButton->setText(
"Show");
231 showButton->setToolTip(
"");
233 showButton->setWhatsThis(text);
235 connect(showButton, SIGNAL(clicked()),
p_dialog, SLOT(show()));
237 QHBoxLayout *layout =
new QHBoxLayout;
238 layout->setMargin(0);
239 layout->addWidget(sampleLabel);
241 layout->addWidget(lineLabel);
243 layout->addWidget(showButton);
244 layout->addStretch(1);
245 hbox->setLayout(layout);
256 if(s == Qt::LeftButton) {
295 if(cvp == NULL)
return;
298 cvp->viewportToCube(p.x(), p.y(), sample, line);
301 if((sample < 0.5) || (line < 0.5) ||
302 (sample > cvp->cubeSamples() + 0.5) || (line > cvp->cubeLines() + 0.5)) {
306 int isamp = (int)(sample + 0.5);
307 int iline = (int)(line + 0.5);
310 Brick *brick =
new Brick(1, 1, 1, cvp->cube()->pixelType());
318 p_ulSamp = isamp - (int)floor(sampDiff);
319 p_ulLine = iline - (int)floor(lineDiff);
327 if(y < 1 || y > cvp->cubeLines()) {
332 if(x < 1 || x > cvp->cubeSamples()) {
336 brick->SetBasePosition(x, y, cvp->grayBand());
337 cvp->cube()->read(*brick);
338 stats.AddData(brick->at(0));
339 pixelData[i][j] = brick->at(0);
348 if (stats.ValidPixels()) {
349 p_minLabel->setText(QString(
"Minimum: %1").arg(stats.Minimum()));
350 p_maxLabel->setText(QString(
"Maximum: %1").arg(stats.Maximum()));
351 p_avgLabel->setText(QString(
"Average: %1").arg(stats.Average()));
352 p_stdevLabel->setText(QString(
"Standard Dev: %1").arg(stats.StandardDeviation(), 0,
'f', 6));
372 if(samps !=
"" && samps.toInt() !=
p_boxSamps && samps.toInt() > 0) {
392 if(lines !=
"" && lines.toInt() !=
p_boxLines && lines.toInt() > 0) {
413 hbar->setSliderPosition((hbar->maximum() + hbar->minimum()) / 2);
414 vbar->setSliderPosition((vbar->maximum() + vbar->minimum()) / 2);
434 p_showDeviation(false) {
445 setMouseTracking(
true);
446 setBackgroundRole(QPalette::Dark);
447 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
457 return QSize(460, 460);
510 resize(this->
sizeHint().width(), this->size().height());
517 resize(this->size().width(), this->
sizeHint().height());
587 for(
int i = 0; i < data.size(); i++) {
588 for(
int j = 0; j < data[i].size(); j++) {
596 for(
int i = 0; i < data.size(); i++) {
597 hist.AddData(data[i].data(), data[i].size());
601 if(hist.Percent(0.5) != hist.Percent(99.5)) {
655 int i = (int)(diff * 255.0);
656 c = QColor(i, 255 - i, 0);
665 c = QColor(visualValue, visualValue, visualValue);
675 p.drawText(rect, Qt::AlignCenter, QString::number(dn));
689 p.setPen(QPen(Qt::red, 1));
691 p.translate(midX, midY);
704 QPainter painter(
this);
709 painter.drawPixmap(midX, midY,
p_pixmap);
721 int x = (int)ceil((event->x() - startX) /
p_boxWidth);
722 int y = (int)ceil((event->y() - startY) /
p_boxHeight);
727 emit
setDn(
"DN: n/a");
736 emit
setDn(QString(
"DN: %1").arg(dn));
748 emit
setDn(
"DN: n/a");
Buffer for containing a three dimensional section of an image.
Container of a cube histogram.
Cube display widget for certain Isis MDI applications.
This class is used to accumulate statistics on double arrays.
double Average() const
Computes and returns the average.
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.
BigInt TotalPixels() const
Returns the total number of pixels processed (valid and invalid).
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
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.
double StandardDeviation() const
Computes and returns the standard deviation.
void Reset()
Reset all accumulators and counters to zero.
void AddPair(const double input, const double output)
Adds a stretch pair to the list of pairs.
void SetNull(const double value)
Sets the mapping for NULL pixels.
void SetHrs(const double value)
Sets the mapping for HRS pixels.
void SetHis(const double value)
Sets the mapping for HIS pixels.
void SetLis(const double value)
Sets the mapping for LIS pixels.
void ClearPairs()
Clears the stretch pairs.
double Map(const double value) const
Maps an input value to an output value based on the stretch pairs and/or special pixel mappings.
void SetLrs(const double value)
Sets the mapping for LRS pixels.
Tool to visualize statistics in an n * m box.
void showText(bool b)
Show/Hide text.
bool p_showPixels
Display pixels?
void updateSize()
Update the size of the box.
Statistics p_stats
Stats used for calculating stretch and deviation.
int p_boxSamps
Sample size for box.
void showDeviation(bool b)
Show/Hide deviation.
int p_boxLines
Line size for box.
bool p_set
Boolean to see if data is set.
int p_oldWidth
Previous box width in pixels.
QSize sizeHint() const
Size hint for this widget.
void setLines(int lines)
Set box line size.
void showPixels(bool b)
Show/Hide pixels.
void paintPixmap()
Paint the pixmap.
QVector< QVector< double > > p_pixelData
Stored pixel values.
Stretch p_stretch
Stretch used to display pixels.
void paintEvent(QPaintEvent *event)
Paint pixmap to the widget.
bool p_showText
Display text?
void setDn(const QString st)
Signal to set the DN label to st.
bool p_showDeviation
Display deviation?
int p_ulLine
Upper left line of region captured.
void setSamples(int samps)
Set box sample size.
QPixmap p_pixmap
Pixmap used for drawing.
void leaveEvent(QEvent *event)
Mouse left widget, update labels.
int p_oldHeight
Previous box height in pixels.
void setBoxSize(int size)
Set box size in pixels.
int p_boxHeight
Box height in pixels.
VisualDisplay(QWidget *parent=0)
Constructor for visual display.
void setSample(const QString st)
Signal to set the Sample label to st.
int p_ulSamp
Upper left sample of region captured.
void setLine(const QString st)
Signal to set the Line label to st.
int p_boxWidth
Box width in pixels.
void mouseMoveEvent(QMouseEvent *event)
Called when the mouse moves over this widget.
void setPixelData(QVector< QVector< double > > data, int samp, int line)
Set pixel data and upper left sample/line.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
const double Null
Value for an Isis Null pixel.
bool IsSpecial(const double d)
Returns if the input pixel is special.
QString PixelToString(double d, double precision=8)
Takes a double pixel value and returns the name of the pixel type as a string.