mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Refactor: Extract getPartIndexFromPoint to avoid duplication.
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RigFemPartCollection.h"
|
||||
|
||||
#include "RigHexIntersectionTools.h"
|
||||
|
||||
#include "cvfBoundingBox.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -181,6 +184,40 @@ void RigFemPartCollection::findIntersectingGlobalElementIndices( const cvf::Boun
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RigFemPartCollection::getPartIndexFromPoint( const cvf::Vec3d& point ) const
|
||||
{
|
||||
const int idx = -1;
|
||||
|
||||
// Find candidates for intersected global elements
|
||||
const cvf::BoundingBox intersectingBb( point, point );
|
||||
std::vector<size_t> intersectedGlobalElementIndexCandidates;
|
||||
findIntersectingGlobalElementIndices( intersectingBb, &intersectedGlobalElementIndexCandidates );
|
||||
|
||||
if ( intersectedGlobalElementIndexCandidates.empty() ) return idx;
|
||||
|
||||
// Iterate through global element candidates and check if point is in hexCorners
|
||||
for ( const auto& globalElementIndex : intersectedGlobalElementIndexCandidates )
|
||||
{
|
||||
const auto [part, elementIndex] = partAndElementIndex( globalElementIndex );
|
||||
|
||||
// Find nodes from element
|
||||
std::array<cvf::Vec3d, 8> coordinates;
|
||||
if ( part->fillElementCoordinates( elementIndex, coordinates ) )
|
||||
{
|
||||
if ( RigHexIntersectionTools::isPointInCell( point, coordinates.data() ) )
|
||||
{
|
||||
return part->elementPartId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Utilize first part to have an id
|
||||
return idx;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
|
||||
size_t globalElementNodeResultIdx( int part, int elementIdx, int elmLocalNodeIdx ) const;
|
||||
|
||||
int getPartIndexFromPoint( const cvf::Vec3d& point ) const;
|
||||
|
||||
private:
|
||||
cvf::Collection<RigFemPart> m_femParts;
|
||||
std::vector<size_t> m_partElementOffset;
|
||||
|
||||
Reference in New Issue
Block a user