#3289 Well path creation. When clicking on a well path, use tangent. Rename arguments

This commit is contained in:
Bjørn Erik Jensen 2018-10-01 10:07:43 +02:00
parent 5a51111db2
commit 063b7121b1
4 changed files with 109 additions and 15 deletions

View File

@ -17,9 +17,17 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RicCreateWellTargetsPickEventHandler.h"
#include "RiaOffshoreSphericalCoords.h"
#include "RigWellPath.h"
#include "Rim3dView.h"
#include "RimWellPathGeometryDef.h"
#include "RimWellPathTarget.h"
#include "RimWellPath.h"
#include "RivWellPathSourceInfo.h"
#include "cafSelectionManager.h"
#include "cafDisplayCoordTransform.h"
@ -68,18 +76,45 @@ bool RicCreateWellTargetsPickEventHandler::handlePickEvent(const Ric3DPickEvent&
if ( m_geometryToAddTargetsTo )
{
Rim3dView* rimView = eventObject.m_view;
cvf::Vec3d targetPointInDomain = cvf::Vec3d::ZERO;
// If clicked on an other well path, snap target point to well path center line
auto firstPickItem = eventObject.m_pickItemInfos.front();
auto wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(firstPickItem.sourceInfo());
auto intersectionPointInDomain = rimView->displayCoordTransform()->transformToDomainCoord(firstPickItem.globalPickedPoint());
bool doSetAzimuthAndInclination;
double azimuth = 0.0, inclination = 0.0;
if (wellPathSourceInfo)
{
targetPointInDomain = wellPathSourceInfo->closestPointOnCenterLine(firstPickItem.faceIdx(), intersectionPointInDomain);
double md = wellPathSourceInfo->measuredDepth(firstPickItem.faceIdx(), intersectionPointInDomain);
doSetAzimuthAndInclination = calculateAzimuthAndInclinationAtMd(md, wellPathSourceInfo->wellPath()->wellPathGeometry(), &azimuth, &inclination);
}
else
{
targetPointInDomain = intersectionPointInDomain;
doSetAzimuthAndInclination = false;
}
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
cvf::Vec3d domainCoord = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint());
if (!m_geometryToAddTargetsTo->firstActiveTarget())
{
m_geometryToAddTargetsTo->setReferencePointXyz(domainCoord);
m_geometryToAddTargetsTo->setReferencePointXyz(targetPointInDomain);
}
cvf::Vec3d referencePoint = m_geometryToAddTargetsTo->referencePointXyz();
cvf::Vec3d relativeTagetPoint = domainCoord - referencePoint;
cvf::Vec3d relativeTagetPoint = targetPointInDomain - referencePoint;
RimWellPathTarget* newTarget = new RimWellPathTarget;
newTarget->setAsPointTargetXYD(cvf::Vec3d(relativeTagetPoint.x(), relativeTagetPoint.y(), -relativeTagetPoint.z()));
if (doSetAzimuthAndInclination)
{
newTarget->setAsPointXYZAndTangentTarget(cvf::Vec3d(relativeTagetPoint.x(), relativeTagetPoint.y(), relativeTagetPoint.z()), azimuth, inclination);
}
else
{
newTarget->setAsPointTargetXYD(cvf::Vec3d(relativeTagetPoint.x(), relativeTagetPoint.y(), -relativeTagetPoint.z()));
}
m_geometryToAddTargetsTo->insertTarget(nullptr, newTarget);
@ -91,3 +126,56 @@ bool RicCreateWellTargetsPickEventHandler::handlePickEvent(const Ric3DPickEvent&
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCreateWellTargetsPickEventHandler::calculateAzimuthAndInclinationAtMd(double measuredDepth,
const RigWellPath* wellPathGeometry,
double *azimuth,
double *inclination) const
{
int mdIndex = -1;
auto mdList = wellPathGeometry->measureDepths();
for (int i = 0; i < mdList.size(); i++)
{
if (mdList[i] > measuredDepth)
{
mdIndex = i - 1;
break;
}
}
auto ptList = wellPathGeometry->wellPathPoints();
if (mdIndex > 0 && mdIndex < ptList.size() - 2)
{
auto v1 = cvf::Vec3d(ptList[mdIndex - 1]);
auto v2 = cvf::Vec3d(ptList[mdIndex]);
auto v3 = cvf::Vec3d(ptList[mdIndex + 1]);
auto v4 = cvf::Vec3d(ptList[mdIndex + 2]);
auto v21 = v2 - v1;
auto v32 = v3 - v2;
auto v43 = v4 - v3;
v21.normalize();
v32.normalize();
v43.normalize();
auto v13mean = (v21 + v32) / 2;
auto v24mean = (v32 + v43) / 2;
double weight = (measuredDepth - mdList[mdIndex]) / (mdList[mdIndex + 1] - mdList[mdIndex]);
auto vTan = v13mean * weight + v24mean * (1 - weight);
RiaOffshoreSphericalCoords coords(vTan);
*azimuth = coords.azi();
*inclination = coords.inc();
return true;
}
*azimuth = 0.0;
*inclination = 0.0;
return false;
}

View File

@ -23,6 +23,7 @@
#include "cafPdmPointer.h"
class RimWellPathGeometryDef;
class RigWellPath;
//==================================================================================================
///
@ -38,5 +39,11 @@ protected:
virtual bool handlePickEvent(const Ric3DPickEvent& eventObject) override;
virtual void notifyUnregistered() override;
private:
bool calculateAzimuthAndInclinationAtMd(double measuredDepth,
const RigWellPath* wellPathGeometry,
double *azimuth,
double *inclination) const;
};

View File

@ -61,12 +61,12 @@ RimWellPath* RivWellPathSourceInfo::wellPath() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RivWellPathSourceInfo::measuredDepth(size_t triangleIndex, const cvf::Vec3d& globalIntersection) const
double RivWellPathSourceInfo::measuredDepth(size_t triangleIndex, const cvf::Vec3d& globalIntersectionInDomain) const
{
size_t firstSegmentIndex = cvf::UNDEFINED_SIZE_T;
double norm = 0.0;
normalizedIntersection(triangleIndex, globalIntersection, &firstSegmentIndex, &norm);
normalizedIntersection(triangleIndex, globalIntersectionInDomain, &firstSegmentIndex, &norm);
double firstDepth = m_wellPath->wellPathGeometry()->m_measuredDepths[firstSegmentIndex];
double secDepth = m_wellPath->wellPathGeometry()->m_measuredDepths[firstSegmentIndex + 1];
@ -77,12 +77,12 @@ double RivWellPathSourceInfo::measuredDepth(size_t triangleIndex, const cvf::Vec
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RivWellPathSourceInfo::closestPointOnCenterLine(size_t triangleIndex, const cvf::Vec3d& globalIntersection) const
cvf::Vec3d RivWellPathSourceInfo::closestPointOnCenterLine(size_t triangleIndex, const cvf::Vec3d& globalIntersectionInDomain) const
{
size_t firstSegmentIndex = cvf::UNDEFINED_SIZE_T;
double norm = 0.0;
normalizedIntersection(triangleIndex, globalIntersection, &firstSegmentIndex, &norm);
normalizedIntersection(triangleIndex, globalIntersectionInDomain, &firstSegmentIndex, &norm);
cvf::Vec3d firstDepth = m_wellPath->wellPathGeometry()->m_wellPathPoints[firstSegmentIndex];
cvf::Vec3d secDepth = m_wellPath->wellPathGeometry()->m_wellPathPoints[firstSegmentIndex + 1];
@ -93,18 +93,17 @@ cvf::Vec3d RivWellPathSourceInfo::closestPointOnCenterLine(size_t triangleIndex,
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivWellPathSourceInfo::normalizedIntersection(size_t triangleIndex, const cvf::Vec3d& globalIntersection,
void RivWellPathSourceInfo::normalizedIntersection(size_t triangleIndex, const cvf::Vec3d& globalIntersectionInDomain,
size_t* firstSegmentIndex, double* normalizedSegmentIntersection) const
{
size_t segIndex = segmentIndex(triangleIndex);
RigWellPath* rigWellPath = m_wellPath->wellPathGeometry();
cvf::Vec3d segmentStart = rigWellPath->m_wellPathPoints[segIndex];
cvf::Vec3d segmentEnd = rigWellPath->m_wellPathPoints[segIndex + 1];
double norm = 0.0;
cvf::Vec3d pointOnLine = cvf::GeometryTools::projectPointOnLine(segmentStart, segmentEnd, globalIntersection, &norm);
cvf::Vec3d pointOnLine = cvf::GeometryTools::projectPointOnLine(segmentStart, segmentEnd, globalIntersectionInDomain, &norm);
norm = cvf::Math::clamp(norm, 0.0, 1.0);
*firstSegmentIndex = segIndex;

View File

@ -40,12 +40,12 @@ public:
RimWellPath* wellPath() const;
size_t segmentIndex(size_t triangleIndex) const;
double measuredDepth(size_t triangleIndex, const cvf::Vec3d& globalIntersection) const;
cvf::Vec3d closestPointOnCenterLine(size_t triangleIndex, const cvf::Vec3d& globalIntersection) const;
double measuredDepth(size_t triangleIndex, const cvf::Vec3d& globalIntersectionInDomain) const;
cvf::Vec3d closestPointOnCenterLine(size_t triangleIndex, const cvf::Vec3d& globalIntersectionInDomain) const;
private:
void normalizedIntersection(size_t triangleIndex,
const cvf::Vec3d& globalIntersection,
const cvf::Vec3d& globalIntersectionInDomain,
size_t* firstSegmentIndex,
double* normalizedSegmentIntersection) const;