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;
301 if((sample < 0.5) || (line < 0.5) ||
306 int isamp = (int)(sample + 0.5);
307 int iline = (int)(line + 0.5);
318 p_ulSamp = isamp - (int)floor(sampDiff);
319 p_ulLine = iline - (int)floor(lineDiff);
339 pixelData[i][j] = brick->
at(0);
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);
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++) {
594 if(fabs(
p_stats.BestMinimum()) < DBL_MAX && fabs(
p_stats.BestMaximum()) < DBL_MAX) {
596 for(
int i = 0; i < data.size(); i++) {
597 hist.
AddData(data[i].data(), data[i].size());
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.
void SetBasePosition(const int start_sample, const int start_line, const int start_band)
This method is used to set the base position of the shape buffer.
double at(const int index) const
Returns the value in the shape buffer at the given index.
PixelType pixelType() const
void read(Blob &blob, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
This method will read data from the specified Blob object.
int cubeLines() const
Return the number of lines in the cube.
int cubeSamples() const
Return the number of samples in the cube.
void viewportToCube(int x, int y, double &sample, double &line) const
Turns a viewport into a cube.
Container of a cube histogram.
double Percent(const double percent) const
Computes and returns the value at X percent of the histogram.
virtual void AddData(const double *data, const unsigned int count)
Add an array of doubles to the histogram counters.
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.
BigInt ValidPixels() const
Returns the total number of valid pixels processed.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
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.
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.