Salome HOME
PAL7358. Take care of orientation when creating volumes
authoreap <eap@opencascade.com>
Fri, 21 Jan 2005 13:12:53 +0000 (13:12 +0000)
committereap <eap@opencascade.com>
Fri, 21 Jan 2005 13:12:53 +0000 (13:12 +0000)
src/StdMeshers/StdMeshers_Hexa_3D.cxx
src/StdMeshers/StdMeshers_Penta_3D.cxx

index f80cd53..1eea741 100644 (file)
@@ -37,6 +37,8 @@ using namespace std;
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_FacePosition.hxx"
+#include "SMDS_VolumeTool.hxx"
+#include "SMDS_VolumeOfNodes.hxx"
 
 #include <TopExp.hxx>
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
@@ -56,7 +58,7 @@ using namespace std;
 #include "Utils_ExceptHandlers.hxx"
 
 //modified by NIZNHY-PKV Wed Nov 17 15:31:58 2004 f
-#include <StdMeshers_Penta_3D.hxx>
+#include "StdMeshers_Penta_3D.hxx"
 
 static bool ComputePentahedralMesh(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
 //modified by NIZNHY-PKV Wed Nov 17 15:32:00 2004 t
@@ -701,11 +703,34 @@ bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
                }
        }
 
+  // find orientation of furute volumes according to MED convention
+  vector< bool > forward( nbx * nby );
+  SMDS_VolumeTool vTool;
+  for (int i = 0; i < nbx - 1; i++)
+    for (int j = 0; j < nby - 1; j++)
+    {
+      int n1 = j * nbx + i;
+      int n2 = j * nbx + i + 1;
+      int n3 = (j + 1) * nbx + i + 1;
+      int n4 = (j + 1) * nbx + i;
+      int n5 = nbx * nby + j * nbx + i;
+      int n6 = nbx * nby + j * nbx + i + 1;
+      int n7 = nbx * nby + (j + 1) * nbx + i + 1;
+      int n8 = nbx * nby + (j + 1) * nbx + i;
+
+      SMDS_VolumeOfNodes tmpVol (np[n1].node,np[n2].node,np[n3].node,np[n4].node,
+                                 np[n5].node,np[n6].node,np[n7].node,np[n8].node);
+      vTool.Set( &tmpVol );
+      forward[ n1 ] = vTool.IsForward();
+    }
+
        //2.1 - for each node of the cube (less 3 *1 Faces):
        //      - store hexahedron in SMESHDS
        MESSAGE("Storing hexahedron into the DS");
        for (int i = 0; i < nbx - 1; i++)
                for (int j = 0; j < nby - 1; j++)
+                {
+                        bool isForw = forward.at( j * nbx + i );
                        for (int k = 0; k < nbz - 1; k++)
                        {
                                int n1 = k * nbx * nby + j * nbx + i;
@@ -717,46 +742,32 @@ bool StdMeshers_Hexa_3D::Compute(SMESH_Mesh & aMesh,
                                int n7 = (k + 1) * nbx * nby + (j + 1) * nbx + i + 1;
                                int n8 = (k + 1) * nbx * nby + (j + 1) * nbx + i;
 
-//    MESSAGE(" "<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<" "<<n7<<" "<<n8);
-                               //MESSAGE(" "<<np[n1].nodeId<<" "<<np[n2].nodeId<<" "<<np[n3].nodeId<<" "<<np[n4].nodeId<<" "<<np[n5].nodeId<<" "<<np[n6].nodeId<<" "<<np[n7].nodeId<<" "<<np[n8].nodeId);
-
-                               SMDS_MeshVolume * elt = meshDS->AddVolume(np[n1].node,
-                                       np[n2].node,
-                                       np[n3].node,
-                                       np[n4].node,
-                                       np[n5].node,
-                                       np[n6].node,
-                                       np[n7].node,
-                                       np[n8].node);
-                                ;
-                               meshDS->SetMeshElementOnShape(elt, aShell);
+                               SMDS_MeshVolume * elt;
+                                if ( isForw )
+                                  elt = meshDS->AddVolume(np[n1].node,
+                                                          np[n2].node,
+                                                          np[n3].node,
+                                                          np[n4].node,
+                                                          np[n5].node,
+                                                          np[n6].node,
+                                                          np[n7].node,
+                                                          np[n8].node);
+                                else
+                                  elt = meshDS->AddVolume(np[n1].node,
+                                                          np[n4].node,
+                                                          np[n3].node,
+                                                          np[n2].node,
+                                                          np[n5].node,
+                                                          np[n8].node,
+                                                          np[n7].node,
+                                                          np[n6].node);
 
-                               // *** 5 tetrahedres ... verifier orientations,
-                               //     mettre en coherence &vec quadrangles-> triangles
-                               //     choisir afficher 1 parmi edges, face et volumes
-//    int tetra1 = meshDS->AddVolume(np[n1].nodeId,
-//                   np[n2].nodeId,
-//                   np[n4].nodeId,
-//                   np[n5].nodeId);
-//    int tetra2 = meshDS->AddVolume(np[n2].nodeId,
-//                   np[n3].nodeId,
-//                   np[n4].nodeId,
-//                   np[n7].nodeId);
-//    int tetra3 = meshDS->AddVolume(np[n5].nodeId,
-//                   np[n6].nodeId,
-//                   np[n7].nodeId,
-//                   np[n2].nodeId);
-//    int tetra4 = meshDS->AddVolume(np[n5].nodeId,
-//                   np[n7].nodeId,
-//                   np[n8].nodeId,
-//                   np[n4].nodeId);
-//    int tetra5 = meshDS->AddVolume(np[n5].nodeId,
-//                   np[n7].nodeId,
-//                   np[n2].nodeId,
-//                   np[n4].nodeId);
+                               meshDS->SetMeshElementOnShape(elt, aShell);
 
-                       }
 
+                              }
+                      }
+  if ( np ) delete [] np;
        //MESSAGE("End of StdMeshers_Hexa_3D::Compute()");
        return true;
 }
index 30362f4..90dbd5d 100644 (file)
 //  File   : StdMeshers_Penta_3D.cxx
 //  Module : SMESH
 
-using namespace std;
-
-#include <StdMeshers_Penta_3D.hxx>
-
-#include <stdio.h>
-
-#include <algorithm>
+#include "StdMeshers_Penta_3D.hxx"
 
 #include "utilities.h"
 #include "Utils_ExceptHandlers.hxx"
 
+#include "SMDS_MeshElement.hxx"
+#include "SMDS_VolumeOfNodes.hxx"
+#include "SMDS_VolumeTool.hxx"
+#include "SMESHDS_SubMesh.hxx"
+#include "SMESH_Mesh.hxx"
+#include "SMESH_subMesh.hxx"
+
+#include <BRep_Tool.hxx>
 #include <TopAbs_ShapeEnum.hxx>
-#include <TopTools_IndexedMapOfShape.hxx>
 #include <TopExp.hxx>
-#include <SMESH_Mesh.hxx>
-#include <SMESH_subMesh.hxx>
-#include <SMESHDS_SubMesh.hxx>
-
-#include <SMDS_MeshElement.hxx>
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Edge.hxx>
 #include <TopoDS.hxx>
-#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
-#include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <gp_Pnt.hxx>
-#include <BRep_Tool.hxx>
+#include <TopoDS_Edge.hxx>
 #include <TopoDS_Shell.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <gp_Pnt.hxx>
+
+#include <stdio.h>
+#include <algorithm>
+
+using namespace std;
 
 typedef map < int, int, less<int> >::iterator   \
   StdMeshers_IteratorOfDataMapOfIntegerInteger;
@@ -380,11 +381,12 @@ void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
 {
   myErrorStatus=0;
   //
-  double aX, aY, aZ, aD, aTol2;
+  double aX, aY, aZ, aD, aTol2, minD;
   gp_Pnt aP1, aP2;
   //
   SMESH_Mesh* pMesh=GetMesh();
   aTol2=myTol3D*myTol3D;
+  minD = 1.e100;
   SMDS_MeshNode* pNode=NULL;
   //
   myBlock.Point(aParams, aS, aP1);
@@ -399,18 +401,20 @@ void StdMeshers_Penta_3D::FindNodeOnShape(const TopoDS_Shape& aS,
     aP2.SetCoord(aX, aY, aZ);
     aD=(double)aP1.SquareDistance(aP2);
     //printf("** D=%lf ", aD, aTol2);
-    if (aD<aTol2) {
+    if (aD < minD) {
       pNode=(SMDS_MeshNode*)aNode;
       aTN.SetNode(pNode);
+      minD = aD;
       //printf(" Ok\n");
-      return; 
+      if (aD<aTol2)
+        return; 
     }
   }
   //
   //printf(" KO\n");
-  aTN.SetNode(pNode);
-  MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
-  myErrorStatus=11; // can not find the node;
+  //aTN.SetNode(pNode);
+  //MESSAGE("StdMeshers_Penta_3D::FindNodeOnShape(), can not find the node");
+  //myErrorStatus=11; // can not find the node;
 }
 
 //=======================================================================
@@ -482,6 +486,7 @@ void StdMeshers_Penta_3D::MakeVolumeMesh()
       ++k;
     }
     //
+    bool forward = true;
     for (i=0; i<ik; ++i){
       i1=i;
       i2=i+1;
@@ -496,16 +501,45 @@ void StdMeshers_Penta_3D::MakeVolumeMesh()
        const SMDS_MeshNode* aN2=aTN2.Node();
        aN[j+nbFaceNodes]=aN2;
       }
-      //
+      // check if volume orientation will be ok
+      if ( i == 0 ) {
+        SMDS_VolumeTool vTool;
+        switch ( nbFaceNodes ) {
+        case 3: {
+          SMDS_VolumeOfNodes tmpVol (aN[0], aN[1], aN[2],
+                                     aN[3], aN[4], aN[5]);
+          vTool.Set( &tmpVol );
+          break;
+        }
+        case 4: {
+          SMDS_VolumeOfNodes tmpVol(aN[0], aN[1], aN[2], aN[3],
+                                    aN[4], aN[5], aN[6], aN[7]);
+          vTool.Set( &tmpVol );
+          break;
+        }
+        default:
+          continue;
+        }
+        forward = vTool.IsForward();
+      }
+      // add volume
       SMDS_MeshVolume* aV = 0;
       switch ( nbFaceNodes ) {
       case 3:
-       aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
-                               aN[3], aN[4], aN[5]);
+        if ( forward )
+          aV = meshDS->AddVolume(aN[0], aN[1], aN[2],
+                                 aN[3], aN[4], aN[5]);
+        else
+          aV = meshDS->AddVolume(aN[0], aN[2], aN[1],
+                                 aN[3], aN[5], aN[4]);
         break;
       case 4:
-       aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
-                               aN[4], aN[5], aN[6], aN[7]);
+        if ( forward )
+          aV = meshDS->AddVolume(aN[0], aN[1], aN[2], aN[3],
+                                 aN[4], aN[5], aN[6], aN[7]);
+        else
+          aV = meshDS->AddVolume(aN[0], aN[3], aN[2], aN[1],
+                                 aN[4], aN[7], aN[6], aN[5]);
         break;
       default:
         continue;