Salome HOME
bos #20256: [CEA 18523] Porting SMESH to int 64 bits
[modules/smesh.git] / src / SMDS / SMDS_MeshVolume.cxx
index 755285447cb721d880293adb649e1a32a9fcedea..8147520c50b3f695dc35643df15254791561a062 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -50,7 +50,7 @@ void SMDS_MeshVolume::init( const std::vector<const SMDS_MeshNode*>& nodes,
       ptIds.push_back( nodes[ iN++ ]->GetVtkID() );
   }
 
-  int vtkID = getGrid()->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]);
+  vtkIdType vtkID = getGrid()->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]);
   setVtkID( vtkID );
 }
 
@@ -75,20 +75,60 @@ void SMDS_MeshVolume::init( const std::vector<vtkIdType>& vtkNodeIds )
   SMDS_MeshCell::init( aType, vtkNodeIds );
 }
 
+bool SMDS_MeshVolume::ChangeNodes(const std::vector<const SMDS_MeshNode*>& nodes,
+                                  const std::vector<int>&                  quantities) const
+{
+  if ( !IsPoly() )
+    return false;
+
+  vtkIdType nFaces = 0;
+  vtkIdType const *tmp(nullptr);
+  getGrid()->GetFaceStream( GetVtkID(), nFaces, tmp );
+  vtkIdType *ptIds = const_cast<vtkIdType*>( tmp );
+
+  // stream size and nb faces should not change
+
+  if ((int) quantities.size() != nFaces )
+  {
+    return false;
+  }
+  size_t id = 0, nbPoints = 0;
+  for ( int i = 0; i < nFaces; i++ )
+  {
+    int nodesInFace = ptIds[id];
+    nbPoints += nodesInFace;
+    id += (nodesInFace + 1);
+  }
+  if ( nodes.size() != nbPoints )
+  {
+    return false;
+  }
+
+  // update ptIds
+  size_t iP = 0, iN = 0;
+  for ( size_t i = 0; i < quantities.size(); ++i )
+  {
+    ptIds[ iP++ ] = quantities[ i ]; // nb face nodes
+    for ( int j = 0; j < quantities[ i ]; ++j )
+      ptIds[ iP++ ] = nodes[ iN++ ]->GetVtkID();
+  }
+  return true;
+}
+
 const SMDS_MeshNode* SMDS_MeshVolume::GetNode(const int ind) const
 {
   if ( !IsPoly() )
     return SMDS_MeshCell::GetNode( ind );
 
   vtkIdType nFaces = 0;
-  vtkIdType* ptIds = 0;
+  vtkIdType const *ptIds(nullptr);
   getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
   int id = 0, nbPoints = 0;
   for (int i = 0; i < nFaces; i++)
   {
     int nodesInFace = ptIds[id];
     if ( ind < nbPoints + nodesInFace )
-      return GetMesh()->FindNodeVtk( ptIds[ ind + i ]);
+      return GetMesh()->FindNodeVtk( ptIds[ 1 + ind + i ]);
     nbPoints += nodesInFace;
     id += (nodesInFace + 1);
   }
@@ -100,7 +140,7 @@ int SMDS_MeshVolume::NbNodes() const
     return SMDS_MeshCell::NbNodes();
 
   vtkIdType nFaces = 0;
-  vtkIdType* ptIds = 0;
+  vtkIdType const *ptIds(nullptr);
   getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
   int id = 0, nbPoints = 0;
   for (int i = 0; i < nFaces; i++)
@@ -118,7 +158,7 @@ int SMDS_MeshVolume::NbFaces() const
     return SMDS_MeshCell::NbFaces();
 
   vtkIdType nFaces = 0;
-  vtkIdType* ptIds = 0;
+  vtkIdType const *ptIds(nullptr);
   getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
   return nFaces;
   
@@ -129,7 +169,7 @@ int SMDS_MeshVolume::NbEdges() const
     return SMDS_MeshCell::NbEdges();
 
   vtkIdType nFaces = 0;
-  vtkIdType* ptIds = 0;
+  vtkIdType const *ptIds(nullptr);
   getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
   int id = 0, nbEdges = 0;
   for (int i = 0; i < nFaces; i++)
@@ -148,7 +188,7 @@ int SMDS_MeshVolume::GetNodeIndex( const SMDS_MeshNode* node ) const
     return SMDS_MeshCell::GetNodeIndex( node );
 
   vtkIdType nFaces = 0;
-  vtkIdType* ptIds = 0;
+  vtkIdType const *ptIds(nullptr);
   getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
   int id = 0;
   for (int iF = 0; iF < nFaces; iF++)
@@ -161,7 +201,7 @@ int SMDS_MeshVolume::GetNodeIndex( const SMDS_MeshNode* node ) const
   }
   return -1;
 }
-bool SMDS_MeshVolume::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
+bool SMDS_MeshVolume::ChangeNodes(const SMDS_MeshNode* /*nodes*/[], const int /*nbNodes*/)
 {
   return false;
 }
@@ -188,7 +228,7 @@ int SMDS_MeshVolume::NbFaceNodes (const int face_ind) const
     return SMDS_VolumeTool( this ).NbFaceNodes( face_ind-1 );
 
   vtkIdType nFaces = 0;
-  vtkIdType* ptIds = 0;
+  vtkIdType const *ptIds(nullptr);
   getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
   int id = 0, nbNodes = 0;
   for (int i = 0; i < nFaces; i++)
@@ -210,7 +250,7 @@ const SMDS_MeshNode* SMDS_MeshVolume::GetFaceNode (const int face_ind, const int
     return SMDS_VolumeTool( this ).GetFaceNodes( face_ind-1 )[ node_ind - 1 ];
 
   vtkIdType nFaces = 0;
-  vtkIdType* ptIds = 0;
+  vtkIdType const *ptIds(nullptr);
   getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds);
   int id = 0;
   for (int i = 0; i < nFaces; i++)
@@ -232,7 +272,7 @@ std::vector<int> SMDS_MeshVolume::GetQuantities() const
   if ( IsPoly() )
   {
     vtkIdType nFaces = 0;
-    vtkIdType* ptIds = 0;
+    vtkIdType const *ptIds(nullptr);
     getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
     int id = 0;
     for (int i = 0; i < nFaces; i++)