Skip to content

Commit

Permalink
Working cell visibility filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Nov 4, 2024
1 parent d52ff27 commit db8d0e9
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RimGeoMechContourMapProjection.h"

#include "RiaImageTools.h"

#include "RigContourMapCalculator.h"
#include "RigContourMapGrid.h"
#include "RigContourMapProjection.h"
Expand Down Expand Up @@ -219,67 +217,6 @@ void RimGeoMechContourMapProjection::updateGridInformation()
m_paddingAroundPorePressureRegion );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<bool> RimGeoMechContourMapProjection::getMapCellVisibility()
{
cvf::Vec2ui nCellsIJ = numberOfElementsIJ();
std::vector<std::vector<unsigned int>> distanceImage( nCellsIJ.x(), std::vector<unsigned int>( nCellsIJ.y(), 0u ) );

std::vector<bool> mapCellVisibility;
RigFemResultAddress resAddr = view()->cellResult()->resultAddress();

if ( m_limitToPorePressureRegions )
{
resAddr = RigFemAddressDefines::elementNodalPorBarAddress();
}

std::vector<double> cellResults = generateResultsFromAddress( resAddr, mapCellVisibility, view()->currentTimeStep() );

mapCellVisibility.resize( numberOfCells(), true );
CVF_ASSERT( mapCellVisibility.size() == cellResults.size() );

{
cvf::BoundingBox validResBoundingBox;
for ( size_t cellIndex = 0; cellIndex < cellResults.size(); ++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 ) );
}
else
{
mapCellVisibility[cellIndex] = false;
}
}

if ( m_limitToPorePressureRegions && m_paddingAroundPorePressureRegion > 0.0 )
{
RiaImageTools::distanceTransform2d( distanceImage );

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 / sampleSpacing() );
for ( size_t cellIndex = 0; cellIndex < cellResults.size(); ++cellIndex )
{
if ( !mapCellVisibility[cellIndex] )
{
cvf::Vec2ui ij = m_contourMapGrid->ijFromCellIndex( cellIndex );
if ( distanceImage[ij.x()][ij.y()] < cellPadding * cellPadding )
{
mapCellVisibility[cellIndex] = true;
}
}
}
}
}
return mapCellVisibility;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class RimGeoMechContourMapProjection : public RimContourMapProjection
using CellIndexAndResult = RimContourMapProjection::CellIndexAndResult;

// GeoMech implementation specific data generation methods
std::vector<bool> getMapCellVisibility() override;
cvf::ref<cvf::UByteArray> getCellVisibility() const override;
cvf::BoundingBox calculateExpandedPorBarBBox( int timeStep, int frameIndex ) const;
void updateGridInformation() override;
Expand Down
15 changes: 2 additions & 13 deletions ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void RimContourMapProjection::generateResultsIfNecessary( int timeStep )
m_contourMapProjection->generateGridMapping( m_resultAggregation() );
}
progress.setProgress( 20 );
m_mapCellVisibility = getMapCellVisibility();
m_mapCellVisibility = m_contourMapProjection->getMapCellVisibility( timeStep, m_resultAggregation() );
progress.setProgress( 30 );
}
else
Expand Down Expand Up @@ -534,20 +534,12 @@ cvf::ref<cvf::UByteArray> RimContourMapProjection::getCellVisibility() const
return baseView()->currentTotalCellVisibility();
}

//--------------------------------------------------------------------------------------------------
/// Empty default implementation
//--------------------------------------------------------------------------------------------------
std::vector<bool> RimContourMapProjection::getMapCellVisibility()
{
return std::vector<bool>( numberOfCells(), true );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimContourMapProjection::mapCellVisibilityNeedsUpdating()
{
std::vector<bool> mapCellVisiblity = getMapCellVisibility();
std::vector<bool> mapCellVisiblity = m_contourMapProjection->getMapCellVisibility( m_currentResultTimestep, m_resultAggregation() );
return !( mapCellVisiblity == m_mapCellVisibility );
}

Expand All @@ -556,9 +548,6 @@ bool RimContourMapProjection::mapCellVisibilityNeedsUpdating()
//--------------------------------------------------------------------------------------------------
void RimContourMapProjection::generateVertexResults()
{
// size_t nCells = numberOfCells();
// if ( nCells != m_aggregatedResults.size() ) return;

m_contourMapProjection->generateVertexResults();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class RimContourMapProjection : public RimCheckableNamedObject

virtual std::pair<double, double> minmaxValuesAllTimeSteps();

virtual std::vector<bool> getMapCellVisibility();
bool mapCellVisibilityNeedsUpdating();
static std::vector<std::vector<std::pair<size_t, double>>> generateGridMapping( RimContourMapProjection& contourMapProjection,
const RigContourMapGrid& contourMapGrid );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include "cafPdmField.h"
#include "cafPdmObject.h"

#include "cvfBoundingBox.h"

class RigActiveCellInfo;
class RigMainGrid;
class RigContourMapGrid;
Expand Down
17 changes: 0 additions & 17 deletions ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,6 @@ cvf::ref<cvf::UByteArray> RigContourMapProjection::getCellVisibility() const
return m_cellGridIdxVisibility;
}

//--------------------------------------------------------------------------------------------------
/// Empty default implementation
//--------------------------------------------------------------------------------------------------
std::vector<bool> RigContourMapProjection::getMapCellVisibility()
{
return std::vector<bool>( numberOfCells(), true );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigContourMapProjection::mapCellVisibilityNeedsUpdating()
{
std::vector<bool> mapCellVisiblity = getMapCellVisibility();
return !( mapCellVisiblity == m_mapCellVisibility );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
11 changes: 2 additions & 9 deletions ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class RigContourMapProjection

std::vector<double> generateVertexResults();

// double sampleSpacingFactor() const;
// void setSampleSpacingFactor( double spacingFactor );

double maxValue() const;
double minValue() const;

Expand Down Expand Up @@ -102,6 +99,8 @@ class RigContourMapProjection
// Cell index and position conversion
std::vector<CellIndexAndResult> cellsAtIJ( uint i, uint j ) const;

virtual std::vector<bool> getMapCellVisibility( int viewStepIndex, RigContourMapCalculator::ResultAggregationEnum resultAggregation ) = 0;

protected:
double calculateValueInMapCell( uint i,
uint j,
Expand All @@ -112,21 +111,15 @@ class RigContourMapProjection
double maxValue( const std::vector<double>& aggregatedResults ) const;
double minValue( const std::vector<double>& aggregatedResults ) const;

virtual std::vector<bool> getMapCellVisibility();
bool mapCellVisibilityNeedsUpdating();
static std::vector<std::vector<std::pair<size_t, double>>> generateGridMapping( RigContourMapProjection& contourMapProjection,
const RigContourMapGrid& contourMapGrid );

// void generateTrianglesWithVertexValues();

static double sumTriangleAreas( const std::vector<cvf::Vec4d>& triangles );

double valueInCell( uint i, uint j ) const;
bool hasResultInCell( uint i, uint j ) const;
double calculateValueAtVertex( uint i, uint j ) const;

// double gridEdgeOffset() const;

protected:
cvf::ref<cvf::UByteArray> m_cellGridIdxVisibility;
std::vector<double> m_aggregatedResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ std::vector<double> RigEclipseContourMapProjection::generateResults( const RigEc
m_useActiveCellInfo = m_resultData.isUsingGlobalActiveIndex( resultAddress );
}

// TODO
auto isTernaryResult = []( const RigEclipseResultAddress& address ) -> bool
{
return address.resultCatType() == RiaDefines::ResultCatType::DYNAMIC_NATIVE &&
Expand Down Expand Up @@ -108,11 +107,6 @@ std::vector<double> RigEclipseContourMapProjection::generateResults( const RigEc
// TODO: this was RimEclipseCellColors->hasStaticResult()
if ( resultAddress.resultCatType() == RiaDefines::ResultCatType::STATIC_NATIVE && timeStep > 0 ) timeStep = 0;

// RigEclipseResultAddress resAddr( cellColors->resultType(),
// cellColors->resultVariable(),
// cellColors->timeLapseBaseTimeStep(),
// cellColors->caseDiffIndex() );

// When loading a project file, grid calculator results are not computed the first time this function is
// called. Must check if result is loaded. See RimReloadCaseTools::updateAll3dViews()
if ( resultAddress.isValid() && m_resultData.hasResultEntry( resultAddress ) && m_resultData.isResultLoaded( resultAddress ) )
Expand Down Expand Up @@ -322,3 +316,13 @@ size_t RigEclipseContourMapProjection::gridResultIndex( size_t globalCellIdx ) c

return globalCellIdx;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<bool> RigEclipseContourMapProjection::getMapCellVisibility( int viewStepIndex,
RigContourMapCalculator::ResultAggregationEnum resultAggregation )

{
return std::vector<bool>( numberOfCells(), true );
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ class RigEclipseContourMapProjection : public RigContourMapProjection
RigEclipseContourMapProjection( const RigContourMapGrid& contourMapGrid,
RigEclipseCaseData& eclipseCaseData,
RigCaseCellResultsData& resultData );
~RigEclipseContourMapProjection();
virtual ~RigEclipseContourMapProjection();

std::vector<double> generateResults( const RigEclipseResultAddress& resultAddress,
RigContourMapCalculator::ResultAggregationEnum resultAggregation,
int timeStep );

std::vector<bool> getMapCellVisibility( int viewStepIndex, RigContourMapCalculator::ResultAggregationEnum resultAggregation ) override;

protected:
using CellIndexAndResult = RigContourMapProjection::CellIndexAndResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,29 @@ cvf::BoundingBox RigGeoMechContourMapProjection::calculateExpandedPorBarBBox( Ri
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<bool> RigGeoMechContourMapProjection::getMapCellVisibility()
std::vector<bool> RigGeoMechContourMapProjection::getMapCellVisibility( int viewStepIndex,
RigContourMapCalculator::ResultAggregationEnum resultAggregation )
{
return getMapCellVisibility( m_currentResultAddr, viewStepIndex, resultAggregation );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<bool> RigGeoMechContourMapProjection::getMapCellVisibility( RigFemResultAddress resAddr,
int viewStepIndex,
RigContourMapCalculator::ResultAggregationEnum resultAggregation )
{
cvf::Vec2ui nCellsIJ = numberOfElementsIJ();
std::vector<std::vector<unsigned int>> distanceImage( nCellsIJ.x(), std::vector<unsigned int>( nCellsIJ.y(), 0u ) );

std::vector<bool> mapCellVisibility;
RigFemResultAddress resAddr = m_currentResultAddr; // view()->cellResult()->resultAddress();
std::vector<bool> mapCellVisibility;

if ( m_limitToPorePressureRegions )
{
resAddr = RigFemAddressDefines::elementNodalPorBarAddress();
}

// TODO: fix timestep: was view()->currentTimeStep() );
int viewStepIndex = 0;

// TODO: get this from somewhere???
RigContourMapCalculator::ResultAggregationEnum resultAggregation = RigContourMapCalculator::ResultAggregationEnum::RESULTS_MEAN_VALUE;

std::vector<double> cellResults = generateResultsFromAddress( resAddr, mapCellVisibility, resultAggregation, viewStepIndex );

mapCellVisibility.resize( numberOfCells(), true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ class RigGeoMechContourMapProjection : public RigContourMapProjection
int frameIndex,
double padding );

std::vector<bool> getMapCellVisibility( int viewStepIndex, RigContourMapCalculator::ResultAggregationEnum resultAggregation ) override;

std::vector<bool> getMapCellVisibility( RigFemResultAddress resAddr,
int viewStepIndex,
RigContourMapCalculator::ResultAggregationEnum resultAggregation );

protected:
using CellIndexAndResult = RigContourMapProjection::CellIndexAndResult;

// GeoMech implementation specific data generation methods
std::vector<bool> getMapCellVisibility() override;
std::vector<double> retrieveParameterWeights() override;
std::vector<size_t> findIntersectingCells( const cvf::BoundingBox& bbox ) const override;
size_t kLayer( size_t globalCellIdx ) const override;
Expand Down

0 comments on commit db8d0e9

Please sign in to comment.