Salome HOME
[bos #40653][CEA] New mesh import export formats with meshio.
[modules/smesh.git] / src / OBJECT / SMESH_DeviceActor.cxx
index 2f6ccd06f0044e7a26e03d7b5a87c80db50f26f9..be17fe3c30317da05193bf43c17d083e1e28f2d5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  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 "SMESH_ControlsDef.hxx"
 #include "SMESH_ActorUtils.h"
 #include "SMESH_FaceOrientationFilter.h"
-#include "VTKViewer_CellLocationsArray.h"
+//#include "VTKViewer_CellLocationsArray.h"
 #include "VTKViewer_PolyDataMapper.h"
 
 #include <VTKViewer_Transform.h>
 #include <VTKViewer_TransformFilter.h>
 #include <VTKViewer_ExtractUnstructuredGrid.h>
+#include <VTKViewer_Actor.h>
 
 // VTK Includes
 #include <vtkObjectFactory.h>
@@ -59,7 +60,7 @@
 #include <vtkUnsignedCharArray.h>
 
 #include <vtkImplicitBoolean.h>
-#include <vtkPassThroughFilter.h>
+#include <vtkPassThrough.h>
 
 #include <vtkRenderer.h>
 
 
 #include "utilities.h"
 
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
 
 using namespace std;
 
 
-vtkStandardNewMacro(SMESH_DeviceActor);
+vtkStandardNewMacro(SMESH_DeviceActor)
 
 
 SMESH_DeviceActor
 ::SMESH_DeviceActor()
 {
-  if(MYDEBUG) MESSAGE("SMESH_DeviceActor - "<<this);
+  MESSAGE("SMESH_DeviceActor - "<<this);
 
   myIsShrinkable = false;
   myIsShrunk = false;
@@ -94,8 +90,8 @@ SMESH_DeviceActor
   myMapper = VTKViewer_PolyDataMapper::New();
   myPlaneCollection = vtkPlaneCollection::New();
 
-  vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
-                                                                 myPolygonOffsetUnits);
+  VTKViewer_Actor::GetDefaultPolygonOffsetParameters(myPolygonOffsetFactor,
+                                                     myPolygonOffsetUnits);
 
   myMapper->UseLookupTableScalarRangeOn();
   myMapper->SetColorModeToMapScalars();
@@ -117,7 +113,7 @@ SMESH_DeviceActor
   myTransformFilter = VTKViewer_TransformFilter::New();
 
   for(int i = 0; i < 6; i++)
-    myPassFilter.push_back(vtkPassThroughFilter::New());
+    myPassFilter.push_back(vtkPassThrough::New());
 
   // Orientation of faces
   myIsFacesOriented = false;
@@ -139,7 +135,7 @@ SMESH_DeviceActor
 SMESH_DeviceActor
 ::~SMESH_DeviceActor()
 {
-  if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<<this);
+  MESSAGE("~SMESH_DeviceActor - "<<this);
 
   myMapper->Delete();
   // myPlaneCollection->Delete(); -- it is vtkSmartPointer
@@ -160,7 +156,7 @@ SMESH_DeviceActor
 
   myTransformFilter->Delete();
 
-  for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
+  for(size_t i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
     myPassFilter[i]->Delete();
 
   myShrinkFilter->Delete();
@@ -409,7 +405,7 @@ SMESH_DeviceActor
       aNbCells = 0;
       for(; anIter != aValues.end(); anIter++){
         const Length2D::Value& aValue = *anIter;
-        int aNode[2] = {
+        vtkIdType aNode[2] = {
           myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
           myVisualObj->GetNodeVTKId(aValue.myPntId[1])
         };
@@ -425,12 +421,13 @@ SMESH_DeviceActor
       aCellTypesArray->SetNumberOfTuples( aNbCells );
       aScalars->SetNumberOfTuples( aNbCells );
 
-      VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
+      vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
       aCellLocationsArray->SetNumberOfComponents( 1 );
       aCellLocationsArray->SetNumberOfTuples( aNbCells );
 
       aConnectivity->InitTraversal();
-      for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+      vtkIdType const *pts(nullptr);
+      for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
         aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
 
       aDataSet->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity );
@@ -473,7 +470,7 @@ SMESH_DeviceActor
       aNbCells = 0;
       for(; anIter != aValues.end(); anIter++){
         const MultiConnection2D::Value& aValue = (*anIter).first;
-        int aNode[2] = {
+        vtkIdType aNode[2] = {
           myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
           myVisualObj->GetNodeVTKId(aValue.myPntId[1])
         };
@@ -489,12 +486,13 @@ SMESH_DeviceActor
       aCellTypesArray->SetNumberOfTuples( aNbCells );
       aScalars->SetNumberOfTuples( aNbCells );
 
-      VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
+      vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
       aCellLocationsArray->SetNumberOfComponents( 1 );
       aCellLocationsArray->SetNumberOfTuples( aNbCells );
 
       aConnectivity->InitTraversal();
-      for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+      vtkIdType const *pts(nullptr);
+      for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
         aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
 
       aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
@@ -506,6 +504,80 @@ SMESH_DeviceActor
       theLookupTable->SetRange(aScalars->GetRange());
       theLookupTable->Build();
 
+      myMergeFilter->SetScalarsData(aDataSet);
+      aDataSet->Delete();
+    }
+    else if (Warping3D* aWarping3D = dynamic_cast<Warping3D*>(theFunctor.get())){
+
+      SMESH::Controls::Warping3D::WValues aValues;
+
+      aWarping3D->GetValues(aValues);
+      vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
+      vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
+
+      aDataSet->SetPoints(aGrid->GetPoints());
+
+      vtkIdType aNbCells = aValues.size();
+
+      vtkDoubleArray* aScalars = vtkDoubleArray::New();
+      aScalars->SetNumberOfComponents(1);
+      aScalars->SetNumberOfTuples(aNbCells);
+
+      vtkIdType aCellsSize = 3 * aNbCells;
+      vtkCellArray* aConnectivity = vtkCellArray::New();
+      aConnectivity->Allocate(aCellsSize, 0);
+
+      vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+      aCellTypesArray->SetNumberOfComponents(1);
+      aCellTypesArray->Allocate(aNbCells* aCellTypesArray->GetNumberOfComponents());
+
+      Warping3D::WValues::const_iterator anIter = aValues.begin();
+      aNbCells = 0;
+      for (; anIter != aValues.end(); anIter++) {
+
+        const Warping3D::Value& aValue = *anIter;
+        vtkIdList* anIdList = vtkIdList::New();
+        anIdList->SetNumberOfIds(aValue.myPntIds.size());
+        bool isExist = true;
+        for (int i = 0; i < aValue.myPntIds.size(); ++i)
+        {
+          int aVTKId = myVisualObj->GetNodeVTKId(aValue.myPntIds[i]);
+          if (aVTKId < 0)
+          {
+            isExist = false;
+            break;
+          }
+          anIdList->SetId(i, aVTKId);
+        }
+        if (isExist)
+        {
+          aConnectivity->InsertNextCell(anIdList);
+          aCellTypesArray->InsertNextValue(VTK_POLYGON);
+          aScalars->SetValue(aNbCells, aValue.myWarp);
+          aNbCells++;
+        }
+      }
+      aCellTypesArray->SetNumberOfTuples(aNbCells);
+      aScalars->SetNumberOfTuples(aNbCells);
+
+      vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
+      aCellLocationsArray->SetNumberOfComponents(1);
+      aCellLocationsArray->SetNumberOfTuples(aNbCells);
+
+      aConnectivity->InitTraversal();
+      vtkIdType const* pts(nullptr);
+      for (vtkIdType idType = 0, npts; aConnectivity->GetNextCell(npts, pts); idType++)
+        aCellLocationsArray->SetValue(idType, aConnectivity->GetTraversalLocation(npts));
+
+      aDataSet->SetCells(aCellTypesArray, aCellLocationsArray, aConnectivity);
+      SetUnstructuredGrid(aDataSet);
+
+      aDataSet->GetCellData()->SetScalars(aScalars);
+      aScalars->Delete();
+
+      theLookupTable->SetRange(aScalars->GetRange());
+      theLookupTable->Build();
+
       myMergeFilter->SetScalarsData(aDataSet);
       aDataSet->Delete();
     }
@@ -570,7 +642,7 @@ SMESH_DeviceActor
     FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
     for(; anIter != aBorders.end(); anIter++){
       const FreeEdges::Border& aBorder = *anIter;
-      int aNode[2] = {
+      vtkIdType aNode[2] = {
         myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
         myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
       };
@@ -583,12 +655,13 @@ SMESH_DeviceActor
       }
     }
     
-    VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
+    vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
     aCellLocationsArray->SetNumberOfComponents( 1 );
     aCellLocationsArray->SetNumberOfTuples( aNbCells );
     
     aConnectivity->InitTraversal();
-    for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+    vtkIdType const *pts(nullptr);
+    for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
       aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
     
     aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
@@ -600,7 +673,7 @@ SMESH_DeviceActor
            ( aPredicate = dynamic_cast<CoincidentNodes*>(theFunctor.get())))
   {
     myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
-    vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
+    vtkIdType aNbNodes = FromSmIdType<vtkIdType>(myVisualObj->GetNbEntities(SMDSAbs_Node));
     for( vtkIdType i = 0; i < aNbNodes; i++ ){
       vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
       if(aPredicate->IsSatisfy(anObjId))
@@ -748,7 +821,7 @@ SMESH_DeviceActor
 {
   bool aShowFaceOrientation = myIsFacesOriented;
   aShowFaceOrientation &= vtkLODActor::GetVisibility(); //GetVisibility(); -- avoid calling GetUnstructuredGrid()  
-  aShowFaceOrientation &= myRepresentation == eSurface;
+  aShowFaceOrientation &= ( myRepresentation != ePoint );
   myFaceOrientation->SetVisibility(aShowFaceOrientation);
 }
 
@@ -779,6 +852,8 @@ SMESH_DeviceActor
     myGeomFilter->SetInside(false);
     myGeomFilter->SetWireframeMode(false);
     GetProperty()->SetRepresentation(theMode);
+  case eNoneRepr:
+    return;
   }
   SetMarkerEnabled(theMode == ePoint);
   myRepresentation = theMode;
@@ -835,9 +910,9 @@ SMESH_DeviceActor
 }
 
 
-int
+vtkIdType
 SMESH_DeviceActor
-::GetNodeObjId(int theVtkID)
+::GetNodeObjId(vtkIdType theVtkID)
 {
   vtkIdType anID = theVtkID;
 
@@ -845,25 +920,31 @@ SMESH_DeviceActor
     anID = myExtractGeometry->GetNodeObjId(theVtkID);
 
   vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
-  if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
+  MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
   return aRetID;
 }
 
 double* 
 SMESH_DeviceActor
-::GetNodeCoord(int theObjID)
+::GetNodeCoord(vtkIdType theObjID)
 {
   vtkDataSet* aDataSet = myMergeFilter->GetOutput();
   vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
   double* aCoord = (anID >=0 && anID < aDataSet->GetNumberOfPoints()) ? aDataSet->GetPoint(anID) : NULL;
-  if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
+  MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
   return aCoord;
 }
 
+vtkIdType
+SMESH_DeviceActor
+::GetNodeVtkId(vtkIdType theObjID) 
+{
+  return myVisualObj->GetNodeVTKId(theObjID);
+}
 
-int
+vtkIdType
 SMESH_DeviceActor
-::GetElemObjId(int theVtkID)
+::GetElemObjId(vtkIdType theVtkID)
 {
   vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
   if(anId < 0) 
@@ -880,20 +961,20 @@ SMESH_DeviceActor
     return -1;
 
   vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
-  if(MYDEBUG) 
-     MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
+
+  MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
   return aRetID;
 }
 
 vtkCell* 
 SMESH_DeviceActor
-::GetElemCell(int theObjID)
+::GetElemCell(vtkIdType theObjID)
 {
   vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
   vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
   vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
-  if(MYDEBUG) 
-    MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
+
+  MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
   return aCell;
 }