Salome HOME
Merge from V6_4_BR 05/12/2011
[modules/smesh.git] / src / SMDS / SMDS_VtkVolume.cxx
index b76fe9d65bbc2e0d2ed2d9ee3d8306a25d0e4375..d4f4a9abc4dbd76de601aba20c02f25c0871fb47 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2010-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "SMDS_VtkVolume.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_Mesh.hxx"
@@ -21,8 +40,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 +82,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,22 +95,27 @@ 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;
+      // EAP: a right approach is:
+      // - either the user should care of order of nodes or
+      // - the user should use a service method arranging nodes if he
+      //   don't want or can't to do it by him-self
+      // The method below works OK only with planar faces
+      //
+      // 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)
+      //if (isFaceForward)
         for (int n = 0; n < nf; n++)
           ptIds.push_back(facePts[n]);
-      else
-        for (int n = nf - 1; n >= 0; n--)
-          ptIds.push_back(facePts[n]);
+      // else
+      //   for (int n = nf - 1; n >= 0; n--)
+      //     ptIds.push_back(facePts[n]);
       k += nf;
     }
   myVtkID = grid->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]);
@@ -571,9 +595,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