2 #include "MeasureTool.h"
4 #include <QApplication>
10 #include <QMessageBox>
13 #include <geos/geom/Geometry.h>
14 #include <geos/geom/Point.h>
52 "Start\nLatitude:Start\nLongitude:End\nLatitude:End\nLongitude",
53 "Ground Range", -1, Qt::Horizontal,
"Start Latitude/Longitude to End Latitude/Longitude");
55 "Pixel Range", -1, Qt::Horizontal,
"Start Sample/Line to End Sample/Line");
64 m_tableWin->
addToTable(
false,
"Segments Sum\nkm",
"Segments Sum", -1, Qt::Horizontal,
"Sum of Segment lengths in kilometers");
65 m_tableWin->
addToTable(
false,
"Segment Number",
"Segment Number", -1, Qt::Horizontal,
"Segment number of a segmented line");
86 action->setIcon(QPixmap(
toolIconDir() +
"/measure.png"));
87 action->setToolTip(
"Measure (M)");
88 action->setShortcut(Qt::Key_M);
91 "<b>Function:</b> Measure features in active viewport \
92 <p><b>Shortcut:</b> M</p> ";
93 action->setWhatsThis(text);
109 QToolButton *measureButton =
new QToolButton(hbox);
110 measureButton->setText(
"Table");
111 measureButton->setToolTip(
"Record Measurement Data in Table");
113 "<b>Function:</b> This button will bring up a table that will record the \
114 starting and ending points of the line, along with the distance between \
115 the two points on the image. To measure the distance between two points, \
116 click on the first point and releasing the mouse at the second point. \
117 <p><b>Shortcut:</b> CTRL+M</p>";
118 measureButton->setWhatsThis(text);
119 measureButton->setShortcut(Qt::CTRL + Qt::Key_M);
120 connect(measureButton, SIGNAL(clicked()),
m_tableWin, SLOT(showTable()));
121 connect(measureButton, SIGNAL(clicked()),
m_tableWin, SLOT(syncColumns()));
122 connect(measureButton, SIGNAL(clicked()),
m_tableWin, SLOT(
raise()));
123 measureButton->setEnabled(
true);
141 QString text2 =
"<b>Function: </b> Shows the length of the line drawn on \
146 m_showAllSegments =
new QCheckBox(hbox);
147 m_showAllSegments->setText(
"Show All Segments");
156 connect(rubberBandTool(), SIGNAL(modeChanged()),
this, SLOT(
updateUnitsCombo()));
158 QHBoxLayout *layout =
new QHBoxLayout(hbox);
159 layout->setMargin(0);
163 layout->addWidget(measureButton);
164 layout->addWidget(m_showAllSegments);
165 layout->addStretch(1);
166 hbox->setLayout(layout);
177 if (miComboUnit >= 0) {
182 m_showAllSegments->setEnabled(
false);
184 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode ||
185 rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
187 if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
188 m_showAllSegments->setEnabled(
true);
194 if (miComboUnit < 0 || miComboUnit > 2) {
198 else if (rubberBandTool()->currentMode() == RubberBandTool::AngleMode) {
201 if (miComboUnit > 1 || miComboUnit < 0) {
209 if (miComboUnit < 0 || miComboUnit > 2) {
277 if (rubberBandTool()->currentMode() != RubberBandTool::AngleMode &&
m_unitsComboBox->currentIndex() != 2) {
279 QMessageBox::information((
QWidget *)parent(),
"Error",
280 "File must have a Camera Model or Projection to measure in km or m");
326 ASSERT(row < m_tableWin->table()->rowCount());
424 int requiredRows = m_distanceSegments.size() + row;
429 for (
int r = 0; r < rowDiff; r++) {
434 if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode &&
435 m_distanceSegments.size() > 0) {
436 double distanceSum = 0;
437 for (
int i = 0; i < m_distanceSegments.size(); i++) {
439 if (m_startLatSegments[i] !=
Null && m_startLonSegments[i] !=
Null) {
448 if (m_endLatSegments[i] !=
Null && m_endLonSegments[i] !=
Null) {
457 if (m_startSampSegments[i] !=
Null && m_startLineSegments[i] !=
Null) {
466 if (m_endSampSegments[i] !=
Null && m_endLineSegments[i] !=
Null) {
475 if (m_pixDistSegments[i] !=
Null) {
482 if (m_distanceSegments[i] !=
Null) {
497 if (distanceSum !=
Null) {
535 void MeasureTool::addRow() {
539 QTableWidgetItem *item =
new QTableWidgetItem(
"");
543 QAbstractItemView::PositionAtBottom);
573 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode ||
574 rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
575 m_distanceSegments.clear();
576 m_pixDistSegments.clear();
577 m_startSampSegments.clear();
578 m_endSampSegments.clear();
579 m_startLineSegments.clear();
580 m_endLineSegments.clear();
581 m_startLatSegments.clear();
582 m_endLatSegments.clear();
583 m_startLonSegments.clear();
584 m_endLonSegments.clear();
586 for (
int startIndex = 0; startIndex < rubberBandTool()->
vertices().size() - 1; startIndex++) {
587 QPoint start = rubberBandTool()->
vertices()[startIndex];
588 QPoint end = rubberBandTool()->
vertices()[startIndex + 1];
590 setDistances(cvp, start, end);
592 if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
593 if (m_distanceSegments.size() < 75) {
594 m_distanceSegments.append(
m_kmDist);
608 if (rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode &&
609 m_pixDistSegments.size()) {
614 for (
int i = 1; i < m_pixDistSegments.size(); i++) {
620 thisDistance).kilometers();
622 thisDistance).meters();
626 else if (rubberBandTool()->currentMode() == RubberBandTool::AngleMode) {
631 geos::geom::Geometry *polygon = rubberBandTool()->
geometry();
632 if (polygon != NULL) {
635 geos::geom::Point *center = polygon->getCentroid();
637 cvp->
viewportToCube((
int)center->getX(), (int)center->getY(), sample, line);
639 if (cvp->
camera() != NULL) {
656 if (rubberBandTool()->currentMode() == RubberBandTool::RectangleMode) {
657 setDistances(cvp, rubberBandTool()->vertices()[0],
658 rubberBandTool()->vertices()[2]);
664 if (m_showAllSegments->isChecked() &&
665 rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
682 double radius =
Null;
693 (m_startSamp <= cvp->cubeSamples() + 0.5) &&
694 (m_endSamp <= cvp->cubeSamples() + 0.5) &&
695 (m_startLine <= cvp->cubeLines() + 0.5) &&
696 (m_endLine <= cvp->cubeLines() + 0.5)) {
713 rproj = (RingPlaneProjection *) cvp->
projection();
744 else if (cvp->
camera() != NULL &&
763 double pixDist = sqrt(lineDif * lineDif + sampDif * sampDif);
772 SurfacePoint startPoint;
773 SurfacePoint endPoint;
775 if (startLat.isValid() && startLon.isValid() &&
776 endLat.isValid() && endLon.isValid() && radiusDist.isValid()) {
777 startPoint = SurfacePoint(startLat, startLon, radiusDist);
778 endPoint = SurfacePoint(endLat, endLon, radiusDist);
781 Distance distance = startPoint.GetDistanceToPoint(endPoint, radiusDist);
790 if (rubberBandTool()->currentMode() == RubberBandTool::LineMode ||
791 rubberBandTool()->currentMode() == RubberBandTool::SegmentedLineMode) {
812 else if (rubberBandTool()->currentMode() == RubberBandTool::AngleMode) {