Salome HOME
Fix for the issue "21203: EDF 1797 SMESH: SIGSEGV with move node on a Mesh with 0D...
[modules/smesh.git] / src / SMDS / SMDS_VtkVolume.cxx
index 45c61be31c0a5877e99cefded937d49482cfee12..15664b6107a1f1b7899a97c7528c0ecf5a961f80 100644 (file)
@@ -21,8 +21,8 @@ SMDS_VtkVolume::SMDS_VtkVolume(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
  */
 void SMDS_VtkVolume::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
 {
+  SMDS_MeshVolume::init();
   vtkUnstructuredGrid* grid = mesh->getGrid();
-  myIdInShape = -1;
   myMeshId = mesh->getMeshId();
   vtkIdType aType = VTK_TETRA;
   switch (nodeIds.size())
@@ -63,9 +63,9 @@ void SMDS_VtkVolume::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
 //#ifdef VTK_HAVE_POLYHEDRON
 void SMDS_VtkVolume::initPoly(std::vector<vtkIdType> nodeIds, std::vector<int> nbNodesPerFace, SMDS_Mesh* mesh)
 {
-  MESSAGE("SMDS_VtkVolume::initPoly");
+  SMDS_MeshVolume::init();
+  //MESSAGE("SMDS_VtkVolume::initPoly");
   SMDS_UnstructuredGrid* grid = mesh->getGrid();
-  // TODO is it useful to orient faces ?
   double center[3];
   this->gravityCenter(grid, &nodeIds[0], nodeIds.size(), &center[0]);
   vector<vtkIdType> ptIds;
@@ -76,14 +76,13 @@ void SMDS_VtkVolume::initPoly(std::vector<vtkIdType> nodeIds, std::vector<int> n
     {
       int nf = nbNodesPerFace[i];
       ptIds.push_back(nf);
-//      double a[3];
-//      double b[3];
-//      double c[3];
-//      grid->GetPoints()->GetPoint(nodeIds[k], a);
-//      grid->GetPoints()->GetPoint(nodeIds[k + 1], b);
-//      grid->GetPoints()->GetPoint(nodeIds[k + 2], c);
-//      bool isFaceForward = this->isForward(a, b, c, center);
-      bool isFaceForward = true;
+      double a[3];
+      double b[3];
+      double c[3];
+      grid->GetPoints()->GetPoint(nodeIds[k], a);
+      grid->GetPoints()->GetPoint(nodeIds[k + 1], b);
+      grid->GetPoints()->GetPoint(nodeIds[k + 2], c);
+      bool isFaceForward = this->isForward(a, b, c, center);
       //MESSAGE("isFaceForward " << i << " " << isFaceForward);
       vtkIdType *facePts = &nodeIds[k];
       if (isFaceForward)
@@ -171,6 +170,7 @@ bool SMDS_VtkVolume::vtkOrder(const SMDS_MeshNode* nodes[], const int nbNodes)
     default:
       break;
   }
+  return true;
 }
 
 SMDS_VtkVolume::~SMDS_VtkVolume()
@@ -355,7 +355,7 @@ const SMDS_MeshNode* SMDS_VtkVolume::GetFaceNode(const int face_ind, const int n
 /*! polyhedron only,
  *  return number of nodes for each face
  */
-const std::vector<int> SMDS_VtkVolume::GetQuantities() const
+const std::vector<int> SMDS_VtkVolume::GetQuantities() const
 {
   vector<int> quantities;
   quantities.clear();
@@ -570,9 +570,10 @@ bool SMDS_VtkVolume::isForward(double* a, double* b, double* c, double* d)
       w[j] = d[j] - a[j];
       //MESSAGE("u,v,w " << u[j] << " " << v[j] << " " << w[j]);
     }
-  double prodmixte = (u[2] * v[3] - u[3] * v[2]) * w[1] + (u[3] * v[1] - u[1] * v[3]) * w[2] + (u[1] * v[2] - u[2]
-      * v[1]) * w[3];
-  return (prodmixte >= 0);
+  double prodmixte = (u[1]*v[2] - u[2]*v[1]) * w[0]
+                   + (u[2]*v[0] - u[0]*v[2]) * w[1]
+                   + (u[0]*v[1] - u[1]*v[0]) * w[2];
+  return (prodmixte < 0);
 }
 
 /*! For polyhedron only