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
|
|
|
|
2019-05-06 03:36:05 -05:00
|
|
|
#include "RiaGuiApplication.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"
|
2021-08-13 09:48:33 -05:00
|
|
|
#include "RigWellPathGeometryTools.h"
|
2018-10-01 03:07:43 -05:00
|
|
|
|
2018-08-29 09:03:31 -05:00
|
|
|
#include "Rim3dView.h"
|
2019-01-31 08:49:12 -06:00
|
|
|
#include "RimEclipseView.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimGeoMechView.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
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
RicCreateWellTargetsPickEventHandler::RicCreateWellTargetsPickEventHandler( gsl::not_null<RimWellPathGeometryDef*> wellGeometryDef )
|
2019-09-06 03:40:57 -05:00
|
|
|
: m_geometryToAddTargetsTo( wellGeometryDef )
|
2018-08-29 09:03:31 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
///
|
2018-08-29 09:03:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:13:38 -06:00
|
|
|
RicCreateWellTargetsPickEventHandler::~RicCreateWellTargetsPickEventHandler()
|
|
|
|
{
|
|
|
|
}
|
2018-08-29 09:03:31 -05:00
|
|
|
|
2019-02-11 06:46:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicCreateWellTargetsPickEventHandler::registerAsPickEventHandler()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaGuiApplication::instance()->setOverrideCursor( Qt::CrossCursor );
|
2019-02-11 06:46:48 -06:00
|
|
|
Ric3dViewPickEventHandler::registerAsPickEventHandler();
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2019-05-06 03:36:05 -05:00
|
|
|
RiaGuiApplication::instance()->restoreOverrideCursor();
|
2018-08-30 06:22:28 -05:00
|
|
|
}
|
|
|
|
|
2018-08-29 09:03:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-16 04:38:35 -06:00
|
|
|
///
|
2018-08-29 09:03:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
bool RicCreateWellTargetsPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eventObject )
|
2018-08-29 09:03:31 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05: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
|
2021-02-26 07:27:59 -06:00
|
|
|
auto firstPickItem = eventObject.m_pickItemInfos.front();
|
|
|
|
auto wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>( firstPickItem.sourceInfo() );
|
2018-10-01 03:07:43 -05:00
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
auto intersectionPointInDomain = rimView->displayCoordTransform()->transformToDomainCoord( firstPickItem.globalPickedPoint() );
|
2021-02-26 07:27:59 -06:00
|
|
|
bool doSetAzimuthAndInclination = false;
|
|
|
|
double azimuth = 0.0;
|
|
|
|
double inclination = 0.0;
|
2018-11-16 04:35:13 -06:00
|
|
|
|
2021-02-26 07:27:59 -06:00
|
|
|
if ( wellPathSourceInfo && wellPathSourceInfo->wellPath() && wellPathSourceInfo->wellPath()->wellPathGeometry() )
|
2018-10-01 03:07:43 -05:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
auto wellPathGeometry = wellPathSourceInfo->wellPath()->wellPathGeometry();
|
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
targetPointInDomain = wellPathSourceInfo->closestPointOnCenterLine( firstPickItem.faceIdx(), intersectionPointInDomain );
|
|
|
|
double md = wellPathSourceInfo->measuredDepth( firstPickItem.faceIdx(), intersectionPointInDomain );
|
2021-08-13 09:48:33 -05:00
|
|
|
|
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
const auto [az, inc] = RigWellPathGeometryTools::calculateAzimuthAndInclinationAtMd( md, wellPathGeometry );
|
|
|
|
azimuth = az;
|
|
|
|
inclination = inc;
|
2021-08-13 09:48:33 -05:00
|
|
|
doSetAzimuthAndInclination = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double rkbDiff = wellPathGeometry->rkbDiff();
|
2021-02-26 07:27:59 -06:00
|
|
|
if ( m_geometryToAddTargetsTo->airGap() == 0.0 && rkbDiff != std::numeric_limits<double>::infinity() )
|
|
|
|
{
|
|
|
|
m_geometryToAddTargetsTo->setAirGap( rkbDiff );
|
|
|
|
}
|
2018-10-01 03:07:43 -05:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( isGridSourceObject( firstPickItem.sourceInfo() ) )
|
2018-10-01 03:07:43 -05:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
targetPointInDomain = intersectionPointInDomain;
|
|
|
|
doSetAzimuthAndInclination = false;
|
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
cvf::Vec3d domainRayOrigin = rimView->displayCoordTransform()->transformToDomainCoord( firstPickItem.globalRayOrigin() );
|
|
|
|
cvf::Vec3d domainRayEnd = targetPointInDomain + ( targetPointInDomain - domainRayOrigin );
|
2021-02-26 07:27:59 -06:00
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
cvf::Vec3d hexElementIntersection = findHexElementIntersection( rimView, firstPickItem, domainRayOrigin, domainRayEnd );
|
2021-02-26 07:27:59 -06:00
|
|
|
CVF_TIGHT_ASSERT( !hexElementIntersection.isUndefined() );
|
|
|
|
if ( !hexElementIntersection.isUndefined() )
|
|
|
|
{
|
|
|
|
targetPointInDomain = hexElementIntersection;
|
|
|
|
}
|
2018-10-01 03:07:43 -05:00
|
|
|
}
|
2019-02-12 09:32:21 -06:00
|
|
|
else
|
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
targetPointInDomain = intersectionPointInDomain;
|
|
|
|
doSetAzimuthAndInclination = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !m_geometryToAddTargetsTo->firstActiveTarget() )
|
|
|
|
{
|
|
|
|
m_geometryToAddTargetsTo->setReferencePointXyz( targetPointInDomain );
|
|
|
|
|
|
|
|
if ( wellPathSourceInfo )
|
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
double mdAtFirstTarget = wellPathSourceInfo->measuredDepth( firstPickItem.faceIdx(), intersectionPointInDomain );
|
2021-02-26 07:27:59 -06:00
|
|
|
|
|
|
|
RimModeledWellPath* modeledWellPath = dynamic_cast<RimModeledWellPath*>( wellPathSourceInfo->wellPath() );
|
|
|
|
if ( modeledWellPath )
|
|
|
|
{
|
|
|
|
mdAtFirstTarget += modeledWellPath->geometryDefinition()->mdAtFirstTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_geometryToAddTargetsTo->setMdAtFirstTarget( mdAtFirstTarget );
|
|
|
|
}
|
2018-08-29 09:03:31 -05:00
|
|
|
}
|
2018-11-16 04:35:13 -06:00
|
|
|
|
2021-02-26 07:27:59 -06:00
|
|
|
cvf::Vec3d referencePoint = m_geometryToAddTargetsTo->anchorPointXyz();
|
|
|
|
cvf::Vec3d relativeTagetPoint = targetPointInDomain - referencePoint;
|
|
|
|
|
|
|
|
RimWellPathTarget* newTarget = new RimWellPathTarget;
|
|
|
|
|
|
|
|
if ( doSetAzimuthAndInclination )
|
2018-10-01 03:07:43 -05:00
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
newTarget->setAsPointXYZAndTangentTarget( cvf::Vec3d( relativeTagetPoint.x(), relativeTagetPoint.y(), relativeTagetPoint.z() ),
|
2021-02-26 07:27:59 -06:00
|
|
|
azimuth,
|
|
|
|
inclination );
|
2018-10-01 03:07:43 -05:00
|
|
|
}
|
2021-02-26 07:27:59 -06:00
|
|
|
else
|
2018-10-01 03:07:43 -05:00
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
newTarget->setAsPointTargetXYD( cvf::Vec3d( relativeTagetPoint.x(), relativeTagetPoint.y(), -relativeTagetPoint.z() ) );
|
2018-10-01 03:07:43 -05:00
|
|
|
}
|
2018-08-29 09:03:31 -05:00
|
|
|
|
2021-02-26 07:27:59 -06:00
|
|
|
m_geometryToAddTargetsTo->insertTarget( nullptr, newTarget );
|
|
|
|
|
|
|
|
m_geometryToAddTargetsTo->updateConnectedEditors();
|
|
|
|
m_geometryToAddTargetsTo->updateWellPathVisualization( true );
|
|
|
|
|
2018-08-29 09:03:31 -05:00
|
|
|
return true; // Todo: See if we really should eat the event instead
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-01 03:07:43 -05:00
|
|
|
|
2019-02-01 00:50:52 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
bool RicCreateWellTargetsPickEventHandler::isGridSourceObject( const cvf::Object* object )
|
2019-02-01 00:50:52 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto sourceInfo = dynamic_cast<const RivSourceInfo*>( object );
|
|
|
|
auto femSourceInfo = dynamic_cast<const RivFemPickSourceInfo*>( object );
|
2019-02-01 00:50:52 -06:00
|
|
|
return sourceInfo || femSourceInfo;
|
|
|
|
}
|
|
|
|
|
2019-01-31 08:49:12 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
cvf::Vec3d RicCreateWellTargetsPickEventHandler::findHexElementIntersection( gsl::not_null<Rim3dView*> view,
|
|
|
|
const RiuPickItemInfo& pickItem,
|
|
|
|
const cvf::Vec3d& domainRayOrigin,
|
|
|
|
const cvf::Vec3d& domainRayEnd )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto sourceInfo = dynamic_cast<const RivSourceInfo*>( pickItem.sourceInfo() );
|
|
|
|
auto femSourceInfo = dynamic_cast<const RivFemPickSourceInfo*>( pickItem.sourceInfo() );
|
2019-01-31 08:49:12 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
size_t cellIndex = cvf::UNDEFINED_SIZE_T;
|
2019-01-31 08:49:12 -06:00
|
|
|
std::array<cvf::Vec3d, 8> cornerVertices;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( sourceInfo )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
|
|
|
size_t gridIndex = sourceInfo->gridIndex();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( sourceInfo->hasCellFaceMapping() )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
cellIndex = sourceInfo->m_cellFaceFromTriangleMapper->cellIndex( pickItem.faceIdx() );
|
|
|
|
|
2021-02-26 07:27:59 -06:00
|
|
|
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>( view.get() );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( eclipseView && eclipseView->mainGrid() )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RigGridBase* hitGrid = eclipseView->mainGrid()->gridByIndex( gridIndex );
|
|
|
|
hitGrid->cellCornerVertices( cellIndex, cornerVertices.data() );
|
2019-01-31 08:49:12 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( femSourceInfo )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
|
|
|
size_t femPartIndex = femSourceInfo->femPartIndex();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( femSourceInfo->triangleToElmMapper() )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
size_t elementIndex = femSourceInfo->triangleToElmMapper()->elementIndex( pickItem.faceIdx() );
|
2019-01-31 08:49:12 -06:00
|
|
|
|
2021-02-26 07:27:59 -06:00
|
|
|
RimGeoMechView* geoMechView = dynamic_cast<RimGeoMechView*>( view.get() );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( geoMechView && geoMechView->femParts() )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
RigFemPart* femPart = geoMechView->femParts()->part( femPartIndex );
|
|
|
|
RigElementType elType = femPart->elementType( elementIndex );
|
2019-01-31 09:18:24 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( elType == HEX8 || elType == HEX8P )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
cellIndex = elementIndex;
|
2019-01-31 09:18:24 -06:00
|
|
|
const RigFemPartGrid* femGrid = femPart->getOrCreateStructGrid();
|
2019-09-06 03:40:57 -05:00
|
|
|
femGrid->cellCornerVertices( cellIndex, cornerVertices.data() );
|
2019-01-31 08:49:12 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( cellIndex )
|
2019-01-31 08:49:12 -06:00
|
|
|
{
|
2019-01-31 09:18:24 -06:00
|
|
|
std::vector<HexIntersectionInfo> intersectionInfo;
|
2023-02-26 03:48:40 -06:00
|
|
|
RigHexIntersectionTools::lineHexCellIntersection( domainRayOrigin, domainRayEnd, cornerVertices.data(), cellIndex, &intersectionInfo );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !intersectionInfo.empty() )
|
2019-01-31 09:18:24 -06:00
|
|
|
{
|
|
|
|
// Sort intersection on distance to ray origin
|
2019-09-06 03:40:57 -05:00
|
|
|
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-2;
|
2023-02-26 03:48:40 -06:00
|
|
|
cvf::Vec3d intersectionRay = intersectionInfo.back().m_intersectionPoint - intersectionInfo.front().m_intersectionPoint;
|
|
|
|
cvf::Vec3d newPoint = intersectionInfo.front().m_intersectionPoint + intersectionRay * eps;
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( RigHexIntersectionTools::isPointInCell( newPoint, cornerVertices.data() ) );
|
2019-01-31 09:18:24 -06:00
|
|
|
return newPoint;
|
|
|
|
}
|
2019-01-31 08:49:12 -06:00
|
|
|
}
|
|
|
|
return cvf::Vec3d::UNDEFINED;
|
|
|
|
}
|