3 #include "SpatialPlotTool.h"
7 #include <geos/geom/Polygon.h>
8 #include <geos/geom/CoordinateArraySequence.h>
9 #include <geos/geom/Point.h>
11 #include <QHBoxLayout>
14 #include <QMessageBox>
15 #include <QStackedWidget>
32 #include "RubberBandComboBox.h"
33 #include "RubberBandTool.h"
89 QString text =
"<b>Function:</b> Create a spatial plot of the selected pixels' DN values.";
115 Interpolator::NearestNeighborType);
117 Interpolator::BiLinearType);
119 Interpolator::CubicConvolutionType);
128 QHBoxLayout *layout =
new QHBoxLayout(wrapper);
129 layout->setMargin(0);
131 layout->addWidget(
new QLabel(
"Interpolation:"));
133 layout->addWidget(abstractToolWidgets);
134 layout->addWidget(m_xUnitsCombo);
135 layout->addStretch(1);
136 wrapper->setLayout(layout);
151 m_xUnitsCombo->currentIndex()).
toInt();
153 while (m_xUnitsCombo->count())
154 m_xUnitsCombo->removeItem(0);
158 bool haveGroundMaps =
true;
163 if (haveGroundMaps) {
168 if (m_xUnitsCombo->findData(preferredUnits) != -1) {
169 m_xUnitsCombo->setCurrentIndex(
170 m_xUnitsCombo->findData(preferredUnits));
173 m_xUnitsCombo->setVisible(m_xUnitsCombo->count() > 1);
186 m_xUnitsCombo->currentIndex()).
toInt(),
213 if (rubberBandTool()->isValid()) {
217 QMessageBox::information(NULL,
"Error",
218 "The selected Area contains no valid pixels",
231 if (activeViewport && rubberBandTool()->isValid()) {
237 m_xUnitsCombo->itemData(m_xUnitsCombo->currentIndex()).
toInt()) {
246 if (data.size() > 0) {
252 (*m_spatialCurves)[viewport]->setData(
new QwtPointSeriesData(data));
253 (*m_spatialCurves)[viewport]->setSource(
254 viewport, rubberBandPoints, band);
273 m_xUnitsCombo->currentIndex()).
toInt();
275 QPen spatialPen(Qt::white);
276 spatialPen.setWidth(1);
277 spatialPen.setStyle(Qt::SolidLine);
285 targetWindow->
add(plotCurve);
324 m_xUnitsCombo->currentIndex()).
toInt();
326 if (cvp && vertices.size()) {
337 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode) {
338 double startSample =
Null;
339 double endSample =
Null;
340 double startLine =
Null;
341 double endLine =
Null;
344 startSample, startLine);
349 int lineLength = qRound(sqrt(pow(startSample - endSample, 2) +
350 pow(startLine - endLine, 2)));
355 if (groundMap->
SetImage(startSample, startLine)) {
356 startPoint = resultToSurfacePoint(groundMap);
359 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
360 tr(
"Failed to project points along line"),
361 tr(
"Failed to project (calculate a latitude, longitude, and radius) for the "
362 "starting point of the line (sample [%1], line [%2]).")
363 .arg(startSample).arg(startLine));
368 if (lineLength > 0) {
369 for(
int index = 0; index <= lineLength; index++) {
371 double sample = (index / (double)lineLength) * (endSample - startSample) +
374 sample -= (interp.
Samples() / 2.0 - 0.5);
376 double line = (index / (double)lineLength) * (endLine - startLine) +
378 line -= (interp.
Lines() / 2.0 - 0.5);
380 dataReader.SetPosition(sample, line, band);
383 double result = interp.
Interpolate(sample + 0.5, line + 0.5, dataReader.DoubleBuffer());
386 double plotXValue = index + 1;
391 if (groundMap->
SetImage(sample, line)) {
395 plotXValue = xDistance.
meters();
400 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
401 tr(
"Failed to project points along line"),
402 tr(
"Failed to project (calculate a latitude, longitude, and radius) for a "
403 "point along the line (sample [%1], line [%2]).")
404 .arg(startSample).arg(startLine));
409 data.append(QPointF(plotXValue, result));
414 QMessageBox::information(NULL,
"Error",
415 "The selected Area contains no valid pixels",
419 else if (rubberBandTool()->currentMode() == RubberBandTool::RotatedRectangleMode) {
449 double clickSample =
Null;
450 double clickLine =
Null;
451 double acrossSample =
Null;
452 double acrossLine =
Null;
453 double endSample =
Null;
454 double endLine =
Null;
457 clickSample, clickLine);
459 acrossSample, acrossLine);
463 double acrossVectorX = acrossSample - clickSample;
464 double acrossVectorY = acrossLine - clickLine;
466 int acrossLength = qRound(sqrt(acrossVectorX * acrossVectorX +
467 acrossVectorY * acrossVectorY));
468 double sampleStepAcross = (1.0 / (double)acrossLength) * acrossVectorX;
469 double lineStepAcross = (1.0 / (double)acrossLength) * acrossVectorY;
471 double lengthVectorSample = endSample - clickSample;
472 double lengthVectorLine = endLine - clickLine;
473 int rectangleLength = qRound(sqrt(lengthVectorSample * lengthVectorSample +
474 lengthVectorLine * lengthVectorLine));
479 double midStartSample = (clickSample + acrossSample) / 2.0;
480 double midStartLine = (clickLine + acrossLine) / 2.0;
481 if (groundMap->
SetImage(midStartSample, midStartLine)) {
482 startPoint = resultToSurfacePoint(groundMap);
485 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
486 tr(
"Failed to project points along line"),
487 tr(
"Failed to project (calculate a latitude, longitude, and radius) for the "
488 "starting point of the line (sample [%1], line [%2]).")
489 .arg(midStartSample).arg(midStartLine));
495 for(
int index = 0; index <= rectangleLength; index++) {
499 double sample = (index / (double)rectangleLength) * lengthVectorSample +
502 sample -= (interp.
Samples() / 2.0 - 0.5);
504 double line = (index / (double)rectangleLength) * lengthVectorLine +
506 line -= (interp.
Lines() / 2.0 - 0.5);
508 double sampleMid = sample + (acrossLength / 2.0) * sampleStepAcross;
509 double lineMid = line + (acrossLength / 2.0) * lineStepAcross;
511 for(
int acrossPixel = 0;
512 acrossPixel <= acrossLength;
514 dataReader.SetPosition(sample, line, band);
516 double pixelValue = interp.
Interpolate(sample + 0.5, line + 0.5,
517 dataReader.DoubleBuffer());
520 acrossStats.
AddData(pixelValue);
523 sample += sampleStepAcross;
524 line += lineStepAcross;
528 double plotXValue = index + 1;
531 if (groundMap->
SetImage(sampleMid, lineMid)) {
535 plotXValue = xDistance.
meters();
540 QMessageBox::warning(qobject_cast<QWidget *>(parent()),
541 tr(
"Failed to project points along line"),
542 tr(
"Failed to project (calculate a latitude, longitude, and radius) for a "
543 "point along the line (sample [%1], line [%2]).")
544 .arg(sampleMid).arg(lineMid));
549 data.append(QPointF(plotXValue, acrossStats.
Average()));
This class defines a body-fixed surface point.
Cube display widget for certain Isis MDI applications.
UniversalGroundMap * universalGroundMap() const
Return the universal ground map associated with the cube (NULL implies none)
const double Null
Value for an Isis Null pixel.
interpType
The interpolator type, including: None, Nearest Neighbor, BiLinear or Cubic Convultion.
PixelType pixelType() const
double Interpolate(const double isamp, const double iline, const double buf[])
Performs an interpolation on the data according to the parameters set in the constructor.
Isis::Camera * Camera() const
Return the camera associated with the ground map (NULL implies none)
The data is a Cube DN value.
bool isGray() const
Is the viewport shown in gray / b&w.
Buffer for containing a two dimensional section of an image.
Combo box for choosing a rubber band type.
int toInt(const QString &string)
Global function to convert from a string to an integer.
void SetType(const interpType &type)
Sets the type of interpolation.
This class is designed to encapsulate the concept of a Latitude.
int redBand() const
Return the red band currently viewed.
double UniversalLatitude() const
Returns the universal latitude of the camera model or projection.
void read(Blob &blob) const
This method will read data from the specified Blob object.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Distance measurement, usually in meters.
This class is used to accumulate statistics on double arrays.
This class is designed to encapsulate the concept of a Longitude.
double meters() const
Get the distance in meters.
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
Cube * cube() const
Return the cube associated with viewport.
int grayBand() const
Return the gray band currently viewed.
int Samples()
Returns the number of samples needed by the interpolator.
double Average() const
Computes and returns the average.
This is a plot curve with information relating it to a particular cube or region of a cube...
Distance GetDistanceToPoint(const SurfacePoint &other) const
Computes and returns the distance between two surface points.
double UniversalLongitude() const
Returns the universal longitude of the camera model or projection.
bool IsSpecial(const double d)
Returns if the input pixel is special.
void viewportToCube(int x, int y, double &sample, double &line) const
Convert a viewport x/y to a cube sample/line (may be outside the cube)
bool SetImage(double sample, double line)
Returns whether the sample/line postion was set successfully in the camera model or projection...
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Distance LocalRadius() const
Returns the local radius at the intersection point.
int Lines()
Returns the number of lines needed by the interpolator.
static QString defaultWindowTitle()
This is the typical suffix for plot windows, it's here in case we want to update all plot windows to ...
The distance is being specified in meters.
double kilometers() const
Get the distance in kilometers.
void replot()
Reset the scale of the plot, replot it and emit plot changed.
The data is in kilometers.
Isis::Projection * Projection() const
Return the projection associated with the ground map (NULL implies none)
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
virtual void add(CubePlotCurve *pc)
This method adds the curves to the plot.
Units
These are all the possible units for the x or y data in a plot curve.
PlotCurve::Units xAxisUnits() const
This is the data-type of the curves' x data in this plot window.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.