Skip to content

Commit

Permalink
Support both AND and OR operations when combining range and index fil…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
jonjenssen committed Mar 11, 2024
1 parent 2386ad8 commit dd0dfe8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
22 changes: 16 additions & 6 deletions ApplicationLibCode/ModelVisualization/RivReservoirViewPartMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++ )
Expand All @@ -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;
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" );

//--------------------------------------------------------------------------------------------------
Expand All @@ -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 );

Expand Down Expand Up @@ -87,6 +107,14 @@ void RimCellFilterCollection::setActive( bool bActive )
updateIconState();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimCellFilterCollection::useAndOperation() const
{
return m_combineFilterMode() == RimCellFilterCollection::AND;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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<RimCase>();
Expand Down Expand Up @@ -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();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -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;
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class RimCellFilterCollection : public caf::PdmObject
CAF_PDM_HEADER_INIT;

public:
enum CombineFilterModeType
{
OR,
AND
};

RimCellFilterCollection();
~RimCellFilterCollection() override;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -97,8 +108,10 @@ class RimCellFilterCollection : public caf::PdmObject
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;
};

0 comments on commit dd0dfe8

Please sign in to comment.