2018-08-29 09:03:31 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-09 08:21:38 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-11-16 04:38:35 -06:00
|
|
|
//
|
2018-08-29 09:03:31 -05:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2018-11-16 04:38:35 -06:00
|
|
|
//
|
2018-08-29 09:03:31 -05:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2018-11-16 04:38:35 -06:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-08-29 09:03:31 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicCreateWellTargetsPickEventHandler.h"
|
2018-10-01 03:07:43 -05:00
|
|
|
|
|
|
|
#include "RiaOffshoreSphericalCoords.h"
|
|
|
|
|
2019-01-31 08:49:12 -06:00
|
|
|
#include "RigFemPart.h"
|
|
|
|
#include "RigFemPartCollection.h"
|
|
|
|
#include "RigFemPartGrid.h"
|
|
|
|
#include "RigHexIntersectionTools.h"
|
|
|
|
#include "RigMainGrid.h"
|
2018-10-01 03:07:43 -05:00
|
|
|
#include "RigWellPath.h"
|
|
|
|
|
2018-08-29 09:03:31 -05:00
|
|
|
#include "Rim3dView.h"
|
2019-01-31 08:49:12 -06:00
|
|
|
#include "RimGeoMechView.h"
|
|
|
|
#include "RimEclipseView.h"
|
2018-11-16 04:38:35 -06:00
|
|
|
#include "RimModeledWellPath.h"
|
|
|
|
#include "RimWellPath.h"
|
2018-08-29 09:03:31 -05:00
|
|
|
#include "RimWellPathGeometryDef.h"
|
|
|
|
#include "RimWellPathTarget.h"
|
2018-11-16 04:38:35 -06:00
|
|
|
|
|
|
|
#include "RiuViewerCommands.h"
|
2018-10-01 03:07:43 -05:00
|
|
|
|
2019-01-31 08:49:12 -06:00
|
|
|
#include "RivFemPartGeometryGenerator.h"
|
|
|
|
#include "RivFemPickSourceInfo.h"
|
|
|
|
#include "RivSourceInfo.h"
|
2018-10-01 03:07:43 -05:00
|
|
|
#include "RivWellPathSourceInfo.h"
|
2018-08-29 09:03:31 -05:00
|
|
|
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
2018-11-16 04:38:35 -06:00
|
|
|
#include "cafSelectionManager.h"
|
2018-08-29 09:03:31 -05:00
|
|
|
|
2019-01-31 08:49:12 -06:00
|
|
|
#include "cvfStructGridGeometryGenerator.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
2018-08-29 09:03:31 -05:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
///
|
2018-08-29 09:03:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicCreateWellTargetsPickEventHandler::RicCreateWellTargetsPickEventHandler(RimWellPathGeometryDef* wellGeometryDef)
|
|
|
|
: m_geometryToAddTargetsTo(wellGeometryDef)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
///
|
2018-08-29 09:03:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
RicCreateWellTargetsPickEventHandler::~RicCreateWellTargetsPickEventHandler() {}
|
2018-08-29 09:03:31 -05:00
|
|
|
|
2018-08-30 06:22:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
///
|
2018-08-30 06:22:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicCreateWellTargetsPickEventHandler::notifyUnregistered()
|
|
|
|
{
|
|
|
|
m_geometryToAddTargetsTo->enableTargetPointPicking(false);
|
|
|
|
}
|
|
|
|
|
2018-08-29 09:03:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
///
|
2018-08-29 09:03:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicCreateWellTargetsPickEventHandler::handlePickEvent(const Ric3DPickEvent& eventObject)
|
|
|
|
{
|
|
|
|
if (!caf::SelectionManager::instance()->isSelected(m_geometryToAddTargetsTo.p(), 0))
|
|
|
|
{
|
|
|
|
m_geometryToAddTargetsTo->enableTargetPointPicking(false);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-16 04:38:35 -06:00
|
|
|
if (m_geometryToAddTargetsTo)
|
2018-08-29 09:03:31 -05:00
|
|
|
{
|
2018-11-16 04:38:35 -06:00
|
|
|
Rim3dView* rimView = eventObject.m_view;
|
2018-10-01 03:07:43 -05:00
|
|
|
cvf::Vec3d targetPointInDomain = cvf::Vec3d::ZERO;
|
|
|
|
|
|
|
|
// If clicked on an other well path, snap target point to well path center line
|
2018-11-16 04:38:35 -06:00
|
|
|
auto firstPickItem = eventObject.m_pickItemInfos.front();
|
2018-10-01 03:07:43 -05:00
|
|
|
auto wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(firstPickItem.sourceInfo());
|
|
|
|
|
2018-11-16 04:38:35 -06:00
|
|
|
auto intersectionPointInDomain =
|
|
|
|
rimView->displayCoordTransform()->transformToDomainCoord(firstPickItem.globalPickedPoint());
|
|
|
|
bool doSetAzimuthAndInclination = false;
|
|
|
|
double azimuth = 0.0;
|
|
|
|
double inclination = 0.0;
|
2018-11-16 04:35:13 -06:00
|
|
|
|
2018-10-01 03:07:43 -05:00
|
|
|
if (wellPathSourceInfo)
|
|
|
|
{
|
2018-11-16 04:38:35 -06:00
|
|
|
targetPointInDomain =
|
|
|
|
wellPathSourceInfo->closestPointOnCenterLine(firstPickItem.faceIdx(), intersectionPointInDomain);
|
2018-10-01 03:07:43 -05:00
|
|
|
|
2018-11-16 04:38:35 -06:00
|
|
|
double md = wellPathSourceInfo->measuredDepth(firstPickItem.faceIdx(), intersectionPointInDomain);
|
|
|
|
doSetAzimuthAndInclination = calculateAzimuthAndInclinationAtMd(
|
|
|
|
md, wellPathSourceInfo->wellPath()->wellPathGeometry(), &azimuth, &inclination);
|
2018-10-01 03:07:43 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-16 04:38:35 -06:00
|
|
|
targetPointInDomain = intersectionPointInDomain;
|
2018-10-01 03:07:43 -05:00
|
|
|
doSetAzimuthAndInclination = false;
|
2019-01-31 08:49:12 -06:00
|
|
|
|
|
|
|
cvf::Vec3d domainRayOrigin =
|
|
|
|
rimView->displayCoordTransform()->transformToDomainCoord(firstPickItem.globalRayOrigin());
|
|
|
|
cvf::Vec3d domainRayEnd = targetPointInDomain + (targetPointInDomain - domainRayOrigin);
|
|
|
|
|
|
|
|
cvf::Vec3d hexElementIntersection = findHexElementIntersection(rimView, firstPickItem, domainRayOrigin, domainRayEnd);
|
|
|
|
CVF_ASSERT(!hexElementIntersection.isUndefined());
|
|
|
|
if (!hexElementIntersection.isUndefined())
|
|
|
|
{
|
|
|
|
targetPointInDomain = hexElementIntersection;
|
|
|
|
}
|
2018-10-01 03:07:43 -05:00
|
|
|
}
|
2018-08-29 09:03:31 -05:00
|
|
|
|
|
|
|
if (!m_geometryToAddTargetsTo->firstActiveTarget())
|
|
|
|
{
|
2018-10-01 03:07:43 -05:00
|
|
|
m_geometryToAddTargetsTo->setReferencePointXyz(targetPointInDomain);
|
2018-11-16 04:38:35 -06:00
|
|
|
|
2018-11-16 04:35:13 -06:00
|
|
|
if (wellPathSourceInfo)
|
|
|
|
{
|
|
|
|
double mdrkbAtFirstTarget = wellPathSourceInfo->measuredDepth(firstPickItem.faceIdx(), intersectionPointInDomain);
|
|
|
|
|
|
|
|
RimModeledWellPath* modeledWellPath = dynamic_cast<RimModeledWellPath*>(wellPathSourceInfo->wellPath());
|
|
|
|
if (modeledWellPath)
|
|
|
|
{
|
|
|
|
mdrkbAtFirstTarget += modeledWellPath->geometryDefinition()->mdrkbAtFirstTarget();
|
|
|
|
}
|
2018-11-16 04:38:35 -06:00
|
|
|
|
2018-11-16 04:35:13 -06:00
|
|
|
m_geometryToAddTargetsTo->setMdrkbAtFirstTarget(mdrkbAtFirstTarget);
|
|
|
|
}
|
2018-08-29 09:03:31 -05:00
|
|
|
}
|
2018-11-16 04:35:13 -06:00
|
|
|
|
2018-11-16 04:38:35 -06:00
|
|
|
cvf::Vec3d referencePoint = m_geometryToAddTargetsTo->referencePointXyz();
|
2018-10-01 03:07:43 -05:00
|
|
|
cvf::Vec3d relativeTagetPoint = targetPointInDomain - referencePoint;
|
2018-09-10 09:32:24 -05:00
|
|
|
|
2018-08-29 09:03:31 -05:00
|
|
|
RimWellPathTarget* newTarget = new RimWellPathTarget;
|
2018-10-01 03:07:43 -05:00
|
|
|
|
|
|
|
if (doSetAzimuthAndInclination)
|
|
|
|
{
|
2018-11-16 04:38:35 -06:00
|
|
|
newTarget->setAsPointXYZAndTangentTarget(
|
|
|
|
cvf::Vec3d(relativeTagetPoint.x(), relativeTagetPoint.y(), relativeTagetPoint.z()), azimuth, inclination);
|
2018-10-01 03:07:43 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newTarget->setAsPointTargetXYD(cvf::Vec3d(relativeTagetPoint.x(), relativeTagetPoint.y(), -relativeTagetPoint.z()));
|
|
|
|
}
|
2018-08-29 09:03:31 -05:00
|
|
|
|
|
|
|
m_geometryToAddTargetsTo->insertTarget(nullptr, newTarget);
|
|
|
|
|
|
|
|
m_geometryToAddTargetsTo->updateConnectedEditors();
|
|
|
|
m_geometryToAddTargetsTo->updateWellPathVisualization();
|
|
|
|
|
|
|
|
return true; // Todo: See if we really should eat the event instead
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-01 03:07:43 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
///
|
2018-10-01 03:07:43 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
bool RicCreateWellTargetsPickEventHandler::calculateAzimuthAndInclinationAtMd(double measuredDepth,
|
2018-10-01 03:07:43 -05:00
|
|
|
const RigWellPath* wellPathGeometry,
|
2018-11-16 04:38:35 -06:00
|
|
|
double* azimuth,
|
|
|
|
double* inclination) const
|
2018-10-01 03:07:43 -05:00
|
|
|
{
|
2018-11-16 04:38:35 -06:00
|
|
|
int mdIndex = -1;
|
|
|
|
auto mdList = wellPathGeometry->measureDepths();
|
2018-10-01 03:07:43 -05:00
|
|
|
|
2018-10-02 06:00:51 -05:00
|
|
|
for (int i = 0; i < (int)mdList.size(); i++)
|
2018-10-01 03:07:43 -05:00
|
|
|
{
|
|
|
|
if (mdList[i] > measuredDepth)
|
|
|
|
{
|
|
|
|
mdIndex = i - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ptList = wellPathGeometry->wellPathPoints();
|
2018-10-02 06:00:51 -05:00
|
|
|
if (mdIndex > 0 && mdIndex < (int)ptList.size() - 2)
|
2018-10-01 03:07:43 -05:00
|
|
|
{
|
|
|
|
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]);
|
2018-11-16 04:38:35 -06:00
|
|
|
auto vTan = v13mean * weight + v24mean * (1 - weight);
|
2018-10-01 03:07:43 -05:00
|
|
|
|
|
|
|
RiaOffshoreSphericalCoords coords(vTan);
|
2018-11-16 04:38:35 -06:00
|
|
|
*azimuth = coords.azi();
|
2018-10-01 03:07:43 -05:00
|
|
|
*inclination = coords.inc();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-16 04:38:35 -06:00
|
|
|
*azimuth = 0.0;
|
2018-10-01 03:07:43 -05:00
|
|
|
*inclination = 0.0;
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-31 08:49:12 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Vec3d RicCreateWellTargetsPickEventHandler::findHexElementIntersection(Rim3dView* view, const RiuPickItemInfo& pickItem, const cvf::Vec3d& domainRayOrigin, const cvf::Vec3d& domainRayEnd)
|
|
|
|
{
|
|
|
|
auto sourceInfo = dynamic_cast<const RivSourceInfo*>(pickItem.sourceInfo());
|
|
|
|
auto femSourceInfo = dynamic_cast<const RivFemPickSourceInfo*>(pickItem.sourceInfo());
|
|
|
|
|
|
|
|
size_t cellIndex = cvf::UNDEFINED_SIZE_T;
|
|
|
|
std::array<cvf::Vec3d, 8> cornerVertices;
|
|
|
|
double characteristicLength = 0.0;
|
|
|
|
if (sourceInfo)
|
|
|
|
{
|
|
|
|
size_t gridIndex = sourceInfo->gridIndex();
|
|
|
|
if (sourceInfo->hasCellFaceMapping())
|
|
|
|
{
|
|
|
|
cellIndex = sourceInfo->m_cellFaceFromTriangleMapper->cellIndex(pickItem.faceIdx());
|
|
|
|
|
|
|
|
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(view);
|
|
|
|
if (eclipseView && eclipseView->mainGrid())
|
|
|
|
{
|
|
|
|
RigGridBase* hitGrid = eclipseView->mainGrid()->gridByIndex(gridIndex);
|
|
|
|
hitGrid->cellCornerVertices(cellIndex, cornerVertices.data());
|
|
|
|
double dx, dy, dz;
|
|
|
|
hitGrid->characteristicCellSizes(&dx, &dy, &dz);
|
|
|
|
characteristicLength = dz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (femSourceInfo)
|
|
|
|
{
|
|
|
|
size_t femPartIndex = femSourceInfo->femPartIndex();
|
|
|
|
if (femSourceInfo->triangleToElmMapper())
|
|
|
|
{
|
|
|
|
size_t elementIndex = femSourceInfo->triangleToElmMapper()->elementIndex(pickItem.faceIdx());
|
|
|
|
|
|
|
|
RimGeoMechView* geoMechView = dynamic_cast<RimGeoMechView*>(view);
|
|
|
|
if (geoMechView && geoMechView->femParts())
|
|
|
|
{
|
|
|
|
RigFemPart* femPart = geoMechView->femParts()->part(femPartIndex);
|
|
|
|
if (femPart->elementType(cellIndex) == HEX8 || femPart->elementType(cellIndex) == HEX8P)
|
|
|
|
{
|
|
|
|
cellIndex = elementIndex;
|
|
|
|
femPart->getOrCreateStructGrid()->cellCornerVertices(cellIndex, cornerVertices.data());
|
|
|
|
characteristicLength = femPart->characteristicElementSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HexIntersectionInfo> intersectionInfo;
|
|
|
|
RigHexIntersectionTools::lineHexCellIntersection(domainRayOrigin, domainRayEnd, cornerVertices.data(), cellIndex, &intersectionInfo);
|
|
|
|
if (!intersectionInfo.empty())
|
|
|
|
{
|
|
|
|
// Sort intersection on distance to ray origin
|
|
|
|
CVF_ASSERT(intersectionInfo.size() > 1);
|
|
|
|
std::sort(intersectionInfo.begin(), intersectionInfo.end(),
|
|
|
|
[&domainRayOrigin](const HexIntersectionInfo& lhs, const HexIntersectionInfo& rhs)
|
|
|
|
{
|
|
|
|
return (lhs.m_intersectionPoint - domainRayOrigin).lengthSquared() < (rhs.m_intersectionPoint - domainRayOrigin).lengthSquared();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const double eps = 1.0e-3;
|
|
|
|
cvf::Vec3d intersectionRay = intersectionInfo.back().m_intersectionPoint - intersectionInfo.front().m_intersectionPoint;
|
|
|
|
cvf::Vec3d newPoint = intersectionInfo.front().m_intersectionPoint + intersectionRay * eps;
|
|
|
|
CVF_ASSERT(RigHexIntersectionTools::isPointInCell(newPoint, cornerVertices.data()));
|
|
|
|
return newPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cvf::Vec3d::UNDEFINED;
|
|
|
|
}
|