#3927 Measurements : Compute horizontal area of polygon

This commit is contained in:
Magne Sjaastad
2019-01-03 11:34:50 +01:00
parent 5bf13140e3
commit ecb1b83dfa
2 changed files with 55 additions and 16 deletions

View File

@@ -26,6 +26,8 @@
#include "RiuViewerCommands.h"
#include "cvfGeometryTools.h"
CAF_PDM_SOURCE_INIT(RimMeasurement, "RimMeasurement");
//--------------------------------------------------------------------------------------------------
@@ -107,11 +109,16 @@ void RimMeasurement::removeAllPoints()
QString RimMeasurement::label() const
{
auto lengths = calculateLenghts();
return QString("Total length: \t%1\nLast length: \t%2\nTotal horizontal length: \t%3\nLast horizontal length: \t%4")
.arg(lengths.totalLength)
.arg(lengths.lastSegmentLength)
.arg(lengths.totalHorizontalLength)
.arg(lengths.lastSegmentHorisontalLength);
auto text = QString("Total length: \t%1\nLast length: \t%2\nTotal horizontal length: \t%3\nLast horizontal length: \t%4")
.arg(lengths.totalLength)
.arg(lengths.lastSegmentLength)
.arg(lengths.totalHorizontalLength)
.arg(lengths.lastSegmentHorisontalLength);
text += QString("\nArea : %1").arg(lengths.area);
return text;
}
//--------------------------------------------------------------------------------------------------
@@ -136,6 +143,20 @@ RimMeasurement::Lengths RimMeasurement::calculateLenghts() const
lengths.totalHorizontalLength += lengths.lastSegmentHorisontalLength;
}
{
std::vector<Vec3d> pointsProjectedInZPlane;
for (const auto& p : m_pointsInDomainCoords)
{
auto pointInZ = p;
pointInZ.z() = 0.0;
pointsProjectedInZPlane.push_back(pointInZ);
}
Vec3d area = cvf::GeometryTools::polygonAreaNormal3D(pointsProjectedInZPlane);
lengths.area = cvf::Math::abs(area.z());
}
return lengths;
}