1 #include "StatisticsTool.h"
9 #include <QIntValidator>
12 #include <QMouseEvent>
14 #include <QRadioButton>
15 #include <QScrollArea>
17 #include <QStackedWidget>
19 #include <QToolButton>
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);
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());
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");