316 QList<QPoint> vertices = rubberBandTool()->
vertices();
318 QVector<QPointF> data;
321 m_xUnitsCombo->currentIndex()).
toInt();
323 if (cvp && vertices.size()) {
329 Portal dataReader(interp.Samples(), interp.Lines(),
330 cvp->cube()->pixelType());
332 int band = ((cvp->isGray()) ? cvp->grayBand() : cvp->redBand());
334 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode) {
335 double startSample =
Null;
336 double endSample =
Null;
337 double startLine =
Null;
338 double endLine =
Null;
340 cvp->viewportToCube(vertices[0].x(), vertices[0].y(),
341 startSample, startLine);
342 cvp->viewportToCube(vertices[1].x(), vertices[1].y(),
346 int lineLength = qRound(sqrt(pow(startSample - endSample, 2) +
347 pow(startLine - endLine, 2)));
352 if (groundMap->
SetImage(startSample, startLine)) {
353 startPoint = resultToSurfacePoint(groundMap);
356 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
357 tr(
"Failed to project points along line"),
358 tr(
"Failed to project (calculate a latitude, longitude, and radius) for the "
359 "starting point of the line (sample [%1], line [%2]).")
360 .arg(startSample).arg(startLine));
365 if (lineLength > 0) {
366 for(
int index = 0; index <= lineLength; index++) {
368 double sample = (index / (double)lineLength) * (endSample - startSample) +
371 sample -= (interp.Samples() / 2.0 - 0.5);
373 double line = (index / (double)lineLength) * (endLine - startLine) +
375 line -= (interp.Lines() / 2.0 - 0.5);
377 dataReader.SetPosition(sample, line, band);
378 cvp->cube()->read(dataReader);
380 double result = interp.Interpolate(sample + 0.5, line + 0.5, dataReader.DoubleBuffer());
383 double plotXValue = index + 1;
388 if (groundMap->
SetImage(sample, line)) {
389 Distance xDistance = startPoint.GetDistanceToPoint(resultToSurfacePoint(groundMap));
392 plotXValue = xDistance.
meters();
394 plotXValue = xDistance.kilometers();
397 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
398 tr(
"Failed to project points along line"),
399 tr(
"Failed to project (calculate a latitude, longitude, and radius) for a "
400 "point along the line (sample [%1], line [%2]).")
401 .arg(startSample).arg(startLine));
406 data.append(QPointF(plotXValue, result));
411 QMessageBox::information(NULL,
"Error",
412 "The selected Area contains no valid pixels",
416 else if (rubberBandTool()->currentMode() == RubberBandTool::RotatedRectangleMode) {
446 double clickSample =
Null;
447 double clickLine =
Null;
448 double acrossSample =
Null;
449 double acrossLine =
Null;
450 double endSample =
Null;
451 double endLine =
Null;
453 cvp->viewportToCube(vertices[0].x(), vertices[0].y(),
454 clickSample, clickLine);
455 cvp->viewportToCube(vertices[1].x(), vertices[1].y(),
456 acrossSample, acrossLine);
457 cvp->viewportToCube(vertices[3].x(), vertices[3].y(),
460 double acrossVectorX = acrossSample - clickSample;
461 double acrossVectorY = acrossLine - clickLine;
464 int acrossLength = qRound(sqrt(acrossVectorX * acrossVectorX +
465 acrossVectorY * acrossVectorY));
467 double sampleStepAcross = (1.0 / (double)acrossLength) * acrossVectorX;
468 double lineStepAcross = (1.0 / (double)acrossLength) * acrossVectorY;
470 double lengthVectorSample = endSample - clickSample;
471 double lengthVectorLine = endLine - clickLine;
474 int rectangleLength = qRound(sqrt(lengthVectorSample * lengthVectorSample +
475 lengthVectorLine * lengthVectorLine));
478 if (rectangleLength == 0) {
485 double midStartSample = (clickSample + acrossSample) / 2.0;
486 double midStartLine = (clickLine + acrossLine) / 2.0;
487 if (groundMap->
SetImage(midStartSample, midStartLine)) {
488 startPoint = resultToSurfacePoint(groundMap);
491 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
492 tr(
"Failed to project points along line"),
493 tr(
"Failed to project (calculate a latitude, longitude, and radius) for the "
494 "starting point of the line (sample [%1], line [%2]).")
495 .arg(midStartSample).arg(midStartLine));
501 for(
int index = 0; index <= rectangleLength; index++) {
505 double sample = (index / (double)rectangleLength) * lengthVectorSample +
508 sample -= (interp.Samples() / 2.0 - 0.5);
510 double line = (index / (double)rectangleLength) * lengthVectorLine +
512 line -= (interp.Lines() / 2.0 - 0.5);
514 double sampleMid = sample + (acrossLength / 2.0) * sampleStepAcross;
515 double lineMid = line + (acrossLength / 2.0) * lineStepAcross;
519 for(
int acrossPixel = 0;
520 acrossPixel <= acrossLength;
522 dataReader.SetPosition(sample, line, band);
523 cvp->cube()->read(dataReader);
524 double pixelValue = interp.Interpolate(sample + 0.5, line + 0.5,
525 dataReader.DoubleBuffer());
528 acrossStats.AddData(pixelValue);
531 sample += sampleStepAcross;
532 line += lineStepAcross;
536 double plotXValue = index + 1;
539 if (groundMap->
SetImage(sampleMid, lineMid)) {
540 Distance xDistance = startPoint.GetDistanceToPoint(resultToSurfacePoint(groundMap));
543 plotXValue = xDistance.
meters();
545 plotXValue = xDistance.kilometers();
548 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
549 tr(
"Failed to project points along line"),
550 tr(
"Failed to project (calculate a latitude, longitude, and radius) for a "
551 "point along the line (sample [%1], line [%2]).")
552 .arg(sampleMid).arg(lineMid));
557 data.append(QPointF(plotXValue, acrossStats.Average()));