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 2eb5ff1
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,21 @@ 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 );
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 +195,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 @@ -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;
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 @@ -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 @@ -343,18 +343,16 @@ void RigEclipseToStimPlanCellTransmissibilityCalculator::calculateStimPlanCellsM
std::vector<size_t>
RigEclipseToStimPlanCellTransmissibilityCalculator::getPotentiallyFracturedCellsForPolygon( const std::vector<cvf::Vec3d>& polygon ) const
{
std::vector<size_t> cellIndices;

const RigMainGrid* mainGrid = m_case->eclipseCaseData()->mainGrid();
if ( !mainGrid ) return cellIndices;
if ( !mainGrid ) return {};

cvf::BoundingBox polygonBBox;
for ( const cvf::Vec3d& nodeCoord : polygon )
{
polygonBBox.add( nodeCoord );
}

mainGrid->findIntersectingCells( polygonBBox, &cellIndices );
std::vector<size_t> cellIndices = mainGrid->findIntersectingCells( polygonBBox );

std::vector<size_t> cellIndicesToLeafCells;
for ( const size_t& index : cellIndices )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,8 @@ RigCaseToCaseRangeFilterMapper::CellMatchType RigCaseToCaseRangeFilterMapper::fi
for ( int i = 0; i < 8; ++i )
elmBBox.add( elmCorners[i] );

std::vector<size_t> closeCells;
masterEclGrid->findIntersectingCells( elmBBox,
&closeCells ); // This might actually miss the exact one, but we have no other
// alternative yet.
// This might actually miss the exact one, but we have no other alternative yet.
std::vector<size_t> closeCells = masterEclGrid->findIntersectingCells( elmBBox );

size_t globCellIdxToBestMatch = cvf::UNDEFINED_SIZE_T;
double sqDistToClosestCellCenter = HUGE_VAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ void RigCellFaceGeometryTools::extractConnectionsForFace( const RigFault::FaultF
bb.add( mainGridNodes[sourceFaceIndices[2]] );
bb.add( mainGridNodes[sourceFaceIndices[3]] );

std::vector<size_t> closeCells;
mainGrid->findIntersectingCells( bb, &closeCells );
std::vector<size_t> closeCells = mainGrid->findIntersectingCells( bb );

cvf::StructGridInterface::FaceType candidateFace = cvf::StructGridInterface::oppositeFace( sourceCellFace );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ void RigEclipseWellLogExtractor::curveData( const RigResultAccessor* resultAcces
//--------------------------------------------------------------------------------------------------
std::vector<size_t> RigEclipseWellLogExtractor::findCloseCellIndices( const cvf::BoundingBox& bb )
{
std::vector<size_t> closeCells;
m_caseData->mainGrid()->findIntersectingCells( bb, &closeCells );
return closeCells;
return m_caseData->mainGrid()->findIntersectingCells( bb );
}

//--------------------------------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ size_t RigMainGrid::findReservoirCellIndexFromPoint( const cvf::Vec3d& point ) c
cvf::BoundingBox pointBBox;
pointBBox.add( point );

std::vector<size_t> cellIndices;
m_mainGrid->findIntersectingCells( pointBBox, &cellIndices );
std::vector<size_t> cellIndices = m_mainGrid->findIntersectingCells( pointBBox );

cvf::Vec3d hexCorners[8];
for ( size_t cellIndex : cellIndices )
Expand Down Expand Up @@ -781,11 +780,12 @@ const RigFault* RigMainGrid::findFaultFromCellIndexAndCellFace( size_t reservoir
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigMainGrid::findIntersectingCells( const cvf::BoundingBox& inputBB, std::vector<size_t>* cellIndices ) const
std::vector<size_t> RigMainGrid::findIntersectingCells( const cvf::BoundingBox& inputBB ) const
{
CVF_ASSERT( m_cellSearchTree.notNull() );

m_cellSearchTree->findIntersections( inputBB, cellIndices );
std::vector<size_t> cellIndices;
m_cellSearchTree->findIntersections( inputBB, &cellIndices );
return cellIndices;
}

//--------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions ApplicationLibCode/ReservoirDataModel/RigMainGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class RigMainGrid : public RigGridBase
cvf::Vec3d displayModelOffset() const override;
void setDisplayModelOffset( cvf::Vec3d offset );

void setFlipAxis( bool flipXAxis, bool flipYAxis );
void findIntersectingCells( const cvf::BoundingBox& inputBB, std::vector<size_t>* cellIndices ) const;
void setFlipAxis( bool flipXAxis, bool flipYAxis );
std::vector<size_t> findIntersectingCells( const cvf::BoundingBox& inputBB ) const;

cvf::BoundingBox boundingBox() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ cvf::Vec3d RigStimPlanModelTools::calculateTSTDirection( RigEclipseCaseData* ecl

// Find upper face of cells close to the anchor point
cvf::BoundingBox boundingBox( anchorPosition - boundingBoxSize, anchorPosition + boundingBoxSize );
std::vector<size_t> closeCells;
mainGrid->findIntersectingCells( boundingBox, &closeCells );
std::vector<size_t> closeCells = mainGrid->findIntersectingCells( boundingBox );

// The stratigraphic thickness is the averge of normals of the top face
cvf::Vec3d direction = cvf::Vec3d::ZERO;
Expand Down

0 comments on commit 2eb5ff1

Please sign in to comment.