From dd0dfe8bbe2c0177b5f597c0f9af2a5cdcf47bc9 Mon Sep 17 00:00:00 2001 From: jonjenssen Date: Mon, 11 Mar 2024 12:47:56 +0100 Subject: [PATCH 1/3] Support both AND and OR operations when combining range and index filters --- .../RivReservoirViewPartMgr.cpp | 22 +++++-- .../CellFilters/RimCellFilterCollection.cpp | 57 +++++++++++++++++++ .../CellFilters/RimCellFilterCollection.h | 17 +++++- 3 files changed, 88 insertions(+), 8 deletions(-) diff --git a/ApplicationLibCode/ModelVisualization/RivReservoirViewPartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivReservoirViewPartMgr.cpp index ac55abb8f4..5e39ce8166 100644 --- a/ApplicationLibCode/ModelVisualization/RivReservoirViewPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivReservoirViewPartMgr.cpp @@ -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( 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 { diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp index c6b0c38d64..a780967147 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp @@ -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::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.03.12" ) ) + { + 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(); @@ -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( attribute ); + if ( myAttr ) + { + myAttr->m_useSingleWidgetInsteadOfLabelAndEditorWidget = true; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.h b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.h index 7184a32541..45e23fc90b 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.h +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.h @@ -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 @@ class RimCellFilterCollection : public caf::PdmObject 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 @@ class RimCellFilterCollection : public caf::PdmObject 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 @@ class RimCellFilterCollection : public caf::PdmObject void setAutoName( RimCellFilter* pFilter ); void addFilter( RimCellFilter* pFilter ); - caf::PdmChildArrayField m_cellFilters; - caf::PdmField m_isActive; + caf::PdmChildArrayField m_cellFilters; + caf::PdmField m_isActive; + caf::PdmField m_combineModeLabel; + caf::PdmField> m_combineFilterMode; caf::PdmChildArrayField m_rangeFilters_OBSOLETE; }; From 19d9860745e44a9986b9a6ec1f8eff1ed089f154 Mon Sep 17 00:00:00 2001 From: jonjenssen Date: Mon, 11 Mar 2024 14:04:15 +0100 Subject: [PATCH 2/3] Support AND/OR in geomech views, too --- .../RivFemElmVisibilityCalculator.cpp | 19 +++++++++++++++---- .../RivFemElmVisibilityCalculator.h | 3 ++- .../RivGeoMechVizLogic.cpp | 3 ++- .../RimGeoMechContourMapProjection.cpp | 3 ++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ApplicationLibCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp b/ApplicationLibCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp index ece33dd2d1..02791790cc 100644 --- a/ApplicationLibCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp +++ b/ApplicationLibCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp @@ -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 diff --git a/ApplicationLibCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.h b/ApplicationLibCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.h index 1b2529ad75..a0d3a567bd 100644 --- a/ApplicationLibCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.h +++ b/ApplicationLibCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.h @@ -41,7 +41,8 @@ class RivFemElmVisibilityCalculator 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, diff --git a/ApplicationLibCode/GeoMech/GeoMechVisualization/RivGeoMechVizLogic.cpp b/ApplicationLibCode/GeoMech/GeoMechVisualization/RivGeoMechVizLogic.cpp index dca38c6410..223ef6f37a 100644 --- a/ApplicationLibCode/GeoMech/GeoMechVisualization/RivGeoMechVizLogic.cpp +++ b/ApplicationLibCode/GeoMech/GeoMechVisualization/RivGeoMechVizLogic.cpp @@ -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 ) { diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapProjection.cpp b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapProjection.cpp index 1d092dc7b5..5e8d3946b8 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapProjection.cpp +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapProjection.cpp @@ -161,7 +161,8 @@ cvf::ref RimGeoMechContourMapProjection::getCellVisibility() co cellRangeFilter, &indexIncludeVis, &indexExcludeVis, - view()->cellFilterCollection()->hasActiveIncludeIndexFilters() ); + view()->cellFilterCollection()->hasActiveIncludeIndexFilters(), + view()->cellFilterCollection()->useAndOperation() ); } if ( view()->propertyFilterCollection()->isActive() ) { From 58afecd49dac70342e3c46a7d24aca414825a4b9 Mon Sep 17 00:00:00 2001 From: jonjenssen Date: Mon, 11 Mar 2024 19:55:23 +0100 Subject: [PATCH 3/3] Update version --- .../ProjectDataModel/CellFilters/RimCellFilterCollection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp index a780967147..5fe2bb0774 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp @@ -153,7 +153,7 @@ void RimCellFilterCollection::initAfterRead() } // fallback to OR mode for older projects made without AND support - if ( RimProject::current()->isProjectFileVersionEqualOrOlderThan( "2023.03.12" ) ) + if ( RimProject::current()->isProjectFileVersionEqualOrOlderThan( "2023.12.0" ) ) { m_combineFilterMode = RimCellFilterCollection::OR; }