Salome HOME
0020105: EDF 862 SMESH : Creation of the skin elements (2D) of a 3D Mesh
[modules/smesh.git] / src / SMESH / SMESH_MesherHelper.cxx
index 06a528ebb9827b23823a7a737220bbb888c9434e..0b7d4fb85e2ffe156a9dc859c65786086408d293 100644 (file)
@@ -54,6 +54,8 @@
 
 #include <utilities.h>
 
+#include <limits>
+
 #define RETURN_BAD_RESULT(msg) { MESSAGE(msg); return false; }
 
 namespace {
@@ -721,10 +723,14 @@ SMDS_MeshFace* SMESH_MesherHelper::AddFace(const SMDS_MeshNode* n1,
                                            const SMDS_MeshNode* n2,
                                            const SMDS_MeshNode* n3,
                                            const int id,
-                                          const bool force3d)
+                                           const bool force3d)
 {
   SMESHDS_Mesh * meshDS = GetMeshDS();
   SMDS_MeshFace* elem = 0;
+
+  if( n1==n2 || n2==n3 || n3==n1 )
+    return elem;
+
   if(!myCreateQuadratic) {
     if(id)
       elem = meshDS->AddFaceWithID(n1, n2, n3, id);
@@ -758,10 +764,30 @@ SMDS_MeshFace* SMESH_MesherHelper::AddFace(const SMDS_MeshNode* n1,
                                            const SMDS_MeshNode* n3,
                                            const SMDS_MeshNode* n4,
                                            const int id,
-                                          const bool force3d)
+                                           const bool force3d)
 {
   SMESHDS_Mesh * meshDS = GetMeshDS();
   SMDS_MeshFace* elem = 0;
+
+  if( n1==n2 ) {
+    return AddFace(n1,n3,n4,id,force3d);
+  }
+  if( n1==n3 ) {
+    return AddFace(n1,n2,n4,id,force3d);
+  }
+  if( n1==n4 ) {
+    return AddFace(n1,n2,n3,id,force3d);
+  }
+  if( n2==n3 ) {
+    return AddFace(n1,n2,n4,id,force3d);
+  }
+  if( n2==n4 ) {
+    return AddFace(n1,n2,n3,id,force3d);
+  }
+  if( n3==n4 ) {
+    return AddFace(n1,n2,n3,id,force3d);
+  }
+
   if(!myCreateQuadratic) {
     if(id)
       elem = meshDS->AddFaceWithID(n1, n2, n3, n4, id);
@@ -798,7 +824,7 @@ SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
                                                const SMDS_MeshNode* n5,
                                                const SMDS_MeshNode* n6,
                                                const int id,
-                                              const bool force3d)
+                                               const bool force3d)
 {
   SMESHDS_Mesh * meshDS = GetMeshDS();
   SMDS_MeshVolume* elem = 0;
@@ -845,7 +871,7 @@ SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
                                                const SMDS_MeshNode* n3,
                                                const SMDS_MeshNode* n4,
                                                const int id, 
-                                              const bool force3d)
+                                               const bool force3d)
 {
   SMESHDS_Mesh * meshDS = GetMeshDS();
   SMDS_MeshVolume* elem = 0;
@@ -887,7 +913,7 @@ SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
                                                const SMDS_MeshNode* n4,
                                                const SMDS_MeshNode* n5,
                                                const int id, 
-                                              const bool force3d)
+                                               const bool force3d)
 {
   SMDS_MeshVolume* elem = 0;
   if(!myCreateQuadratic) {
@@ -938,7 +964,7 @@ SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
                                                const SMDS_MeshNode* n7,
                                                const SMDS_MeshNode* n8,
                                                const int id,
-                                              const bool force3d)
+                                               const bool force3d)
 {
   SMESHDS_Mesh * meshDS = GetMeshDS();
   SMDS_MeshVolume* elem = 0;
@@ -1380,7 +1406,7 @@ namespace { // Structures used by FixQuadraticElements()
     bool IsBoundary() const { return !_qfaces[1]; }
 
     void RemoveFace( const QFace* face ) const
-    { _qfaces[(face == _qfaces[1])] = 0; if (!_qfaces[0]) swap(_qfaces[0],_qfaces[1]); }
+    { _qfaces[(face == _qfaces[1])] = 0; if (!_qfaces[0]) std::swap(_qfaces[0],_qfaces[1]); }
 
     const QFace* NextFace( const QFace* f ) const
     { return _qfaces[0]==f ? _qfaces[1] : _qfaces[0]; }
@@ -1399,7 +1425,7 @@ namespace { // Structures used by FixQuadraticElements()
   // --------------------------------------------------------------------
   typedef list< TChainLink > TChain;
   typedef set < TChainLink > TLinkSet;
-  typedef TLinkSet::iterator TLinkInSet;
+  typedef TLinkSet::const_iterator TLinkInSet;
 
   const int theFirstStep = 5;
 
@@ -1487,7 +1513,7 @@ namespace { // Structures used by FixQuadraticElements()
   ostream& operator << (ostream& out, const QFace& f)
   {
     out <<"QFace nodes: "/*<< &f << "  "*/;
-    for ( TIDSortedElemSet::iterator n = f.begin(); n != f.end(); ++n )
+    for ( TIDSortedElemSet::const_iterator n = f.begin(); n != f.end(); ++n )
       out << (*n)->GetID() << " ";
     out << " \tvolumes: "
         << (f._volumes[0] ? f._volumes[0]->GetID() : 0) << " "
@@ -1834,7 +1860,7 @@ namespace { // Structures used by FixQuadraticElements()
     if ( iFaceCont > 0 ) // continues faces found, set one by the other
     {
       if ( iFaceCont != 1 )
-        swap( _faces[1], _faces[iFaceCont] );
+        std::swap( _faces[1], _faces[iFaceCont] );
     }
     else if ( _faces.size() > 1 ) // not found, set NULL by the first face
     {
@@ -1929,7 +1955,7 @@ namespace { // Structures used by FixQuadraticElements()
         }
       }
       curBndLinks->clear();
-      swap( curBndLinks, newBndLinks );
+      std::swap( curBndLinks, newBndLinks );
     }
   }