From: kosta Date: Thu, 13 Apr 2023 16:54:13 +0000 (+0100) Subject: [bos #32736][CEA] Threshold of criteria. Using vtkThreshold filter for hiding cells... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=26cb19a6fecbc8c0a5daeb6c61a24326aaf93a65;p=modules%2Fsmesh.git [bos #32736][CEA] Threshold of criteria. Using vtkThreshold filter for hiding cells instead of lookup table. --- diff --git a/src/OBJECT/SMESH_Actor.cxx b/src/OBJECT/SMESH_Actor.cxx index e61144f6b..c1c6cdc3f 100644 --- a/src/OBJECT/SMESH_Actor.cxx +++ b/src/OBJECT/SMESH_Actor.cxx @@ -80,6 +80,9 @@ #include #include +#include +#include + #include "utilities.h" @@ -838,6 +841,7 @@ void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode ) my3DActor->GetMapper()->SetScalarVisibility(false); myBallActor->GetMapper()->SetScalarVisibility(false); myScalarBarActor->SetVisibility(false); + ClipThreshold(false); bool anIsScalarVisible = theMode > eNone; @@ -2487,6 +2491,41 @@ void SMESH_ActorDef::UpdateScalarBar() } +// Hides the cells beyond threshold if isThresholdOn == true. +void SMESH_ActorDef::ClipThreshold(bool isThresholdOn, double min /*= 0.0*/, double max /*= 0.0*/) +{ + myIsClipThresholdOn = isThresholdOn; + + if (isThresholdOn) + { + // Initialize the filter + vtkSmartPointer threshold = vtkSmartPointer::New(); + + // We have set scalar data with SMESH_DeviceActor::SetControlMode() call as vtkDataSetAttributes::SCALARS. + // So, we don't need to pass an array name in SetInputArrayToProcess(). + threshold->SetInputConnection(myControlActor->myMergeFilter->GetOutputPort()); + threshold->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, vtkDataSetAttributes::SCALARS); + + // Set range + threshold->SetThresholdFunction(vtkThreshold::THRESHOLD_BETWEEN); + threshold->SetLowerThreshold(min); + threshold->SetUpperThreshold(max); + + // Debug output + threshold->Update(); + SCRUTE(threshold->GetOutput()->GetNumberOfCells()); + + // Add to the filters' chain + vtkAlgorithmOutput* port = threshold->GetOutputPort(); + myControlActor->myPassFilter[0]->SetInputConnection(port); + } + else + { + // Restore the filters' chain + myControlActor->SetImplicitFunctionUsed(myControlActor->myIsImplicitFunctionUsed); + } +} + void SMESH_ActorDef::UpdateDistribution() { if(SMESH::Controls::NumericalFunctor* fun = diff --git a/src/OBJECT/SMESH_Actor.h b/src/OBJECT/SMESH_Actor.h index ac9fd48cd..b7e83ad7b 100644 --- a/src/OBJECT/SMESH_Actor.h +++ b/src/OBJECT/SMESH_Actor.h @@ -166,6 +166,8 @@ class SMESHOBJECT_EXPORT SMESH_Actor: public SALOME_Actor virtual void UpdateScalarBar() = 0; virtual void UpdateDistribution() = 0; + virtual void ClipThreshold(bool isThresholdOn, double min = 0.0, double max = 0.0) = 0; + virtual bool IsClipThresholdOn() const = 0; virtual void SetPointsFontProperties( SMESH::LabelFont family, int size, bool bold, bool italic, bool shadow, diff --git a/src/OBJECT/SMESH_ActorDef.h b/src/OBJECT/SMESH_ActorDef.h index 757b47a19..2cca9bfc8 100644 --- a/src/OBJECT/SMESH_ActorDef.h +++ b/src/OBJECT/SMESH_ActorDef.h @@ -226,6 +226,8 @@ class SMESH_ActorDef : public SMESH_Actor virtual void UpdateScalarBar(); virtual void UpdateDistribution(); + virtual void ClipThreshold(bool isThresholdOn, double min = 0.0, double max = 0.0); + virtual bool IsClipThresholdOn() const { return myIsClipThresholdOn; } #ifndef DISABLE_PLOT2DVIEWER virtual SPlot2d_Histogram* GetPlot2Histogram() { return my2dHistogram; } @@ -300,6 +302,7 @@ class SMESH_ActorDef : public SMESH_Actor int myRepresentationCache; bool myIsEntityModeCache; bool myIsPointsVisible; + bool myIsClipThresholdOn = false; bool myIsShrinkable; bool myIsShrunk; diff --git a/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx b/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx index 89faee306..744646966 100644 --- a/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx @@ -50,6 +50,8 @@ #include +#include "utilities.h" + // Qt includes #include #include @@ -569,7 +571,7 @@ bool SMESHGUI_Preferences_ScalarBarDlg::onApply() myLookupTable->SetRange( aMin, aMax ); myLookupTable->SetNumberOfTableValues(myColorsSpin->value()); - applyThreshold(myLookupTable); + applyThreshold(aMin, aMax); bool scaleChanged = (myLogarithmicCheck->isChecked() != (myLookupTable->GetScale() == VTK_SCALE_LOG10)); if (scaleChanged) @@ -663,8 +665,8 @@ void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged() //myLogarithmicCheck->setEnabled(range[0] > 1e-07 && range[1] > 1e-07); myLogarithmicCheck->setEnabled(range[0] != range[1]); - setThresholdFromTable(aLookupTable); - applyThreshold(aLookupTable); + myThresholdCheck->setChecked(myActor->IsClipThresholdOn()); + applyThreshold(range[0], range[1]); } vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty(); @@ -891,29 +893,6 @@ void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources() } } -//================================================================================================= -/*! - * SMESHGUI_Preferences_ScalarBarDlg::setThresholdFromTable() - * - * Checks if the table uses special color for values beyond the min-max range, - * and this color is completely transparent - RGBA(0,0,0,0). - */ -//================================================================================================= -void SMESHGUI_Preferences_ScalarBarDlg::setThresholdFromTable(vtkLookupTable* aLookupTable) -{ - bool isUseBeyondRangeColor = aLookupTable->GetUseAboveRangeColor() && aLookupTable->GetUseBelowRangeColor(); - - if (isUseBeyondRangeColor) - { - const double* aboveRangeColor = aLookupTable->GetAboveRangeColor(); - const double* belowRangeColor = aLookupTable->GetBelowRangeColor(); - - isUseBeyondRangeColor = aboveRangeColor[3] == 0.0 && belowRangeColor[3] == 0.0; - } - - myThresholdCheck->setChecked(isUseBeyondRangeColor); -} - //================================================================================================= /*! * SMESHGUI_Preferences_ScalarBarDlg::applyThreshold() @@ -922,18 +901,8 @@ void SMESHGUI_Preferences_ScalarBarDlg::setThresholdFromTable(vtkLookupTable* aL * Now this color is completely transparent - RGBA(0,0,0,0). */ //================================================================================================= -void SMESHGUI_Preferences_ScalarBarDlg::applyThreshold(vtkLookupTable* aLookupTable) +//void SMESHGUI_Preferences_ScalarBarDlg::applyThreshold(vtkLookupTable* aLookupTable) +void SMESHGUI_Preferences_ScalarBarDlg::applyThreshold(double min, double max) { - const bool isChecked = myThresholdCheck->isChecked(); - - aLookupTable->SetUseAboveRangeColor(isChecked); - aLookupTable->SetUseBelowRangeColor(isChecked); - - if (isChecked) - { - const double beyondRangeColor[4] = {}; - - aLookupTable->SetAboveRangeColor(beyondRangeColor); - aLookupTable->SetBelowRangeColor(beyondRangeColor); - } + myActor->ClipThreshold(myThresholdCheck->isChecked(), min, max); } diff --git a/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.h b/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.h index 11c916ada..204601772 100644 --- a/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.h +++ b/src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.h @@ -73,8 +73,7 @@ public: void initScalarBarFromResources(); protected: - void setThresholdFromTable(vtkLookupTable* aLookupTable); - void applyThreshold(vtkLookupTable* aLookupTable); + void applyThreshold(double min, double max); protected slots: virtual void reject();