mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3927 Measurements : Compute horizontal area of polygon
This commit is contained in:
parent
5bf13140e3
commit
ecb1b83dfa
@ -28,6 +28,10 @@
|
||||
#include "cafDisplayCoordTransform.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include "RivPartPriority.h"
|
||||
|
||||
#include "cvfPart.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -48,22 +52,36 @@ bool RicMeasurementPickEventHandler::handlePickEvent(const Ric3DPickEvent& event
|
||||
|
||||
if (measurement && measurement->isInMeasurementMode())
|
||||
{
|
||||
Rim3dView* rimView = RiaApplication::instance()->activeReservoirView();
|
||||
|
||||
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
|
||||
cvf::Vec3d domainCoord = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint());
|
||||
|
||||
bool isControlButtonDown = QApplication::keyboardModifiers() & Qt::ControlModifier;
|
||||
|
||||
if (!isControlButtonDown)
|
||||
const RiuPickItemInfo* firstGeometryPickInfo = nullptr;
|
||||
for (const auto& info : eventObject.m_pickItemInfos)
|
||||
{
|
||||
if (measurement->pointsInDomainCoords().size() > 1)
|
||||
auto partCandidate = info.pickedPart();
|
||||
if (!firstGeometryPickInfo && partCandidate->priority() != RivPartPriority::PartType::Text)
|
||||
{
|
||||
measurement->removeAllPoints();
|
||||
firstGeometryPickInfo = &info;
|
||||
}
|
||||
}
|
||||
|
||||
measurement->addPointInDomainCoords(domainCoord);
|
||||
Rim3dView* rimView = RiaApplication::instance()->activeReservoirView();
|
||||
|
||||
if (firstGeometryPickInfo && rimView)
|
||||
{
|
||||
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
|
||||
|
||||
cvf::Vec3d domainCoord = transForm->transformToDomainCoord(firstGeometryPickInfo->globalPickedPoint());
|
||||
|
||||
bool isControlButtonDown = QApplication::keyboardModifiers() & Qt::ControlModifier;
|
||||
|
||||
if (!isControlButtonDown)
|
||||
{
|
||||
if (measurement->pointsInDomainCoords().size() > 1)
|
||||
{
|
||||
measurement->removeAllPoints();
|
||||
}
|
||||
}
|
||||
|
||||
measurement->addPointInDomainCoords(domainCoord);
|
||||
}
|
||||
|
||||
// Further Ui processing is stopped when true is returned
|
||||
return true;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user