2 #include "MeasureTool.h"
4 #include <QApplication>
11 #include <QMessageBox>
12 #include <QStackedWidget>
14 #include <QTableWidget>
15 #include <QToolButton>
17 #include <geos/geom/Geometry.h>
18 #include <geos/geom/Point.h>
24 #include "Longitude.h"
25 #include "MdiCubeViewport.h"
26 #include "Projection.h"
27 #include "RingPlaneProjection.h"
28 #include "TProjection.h"
29 #include "SurfacePoint.h"
31 #include "Constants.h"
57 "Start\nLatitude:Start\nLongitude:End\nLatitude:End\nLongitude",
58 "Ground Range", -1, Qt::Horizontal,
"Start Latitude/Longitude to End Latitude/Longitude");
60 "Pixel Range", -1, Qt::Horizontal,
"Start Sample/Line to End Sample/Line");
70 m_tableWin->
addToTable(
false,
"Segments Sum\nkm",
"Segments Sum", -1, Qt::Horizontal,
"Sum of Segment lengths in kilometers");
71 m_tableWin->
addToTable(
false,
"Segment Number",
"Segment Number", -1, Qt::Horizontal,
"Segment number of a segmented line");
92 action->setIcon(QPixmap(
toolIconDir() +
"/measure.png"));
93 action->setToolTip(
"Measure (M)");
94 action->setShortcut(Qt::Key_M);
97 "<b>Function:</b> Measure features in active viewport \
98 <p><b>Shortcut:</b> M</p> ";
99 action->setWhatsThis(text);
115 QToolButton *measureButton =
new QToolButton(hbox);
116 measureButton->setText(
"Table");
117 measureButton->setToolTip(
"Record Measurement Data in Table");
119 "<b>Function:</b> This button will bring up a table that will record the \
120 starting and ending points of the line, along with the distance between \
121 the two points on the image. To measure the distance between two points, \
122 click on the first point and releasing the mouse at the second point. \
123 <p><b>Shortcut:</b> CTRL+M</p>";
124 measureButton->setWhatsThis(text);
125 measureButton->setShortcut(Qt::CTRL + Qt::Key_M);
126 connect(measureButton, SIGNAL(clicked()),
m_tableWin, SLOT(showTable()));
127 connect(measureButton, SIGNAL(clicked()),
m_tableWin, SLOT(syncColumns()));
128 connect(measureButton, SIGNAL(clicked()),
m_tableWin, SLOT(
raise()));
129 measureButton->setEnabled(
true);
148 QString text2 =
"<b>Function: </b> Shows the length of the line drawn on \
153 m_showAllSegments =
new QCheckBox(hbox);
154 m_showAllSegments->setText(
"Show All Segments");
163 connect(rubberBandTool(), SIGNAL(modeChanged()),
this, SLOT(
updateUnitsCombo()));
165 QHBoxLayout *layout =
new QHBoxLayout(hbox);
166 layout->setMargin(0);
170 layout->addWidget(measureButton);
171 layout->addWidget(m_showAllSegments);
172 layout->addStretch(1);
173 hbox->setLayout(layout);
184 if (miComboUnit >= 0) {
189 m_showAllSegments->setEnabled(
false);
191 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode) {
197 if (miComboUnit < 0 || miComboUnit > 3) {
201 else if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
203 if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
204 m_showAllSegments->setEnabled(
true);
210 if (miComboUnit < 0 || miComboUnit > 2) {
214 else if (rubberBandTool()->currentMode() == RubberBandTool::AngleMode) {
217 if (miComboUnit > 1 || miComboUnit < 0) {
225 if (miComboUnit < 0 || miComboUnit > 2) {
293 if (rubberBandTool()->currentMode() != RubberBandTool::AngleMode &&
m_unitsComboBox->currentIndex() != 2) {
295 QMessageBox::information((
QWidget *)parent(),
"Error",
296 "File must have a Camera Model or Projection to measure in km or m");
342 ASSERT(row < m_tableWin->table()->rowCount());
447 int requiredRows = m_distanceSegments.size() + row;
452 for (
int r = 0; r < rowDiff; r++) {
457 if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode &&
458 m_distanceSegments.size() > 0) {
459 double distanceSum = 0;
460 for (
int i = 0; i < m_distanceSegments.size(); i++) {
462 if (m_startLatSegments[i] !=
Null && m_startLonSegments[i] !=
Null) {
471 if (m_endLatSegments[i] !=
Null && m_endLonSegments[i] !=
Null) {
480 if (m_startSampSegments[i] !=
Null && m_startLineSegments[i] !=
Null) {
489 if (m_endSampSegments[i] !=
Null && m_endLineSegments[i] !=
Null) {
498 if (m_pixDistSegments[i] !=
Null) {
505 if (m_distanceSegments[i] !=
Null) {
520 if (distanceSum !=
Null) {
559 void MeasureTool::addRow() {
563 QTableWidgetItem *item =
new QTableWidgetItem(
"");
567 QAbstractItemView::PositionAtBottom);
597 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode ||
598 rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
599 m_distanceSegments.clear();
600 m_pixDistSegments.clear();
601 m_startSampSegments.clear();
602 m_endSampSegments.clear();
603 m_startLineSegments.clear();
604 m_endLineSegments.clear();
605 m_startLatSegments.clear();
606 m_endLatSegments.clear();
607 m_startLonSegments.clear();
608 m_endLonSegments.clear();
610 for (
int startIndex = 0; startIndex < rubberBandTool()->
vertices().size() - 1; startIndex++) {
611 QPoint start = rubberBandTool()->
vertices()[startIndex];
612 QPoint end = rubberBandTool()->
vertices()[startIndex + 1];
614 setDistances(cvp, start, end);
616 if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
617 if (m_distanceSegments.size() < 75) {
618 m_distanceSegments.append(
m_kmDist);
632 if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode &&
633 m_pixDistSegments.size()) {
638 for (
int i = 1; i < m_pixDistSegments.size(); i++) {
644 thisDistance).kilometers();
646 thisDistance).meters();
650 else if (rubberBandTool()->currentMode() == RubberBandTool::AngleMode) {
655 geos::geom::Geometry *polygon = rubberBandTool()->
geometry();
656 if (polygon != NULL) {
659 geos::geom::Point *center = polygon->getCentroid();
661 cvp->
viewportToCube((
int)center->getX(), (
int)center->getY(), sample, line);
663 if (cvp->
camera() != NULL) {
680 if (rubberBandTool()->currentMode() == RubberBandTool::RectangleMode) {
681 setDistances(cvp, rubberBandTool()->vertices()[0],
682 rubberBandTool()->vertices()[2]);
688 if (m_showAllSegments->isChecked() &&
689 rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
707 double radius =
Null;
718 (m_startSamp <= cvp->cubeSamples() + 0.5) &&
719 (m_endSamp <= cvp->cubeSamples() + 0.5) &&
720 (m_startLine <= cvp->cubeLines() + 0.5) &&
721 (m_endLine <= cvp->cubeLines() + 0.5)) {
739 rproj = (RingPlaneProjection *) cvp->
projection();
770 else if (cvp->
camera() != NULL &&
789 double pixDist = sqrt(lineDif * lineDif + sampDif * sampDif);
798 SurfacePoint startPoint;
799 SurfacePoint endPoint;
801 if (startLat.isValid() && startLon.isValid() &&
802 endLat.isValid() && endLon.isValid() && radiusDist.isValid()) {
803 startPoint = SurfacePoint(startLat, startLon, radiusDist);
804 endPoint = SurfacePoint(endLat, endLon, radiusDist);
807 Distance distance = startPoint.GetDistanceToPoint(endPoint, radiusDist);
812 if (cvp->
camera() != NULL) {
816 double slantDist = 0;
825 if ((!statusStart)&&statusEnd) {
830 if (!(statusStart||statusEnd)) {
837 double dRA = (ra1 - ra2);
839 double angle = acos(sin(dec1)*sin(dec2) + cos(dec1)*cos(dec2)*cos(dRA));
840 double half_angle = angle/2.0;
841 double length = slantDist * sin(half_angle) * 2.0;
850 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode ||
851 rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
880 else if (rubberBandTool()->currentMode() == RubberBandTool::AngleMode) {