Skip to content

Commit

Permalink
Refactor: improve interface for finding intersecting cells.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Jan 3, 2024
1 parent 1a37c75 commit ee8988a
Show file tree
Hide file tree
Showing 29 changed files with 75 additions and 105 deletions.
10 changes: 6 additions & 4 deletions ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,19 +516,21 @@ cvf::BoundingBox RigFemPart::boundingBox() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemPart::findIntersectingElementIndices( const cvf::BoundingBox& inputBB, std::vector<size_t>* elementIndices ) const
std::vector<size_t> RigFemPart::findIntersectingElementIndices( const cvf::BoundingBox& inputBB ) const
{
ensureIntersectionSearchTreeIsBuilt();
findIntersectingElementsWithExistingSearchTree( inputBB, elementIndices );
return findIntersectingElementsWithExistingSearchTree( inputBB );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemPart::findIntersectingElementsWithExistingSearchTree( const cvf::BoundingBox& inputBB, std::vector<size_t>* elementIndices ) const
std::vector<size_t> RigFemPart::findIntersectingElementsWithExistingSearchTree( const cvf::BoundingBox& inputBB ) const
{
CVF_ASSERT( m_elementSearchTree.notNull() );
m_elementSearchTree->findIntersections( inputBB, elementIndices );
std::vector<size_t> elementIndices;
m_elementSearchTree->findIntersections( inputBB, &elementIndices );
return elementIndices;
}

//--------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class RigFemPart : public cvf::Object
cvf::BoundingBox boundingBox() const;
float characteristicElementSize() const;
const std::vector<int>& possibleGridCornerElements() const;
void findIntersectingElementIndices( const cvf::BoundingBox& inputBB, std::vector<size_t>* elementIndices ) const;
void findIntersectingElementsWithExistingSearchTree( const cvf::BoundingBox& inputBB, std::vector<size_t>* elementIndices ) const;
std::vector<size_t> findIntersectingElementIndices( const cvf::BoundingBox& inputBB ) const;
std::vector<size_t> findIntersectingElementsWithExistingSearchTree( const cvf::BoundingBox& inputBB ) const;

void ensureIntersectionSearchTreeIsBuilt() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,20 @@ size_t RigFemPartCollection::globalElementIndex( int partId, size_t localIndex )
//--------------------------------------------------------------------------------------------------
/// Find intersecting global element indexes for a given bounding box
//--------------------------------------------------------------------------------------------------
void RigFemPartCollection::findIntersectingGlobalElementIndices( const cvf::BoundingBox& intersectingBB,
std::vector<size_t>* intersectedGlobalElementIndices ) const
std::vector<size_t> RigFemPartCollection::findIntersectingGlobalElementIndices( const cvf::BoundingBox& intersectingBB ) const
{
std::vector<size_t> intersectedGlobalElementIndices;
for ( const auto& part : m_femParts )
{
std::vector<size_t> foundElements;
part->findIntersectingElementIndices( intersectingBB, &foundElements );
std::vector<size_t> foundElements = part->findIntersectingElementIndices( intersectingBB );
for ( const auto& foundElement : foundElements )
{
const size_t globalIdx = globalElementIndex( part->elementPartId(), foundElement );
intersectedGlobalElementIndices->push_back( globalIdx );
intersectedGlobalElementIndices.push_back( globalIdx );
}
}

return intersectedGlobalElementIndices;
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -193,8 +194,7 @@ int RigFemPartCollection::getPartIndexFromPoint( const cvf::Vec3d& point ) const

// Find candidates for intersected global elements
const cvf::BoundingBox intersectingBb( point, point );
std::vector<size_t> intersectedGlobalElementIndexCandidates;
findIntersectingGlobalElementIndices( intersectingBb, &intersectedGlobalElementIndexCandidates );
std::vector<size_t> intersectedGlobalElementIndexCandidates = findIntersectingGlobalElementIndices( intersectingBb );

if ( intersectedGlobalElementIndexCandidates.empty() ) return idx;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class RigFemPartCollection : public cvf::Object
std::pair<const RigFemPart*, size_t> partAndElementIndex( size_t globalIndex ) const;
size_t globalElementIndex( int partId, size_t localIndex ) const;

void findIntersectingGlobalElementIndices( const cvf::BoundingBox& intersectingBB,
std::vector<size_t>* intersectedGlobalElementIndices ) const;
std::vector<size_t> findIntersectingGlobalElementIndices( const cvf::BoundingBox& intersectingBB ) const;

int nodeIdxFromElementNodeResultIdx( size_t globalResultIdx ) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ void findReferenceElementForNode( const RigFemPart& part, size_t nodeIdx, size_t
bb.add( p1 );
bb.add( p2 );

std::vector<size_t> refElementCandidates;
part.findIntersectingElementIndices( bb, &refElementCandidates );
std::vector<size_t> refElementCandidates = part.findIntersectingElementIndices( bb );

const RigFemPartGrid* grid = part.getOrCreateStructGrid();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ void RivBoxIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray* visi

// Similar code as IntersectionGenerator :

std::vector<size_t> columnCellCandidates;
m_hexGrid->findIntersectingCells( sectionBBox, &columnCellCandidates );
std::vector<size_t> columnCellCandidates = m_hexGrid->findIntersectingCells( sectionBBox );

std::vector<caf::HexGridIntersectionTools::ClipVx> hexPlaneCutTriangleVxes;
hexPlaneCutTriangleVxes.reserve( 5 * 3 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ cvf::BoundingBox RivEclipseIntersectionGrid::boundingBox() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivEclipseIntersectionGrid::findIntersectingCells( const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells ) const
std::vector<size_t> RivEclipseIntersectionGrid::findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const
{
m_mainGrid->findIntersectingCells( intersectingBB, intersectedCells );
return m_mainGrid->findIntersectingCells( intersectingBB );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class RivEclipseIntersectionGrid : public RivIntersectionHexGridInterface
public:
RivEclipseIntersectionGrid( const RigMainGrid* mainGrid, const RigActiveCellInfo* activeCellInfo, bool showInactiveCells );

cvf::Vec3d displayOffset() const override;
cvf::BoundingBox boundingBox() const override;
void findIntersectingCells( const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells ) const override;
bool useCell( size_t cellIndex ) const override;
void cellCornerVertices( size_t cellIndex, cvf::Vec3d cellCorners[8] ) const override;
void cellCornerIndices( size_t cellIndex, size_t cornerIndices[8] ) const override;
const RigFault* findFaultFromCellIndexAndCellFace( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const override;
void setKIntervalFilter( bool enabled, std::string kIntervalStr ) override;
cvf::Vec3d displayOffset() const override;
cvf::BoundingBox boundingBox() const override;
std::vector<size_t> findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const override;
bool useCell( size_t cellIndex ) const override;
void cellCornerVertices( size_t cellIndex, cvf::Vec3d cellCorners[8] ) const override;
void cellCornerIndices( size_t cellIndex, size_t cornerIndices[8] ) const override;
const RigFault* findFaultFromCellIndexAndCellFace( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const override;
void setKIntervalFilter( bool enabled, std::string kIntervalStr ) override;

private:
cvf::cref<RigMainGrid> m_mainGrid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ void RivExtrudedCurveIntersectionGeometryGenerator::calculateArrays( cvf::UByteA
sectionBBox.cutBelow( bottomDepth );
sectionBBox.cutAbove( topDepth );

std::vector<size_t> columnCellCandidates;
m_hexGrid->findIntersectingCells( sectionBBox, &columnCellCandidates );
std::vector<size_t> columnCellCandidates = m_hexGrid->findIntersectingCells( sectionBBox );

cvf::Plane plane;
plane.setFromPoints( p1, p2, p2 + maxHeightVec );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ cvf::BoundingBox RivFemIntersectionGrid::boundingBox() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivFemIntersectionGrid::findIntersectingCells( const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells ) const
std::vector<size_t> RivFemIntersectionGrid::findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const
{
// For FEM models the term element is used instead of cell.
// Each FEM part has a local element index which is transformed into global index for a FEM part collection.
std::vector<size_t> intersectedGlobalElementIndices;
m_femParts->findIntersectingGlobalElementIndices( intersectingBB, &intersectedGlobalElementIndices );

*intersectedCells = intersectedGlobalElementIndices;
return m_femParts->findIntersectingGlobalElementIndices( intersectingBB );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class RivFemIntersectionGrid : public RivIntersectionHexGridInterface
public:
explicit RivFemIntersectionGrid( const RigFemPartCollection* femParts, const RimGeoMechPartCollection* parts );

cvf::Vec3d displayOffset() const override;
cvf::BoundingBox boundingBox() const override;
void findIntersectingCells( const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells ) const override;
bool useCell( size_t cellIndex ) const override;
void cellCornerVertices( size_t cellIndex, cvf::Vec3d cellCorners[8] ) const override;
void cellCornerIndices( size_t cellIndex, size_t cornerIndices[8] ) const override;
const RigFault* findFaultFromCellIndexAndCellFace( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const override;
void setKIntervalFilter( bool enabled, std::string kIntervalStr ) override;
cvf::Vec3d displayOffset() const override;
cvf::BoundingBox boundingBox() const override;
std::vector<size_t> findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const override;
bool useCell( size_t cellIndex ) const override;
void cellCornerVertices( size_t cellIndex, cvf::Vec3d cellCorners[8] ) const override;
void cellCornerIndices( size_t cellIndex, size_t cornerIndices[8] ) const override;
const RigFault* findFaultFromCellIndexAndCellFace( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const override;
void setKIntervalFilter( bool enabled, std::string kIntervalStr ) override;

private:
cvf::cref<RigFemPartCollection> m_femParts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class RigFault;
class RivIntersectionHexGridInterface : public cvf::Object
{
public:
virtual cvf::Vec3d displayOffset() const = 0;
virtual cvf::BoundingBox boundingBox() const = 0;
virtual void findIntersectingCells( const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells ) const = 0;
virtual bool useCell( size_t cellIndex ) const = 0;
virtual void cellCornerVertices( size_t cellIndex, cvf::Vec3d cellCorners[8] ) const = 0;
virtual void cellCornerIndices( size_t cellIndex, size_t cornerIndices[8] ) const = 0;
virtual cvf::Vec3d displayOffset() const = 0;
virtual cvf::BoundingBox boundingBox() const = 0;
virtual std::vector<size_t> findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const = 0;
virtual bool useCell( size_t cellIndex ) const = 0;
virtual void cellCornerVertices( size_t cellIndex, cvf::Vec3d cellCorners[8] ) const = 0;
virtual void cellCornerIndices( size_t cellIndex, size_t cornerIndices[8] ) const = 0;
virtual const RigFault* findFaultFromCellIndexAndCellFace( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const = 0;
virtual void setKIntervalFilter( bool enabled, std::string kIntervalStr ) = 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,7 @@ cvf::ref<cvf::Part> RivWellFracturePartMgr::createContainmentMaskPart( const Rim
frBBox.add( pvd );
}

std::vector<size_t> cellCandidates;
activeView.mainGrid()->findIntersectingCells( frBBox, &cellCandidates );
std::vector<size_t> cellCandidates = activeView.mainGrid()->findIntersectingCells( frBBox );

auto displCoordTrans = activeView.displayCoordTransform();

Expand Down Expand Up @@ -780,8 +779,7 @@ cvf::ref<cvf::Part> RivWellFracturePartMgr::createMaskOfFractureOutsideGrid( con

std::vector<std::vector<cvf::Vec3d>> clippedPolygons;

std::vector<size_t> cellCandidates;
activeView.mainGrid()->findIntersectingCells( frBBox, &cellCandidates );
std::vector<size_t> cellCandidates = activeView.mainGrid()->findIntersectingCells( frBBox );
if ( cellCandidates.empty() )
{
clippedPolygons.push_back( borderOfFractureCellPolygonLocalCsd );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ void RivSurfaceIntersectionGeometryGenerator::calculateArrays()

// Ensure AABB search tree is constructed outside parallel loop
{
std::vector<size_t> triIntersectedCellCandidates;
m_hexGrid->findIntersectingCells( cvf::BoundingBox(), &triIntersectedCellCandidates );
std::vector<size_t> triIntersectedCellCandidates = m_hexGrid->findIntersectingCells( cvf::BoundingBox() );
}

#pragma omp parallel num_threads( 6 ) // More threads have nearly no effect
Expand Down Expand Up @@ -193,8 +192,7 @@ void RivSurfaceIntersectionGeometryGenerator::calculateArrays()

cvf::Vec3d maxHeightVec;

std::vector<size_t> triIntersectedCellCandidates;
m_hexGrid->findIntersectingCells( triangleBBox, &triIntersectedCellCandidates );
std::vector<size_t> triIntersectedCellCandidates = m_hexGrid->findIntersectingCells( triangleBBox );

cvf::Plane plane;
plane.setFromPoints( p0, p1, p2 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,7 @@ int RimPolygonFilter::findEclipseKLayer( const std::vector<cvf::Vec3d>& points,
rayBBox.add( lowestPoint );

// Find the cells intersecting the ray
std::vector<size_t> allCellIndices;
mainGrid->findIntersectingCells( rayBBox, &allCellIndices );
std::vector<size_t> allCellIndices = mainGrid->findIntersectingCells( rayBBox );

// Get the minimum K layer index
int minK = std::numeric_limits<int>::max();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,10 @@ void RimFracture::setStimPlanTimeIndexToPlot( int timeIndex )
//--------------------------------------------------------------------------------------------------
std::vector<size_t> RimFracture::getPotentiallyFracturedCells( const RigMainGrid* mainGrid ) const
{
std::vector<size_t> cellindecies;
if ( !mainGrid ) return cellindecies;
if ( !mainGrid ) return {};

cvf::BoundingBox fractureBBox = boundingBoxInDomainCoords();

mainGrid->findIntersectingCells( fractureBBox, &cellindecies );

return cellindecies;
return mainGrid->findIntersectingCells( fractureBBox );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,7 @@ RimGridView* RimGeoMechContourMapProjection::baseView() const
//--------------------------------------------------------------------------------------------------
std::vector<size_t> RimGeoMechContourMapProjection::findIntersectingCells( const cvf::BoundingBox& bbox ) const
{
std::vector<size_t> allCellIndices;
m_femPart->findIntersectingElementsWithExistingSearchTree( bbox, &allCellIndices );
return allCellIndices;
return m_femPart->findIntersectingElementsWithExistingSearchTree( bbox );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void RimGeoMechFaultReactivationResult::createWellLogCurves()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogExtractionCurve* RimGeoMechFaultReactivationResult::createWellLogExtractionCurveAndAddToTrack( RimWellLogTrack* track,
RimWellLogExtractionCurve* RimGeoMechFaultReactivationResult::createWellLogExtractionCurveAndAddToTrack( RimWellLogTrack* track,
const RigFemResultAddress& resultAddress,
RimModeledWellPath* wellPath,
int partId )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,7 @@ RimGridView* RimEclipseContourMapProjection::baseView() const
//--------------------------------------------------------------------------------------------------
std::vector<size_t> RimEclipseContourMapProjection::findIntersectingCells( const cvf::BoundingBox& bbox ) const
{
std::vector<size_t> allCellIndices;
m_mainGrid->findIntersectingCells( bbox, &allCellIndices );
return allCellIndices;
return m_mainGrid->findIntersectingCells( bbox );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ int RimWellIADataAccess::elementIndex( cvf::Vec3d position )

auto part = m_caseData->femParts()->part( 0 );

std::vector<size_t> closeElements;
part->findIntersectingElementIndices( bb, &closeElements );
std::vector<size_t> closeElements = part->findIntersectingElementIndices( bb );
if ( closeElements.empty() ) return -1;

for ( auto elmIdx : closeElements )
Expand Down
Loading

0 comments on commit ee8988a

Please sign in to comment.