Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() );

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
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.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>();
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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand Down
Loading