Salome HOME
[bos #40653][CEA] New mesh import export formats with meshio.
[modules/smesh.git] / src / OBJECT / SMESH_Actor.cxx
index 1cc7927bfba0b9990b80a33dc65dbc72e4fa3ffe..2799e4494d5292f79b638af2bc02776369c57507 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include <vtkImplicitBoolean.h>
 #include <vtkImplicitFunctionCollection.h>
 
+#include <vtkThreshold.h>
+#include <vtkPassThrough.h>
+
 #include "utilities.h"
 
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
 
 SMESH_ActorDef* SMESH_ActorDef::New(){
   return new SMESH_ActorDef();
@@ -114,7 +112,7 @@ SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
 
 SMESH_ActorDef::SMESH_ActorDef()
 {
-  if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
+  MESSAGE("SMESH_ActorDef - "<<this);
 
   SALOME_Actor::SetVisibility(false); // avoid update of pipelines
 
@@ -125,6 +123,7 @@ SMESH_ActorDef::SMESH_ActorDef()
   myIsPointsVisible = false;
   myIsEntityModeCache = false;
   myRepresentationCache = 0;
+  objectEntitiesCache = 0;
 
   myHighlightActor = SMESH_SVTKActor::New();
   myHighlightActor->Delete(); // vtkSmartPointer!
@@ -139,8 +138,8 @@ SMESH_ActorDef::SMESH_ActorDef()
 
   myIsFacesOriented = false;
 
-  int controlsIncrement = SMESH_ActorProps::props()->controlsIncrement();
-  int selectionIncrement = SMESH_ActorProps::props()->selectionIncrement();
+  float  controlsIncrement = (float) SMESH_ActorProps::props()->controlsIncrement();
+  float selectionIncrement = (float) SMESH_ActorProps::props()->selectionIncrement();
 
   myControlsPrecision = -1;
   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
@@ -148,11 +147,11 @@ SMESH_ActorDef::SMESH_ActorDef()
   if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
     myControlsPrecision = mgr->integerValue( "SMESH", "controls_precision", -1);
 
-  double aElem0DSize    = SMESH::GetFloat("SMESH:elem0d_size",5);
-  double aBallElemSize  = SMESH::GetFloat("SMESH:ball_elem_size",10);
-  double aBallElemScale = SMESH::GetFloat("SMESH:ball_elem_scale",1.0);
-  double aLineWidth     = SMESH::GetFloat("SMESH:element_width",1);
-  double aOutlineWidth  = SMESH::GetFloat("SMESH:outline_width",1);
+  float aElem0DSize    = (float) SMESH::GetFloat("SMESH:elem0d_size",5);
+  float aBallElemSize  = (float) SMESH::GetFloat("SMESH:ball_elem_size",10);
+  float aBallElemScale = (float) SMESH::GetFloat("SMESH:ball_elem_scale",1.0);
+  float aLineWidth     = (float) SMESH::GetFloat("SMESH:element_width",1);
+  float aOutlineWidth  = (float) SMESH::GetFloat("SMESH:outline_width",1);
 
   SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
   bool aBoldNd    = true;
@@ -589,7 +588,7 @@ SMESH_ActorDef::SMESH_ActorDef()
 
 SMESH_ActorDef::~SMESH_ActorDef()
 {
-  if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
+  MESSAGE("~SMESH_ActorDef - "<<this);
 
   // Please keep the order same as one in the header file
 
@@ -842,6 +841,8 @@ void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode )
   my3DActor->GetMapper()->SetScalarVisibility(false);
   myBallActor->GetMapper()->SetScalarVisibility(false);
   myScalarBarActor->SetVisibility(false);
+  ClipThreshold(false);
+  SetWireframeOff(false);
 
   bool anIsScalarVisible = theMode > eNone;
 
@@ -952,6 +953,14 @@ void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode )
       myControlActor = my3DActor;
       break;
     }
+    case eScaledJacobian:
+    {
+      SMESH::Controls::ScaledJacobian* aControl = new SMESH::Controls::ScaledJacobian();
+      aControl->SetPrecision( myControlsPrecision );
+      myFunctor.reset( aControl );
+      myControlActor = my3DActor;
+      break;
+    }
     case eMaxElementLength2D:
     {
       SMESH::Controls::MaxElementLength2D* aControl = new SMESH::Controls::MaxElementLength2D();
@@ -1004,6 +1013,14 @@ void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode )
       myControlActor = my2DActor;
       break;
     }
+    case eWarping3D:
+    {
+      SMESH::Controls::Warping3D* aControl = new SMESH::Controls::Warping3D();
+      aControl->SetPrecision(myControlsPrecision);
+      myFunctor.reset(aControl);
+      myControlActor = my3DActor;
+      break;
+    }
     case eSkew:
     {
       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
@@ -1035,7 +1052,7 @@ void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode )
       return;
     }
 
-    int aNbCells = myFunctor ? myVisualObj->GetNbEntities( myFunctor->GetType() ) : 0;
+    smIdType aNbCells = myFunctor ? myVisualObj->GetNbEntities( myFunctor->GetType() ) : 0;
     bool aShowOnlyScalarBarTitle = false;
     if(aNbCells) {
       //myControlMode = theMode;
@@ -1069,6 +1086,10 @@ void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode )
         my1DExtActor->SetExtControlMode(myFunctor,myScalarBarActor,myLookupTable);
         UpdateDistribution();
         break;
+      case eWarping3D:
+        my2DExtActor->SetExtControlMode(myFunctor, myScalarBarActor, myLookupTable);
+        UpdateDistribution();
+        break;
       default:
         myControlActor->SetControlMode(myFunctor,myScalarBarActor,myLookupTable);
         UpdateDistribution();
@@ -1111,7 +1132,6 @@ void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode )
     QString aTitle = QString(myScalarBarActor->GetTitle());
     aTitle.replace(QRegExp("(:\\s).*"),"\\1"+ QString::number(GetNumberControlEntities()));
     myScalarBarActor->SetTitle(aTitle.toUtf8().constData());
-
   }
   else {
     if(theCheckEntityMode){
@@ -1135,7 +1155,7 @@ void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode )
   //Update();
 }
 
-int SMESH_ActorDef::GetNumberControlEntities()
+smIdType SMESH_ActorDef::GetNumberControlEntities()
 {
   SMESH_DeviceActor* anAct = NULL;
   switch(myControlMode){
@@ -1161,7 +1181,7 @@ int SMESH_ActorDef::GetNumberControlEntities()
       break;
     default:;
   }
-  return (anAct) ? anAct->GetUnstructuredGrid()->GetNumberOfCells() : -1;
+  return anAct ? anAct->GetUnstructuredGrid()->GetNumberOfCells() : -1;
 }
 
 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer)
@@ -1453,27 +1473,27 @@ void SMESH_ActorDef::UnShrink()
 }
 
 
-int SMESH_ActorDef::GetNodeObjId(int theVtkID)
+vtkIdType SMESH_ActorDef::GetNodeObjId(vtkIdType theVtkID)
 {
   return myPickableActor->GetNodeObjId(theVtkID);
 }
 
-double* SMESH_ActorDef::GetNodeCoord(int theObjID)
+double* SMESH_ActorDef::GetNodeCoord(vtkIdType theObjID)
 {
   return myPickableActor->GetNodeCoord(theObjID);
 }
 
-int SMESH_ActorDef::GetNodeVtkId(int theObjID)
+vtkIdType SMESH_ActorDef::GetNodeVtkId(vtkIdType theObjID)
 {
   return myPickableActor->GetNodeVtkId(theObjID);
 }
 
-int SMESH_ActorDef::GetElemObjId(int theVtkID)
+vtkIdType SMESH_ActorDef::GetElemObjId(vtkIdType theVtkID)
 {
   return myPickableActor->GetElemObjId(theVtkID);
 }
 
-vtkCell* SMESH_ActorDef::GetElemCell(int theObjID)
+vtkCell* SMESH_ActorDef::GetElemCell(vtkIdType theObjID)
 {
   return myPickableActor->GetElemCell(theObjID);
 }
@@ -1507,12 +1527,14 @@ void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation)
   my3DExtActor->VisibilityOff();
 
   myScalarBarActor->VisibilityOff();
+  
 
   if ( GetVisibility() ) {
     if ( theIsUpdateRepersentation )
       SetRepresentation(GetRepresentation());
-
-    if(myControlMode != eNone) {
+  
+    // Avoid calling VisibilityOn of ExtActor after editing hypothesis. Use the same criteria than scalarBarActor
+    if( myControlMode != eNone && myFunctor && myVisualObj->GetNbEntities( myFunctor->GetType() ) ) { 
       switch(myControlMode) {
       case eFreeNodes:
       case eCoincidentNodes:
@@ -1533,6 +1555,7 @@ void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation)
       case eBareBorderFace:
       case eOverConstrainedFace:
       case eCoincidentElems2D:
+      case eWarping3D:
         my2DExtActor->VisibilityOn();
         break;
       case eBareBorderVolume:
@@ -1542,14 +1565,14 @@ void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation)
         break;
       default:;
       }
-      if ( myFunctor && myVisualObj->GetNbEntities( myFunctor->GetType() ))
-        myScalarBarActor->VisibilityOn();
-    }
+      myScalarBarActor->VisibilityOn();
+    }    
 
     if ( GetPickable( ))
       myPickableActor->VisibilityOn();
 
-    if ( GetRepresentation() != ePoint )
+    if ( GetRepresentation() != ePoint && 
+      !(IsClipThresholdOn() && GetActorForThreshold() != myControlActor)) // Avoid calling VisibilityOn if for display result of Threshold Criteria need only ExtActor
     {
       if(myEntityMode & e0DElements  ){
         my0DActor->VisibilityOn();
@@ -1643,7 +1666,8 @@ void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
       theMode |= eVolumes;
   }
 
-  myBaseActor->myGeomFilter->SetInside(myEntityMode != anObjectEntities);
+  // rnv : Fix volume selection on Display Entity
+  //myBaseActor->myGeomFilter->SetInside(myEntityMode != anObjectEntities);
 
   if ( anObjectEntities == 0 && myRepresentation != ePoint ) // no elements, show nodes
   {
@@ -1651,6 +1675,12 @@ void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
     SetRepresentation( ePoint );
   }
 
+  if ( anObjectEntities != 0 && objectEntitiesCache == 0 )
+  {
+    objectEntitiesCache = anObjectEntities;
+    SetRepresentation( eSurface );
+  }
+
   if ( myEntityMode != theMode )
   {
     myEntityMode = theMode; // entities to show
@@ -1664,11 +1694,11 @@ void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
 
 void SMESH_ActorDef::SetRepresentation (int theMode)
 {
-  int aNbEdges   = myVisualObj->GetNbEntities(SMDSAbs_Edge);
-  int aNbFaces   = myVisualObj->GetNbEntities(SMDSAbs_Face);
-  int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
-  int aNb0Ds     = myVisualObj->GetNbEntities(SMDSAbs_0DElement);
-  int aNbBalls   = myVisualObj->GetNbEntities(SMDSAbs_Ball);
+  smIdType aNbEdges   = myVisualObj->GetNbEntities(SMDSAbs_Edge);
+  smIdType aNbFaces   = myVisualObj->GetNbEntities(SMDSAbs_Face);
+  smIdType aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
+  smIdType aNb0Ds     = myVisualObj->GetNbEntities(SMDSAbs_0DElement);
+  smIdType aNbBalls   = myVisualObj->GetNbEntities(SMDSAbs_Ball);
 
   if ( myRepresentationCache && aNbEdges + aNbFaces + aNbVolumes + aNb0Ds + aNbBalls )
   {
@@ -1713,7 +1743,7 @@ void SMESH_ActorDef::SetRepresentation (int theMode)
   myPickableActor = myBaseActor;
   vtkProperty *aProp = NULL, *aBackProp = NULL;
   vtkProperty *aPropVN = NULL, *aPropVR = NULL;
-  SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
+  SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::eNoneRepr;
   SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
   switch (myRepresentation) {
   case ePoint:
@@ -1818,6 +1848,8 @@ void SMESH_ActorDef::UpdateHighlight()
   case SMESH_DeviceActor::eSurface:
   case SMESH_DeviceActor::eWireframe:
     {
+      anIsVisible = anIsVisible && !IsWireframeOff();
+
       if(myIsHighlighted) {
         myHighlitableActor->SetProperty(myHighlightProp);
       }else if(myIsPreselected){
@@ -1926,7 +1958,7 @@ void SMESH_ActorDef::Render(vtkRenderer* /*ren*/)
 
 void SMESH_ActorDef::Update()
 {
-  if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
+  MESSAGE("SMESH_ActorDef::Update");
 
   myVisualObj->Update();
 
@@ -2125,8 +2157,8 @@ void SMESH_ActorDef::UpdateSelectionProps()
 {
   QColor selectionColor = SMESH_ActorProps::props()->selectionColor();
   QColor highlightColor = SMESH_ActorProps::props()->highlightColor();
-  int selectionIncrement = SMESH_ActorProps::props()->selectionIncrement();
-  double width = GetLineWidth();
+  float  selectionIncrement = (float) SMESH_ActorProps::props()->selectionIncrement();
+  float  width = (float) GetLineWidth();
   myHighlightProp->SetColor(selectionColor.redF(), selectionColor.greenF(), selectionColor.blueF());
   myHighlightProp->SetLineWidth(width + selectionIncrement);
   myPreselectProp->SetColor(highlightColor.redF(), highlightColor.greenF(), highlightColor.blueF());
@@ -2142,17 +2174,17 @@ double SMESH_ActorDef::GetLineWidth()
 
 void SMESH_ActorDef::SetLineWidth(double theVal)
 {
-  int controlsIncrement = SMESH_ActorProps::props()->controlsIncrement();
-  int selectionIncrement = SMESH_ActorProps::props()->selectionIncrement();
+  float  controlsIncrement = (float) SMESH_ActorProps::props()->controlsIncrement();
+  float selectionIncrement = (float) SMESH_ActorProps::props()->selectionIncrement();
 
-  myEdgeProp->SetLineWidth(theVal);
+  myEdgeProp->SetLineWidth((float) theVal);
 
-  my1DProp->SetLineWidth(theVal + controlsIncrement);
-  my1DExtProp->SetLineWidth(theVal + controlsIncrement);
-  my2DExtProp->SetLineWidth(theVal + controlsIncrement);
-  my3DExtProp->SetLineWidth(theVal + controlsIncrement);
-  myHighlightProp->SetLineWidth(theVal + selectionIncrement);
-  myPreselectProp->SetLineWidth(theVal + selectionIncrement);
+  my1DProp       ->SetLineWidth((float) theVal + controlsIncrement);
+  my1DExtProp    ->SetLineWidth((float) theVal + controlsIncrement);
+  my2DExtProp    ->SetLineWidth((float) theVal + controlsIncrement);
+  my3DExtProp    ->SetLineWidth((float) theVal + controlsIncrement);
+  myHighlightProp->SetLineWidth((float) theVal + selectionIncrement);
+  myPreselectProp->SetLineWidth((float) theVal + selectionIncrement);
   Modified();
 }
 
@@ -2163,21 +2195,21 @@ double SMESH_ActorDef::GetOutlineWidth()
 
 void SMESH_ActorDef::SetOutlineWidth(double theVal)
 {
-  myOutLineProp->SetLineWidth(theVal);
+  myOutLineProp->SetLineWidth((float) theVal);
   Modified();
 }
 
 void SMESH_ActorDef::Set0DSize(double theVal)
 {
-  my0DProp->SetPointSize(theVal);
-  myHighlightProp->SetPointSize(theVal);
-  myPreselectProp->SetPointSize(theVal);
+  my0DProp       ->SetPointSize((float) theVal);
+  myHighlightProp->SetPointSize((float) theVal);
+  myPreselectProp->SetPointSize((float) theVal);
 
   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) {
-    aCustom->Set0DSize(theVal);
+    aCustom->Set0DSize((float) theVal);
   }
   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) {
-    aCustom->Set0DSize(theVal);
+    aCustom->Set0DSize((float) theVal);
   }
 
   Modified();
@@ -2190,13 +2222,13 @@ double SMESH_ActorDef::Get0DSize()
 
 void SMESH_ActorDef::SetBallSize(double theVal)
 {
-  myBallProp->SetPointSize(theVal);
+  myBallProp->SetPointSize((float) theVal);
 
   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) {
-    aCustom->SetBallSize(theVal);
+    aCustom->SetBallSize((float) theVal);
   }
   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) {
-    aCustom->SetBallSize(theVal);
+    aCustom->SetBallSize((float) theVal);
   }
 
   Modified();
@@ -2225,7 +2257,7 @@ void SMESH_ActorDef::SetBallScale( double theVal )
   Modified();
 }
 
-int SMESH_ActorDef::GetObjDimension( const int theObjId )
+int SMESH_ActorDef::GetObjDimension( const vtkIdType theObjId )
 {
   return myVisualObj->GetElemDimension( theObjId );
 }
@@ -2484,6 +2516,71 @@ void SMESH_ActorDef::UpdateScalarBar()
 
 }
 
+// Get Actor for Threshold criteria compute
+SMESH_DeviceActor* SMESH_ActorDef::GetActorForThreshold()
+{
+  switch (myControlMode) {
+  case eLength2D:
+    return my1DExtActor;
+  case eWarping3D:
+    return my2DExtActor;
+  default:;
+    return myControlActor;
+  }
+}
+
+// Hides the cells beyond threshold if isThresholdOn == true.
+void SMESH_ActorDef::ClipThreshold(bool isThresholdOn,double min /*= 0.0*/, double max /*= 0.0*/)
+{
+  SMESH_DeviceActor* anActor = GetActorForThreshold();
+  if (anActor != myControlActor)
+    myControlActor->VisibilityOff();
+
+  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(anActor->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();
+    anActor->myPassFilter[0]->SetInputConnection(port);
+  }
+  else
+  {
+    // Restore the filters' chain
+    anActor->SetImplicitFunctionUsed(anActor->myIsImplicitFunctionUsed);
+    // Restore Actor filters when after Controls, which not use ExtACtor was called Controls, which use ExtActor
+    // For avoid artifact's
+    if (anActor != myControlActor)
+      myControlActor->SetImplicitFunctionUsed(myControlActor->myIsImplicitFunctionUsed);
+
+    myControlActor->VisibilityOn();
+  }
+}
+
+// Hides the wireframe if isWireframeOff == true.
+void SMESH_ActorDef::SetWireframeOff(bool isWireframeOff)
+{
+  myIsWireframeOff = isWireframeOff;
+
+  UpdateHighlight();
+}
+
 void SMESH_ActorDef::UpdateDistribution()
 {
   if(SMESH::Controls::NumericalFunctor* fun =
@@ -2495,7 +2592,7 @@ void SMESH_ActorDef::UpdateDistribution()
     SMESH_VisualObjDef::TEntityList elems;
     if ( dynamic_cast<SMESH_SubMeshObj*>(myVisualObj.get()))
       dynamic_cast<SMESH_SubMeshObj*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
-    std::vector<int> elemIds; elemIds.reserve( elems.size() );
+    std::vector<smIdType> elemIds; elemIds.reserve( elems.size() );
     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
       elemIds.push_back( (*e)->GetID());
     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
@@ -2656,7 +2753,7 @@ void SMESH_ActorDef::UpdateFilter()
   }
   if ( GetVisibility() )
     aFilter->Update();
-  if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
+  MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
 }
 
 #ifndef DISABLE_PLOT2DVIEWER
@@ -2681,7 +2778,7 @@ SPlot2d_Histogram* SMESH_ActorDef::UpdatePlot2Histogram()
     SMESH_VisualObjDef::TEntityList elems;
     if ( dynamic_cast<SMESH_SubMeshObj*>(myVisualObj.get()))
       dynamic_cast<SMESH_SubMeshObj*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
-    std::vector<int> elemIds;
+    std::vector<smIdType> elemIds;
 
     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
       elemIds.push_back( (*e)->GetID());