Refactor: Extract getPartIndexFromPoint to avoid duplication.

This commit is contained in:
Kristian Bendiksen
2024-01-03 09:00:32 +01:00
parent 62c7007654
commit ffa117e736
6 changed files with 46 additions and 76 deletions

View File

@@ -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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -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;