]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
[bos #32736][CEA] Threshold of criteria. Using vtkThreshold filter for hiding cells...
authorkosta <kleontev@Debian11.kleontev.virtualbox.org>
Thu, 13 Apr 2023 16:54:13 +0000 (17:54 +0100)
committerkosta <kleontev@Debian11.kleontev.virtualbox.org>
Thu, 13 Apr 2023 16:54:13 +0000 (17:54 +0100)
src/OBJECT/SMESH_Actor.cxx
src/OBJECT/SMESH_Actor.h
src/OBJECT/SMESH_ActorDef.h
src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.cxx
src/SMESHGUI/SMESHGUI_Preferences_ScalarBarDlg.h

index e61144f6b04299ef099f77ed6b77c537bd1d734b..c1c6cdc3f9ba1960b4026df44cc052952e7dbcda 100644 (file)
@@ -80,6 +80,9 @@
 #include <vtkImplicitBoolean.h>
 #include <vtkImplicitFunctionCollection.h>
 
+#include <vtkThreshold.h>
+#include <vtkPassThrough.h>
+
 #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<vtkThreshold> threshold = vtkSmartPointer<vtkThreshold>::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 =
index ac9fd48cd1e3c337d9d140453d3621458eb426e4..b7e83ad7bb3b11a3c8c2122956295e7d4fa7f1fe 100644 (file)
@@ -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,
index 757b47a197bdd5188c1fc60db9ad69dd741850b7..2cca9bfc8d845141b8d20e0f75fb33d274167bb6 100644 (file)
@@ -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;
index 89faee306142ddd584cb616f0e1f2aa3b41bb764..7446469668476745a0b4811ddd95af032fed689b 100644 (file)
@@ -50,6 +50,8 @@
 
 #include <QtxColorButton.h>
 
+#include "utilities.h"
+
 // Qt includes
 #include <QButtonGroup>
 #include <QCheckBox>
@@ -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);
 }
index 11c916ada57e3040966866ceac54fc57c6ddcb47..204601772f25da25cf8c65a15cd66d1eb6e50f01 100644 (file)
@@ -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();