1 #include "HistogramTool.h"
3 #include <geos/geom/Point.h>
10 #include <QVBoxLayout>
13 #include "CubePlotCurve.h"
14 #include "ImageHistogram.h"
15 #include "Histogram.h"
16 #include "HistogramItem.h"
17 #include "HistogramPlotWindow.h"
18 #include "MdiCubeViewport.h"
19 #include "PolygonTools.h"
20 #include "RubberBandComboBox.h"
62 action->setIcon(QPixmap(
toolIconDir() +
"/histogram.png"));
63 action->setToolTip(
"Histogram (H)");
64 action->setShortcut(Qt::Key_H);
67 "<b>Function:</b> Plot histogram in active viewport \
68 <p><b>Shortcut:</b> H</p> ";
69 action->setWhatsThis(text);
94 QHBoxLayout *layout =
new QHBoxLayout(wrapper);
97 layout->addWidget(abstractToolWidgets);
98 layout->addStretch(1);
99 wrapper->setLayout(layout);
130 qobject_cast<QWidget *>(parent()));
146 if(rubberBandTool()->isValid()) {
151 QMessageBox::information(NULL,
"Error",
152 "Cannot create histogram on colored viewport",
157 QMessageBox::information(NULL,
"Error",
158 "The selected Area contains no valid pixels",
170 if (activeViewport && rubberBandTool()->isValid()) {
176 if(rubberBandTool()->currentMode() == RubberBandTool::CircleMode) {
177 geos::geom::Geometry *p = rubberBandTool()->
geometry();
178 geos::geom::CoordinateSequence *c = p->getCoordinates();
179 for(
int i = 0; i < (int)c->getSize(); i++) {
180 QPoint point((
int)(c->getX(i) + 0.5), (
int)(c->getY(i) + 0.5));
181 vertices.append(point);
186 vertices = rubberBandTool()->
vertices();
189 if(vertices.size() < 1)
return;
191 Cube *cube = activeViewport->
cube();
192 int band = activeViewport->
grayBand();
196 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode) {
197 double ssamp, sline, esamp, eline;
198 activeViewport->
viewportToCube(vertices[0].rx(), vertices[0].ry(),
201 activeViewport->
viewportToCube(vertices[1].rx(), vertices[1].ry(),
204 QLine line((
int)ssamp, (
int)sline, (
int)esamp, (
int)eline);
208 int x, y, xinc, yinc;
214 int sx = line.p1().x();
215 int ex = line.p2().x();
216 int sy = line.p1().y();
217 int ey = line.p2().y();
237 slope = (double)(ex - sx) / (double)(ey - sy);
239 for(i = 0; i < ysize; i++) {
240 x = (int)(slope * (
double)(y - sy) + (
double) sx + 0.5);
242 QPoint *pt =
new QPoint;
245 linePts->push_back(pt);
249 else if(xsize == 1) {
250 QPoint *pt =
new QPoint;
253 linePts->push_back(pt);
256 slope = (double)(ey - sy) / (double)(ex - sx);
258 for(i = 0; i < xsize; i++) {
259 y = (int)(slope * (
double)(x - sx) + (
double) sy + 0.5);
261 QPoint *pt =
new QPoint;
264 linePts->push_back(pt);
269 if(linePts->empty()) {
270 QMessageBox::information((
QWidget *)parent(),
271 "Error",
"No points in edit line");
278 for(
int i = 0; linePts && i < (int)linePts->size(); i++) {
279 QPoint *pt = (*linePts)[i];
292 else if(rubberBandTool()->currentMode() == RubberBandTool::RectangleMode) {
293 double ssamp, sline, esamp, eline;
302 ssamp = round(ssamp);
303 sline = round(sline);
304 esamp = round(esamp);
305 eline = round(eline);
307 int nsamps = (int)(std::fabs(esamp - ssamp) + 1);
309 Brick *brick =
new Brick(*cube, nsamps, 1, 1);
312 for(
int line = (
int)std::min(sline, eline); line <= (int)std::max(sline, eline); line++) {
313 int isamp = std::min(ssamp,esamp);
322 geos::geom::Geometry *polygon = rubberBandTool()->
geometry();
324 std::vector <int> x_contained, y_contained;
325 if(polygon != NULL) {
326 const geos::geom::Envelope *envelope = polygon->getEnvelopeInternal();
327 double ssamp, esamp, sline, eline;
329 (
int)floor(envelope->getMinY()),
332 (
int)ceil(envelope->getMaxY()),
336 for(
int y = (
int)sline; y <= (int)eline; y++) {
337 for(
int x = (
int)ssamp; x <= (int)esamp; x++) {
340 geos::geom::Coordinate c(x1, y1);
341 geos::geom::Point *p = globalFactory->createPoint(c);
342 bool contains = p->within(polygon);
346 x_contained.push_back(x);
347 y_contained.push_back(y);
357 for(
unsigned int j = 0; j < x_contained.size(); j++) {
371 for(
int i = 0; i < hist.
Bins(); i++) {
377 cumPctData.append(QPointF(hist.
BinMiddle(i), cumpct));
387 double maxYValue = DBL_MIN;
388 double minYValue = DBL_MAX;
391 for(
int y = 0; y < binCountData.size(); y++) {
392 intervals[y].interval = QwtInterval(binCountData[y].x(), binCountData[y].x() + hist.
BinSize());
394 intervals[y].value = binCountData[y].y();
395 if(binCountData[y].y() > maxYValue) maxYValue = binCountData[y].y();
396 if(binCountData[y].y() < minYValue) minYValue = binCountData[y].y();
399 if (binCountData.size()) {
408 QLabel *label =
new QLabel(
" Average = " + QString::number(hist.
Average()) +
'\n' +
409 "\n Minimum = " + QString::number(hist.
Minimum()) +
'\n' +
410 "\n Maximum = " + QString::number(hist.
Maximum()) +
'\n' +
412 "\n Variance = " + QString::number(hist.
Variance()) +
'\n' +
413 "\n Median = " + QString::number(hist.
Median()) +
'\n' +
414 "\n Mode = " + QString::number(hist.
Mode()) +
'\n' +
415 "\n Skew = " + QString::number(hist.
Skew()), targetWindow);
418 QVBoxLayout *dockLayout =
new QVBoxLayout;
419 dockLayout->addWidget(label);
420 dockLayout->addStretch();
423 dockContents->setLayout(dockLayout);
424 targetWindow->getDockWidget()->setWidget(dockContents);
450 QPen percentagePen(Qt::red);
451 percentagePen.setWidth(2);