Support both AND and OR operations when combining range and index filters (#11275)

Support both AND and OR operations when combining range and index filters
This commit is contained in:
jonjenssen 2024-03-11 20:02:47 +01:00 committed by GitHub
parent 2386ad8985
commit fb5758a363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 109 additions and 15 deletions

View File

@ -57,7 +57,8 @@ void RivFemElmVisibilityCalculator::computeRangeVisibility( cvf::UByteArray*
const cvf::CellRangeFilter& rangeFilter,
const cvf::UByteArray* indexIncludeVisibility,
const cvf::UByteArray* indexExcludeVisibility,
bool useIndexInclude )
bool useIndexInclude,
bool useAndOperation )
{
elmVisibilities->resize( femPart->elementCount() );
@ -74,9 +75,19 @@ void RivFemElmVisibilityCalculator::computeRangeVisibility( cvf::UByteArray*
for ( int elmIdx = 0; elmIdx < femPart->elementCount(); ++elmIdx )
{
grid->ijkFromCellIndex( elmIdx, &mainGridI, &mainGridJ, &mainGridK );
( *elmVisibilities )[elmIdx] =
( ( *indexIncludeVisibility )[elmIdx] || rangeFilter.isCellVisible( mainGridI, mainGridJ, mainGridK, false ) ) &&
( *indexExcludeVisibility )[elmIdx];
if ( useAndOperation )
{
( *elmVisibilities )[elmIdx] =
( ( *indexIncludeVisibility )[elmIdx] && rangeFilter.isCellVisible( mainGridI, mainGridJ, mainGridK, false ) ) &&
( *indexExcludeVisibility )[elmIdx];
}
else
{
( *elmVisibilities )[elmIdx] =
( ( *indexIncludeVisibility )[elmIdx] || rangeFilter.isCellVisible( mainGridI, mainGridJ, mainGridK, false ) ) &&
( *indexExcludeVisibility )[elmIdx];
}
}
}
else

View File

@ -41,7 +41,8 @@ public:
const cvf::CellRangeFilter& rangeFilter,
const cvf::UByteArray* indexIncludeVisibility,
const cvf::UByteArray* indexExcludeVisibility,
bool useIndexInclude );
bool useIndexInclude,
bool useAndOperation );
static void computePropertyVisibility( cvf::UByteArray* cellVisibility,
const RigFemPart* grid,

View File

@ -251,7 +251,8 @@ RivGeoMechPartMgr* RivGeoMechVizLogic::getUpdatedPartMgr( RivGeoMechPartMgrCache
cellRangeFilter,
&indexIncludeVisibility,
&indexExcludeVisibility,
m_geomechView->cellFilterCollection()->hasActiveIncludeIndexFilters() );
m_geomechView->cellFilterCollection()->hasActiveIncludeIndexFilters(),
m_geomechView->cellFilterCollection()->useAndOperation() );
}
else if ( pMgrKey.geometryType() == PROPERTY_FILTERED )
{

View File

@ -749,9 +749,11 @@ void RivReservoirViewPartMgr::computeFilterVisibility( RivCellSetEnum
parentGridVisibilities = reservoirGridPartMgr->cellVisibility( parentGridIndex );
}
bool hasAdditiveRangeFilters = cellFilterColl->hasActiveIncludeRangeFilters() ||
m_reservoirView->wellCollection()->hasVisibleWellCells();
bool hasAdditiveIndexFilters = cellFilterColl->hasActiveIncludeIndexFilters();
const bool hasAdditiveRangeFilters = cellFilterColl->hasActiveIncludeRangeFilters() ||
m_reservoirView->wellCollection()->hasVisibleWellCells();
const bool hasAdditiveIndexFilters = cellFilterColl->hasActiveIncludeIndexFilters();
const bool useAndOperation = cellFilterColl->useAndOperation();
#pragma omp parallel for
for ( int cellIndex = 0; cellIndex < static_cast<int>( grid->cellCount() ); cellIndex++ )
@ -771,7 +773,7 @@ void RivReservoirViewPartMgr::computeFilterVisibility( RivCellSetEnum
size_t mainGridJ;
size_t mainGridK;
bool isInSubGridArea = cell.subGrid() != nullptr;
const bool isInSubGridArea = cell.subGrid() != nullptr;
grid->ijkFromCellIndex( cellIndex, &mainGridI, &mainGridJ, &mainGridK );
bool nativeRangeVisibility = false;
@ -780,8 +782,16 @@ void RivReservoirViewPartMgr::computeFilterVisibility( RivCellSetEnum
{
if ( hasAdditiveIndexFilters )
{
nativeRangeVisibility = indexIncludeVisibility[cellIndex] ||
gridCellRangeFilter.isCellVisible( mainGridI, mainGridJ, mainGridK, isInSubGridArea );
if ( useAndOperation )
{
nativeRangeVisibility = indexIncludeVisibility[cellIndex] &&
gridCellRangeFilter.isCellVisible( mainGridI, mainGridJ, mainGridK, isInSubGridArea );
}
else
{
nativeRangeVisibility = indexIncludeVisibility[cellIndex] ||
gridCellRangeFilter.isCellVisible( mainGridI, mainGridJ, mainGridK, isInSubGridArea );
}
}
else
{

View File

@ -24,6 +24,7 @@
#include "RimCellIndexFilter.h"
#include "RimCellRangeFilter.h"
#include "RimPolygonFilter.h"
#include "RimProject.h"
#include "RimUserDefinedFilter.h"
#include "RimUserDefinedIndexFilter.h"
#include "RimViewController.h"
@ -32,8 +33,21 @@
#include "cafPdmFieldReorderCapability.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
#include "cafPdmUiLabelEditor.h"
#include "cvfStructGridGeometryGenerator.h"
namespace caf
{
template <>
void caf::AppEnum<RimCellFilterCollection::CombineFilterModeType>::setUp()
{
addItem( RimCellFilterCollection::AND, "AND", "AND" );
addItem( RimCellFilterCollection::OR, "OR", "OR" );
setDefault( RimCellFilterCollection::AND );
}
} // namespace caf
CAF_PDM_SOURCE_INIT( RimCellFilterCollection, "CellFilterCollection", "RimCellFilterCollection", "CellRangeFilterCollection" );
//--------------------------------------------------------------------------------------------------
@ -47,6 +61,12 @@ RimCellFilterCollection::RimCellFilterCollection()
CAF_PDM_InitScriptableField( &m_isActive, "Active", true, "Active" );
m_isActive.uiCapability()->setUiHidden( true );
CAF_PDM_InitFieldNoDefault( &m_combineFilterMode, "CombineFilterMode", "" );
CAF_PDM_InitField( &m_combineModeLabel, "CombineModeLabel", QString( "" ), "Combine Polygon and Range Filters Using Operation" );
m_combineModeLabel.uiCapability()->setUiEditorTypeName( caf::PdmUiLabelEditor::uiEditorTypeName() );
m_combineModeLabel.xmlCapability()->disableIO();
CAF_PDM_InitFieldNoDefault( &m_cellFilters, "CellFilters", "Filters" );
caf::PdmFieldReorderCapability::addToField( &m_cellFilters );
@ -87,6 +107,14 @@ void RimCellFilterCollection::setActive( bool bActive )
updateIconState();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimCellFilterCollection::useAndOperation() const
{
return m_combineFilterMode() == RimCellFilterCollection::AND;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -124,6 +152,12 @@ void RimCellFilterCollection::initAfterRead()
m_cellFilters.push_back( filter );
}
// fallback to OR mode for older projects made without AND support
if ( RimProject::current()->isProjectFileVersionEqualOrOlderThan( "2023.12.0" ) )
{
m_combineFilterMode = RimCellFilterCollection::OR;
}
// Copy by xml serialization does not give a RimCase parent the first time initAfterRead is called here when creating a new a contour
// view from a 3d view. The second time we get called it is ok, so just skip setting up the filter connections if we have no case.
auto rimCase = firstAncestorOrThisOfType<RimCase>();
@ -161,6 +195,17 @@ caf::PdmFieldHandle* RimCellFilterCollection::objectToggleField()
return &m_isActive;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellFilterCollection::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( &m_combineModeLabel );
uiOrdering.add( &m_combineFilterMode );
uiOrdering.skipRemainingFields();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -182,6 +227,18 @@ void RimCellFilterCollection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTr
updateIconState();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellFilterCollection::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
{
caf::PdmUiLabelEditorAttribute* myAttr = dynamic_cast<caf::PdmUiLabelEditorAttribute*>( attribute );
if ( myAttr )
{
myAttr->m_useSingleWidgetInsteadOfLabelAndEditorWidget = true;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -49,6 +49,12 @@ class RimCellFilterCollection : public caf::PdmObject
CAF_PDM_HEADER_INIT;
public:
enum CombineFilterModeType
{
OR,
AND
};
RimCellFilterCollection();
~RimCellFilterCollection() override;
@ -68,6 +74,8 @@ public:
bool isActive() const;
void setActive( bool bActive );
bool useAndOperation() const;
void compoundCellRangeFilter( cvf::CellRangeFilter* cellRangeFilter, size_t gridIndex ) const;
void updateCellVisibilityByIndex( cvf::UByteArray* cellsIncluded, cvf::UByteArray* cellsExcluded, size_t gridIndex ) const;
@ -87,7 +95,10 @@ public:
protected:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
caf::PdmFieldHandle* objectToggleField() override;
void initAfterRead() override;
@ -97,8 +108,10 @@ private:
void setAutoName( RimCellFilter* pFilter );
void addFilter( RimCellFilter* pFilter );
caf::PdmChildArrayField<RimCellFilter*> m_cellFilters;
caf::PdmField<bool> m_isActive;
caf::PdmChildArrayField<RimCellFilter*> m_cellFilters;
caf::PdmField<bool> m_isActive;
caf::PdmField<QString> m_combineModeLabel;
caf::PdmField<caf::AppEnum<CombineFilterModeType>> m_combineFilterMode;
caf::PdmChildArrayField<RimCellRangeFilter*> m_rangeFilters_OBSOLETE;
};

View File

@ -161,7 +161,8 @@ cvf::ref<cvf::UByteArray> RimGeoMechContourMapProjection::getCellVisibility() co
cellRangeFilter,
&indexIncludeVis,
&indexExcludeVis,
view()->cellFilterCollection()->hasActiveIncludeIndexFilters() );
view()->cellFilterCollection()->hasActiveIncludeIndexFilters(),
view()->cellFilterCollection()->useAndOperation() );
}
if ( view()->propertyFilterCollection()->isActive() )
{