ContourMapProjection: Replace references with naked pointers

Replace reference members and constructor parameters with raw pointers in
RigContourMapProjection and subclasses. Remove cvf::ref usage in
RigEclipseContourMapProjection. Add updateRealizationData() to allow
swapping active cell info and result data per realization without
rebuilding the grid mapping.
This commit is contained in:
Magne Sjaastad
2026-03-19 15:10:43 +01:00
parent ca2a4dcc2c
commit 831751a903
11 changed files with 71 additions and 60 deletions
@@ -249,7 +249,7 @@ void RimEclipseContourMapProjection::updateGridInformation()
cvf::BoundingBox gridBoundingBox = eclipseCase->activeCellsBoundingBox();
m_contourMapGrid = std::make_unique<RigContourMapGrid>( gridBoundingBox, sampleSpacing() );
m_contourMapProjection = std::make_unique<RigEclipseContourMapProjection>( *m_contourMapGrid, *eclipseCaseData, *resultData );
m_contourMapProjection = std::make_unique<RigEclipseContourMapProjection>( m_contourMapGrid.get(), eclipseCaseData, resultData );
}
//--------------------------------------------------------------------------------------------------
@@ -207,7 +207,7 @@ void RimStatisticsContourMapProjection::updateGridInformation()
contourMap->ensureResultsComputed();
m_contourMapGrid = std::make_unique<RigContourMapGrid>( *contourMap->contourMapGrid() );
m_contourMapProjection = std::make_unique<RigStatisticsContourMapProjection>( *m_contourMapGrid );
m_contourMapProjection = std::make_unique<RigStatisticsContourMapProjection>( m_contourMapGrid.get() );
}
//--------------------------------------------------------------------------------------------------
@@ -237,8 +237,8 @@ void RimGeoMechContourMapProjection::updateGridInformation()
expandedBoundingBox = cvf::BoundingBox( minExpandedPoint, maxExpandedPoint );
m_contourMapGrid = std::make_unique<RigContourMapGrid>( gridBoundingBox, expandedBoundingBox, sampleSpacing() );
m_contourMapProjection = std::make_unique<RigGeoMechContourMapProjection>( *geoMechCase->geoMechData(),
*m_contourMapGrid,
m_contourMapProjection = std::make_unique<RigGeoMechContourMapProjection>( geoMechCase->geoMechData(),
m_contourMapGrid.get(),
m_limitToPorePressureRegions,
m_paddingAroundPorePressureRegion );
}
@@ -34,7 +34,7 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigContourMapProjection::RigContourMapProjection( const RigContourMapGrid& contourMapGrid )
RigContourMapProjection::RigContourMapProjection( const RigContourMapGrid* contourMapGrid )
: m_contourMapGrid( contourMapGrid )
, m_currentResultTimestep( -1 )
{
@@ -50,7 +50,7 @@ std::vector<std::vector<std::pair<size_t, double>>>
const std::vector<std::vector<cvf::Vec3d>>& limitToPolygons )
{
m_projected3dGridIndices =
RigContourMapCalculator::generateGridMapping( *this, m_contourMapGrid, resultAggregation, weights, kLayers, limitToPolygons );
RigContourMapCalculator::generateGridMapping( *this, *m_contourMapGrid, resultAggregation, weights, kLayers, limitToPolygons );
return m_projected3dGridIndices;
}
@@ -100,7 +100,7 @@ double RigContourMapProjection::sumAllValues() const
//--------------------------------------------------------------------------------------------------
cvf::Vec2ui RigContourMapProjection::numberOfElementsIJ() const
{
return m_contourMapGrid.numberOfElementsIJ();
return m_contourMapGrid->numberOfElementsIJ();
}
//--------------------------------------------------------------------------------------------------
@@ -108,7 +108,7 @@ cvf::Vec2ui RigContourMapProjection::numberOfElementsIJ() const
//--------------------------------------------------------------------------------------------------
cvf::Vec2ui RigContourMapProjection::numberOfVerticesIJ() const
{
return m_contourMapGrid.numberOfVerticesIJ();
return m_contourMapGrid->numberOfVerticesIJ();
}
//--------------------------------------------------------------------------------------------------
@@ -116,7 +116,7 @@ cvf::Vec2ui RigContourMapProjection::numberOfVerticesIJ() const
//--------------------------------------------------------------------------------------------------
size_t RigContourMapProjection::vertexIndex( unsigned int i, unsigned int j ) const
{
return m_contourMapGrid.vertexIndexFromIJ( i, j );
return m_contourMapGrid->vertexIndexFromIJ( i, j );
}
//--------------------------------------------------------------------------------------------------
@@ -124,7 +124,7 @@ size_t RigContourMapProjection::vertexIndex( unsigned int i, unsigned int j ) co
//--------------------------------------------------------------------------------------------------
double RigContourMapProjection::valueAtVertex( unsigned int i, unsigned int j ) const
{
size_t index = m_contourMapGrid.vertexIndexFromIJ( i, j );
size_t index = m_contourMapGrid->vertexIndexFromIJ( i, j );
if ( index < numberOfVertices() )
{
return m_aggregatedVertexResults.at( index );
@@ -137,7 +137,7 @@ double RigContourMapProjection::valueAtVertex( unsigned int i, unsigned int j )
//--------------------------------------------------------------------------------------------------
unsigned int RigContourMapProjection::numberOfCells() const
{
return m_contourMapGrid.numberOfCells();
return m_contourMapGrid->numberOfCells();
}
//--------------------------------------------------------------------------------------------------
@@ -148,7 +148,7 @@ unsigned int RigContourMapProjection::numberOfValidCells() const
unsigned int validCount = 0u;
for ( unsigned int i = 0; i < numberOfCells(); ++i )
{
cvf::Vec2ui ij = m_contourMapGrid.ijFromCellIndex( i );
cvf::Vec2ui ij = m_contourMapGrid->ijFromCellIndex( i );
if ( hasResultInCell( ij.x(), ij.y() ) )
{
validCount++;
@@ -174,7 +174,7 @@ bool RigContourMapProjection::checkForMapIntersection( const cvf::Vec3d& domainP
CVF_TIGHT_ASSERT( contourMapPoint );
CVF_TIGHT_ASSERT( valueAtPoint );
const cvf::Vec3d& minPoint = m_contourMapGrid.expandedBoundingBox().min();
const cvf::Vec3d& minPoint = m_contourMapGrid->expandedBoundingBox().min();
cvf::Vec3d mapPos3d = domainPoint3d - minPoint;
cvf::Vec2d mapPos2d( mapPos3d.x(), mapPos3d.y() );
cvf::Vec2d gridorigin( minPoint.x(), minPoint.y() );
@@ -195,7 +195,7 @@ bool RigContourMapProjection::checkForMapIntersection( const cvf::Vec3d& domainP
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RigContourMapProjection::origin3d() const
{
return m_contourMapGrid.expandedBoundingBox().min();
return m_contourMapGrid->expandedBoundingBox().min();
}
//--------------------------------------------------------------------------------------------------
@@ -203,7 +203,7 @@ cvf::Vec3d RigContourMapProjection::origin3d() const
//--------------------------------------------------------------------------------------------------
double RigContourMapProjection::topDepthBoundingBox() const
{
return m_contourMapGrid.expandedBoundingBox().max().z();
return m_contourMapGrid->expandedBoundingBox().max().z();
}
//--------------------------------------------------------------------------------------------------
@@ -273,7 +273,7 @@ void RigContourMapProjection::generateVertexResults()
#pragma omp parallel for
for ( int index = 0; index < static_cast<int>( nVertices ); ++index )
{
cvf::Vec2ui ij = m_contourMapGrid.ijFromVertexIndex( index );
cvf::Vec2ui ij = m_contourMapGrid->ijFromVertexIndex( index );
m_aggregatedVertexResults[index] = calculateValueAtVertex( ij.x(), ij.y() );
}
}
@@ -316,10 +316,10 @@ double RigContourMapProjection::sumTriangleAreas( const std::vector<cvf::Vec4d>&
//--------------------------------------------------------------------------------------------------
double RigContourMapProjection::interpolateValue( const cvf::Vec2d& gridPos2d ) const
{
cvf::Vec2ui cellContainingPoint = m_contourMapGrid.ijFromLocalPos( gridPos2d );
cvf::Vec2d cellCenter = m_contourMapGrid.cellCenterPosition( cellContainingPoint.x(), cellContainingPoint.y() );
cvf::Vec2ui cellContainingPoint = m_contourMapGrid->ijFromLocalPos( gridPos2d );
cvf::Vec2d cellCenter = m_contourMapGrid->cellCenterPosition( cellContainingPoint.x(), cellContainingPoint.y() );
double sampleSpacing = m_contourMapGrid.sampleSpacing();
double sampleSpacing = m_contourMapGrid->sampleSpacing();
std::array<cvf::Vec3d, 4> x;
x[0] = cvf::Vec3d( cellCenter + cvf::Vec2d( -sampleSpacing * 0.5, -sampleSpacing * 0.5 ), 0.0 );
x[1] = cvf::Vec3d( cellCenter + cvf::Vec2d( sampleSpacing * 0.5, -sampleSpacing * 0.5 ), 0.0 );
@@ -370,7 +370,7 @@ double RigContourMapProjection::interpolateValue( const cvf::Vec2d& gridPos2d )
//--------------------------------------------------------------------------------------------------
double RigContourMapProjection::valueInCell( unsigned int i, unsigned int j ) const
{
size_t index = m_contourMapGrid.cellIndexFromIJ( i, j );
size_t index = m_contourMapGrid->cellIndexFromIJ( i, j );
if ( index < numberOfCells() )
{
return m_aggregatedResults.at( index );
@@ -396,8 +396,8 @@ double RigContourMapProjection::calculateValueAtVertex( unsigned int vi, unsigne
if ( vi > 0u ) averageIs.push_back( vi - 1 );
if ( vj > 0u ) averageJs.push_back( vj - 1 );
if ( vi < m_contourMapGrid.mapSize().x() ) averageIs.push_back( vi );
if ( vj < m_contourMapGrid.mapSize().y() ) averageJs.push_back( vj );
if ( vi < m_contourMapGrid->mapSize().x() ) averageIs.push_back( vi );
if ( vj < m_contourMapGrid->mapSize().y() ) averageJs.push_back( vj );
RiaWeightedMeanCalculator<double> calc;
for ( unsigned int j : averageJs )
@@ -445,7 +445,7 @@ bool RigContourMapProjection::contourMapCellContainsOnlyInactiveCells( unsigned
//--------------------------------------------------------------------------------------------------
std::vector<std::pair<size_t, double>> RigContourMapProjection::cellsAtIJ( unsigned int i, unsigned int j ) const
{
size_t cellIndex = m_contourMapGrid.cellIndexFromIJ( i, j );
size_t cellIndex = m_contourMapGrid->cellIndexFromIJ( i, j );
if ( cellIndex < m_projected3dGridIndices.size() )
{
return m_projected3dGridIndices[cellIndex];
@@ -458,7 +458,7 @@ std::vector<std::pair<size_t, double>> RigContourMapProjection::cellsAtIJ( unsig
//--------------------------------------------------------------------------------------------------
std::vector<double> RigContourMapProjection::xVertexPositions() const
{
return m_contourMapGrid.xVertexPositions();
return m_contourMapGrid->xVertexPositions();
}
//--------------------------------------------------------------------------------------------------
@@ -466,7 +466,7 @@ std::vector<double> RigContourMapProjection::xVertexPositions() const
//--------------------------------------------------------------------------------------------------
std::vector<double> RigContourMapProjection::yVertexPositions() const
{
return m_contourMapGrid.yVertexPositions();
return m_contourMapGrid->yVertexPositions();
}
//--------------------------------------------------------------------------------------------------
@@ -42,7 +42,7 @@ class RigContourMapProjection
public:
using CellIndexAndResult = std::pair<size_t, double>;
RigContourMapProjection( const RigContourMapGrid& );
RigContourMapProjection( const RigContourMapGrid* );
void clearResults();
void clearGridMapping();
@@ -130,5 +130,5 @@ protected:
std::optional<std::pair<double, double>> m_valueFilter;
const RigContourMapGrid& m_contourMapGrid;
const RigContourMapGrid* m_contourMapGrid;
};
@@ -38,17 +38,17 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigEclipseContourMapProjection::RigEclipseContourMapProjection( const RigContourMapGrid& contourMapGrid,
RigEclipseCaseData& eclipseCaseData,
RigCaseCellResultsData& resultData )
RigEclipseContourMapProjection::RigEclipseContourMapProjection( const RigContourMapGrid* contourMapGrid,
RigEclipseCaseData* eclipseCaseData,
RigCaseCellResultsData* resultData )
: RigContourMapProjection( contourMapGrid )
, m_eclipseCaseData( eclipseCaseData )
, m_resultData( resultData )
, m_kLayers( 0u )
, m_useActiveCellInfo( true )
{
m_mainGrid = m_eclipseCaseData.mainGrid();
m_activeCellInfo = m_eclipseCaseData.activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL );
m_mainGrid = m_eclipseCaseData->mainGrid();
m_activeCellInfo = m_eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL );
m_kLayers = m_mainGrid->cellCountK();
}
@@ -59,6 +59,15 @@ RigEclipseContourMapProjection::~RigEclipseContourMapProjection()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigEclipseContourMapProjection::updateRealizationData( RigActiveCellInfo* activeCellInfo, RigCaseCellResultsData* resultData )
{
m_activeCellInfo = activeCellInfo;
m_resultData = resultData;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -68,7 +77,7 @@ void RigEclipseContourMapProjection::generateAndSaveResults( const RigEclipseRes
RigFloodingSettings& floodingSettings )
{
std::tie( m_useActiveCellInfo, m_aggregatedResults ) =
generateResults( *this, m_contourMapGrid, m_resultData, resultAddress, resultAggregation, timeStep, floodingSettings );
generateResults( *this, *m_contourMapGrid, *m_resultData, resultAddress, resultAggregation, timeStep, floodingSettings );
}
//--------------------------------------------------------------------------------------------------
@@ -80,7 +89,7 @@ std::vector<double> RigEclipseContourMapProjection::generateResults( const RigEc
RigFloodingSettings& floodingSettings ) const
{
std::pair<bool, std::vector<double>> result =
generateResults( *this, m_contourMapGrid, m_resultData, resultAddress, resultAggregation, timeStep, floodingSettings );
generateResults( *this, *m_contourMapGrid, *m_resultData, resultAddress, resultAggregation, timeStep, floodingSettings );
return result.second;
}
@@ -327,7 +336,7 @@ size_t RigEclipseContourMapProjection::gridResultIndex( size_t globalCellIdx ) c
//--------------------------------------------------------------------------------------------------
bool RigEclipseContourMapProjection::isCellActive( size_t globalCellIdx ) const
{
if ( m_useActiveCellInfo && m_activeCellInfo.notNull() )
if ( m_useActiveCellInfo && m_activeCellInfo != nullptr )
{
return m_activeCellInfo->isActive( globalCellIdx );
}
@@ -41,9 +41,9 @@ class RigCaseCellResultsData;
class RigEclipseContourMapProjection : public RigContourMapProjection
{
public:
RigEclipseContourMapProjection( const RigContourMapGrid& contourMapGrid,
RigEclipseCaseData& eclipseCaseData,
RigCaseCellResultsData& resultData );
RigEclipseContourMapProjection( const RigContourMapGrid* contourMapGrid,
RigEclipseCaseData* eclipseCaseData,
RigCaseCellResultsData* resultData );
virtual ~RigEclipseContourMapProjection();
void generateAndSaveResults( const RigEclipseResultAddress& resultAddress,
@@ -64,6 +64,8 @@ public:
int timeStep,
RigFloodingSettings& floodingSettings );
void updateRealizationData( RigActiveCellInfo* activeCellInfo, RigCaseCellResultsData* resultData );
std::vector<bool> getMapCellVisibility( int viewStepIndex, RigContourMapCalculator::ResultAggregationType resultAggregation ) override;
bool isCellActive( size_t globalCellIdx ) const override;
@@ -87,10 +89,10 @@ protected:
RigFloodingSettings& floodingSettings );
protected:
RigEclipseCaseData& m_eclipseCaseData;
RigCaseCellResultsData& m_resultData;
cvf::ref<RigMainGrid> m_mainGrid;
cvf::ref<RigActiveCellInfo> m_activeCellInfo;
size_t m_kLayers;
bool m_useActiveCellInfo;
RigEclipseCaseData* m_eclipseCaseData;
RigCaseCellResultsData* m_resultData;
RigMainGrid* m_mainGrid;
RigActiveCellInfo* m_activeCellInfo;
size_t m_kLayers;
bool m_useActiveCellInfo;
};
@@ -42,8 +42,8 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigGeoMechContourMapProjection::RigGeoMechContourMapProjection( RigGeoMechCaseData& caseData,
const RigContourMapGrid& contourMapGrid,
RigGeoMechContourMapProjection::RigGeoMechContourMapProjection( RigGeoMechCaseData* caseData,
const RigContourMapGrid* contourMapGrid,
bool limitToPorePressureRegions,
double paddingAroundPorePressureRegion )
: RigContourMapProjection( contourMapGrid )
@@ -52,7 +52,7 @@ RigGeoMechContourMapProjection::RigGeoMechContourMapProjection( RigGeoMechCaseDa
, m_paddingAroundPorePressureRegion( paddingAroundPorePressureRegion )
, m_kLayers( 0u )
{
m_femPart = m_caseData.femParts()->part( 0 );
m_femPart = m_caseData->femParts()->part( 0 );
m_femPartGrid = m_femPart->getOrCreateStructGrid();
m_kLayers = m_femPartGrid->cellCountK();
m_femPart->ensureIntersectionSearchTreeIsBuilt();
@@ -143,11 +143,11 @@ std::vector<bool> RigGeoMechContourMapProjection::getMapCellVisibility( RigFemRe
cvf::BoundingBox validResBoundingBox;
for ( size_t cellIndex = 0; cellIndex < cellResults.size(); ++cellIndex )
{
cvf::Vec2ui ij = m_contourMapGrid.ijFromCellIndex( cellIndex );
cvf::Vec2ui ij = m_contourMapGrid->ijFromCellIndex( cellIndex );
if ( cellResults[cellIndex] != std::numeric_limits<double>::infinity() )
{
distanceImage[ij.x()][ij.y()] = 1u;
validResBoundingBox.add( cvf::Vec3d( m_contourMapGrid.cellCenterPosition( ij.x(), ij.y() ), 0.0 ) );
validResBoundingBox.add( cvf::Vec3d( m_contourMapGrid->cellCenterPosition( ij.x(), ij.y() ), 0.0 ) );
}
else
{
@@ -162,12 +162,12 @@ std::vector<bool> RigGeoMechContourMapProjection::getMapCellVisibility( RigFemRe
cvf::Vec3d porExtent = validResBoundingBox.extent();
double radius = std::max( porExtent.x(), porExtent.y() ) * 0.25;
double expansion = m_paddingAroundPorePressureRegion * radius;
size_t cellPadding = std::ceil( expansion / m_contourMapGrid.sampleSpacing() );
size_t cellPadding = std::ceil( expansion / m_contourMapGrid->sampleSpacing() );
for ( size_t cellIndex = 0; cellIndex < cellResults.size(); ++cellIndex )
{
if ( !mapCellVisibility[cellIndex] )
{
cvf::Vec2ui ij = m_contourMapGrid.ijFromCellIndex( cellIndex );
cvf::Vec2ui ij = m_contourMapGrid->ijFromCellIndex( cellIndex );
if ( distanceImage[ij.x()][ij.y()] < cellPadding * cellPadding )
{
mapCellVisibility[cellIndex] = true;
@@ -198,11 +198,11 @@ std::vector<double> RigGeoMechContourMapProjection::generateResultsFromAddress(
RigContourMapCalculator::ResultAggregationType resultAggregation,
int viewerStepIndex ) const
{
RigFemPartResultsCollection* resultCollection = m_caseData.femPartResults();
RigFemPartResultsCollection* resultCollection = m_caseData->femPartResults();
size_t nCells = numberOfCells();
std::vector<double> aggregatedResults = std::vector<double>( nCells, std::numeric_limits<double>::infinity() );
auto [stepIdx, frameIdx] = m_caseData.femPartResults()->stepListIndexToTimeStepAndDataFrameIndex( viewerStepIndex );
auto [stepIdx, frameIdx] = m_caseData->femPartResults()->stepListIndexToTimeStepAndDataFrameIndex( viewerStepIndex );
bool wasInvalid = false;
if ( !resultAddress.isValid() )
@@ -247,7 +247,7 @@ std::vector<double> RigGeoMechContourMapProjection::generateResultsFromAddress(
{
if ( mapCellVisibility.empty() || mapCellVisibility[index] )
{
cvf::Vec2ui ij = m_contourMapGrid.ijFromCellIndex( index );
cvf::Vec2ui ij = m_contourMapGrid->ijFromCellIndex( index );
aggregatedResults[index] = calculateValueInMapCell( ij.x(), ij.y(), resultValues, resultAggregation );
}
}
@@ -34,8 +34,8 @@ class RigGeoMechCaseData;
class RigGeoMechContourMapProjection : public RigContourMapProjection
{
public:
RigGeoMechContourMapProjection( RigGeoMechCaseData& caseData,
const RigContourMapGrid&,
RigGeoMechContourMapProjection( RigGeoMechCaseData* caseData,
const RigContourMapGrid*,
bool limitToPorePressureRegions,
double paddingAroundPorePressureRegion );
@@ -73,7 +73,7 @@ protected:
std::vector<double> gridCellValues( RigFemResultAddress resAddr, std::vector<float>& resultValues ) const;
protected:
RigGeoMechCaseData& m_caseData;
RigGeoMechCaseData* m_caseData;
bool m_limitToPorePressureRegions;
double m_paddingAroundPorePressureRegion;
cvf::ref<RigFemPart> m_femPart;
@@ -29,7 +29,7 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigStatisticsContourMapProjection::RigStatisticsContourMapProjection( const RigContourMapGrid& contourMapGrid )
RigStatisticsContourMapProjection::RigStatisticsContourMapProjection( const RigContourMapGrid* contourMapGrid )
: RigContourMapProjection( contourMapGrid )
{
}
@@ -130,7 +130,7 @@ std::vector<bool> RigStatisticsContourMapProjection::getMapCellVisibility( int v
//--------------------------------------------------------------------------------------------------
std::vector<std::pair<size_t, double>> RigStatisticsContourMapProjection::cellsAtIJ( unsigned int i, unsigned int j ) const
{
size_t cellIndex = m_contourMapGrid.cellIndexFromIJ( i, j );
size_t cellIndex = m_contourMapGrid->cellIndexFromIJ( i, j );
if ( cellIndex < m_aggregatedResults.size() && !std::isinf( m_aggregatedResults[cellIndex] ) &&
!std::isnan( m_aggregatedResults[cellIndex] ) )
{
@@ -32,7 +32,7 @@ class RigContourMapGrid;
class RigStatisticsContourMapProjection : public RigContourMapProjection
{
public:
RigStatisticsContourMapProjection( const RigContourMapGrid& contourMapGrid );
RigStatisticsContourMapProjection( const RigContourMapGrid* contourMapGrid );
virtual ~RigStatisticsContourMapProjection();
std::vector<std::pair<size_t, double>> cellsAtIJ( unsigned int i, unsigned int j ) const override;