Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_3D.cxx
index 4620967b3137f4649c61ae2ff2d40ebb097dc94a..c9031d88c7a75a0af4b065a186f241e37b9bb90b 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS, L3S, LJLL, MENSI
+//
+// 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
+//
 //=============================================================================
 // File      : NETGENPlugin_NETGEN_3D.cxx
 //             Moved here from SMESH_NETGEN_3D.cxx
@@ -17,6 +36,7 @@ using namespace std;
 #include "SMESHDS_Mesh.hxx"
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
+#include "SMESH_MesherHelper.hxx"
 
 #include <BRep_Tool.hxx>
 #include <TopExp.hxx>
@@ -33,7 +53,10 @@ using namespace std;
   Netgen include files
 */
 
-#include "nglib.h"
+namespace nglib {
+#include <nglib.h>
+}
+using namespace nglib;
 
 //=============================================================================
 /*!
@@ -137,6 +160,9 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
   // get triangles on aShell and make a map of nodes to Netgen node IDs
   // -------------------------------------------------------------------
 
+  SMESH_MesherHelper* myTool = new SMESH_MesherHelper(aMesh);
+  bool _quadraticMesh = myTool->IsQuadraticSubMesh(aShape);
+
   typedef map< const SMDS_MeshNode*, int> TNodeToIDMap;
   TNodeToIDMap nodeToNetgenID;
   list< const SMDS_MeshElement* > triangles;
@@ -161,8 +187,10 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
       {
         // check element
         const SMDS_MeshElement* elem = iteratorElem->next();
-        if ( !elem || elem->NbNodes() != 3 ) {
+        if ( !elem ||
+             !( elem->NbNodes()==3 || ( _quadraticMesh && elem->NbNodes()==6) ) ) {
           INFOS( "NETGENPlugin_NETGEN_3D::Compute(), bad mesh");
+          delete myTool; myTool = 0;
           return false;
         }
         // keep a triangle
@@ -173,6 +201,8 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
         while ( triangleNodesIt->more() ) {
          const SMDS_MeshNode * node =
             static_cast<const SMDS_MeshNode *>(triangleNodesIt->next());
+          if(myTool->IsMedium(node))
+            continue;
           nodeToNetgenID.insert( make_pair( node, invalid_ID ));
         }
 #ifdef _DEBUG_
@@ -245,6 +275,7 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
     if ( isDegen ) // all nodes on a degen edge get one netgen ID
       *(shId_ngId->second) = n_id->second;
   }
+
   // set triangles
   list< const SMDS_MeshElement* >::iterator tria = triangles.begin();
   list< bool >::iterator                 reverse = isReversed.begin();
@@ -255,6 +286,8 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
     while ( triangleNodesIt->more() ) {
       const SMDS_MeshNode * node =
         static_cast<const SMDS_MeshNode *>(triangleNodesIt->next());
+      if(myTool->IsMedium(node))
+        continue;
       Netgen_triangle[ *reverse ? 2 - i : i ] = nodeToNetgenID[ node ];
       ++i;
     }
@@ -280,7 +313,8 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
 
   try {
     status = Ng_GenerateVolumeMesh(Netgen_mesh, &Netgen_param);
-  } catch (...) {
+  }
+  catch (...) {
     MESSAGE("An exception has been caught during the Volume Mesh Generation ...");
     status = NG_VOLUME_FAILURE;
   }
@@ -303,8 +337,9 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
     // vector of nodes in which node index == netgen ID
     vector< const SMDS_MeshNode* > nodeVec ( Netgen_NbOfNodesNew + 1 );
     // insert old nodes into nodeVec
-    for ( n_id = nodeToNetgenID.begin(); n_id != nodeToNetgenID.end(); ++n_id )
+    for ( n_id = nodeToNetgenID.begin(); n_id != nodeToNetgenID.end(); ++n_id ) {
       nodeVec.at( n_id->second ) = n_id->first;
+    }
     // create and insert new nodes into nodeVec
     int nodeIndex = Netgen_NbOfNodes + 1;
     int shapeID = meshDS->ShapeToIndex( aShape );
@@ -322,7 +357,7 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
     for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex )
     {
       Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron);
-      SMDS_MeshVolume * elt = meshDS->AddVolume (nodeVec.at( Netgen_tetrahedron[0] ),
+      SMDS_MeshVolume * elt = myTool->AddVolume (nodeVec.at( Netgen_tetrahedron[0] ),
                                                  nodeVec.at( Netgen_tetrahedron[1] ),
                                                  nodeVec.at( Netgen_tetrahedron[2] ),
                                                  nodeVec.at( Netgen_tetrahedron[3] ));
@@ -333,6 +368,8 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh&         aMesh,
   Ng_DeleteMesh(Netgen_mesh);
   Ng_Exit();
 
+  delete myTool; myTool = 0;
+
   return isOK;
 }