Skip to content

Commit

Permalink
#11206 Guard assert when picking in a zoomed scene
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Feb 16, 2024
1 parent 185f62d commit f0a8712
Showing 1 changed file with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

#include "RicCreateWellTargetsPickEventHandler.h"

#include "RiaGuiApplication.h"
#include "RiaOffshoreSphericalCoords.h"

#include "RigFemPart.h"
#include "RigFemPartCollection.h"
#include "RigFemPartGrid.h"
Expand All @@ -30,6 +27,7 @@
#include "RigWellPathGeometryTools.h"

#include "Rim3dView.h"
#include "RimCase.h"
#include "RimEclipseView.h"
#include "RimGeoMechView.h"
#include "RimModeledWellPath.h"
Expand All @@ -47,10 +45,6 @@
#include "cafDisplayCoordTransform.h"
#include "cafSelectionManager.h"

#include "cvfStructGridGeometryGenerator.h"

#include <QDebug>

#include <vector>

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -130,7 +124,14 @@ bool RicCreateWellTargetsPickEventHandler::handle3dPickEvent( const Ric3dPickEve
doSetAzimuthAndInclination = false;

cvf::Vec3d domainRayOrigin = rimView->displayCoordTransform()->transformToDomainCoord( firstPickItem.globalRayOrigin() );
cvf::Vec3d domainRayEnd = targetPointInDomain + ( targetPointInDomain - domainRayOrigin );

auto rayVector = ( targetPointInDomain - domainRayOrigin );
const double minimumRayLenght = rimView->ownerCase()->characteristicCellSize() * 2;
if ( rayVector.length() < minimumRayLenght )
{
rayVector = rayVector.getNormalized() * minimumRayLenght;
}
cvf::Vec3d domainRayEnd = targetPointInDomain + rayVector;

cvf::Vec3d hexElementIntersection = findHexElementIntersection( rimView, firstPickItem, domainRayOrigin, domainRayEnd );
CVF_TIGHT_ASSERT( !hexElementIntersection.isUndefined() );
Expand Down Expand Up @@ -255,22 +256,27 @@ cvf::Vec3d RicCreateWellTargetsPickEventHandler::findHexElementIntersection( gsl
{
std::vector<HexIntersectionInfo> intersectionInfo;
RigHexIntersectionTools::lineHexCellIntersection( domainRayOrigin, domainRayEnd, cornerVertices.data(), cellIndex, &intersectionInfo );
if ( !intersectionInfo.empty() )

if ( intersectionInfo.empty() ) return cvf::Vec3d::UNDEFINED;

if ( intersectionInfo.size() == 1 )
{
// 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-2;
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 intersectionInfo.front().m_intersectionPoint;
}

// Sort intersection on distance to ray origin
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;
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;
}

0 comments on commit f0a8712

Please sign in to comment.