#14345 Add per-case cell filter evaluation with source case override

Add a sourceCaseOverride parameter to RimCellFilter::applyToCellVisibility.
When set, property filters evaluate against the override case's result
values instead of the case the filter is bound to, allowing the same
filter definition to be evaluated against each case in an ensemble.
Combined filters forward the override to their children, and geometry
based filters ignore it.

Add RimCellFilterTools::computeReservoirCellVisibility, which evaluates
a cell filter against a given case for all grids and returns the
visibility indexed by reservoir cell index. Range filters propagate the
parent grid visibility into LGR cells, matching the filtered geometry
of a 3d view.

Also add RimCellFilter::setFilterMode.
This commit is contained in:
Kristian Bendiksen committed 2026-09-16 10:53:31 +02:00
1 parent da28ffe613
commit e9b28c1b02
11 files changed
+377 -16

No files matched your search

@@ -1,6 +1,7 @@
set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimCellFilter.cpp
${CMAKE_CURRENT_LIST_DIR}/RimCellFilterCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimCellFilterTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RimCellRangeFilter.cpp
${CMAKE_CURRENT_LIST_DIR}/RimCombinedFilter.cpp
${CMAKE_CURRENT_LIST_DIR}/RimDataFilterCollection.cpp
@@ -199,6 +199,14 @@ caf::AppEnum<RimCellFilter::FilterModeType> RimCellFilter::filterMode() const
return m_filterMode();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellFilter::setFilterMode( FilterModeType filterMode )
{
m_filterMode = filterMode;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -322,7 +330,10 @@ QList<caf::PdmOptionItemInfo> RimCellFilter::calculateValueOptions( const caf::P
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellFilter::applyToCellVisibility( cvf::UByteArray* cellVisibility, const RigGridBase* grid, size_t /*timeStepIndex*/ )
void RimCellFilter::applyToCellVisibility( cvf::UByteArray* cellVisibility,
const RigGridBase* grid,
size_t /*timeStepIndex*/,
RimEclipseCase* /*sourceCaseOverride*/ )
{
if ( cellVisibility == nullptr || grid == nullptr ) return;
@@ -79,6 +79,7 @@ public:
virtual bool isFilterEnabled() const;
caf::AppEnum<FilterModeType> filterMode() const;
void setFilterMode( FilterModeType filterMode );
QString modeString() const;
bool propagateToSubGrids() const;
@@ -97,7 +98,13 @@ public:
// Unified evaluation: take an incoming per-cell visibility mask and hide the cells that
// this filter rejects (respecting its own INCLUDE/EXCLUDE mode). The default implementation
// bridges the legacy range/index dispatch so existing subclasses do not need to override.
virtual void applyToCellVisibility( cvf::UByteArray* cellVisibility, const RigGridBase* grid, size_t timeStepIndex );
// When sourceCaseOverride is set, property filters evaluate against that case's results instead
// of the case the filter is bound to, allowing the same filter definition to be evaluated
// against each case in an ensemble.
virtual void applyToCellVisibility( cvf::UByteArray* cellVisibility,
const RigGridBase* grid,
size_t timeStepIndex,
RimEclipseCase* sourceCaseOverride = nullptr );
protected:
caf::PdmFieldHandle* userDescriptionField() override;
@@ -0,0 +1,103 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2026 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimCellFilterTools.h"
#include "RigEclipseCaseData.h"
#include "RigGridBase.h"
#include "RigLocalGrid.h"
#include "RigMainGrid.h"
#include "RimCellFilter.h"
#include "RimEclipseCase.h"
//--------------------------------------------------------------------------------------------------
/// Evaluate the filter against the given case for all grids, and return the visibility indexed by
/// reservoir cell index. Property filters are evaluated against the given case's own result values.
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::UByteArray>
RimCellFilterTools::computeReservoirCellVisibility( RimCellFilter* filter, RimEclipseCase* eclipseCase, size_t timeStepIndex )
{
if ( !filter || !eclipseCase || !eclipseCase->eclipseCaseData() || !eclipseCase->eclipseCaseData()->mainGrid() ) return nullptr;
RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData();
cvf::ref<cvf::UByteArray> reservoirVisibility = new cvf::UByteArray( caseData->mainGrid()->totalCellCount() );
reservoirVisibility->setAll( false );
const bool isInclude = ( filter->filterMode() == RimCellFilter::INCLUDE );
// Grid local masks are kept to allow propagation of parent grid visibility into LGRs
std::vector<cvf::ref<cvf::UByteArray>> gridMasks( caseData->gridCount() );
for ( size_t gridIndex = 0; gridIndex < caseData->gridCount(); gridIndex++ )
{
RigGridBase* grid = caseData->grid( gridIndex );
gridMasks[gridIndex] = new cvf::UByteArray( grid->cellCount() );
cvf::UByteArray& gridMask = *gridMasks[gridIndex];
gridMask.setAll( true );
if ( filter->isRangeFilter() )
{
// Range filters evaluate only on their target grid. On other grids an INCLUDE filter
// contributes no cells, while an EXCLUDE filter removes none. Cells in LGRs follow the
// visibility of their parent grid cell, as in the filtered geometry of a 3d view.
const bool isTargetGrid = ( filter->gridIndex() == static_cast<int>( gridIndex ) );
if ( isTargetGrid )
{
filter->applyToCellVisibility( &gridMask, grid, timeStepIndex, eclipseCase );
}
else
{
gridMask.setAll( !isInclude );
}
if ( !grid->isMainGrid() )
{
auto localGrid = static_cast<const RigLocalGrid*>( grid );
const cvf::UByteArray& parentMask = *gridMasks[localGrid->parentGrid()->gridIndex()];
for ( size_t localIdx = 0; localIdx < grid->cellCount(); localIdx++ )
{
const size_t parentCellIndex = grid->cell( localIdx ).parentCellIndex();
if ( isInclude )
{
gridMask[localIdx] = gridMask[localIdx] || parentMask[parentCellIndex];
}
else
{
gridMask[localIdx] = gridMask[localIdx] && parentMask[parentCellIndex];
}
}
}
}
else
{
// Index filters (polygon, user defined) and property filters evaluate on all grids
filter->applyToCellVisibility( &gridMask, grid, timeStepIndex, eclipseCase );
}
for ( size_t localIdx = 0; localIdx < grid->cellCount(); localIdx++ )
{
reservoirVisibility->set( grid->reservoirCellIndex( localIdx ), gridMask[localIdx] );
}
}
return reservoirVisibility;
}
@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2026 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfArray.h"
#include "cvfObject.h"
class RimCellFilter;
class RimEclipseCase;
//==================================================================================================
///
//==================================================================================================
class RimCellFilterTools
{
public:
static cvf::ref<cvf::UByteArray> computeReservoirCellVisibility( RimCellFilter* filter, RimEclipseCase* eclipseCase, size_t timeStepIndex );
};
@@ -104,7 +104,10 @@ void RimCombinedFilter::onGridChanged()
/// INCLUDE/EXCLUDE mode inside applyToCellVisibility), AND/OR combine the masks, then apply this
/// combined filter's INCLUDE/EXCLUDE mode onto the incoming cellVisibility.
//--------------------------------------------------------------------------------------------------
void RimCombinedFilter::applyToCellVisibility( cvf::UByteArray* cellVisibility, const RigGridBase* grid, size_t timeStepIndex )
void RimCombinedFilter::applyToCellVisibility( cvf::UByteArray* cellVisibility,
const RigGridBase* grid,
size_t timeStepIndex,
RimEclipseCase* sourceCaseOverride )
{
if ( cellVisibility == nullptr || grid == nullptr ) return;
@@ -125,7 +128,7 @@ void RimCombinedFilter::applyToCellVisibility( cvf::UByteArray* cellVisibility,
{
cvf::UByteArray childMask( n );
childMask.setAll( 1 );
child->applyToCellVisibility( &childMask, grid, timeStepIndex );
child->applyToCellVisibility( &childMask, grid, timeStepIndex, sourceCaseOverride );
if ( m_combineMode() == CombineMode::AND )
{
@@ -49,7 +49,10 @@ public:
bool isFilterEnabled() const override;
void onGridChanged() override;
void applyToCellVisibility( cvf::UByteArray* cellVisibility, const RigGridBase* grid, size_t timeStepIndex ) override;
void applyToCellVisibility( cvf::UByteArray* cellVisibility,
const RigGridBase* grid,
size_t timeStepIndex,
RimEclipseCase* sourceCaseOverride = nullptr ) override;
// Bridge from legacy collection dispatch: combined filter is declared INDEX-type, so the cell
// filter collection's evaluation path (if ever called) would route through updateCellIndexFilter.
@@ -724,21 +724,36 @@ void RimEclipsePropertyFilter::initAfterRead()
/// uniformly; the body is extracted from the former inline loop in
/// RivReservoirViewPartMgr::computePropertyVisibility.
//--------------------------------------------------------------------------------------------------
void RimEclipsePropertyFilter::applyToCellVisibility( cvf::UByteArray* cellVisibility, const RigGridBase* grid, size_t timeStepIndex )
void RimEclipsePropertyFilter::applyToCellVisibility( cvf::UByteArray* cellVisibility,
const RigGridBase* grid,
size_t timeStepIndex,
RimEclipseCase* sourceCaseOverride )
{
if ( cellVisibility == nullptr || grid == nullptr ) return;
if ( !isActive() || !resultDefinition()->hasResult() ) return;
resultDefinition()->loadResult();
// The result definition carries its own eclipse case binding (set via setEclipseCase). Prefer
// that, since case-level data filters have no view-side property-filter-collection ancestor.
RimEclipseCase* ec = resultDefinition()->eclipseCase();
if ( !ec )
RimEclipseCase* ec = sourceCaseOverride;
if ( ec )
{
auto* container = parentContainer();
auto* view = container ? container->reservoirView() : nullptr;
ec = view ? view->eclipseCase() : nullptr;
// Evaluate against the override case's results. Make sure the result is loaded for that case.
if ( auto cellResultsData = ec->results( resultDefinition()->porosityModel() ) )
{
cellResultsData->ensureKnownResultLoaded( resultDefinition()->eclipseResultAddress() );
}
}
else
{
resultDefinition()->loadResult();
// The result definition carries its own eclipse case binding (set via setEclipseCase). Prefer
// that, since case-level data filters have no view-side property-filter-collection ancestor.
ec = resultDefinition()->eclipseCase();
if ( !ec )
{
auto* container = parentContainer();
auto* view = container ? container->reservoirView() : nullptr;
ec = view ? view->eclipseCase() : nullptr;
}
}
if ( !ec ) return;
RigEclipseCaseData* eclipseCase = ec->eclipseCaseData();
@@ -59,7 +59,10 @@ public:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void initAfterRead() override;
void applyToCellVisibility( cvf::UByteArray* cellVisibility, const RigGridBase* grid, size_t timeStepIndex ) override;
void applyToCellVisibility( cvf::UByteArray* cellVisibility,
const RigGridBase* grid,
size_t timeStepIndex,
RimEclipseCase* sourceCaseOverride = nullptr ) override;
void updateUiFieldsFromActiveResult();