170 if (activeViewport && rubberBandTool()->isValid()) {
174 QList<QPoint> vertices;
176 if(rubberBandTool()->currentMode() == RubberBandTool::CircleMode) {
177 geos::geom::Geometry *p = rubberBandTool()->
geometry();
178 geos::geom::CoordinateSequence *c = p->getCoordinates().release();
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();
193 std::unique_ptr<ImageHistogram> hist;
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;
212 QList<QPoint *> *linePts =
new QList<QPoint *>;
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");
275 hist = std::make_unique<ImageHistogram>(
ImageHistogram(*cube, band, NULL, ssamp, sline, esamp, eline));
279 for(
int i = 0; linePts && i < (int)linePts->size(); i++) {
280 QPoint *pt = (*linePts)[i];
283 brick->SetBasePosition(is, il, band);
285 hist->AddData(brick->DoubleBuffer(), 1);
293 else if(rubberBandTool()->currentMode() == RubberBandTool::RectangleMode) {
294 double ssamp, sline, esamp, eline;
297 activeViewport->viewportToCube(vertices[0].x(), vertices[0].y(),
300 activeViewport->viewportToCube(vertices[2].x(), vertices[2].y(),
303 ssamp = round(ssamp);
304 sline = round(sline);
305 esamp = round(esamp);
306 eline = round(eline);
308 hist = std::make_unique<ImageHistogram>(
ImageHistogram(*cube, band, NULL, ssamp, sline, esamp, eline));
309 int nsamps = (int)(std::fabs(esamp - ssamp) + 1);
311 Brick *brick =
new Brick(*cube, nsamps, 1, 1);
314 for(
int line = (
int)std::min(sline, eline); line <= (int)std::max(sline, eline); line++) {
315 int isamp = std::min(ssamp,esamp);
316 brick->SetBasePosition(isamp, line, band);
318 hist->AddData(brick->DoubleBuffer(), nsamps);
324 geos::geom::Geometry *polygon = rubberBandTool()->
geometry();
326 std::vector <int> x_contained, y_contained;
327 if(polygon != NULL) {
328 const geos::geom::Envelope *envelope = polygon->getEnvelopeInternal();
329 double ssamp, esamp, sline, eline;
330 activeViewport->viewportToCube((
int)floor(envelope->getMinX()),
331 (
int)floor(envelope->getMinY()),
333 activeViewport->viewportToCube((
int)ceil(envelope->getMaxX()),
334 (
int)ceil(envelope->getMaxY()),
338 hist = std::make_unique<ImageHistogram>(
ImageHistogram(*cube, band, NULL, ssamp, sline, esamp, eline));
339 for(
int y = (
int)sline; y <= (int)eline; y++) {
340 for(
int x = (
int)ssamp; x <= (int)esamp; x++) {
342 activeViewport->cubeToViewport(x, y, x1, y1);
343 geos::geom::Coordinate c(x1, y1);
344 geos::geom::Point *p = globalFactory->createPoint(c).release();
345 bool contains = p->within(polygon);
349 x_contained.push_back(x);
350 y_contained.push_back(y);
360 for(
unsigned int j = 0; j < x_contained.size(); j++) {
361 brick->SetBasePosition(x_contained[j], y_contained[j], band);
363 hist->AddData(brick->DoubleBuffer(), 1);
371 QVector<QPointF> binCountData;
372 QVector<QPointF> cumPctData;
374 for(
int i = 0; i < hist->Bins(); i++) {
375 if(hist->BinCount(i) > 0) {
376 binCountData.append(QPointF(hist->BinMiddle(i), hist->BinCount(i)));
378 double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.;
380 cumPctData.append(QPointF(hist->BinMiddle(i), cumpct));
389 QVector<QwtIntervalSample> intervals(binCountData.size());
390 double maxYValue = DBL_MIN;
391 double minYValue = DBL_MAX;
394 for(
int y = 0; y < binCountData.size(); y++) {
395 intervals[y].interval = QwtInterval(binCountData[y].x(), binCountData[y].x() + hist->BinSize());
397 intervals[y].value = binCountData[y].y();
398 if(binCountData[y].y() > maxYValue) maxYValue = binCountData[y].y();
399 if(binCountData[y].y() < minYValue) minYValue = binCountData[y].y();
402 if (binCountData.size()) {
411 QLabel *label =
new QLabel(
" Average = " + QString::number(hist->Average()) +
'\n' +
412 "\n Minimum = " + QString::number(hist->Minimum()) +
'\n' +
413 "\n Maximum = " + QString::number(hist->Maximum()) +
'\n' +
414 "\n Stand. Dev.= " + QString::number(hist->StandardDeviation()) +
'\n' +
415 "\n Variance = " + QString::number(hist->Variance()) +
'\n' +
416 "\n Median = " + QString::number(hist->Median()) +
'\n' +
417 "\n Mode = " + QString::number(hist->Mode()) +
'\n' +
418 "\n Skew = " + QString::number(hist->Skew()), targetWindow);
421 QVBoxLayout *dockLayout =
new QVBoxLayout;
422 dockLayout->addWidget(label);
423 dockLayout->addStretch();
426 dockContents->setLayout(dockLayout);
427 targetWindow->getDockWidget()->setWidget(dockContents);
428 targetWindow->replot();