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();
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");
278 for(
int i = 0; linePts && i < (int)linePts->size(); i++) {
279 QPoint *pt = (*linePts)[i];
282 brick->SetBasePosition(is, il, band);
284 hist.AddData(brick->DoubleBuffer(), 1);
292 else if(rubberBandTool()->currentMode() == RubberBandTool::RectangleMode) {
293 double ssamp, sline, esamp, eline;
296 activeViewport->viewportToCube(vertices[0].x(), vertices[0].y(),
299 activeViewport->viewportToCube(vertices[2].x(), vertices[2].y(),
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);
314 brick->SetBasePosition(isamp, line, band);
316 hist.AddData(brick->DoubleBuffer(), nsamps);
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;
328 activeViewport->viewportToCube((
int)floor(envelope->getMinX()),
329 (
int)floor(envelope->getMinY()),
331 activeViewport->viewportToCube((
int)ceil(envelope->getMaxX()),
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++) {
339 activeViewport->cubeToViewport(x, y, x1, y1);
340 geos::geom::Coordinate c(x1, y1);
341 geos::geom::Point *p = globalFactory->createPoint(c).release();
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++) {
358 brick->SetBasePosition(x_contained[j], y_contained[j], band);
360 hist.AddData(brick->DoubleBuffer(), 1);
368 QVector<QPointF> binCountData;
369 QVector<QPointF> cumPctData;
371 for(
int i = 0; i < hist.Bins(); i++) {
372 if(hist.BinCount(i) > 0) {
373 binCountData.append(QPointF(hist.BinMiddle(i), hist.BinCount(i)));
375 double pct = (double)hist.BinCount(i) / hist.ValidPixels() * 100.;
377 cumPctData.append(QPointF(hist.BinMiddle(i), cumpct));
386 QVector<QwtIntervalSample> intervals(binCountData.size());
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' +
411 "\n Stand. Dev.= " + QString::number(hist.StandardDeviation()) +
'\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);
425 targetWindow->replot();