1 #include "HistogramTool.h" 3 #include <geos/geom/Point.h> 10 #include <QVBoxLayout> 15 #include "HistogramItem.h" 16 #include "HistogramPlotWindow.h" 19 #include "RubberBandComboBox.h" 61 action->setIcon(QPixmap(
toolIconDir() +
"/histogram.png"));
62 action->setToolTip(
"Histogram (H)");
63 action->setShortcut(Qt::Key_H);
66 "<b>Function:</b> Plot histogram in active viewport \ 67 <p><b>Shortcut:</b> H</p> ";
68 action->setWhatsThis(text);
93 QHBoxLayout *layout =
new QHBoxLayout(wrapper);
96 layout->addWidget(abstractToolWidgets);
97 layout->addStretch(1);
98 wrapper->setLayout(layout);
129 qobject_cast<QWidget *>(parent()));
145 if(rubberBandTool()->isValid()) {
150 QMessageBox::information(NULL,
"Error",
151 "Cannot create histogram on colored viewport",
156 QMessageBox::information(NULL,
"Error",
157 "The selected Area contains no valid pixels",
169 if (activeViewport && rubberBandTool()->isValid()) {
175 if(rubberBandTool()->currentMode() == RubberBandTool::CircleMode) {
176 geos::geom::Geometry *p = rubberBandTool()->
geometry();
177 geos::geom::CoordinateSequence *c = p->getCoordinates();
178 for(
int i = 0; i < (int)c->getSize(); i++) {
179 QPoint point((
int)(c->getX(i) + 0.5), (int)(c->getY(i) + 0.5));
180 vertices.append(point);
185 vertices = rubberBandTool()->
vertices();
188 if(vertices.size() < 1)
return;
190 Cube *cube = activeViewport->
cube();
191 int band = activeViewport->
grayBand();
195 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode) {
196 double ssamp, sline, esamp, eline;
197 activeViewport->
viewportToCube(vertices[0].rx(), vertices[0].ry(),
200 activeViewport->
viewportToCube(vertices[1].rx(), vertices[1].ry(),
203 QLine line((
int)ssamp, (
int)sline, (
int)esamp, (
int)eline);
207 int x, y, xinc, yinc;
213 int sx = line.p1().x();
214 int ex = line.p2().x();
215 int sy = line.p1().y();
216 int ey = line.p2().y();
236 slope = (double)(ex - sx) / (double)(ey - sy);
238 for(i = 0; i < ysize; i++) {
239 x = (int)(slope * (
double)(y - sy) + (
double) sx + 0.5);
241 QPoint *pt =
new QPoint;
244 linePts->push_back(pt);
248 else if(xsize == 1) {
249 QPoint *pt =
new QPoint;
252 linePts->push_back(pt);
255 slope = (double)(ey - sy) / (double)(ex - sx);
257 for(i = 0; i < xsize; i++) {
258 y = (int)(slope * (
double)(x - sx) + (
double) sy + 0.5);
260 QPoint *pt =
new QPoint;
263 linePts->push_back(pt);
268 if(linePts->empty()) {
269 QMessageBox::information((
QWidget *)parent(),
270 "Error",
"No points in edit line");
277 for(
int i = 0; linePts && i < (int)linePts->size(); i++) {
278 QPoint *pt = (*linePts)[i];
291 else if(rubberBandTool()->currentMode() == RubberBandTool::RectangleMode) {
292 double ssamp, sline, esamp, eline;
301 ssamp = round(ssamp);
302 sline = round(sline);
303 esamp = round(esamp);
304 eline = round(eline);
306 int nsamps = (int)(std::fabs(esamp - ssamp) + 1);
308 Brick *brick =
new Brick(*cube, nsamps, 1, 1);
311 for(
int line = (
int)std::min(sline, eline); line <= (int)std::max(sline, eline); line++) {
312 int isamp = std::min(ssamp,esamp);
321 geos::geom::Geometry *polygon = rubberBandTool()->
geometry();
323 std::vector <int> x_contained, y_contained;
324 if(polygon != NULL) {
325 const geos::geom::Envelope *envelope = polygon->getEnvelopeInternal();
326 double ssamp, esamp, sline, eline;
328 (
int)floor(envelope->getMinY()),
331 (
int)ceil(envelope->getMaxY()),
335 for(
int y = (
int)sline; y <= (int)eline; y++) {
336 for(
int x = (
int)ssamp; x <= (int)esamp; x++) {
339 geos::geom::Coordinate c(x1, y1);
340 geos::geom::Point *p = globalFactory.createPoint(c);
341 bool contains = p->within(polygon);
345 x_contained.push_back(x);
346 y_contained.push_back(y);
356 for(
unsigned int j = 0; j < x_contained.size(); j++) {
370 for(
int i = 0; i < hist.
Bins(); i++) {
376 cumPctData.append(QPointF(hist.
BinMiddle(i), cumpct));
386 double maxYValue = DBL_MIN;
387 double minYValue = DBL_MAX;
390 for(
int y = 0; y < binCountData.size(); y++) {
391 intervals[y].interval = QwtInterval(binCountData[y].x(), binCountData[y].x() + hist.
BinSize());
393 intervals[y].value = binCountData[y].y();
394 if(binCountData[y].y() > maxYValue) maxYValue = binCountData[y].y();
395 if(binCountData[y].y() < minYValue) minYValue = binCountData[y].y();
398 if (binCountData.size()) {
407 QLabel *label =
new QLabel(
" Average = " + QString::number(hist.
Average()) +
'\n' +
408 "\n Minimum = " + QString::number(hist.
Minimum()) +
'\n' +
409 "\n Maximum = " + QString::number(hist.
Maximum()) +
'\n' +
411 "\n Variance = " + QString::number(hist.
Variance()) +
'\n' +
412 "\n Median = " + QString::number(hist.
Median()) +
'\n' +
413 "\n Mode = " + QString::number(hist.
Mode()) +
'\n' +
414 "\n Skew = " + QString::number(hist.
Skew()), targetWindow);
417 QVBoxLayout *dockLayout =
new QVBoxLayout;
418 dockLayout->addWidget(label);
419 dockLayout->addStretch();
422 dockContents->setLayout(dockLayout);
423 targetWindow->getDockWidget()->setWidget(dockContents);
449 QPen percentagePen(Qt::red);
450 percentagePen.setWidth(2);
Cube display widget for certain Isis MDI applications.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the histogram counters.
void add(HistogramItem *)
Add a HistogramItem to the plot.
double * DoubleBuffer() const
Returns the value of the shape buffer.
double StandardDeviation() const
Computes and returns the standard deviation.
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
The data is a Cube DN value.
Combo box for choosing a rubber band type.
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.
The data is a percentage (0-100).
BigInt ValidPixels() const
Returns the total number of valid pixels processed.
void cubeToViewport(double sample, double line, int &x, int &y) const
Turns a cube into a viewport.
BigInt BinCount(const int index) const
Returns the count at a bin position in the histogram.
double BinMiddle(const int index) const
Returns the value represented by a bin.
double Skew() const
Computes and returns the skew.
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
double Mode() const
Returns the mode.
Container of a cube histogram.
double Variance() const
Computes and returns the variance.
This is the (qwt) plot item for a histogram.
void read(Blob &blob) const
This method will read data from the specified Blob object.
double BinSize() const
Returns the size of an individual bin.
static QString defaultWindowTitle()
This is the typical suffix for plot windows, it's here in case we want to update all plot windows to ...
Namespace for ISIS/Bullet specific routines.
void replot()
Reset the scale of the plot, replot it and emit plot changed.
int Bins() const
Returns the number of bins in the histogram.
double Median() const
Returns the median.
void viewportToCube(int x, int y, double &sample, double &line) const
Turns a viewport into a cube.
double Average() const
Computes and returns the average.
IO Handler for Isis Cubes.