Salome HOME
Merge branch 'rnc/zcracks_doc_integration'
authorRenaud Nédélec <renaud.nedelec@opencascade.com>
Thu, 24 Apr 2014 08:34:21 +0000 (10:34 +0200)
committerRenaud Nédélec <renaud.nedelec@opencascade.com>
Thu, 24 Apr 2014 08:34:21 +0000 (10:34 +0200)
17 files changed:
CMakeLists.txt
src/SMESH/SMESH_MeshEditor.cxx
src/SMESH/SMESH_MesherHelper.cxx
src/SMESH/SMESH_Pattern.cxx
src/SMESH/SMESH_subMesh.cxx
src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx
src/SMESHGUI/SMESHGUI_FilterLibraryDlg.h
src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx
src/SMESHUtils/SMESH_OctreeNode.cxx
src/SMESH_SWIG/smeshBuilder.py
src/StdMeshers/StdMeshers_Cartesian_3D.cxx
src/StdMeshers/StdMeshers_Import_1D2D.cxx
src/StdMeshers/StdMeshers_Quadrangle_2D.cxx
src/StdMeshers/StdMeshers_ViscousLayers.cxx
src/Tools/padder/doc/images/padder_curvedgeom.png [new file with mode: 0644]
src/Tools/padder/doc/images/padder_sphererendering.png
src/Tools/padder/doc/input/padder_userguide.doc

index 4dd5f2eb1d3e738d44affa3307d3f2f5d98b2168..249c3c09dcfc18a3965cde005f4b3c8c2ee71cb3 100755 (executable)
@@ -28,11 +28,11 @@ CMAKE_POLICY(SET CMP0003 NEW)
 STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC)
 
 SET(${PROJECT_NAME_UC}_MAJOR_VERSION 7)
-SET(${PROJECT_NAME_UC}_MINOR_VERSION 3)
-SET(${PROJECT_NAME_UC}_PATCH_VERSION 1)
+SET(${PROJECT_NAME_UC}_MINOR_VERSION 4)
+SET(${PROJECT_NAME_UC}_PATCH_VERSION 0)
 SET(${PROJECT_NAME_UC}_VERSION
   ${${PROJECT_NAME_UC}_MAJOR_VERSION}.${${PROJECT_NAME_UC}_MINOR_VERSION}.${${PROJECT_NAME_UC}_PATCH_VERSION})
-SET(${PROJECT_NAME_UC}_VERSION_DEV 1)
+SET(${PROJECT_NAME_UC}_VERSION_DEV 0)
 
 # Find KERNEL
 # ===========
index 931caa43414d2a0aea00e1bffb4e2a288bf62963..0e4aa3de26f079290297634fabb4806b5881de76 100644 (file)
@@ -1174,7 +1174,7 @@ int SMESH_MeshEditor::Reorient2D (TIDSortedElemSet &       theFaces,
     avoidSet.clear();
     avoidSet.insert(theFace);
 
-    NLink link( theFace->GetNode( 0 ), 0 );
+    NLink link( theFace->GetNode( 0 ), (SMDS_MeshNode *) 0 );
 
     const int nbNodes = theFace->NbCornerNodes();
     for ( int i = 0; i < nbNodes; ++i ) // loop on links of theFace
@@ -1615,7 +1615,7 @@ namespace
     };
   const int theHexTo4Prisms_FB[6*4+1] = // front-back
     {
-      0, 3, 8, 1, 2, 9,    3, 7, 8, 2, 6, 9,    7, 4, 8, 6, 5, 9,   4, 0, 8, 5, 1, 9,    -1
+      0, 3, 9, 1, 2, 8,    3, 7, 9, 2, 6, 8,    7, 4, 9, 6, 5, 8,   4, 0, 9, 5, 1, 8,    -1
     };
 
   const int theHexTo2Prisms_BT_1[6*2+1] =
index a53e644d88f612d30667acc92b14654c36b91f69..784853234b4157551317d0220806b50bffa94f06 100644 (file)
@@ -1436,6 +1436,7 @@ const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1,
     catch ( Standard_Failure& f )
     {
       // issue 22502 / a node is on VERTEX not belonging to E
+      // issue 22568 / both nodes are on non-connected VERTEXes
       return getMediumNodeOnComposedWire(n1,n2,force3d);
     }
   }
@@ -1535,67 +1536,108 @@ const SMDS_MeshNode* SMESH_MesherHelper::getMediumNodeOnComposedWire(const SMDS_
                                                                      const SMDS_MeshNode* n2,
                                                                      bool                 force3d)
 {
-  gp_Pnt middle = 0.5 * XYZ(n1) + 0.5 * XYZ(n2);
+  SMESH_TNodeXYZ p1( n1 ), p2( n2 );
+  gp_Pnt      middle = 0.5 * p1 + 0.5 * p2;
   SMDS_MeshNode* n12 = AddNode( middle.X(), middle.Y(), middle.Z() );
 
   // To find position on edge and 3D position for n12,
   // project <middle> to 2 edges and select projection most close to <middle>
 
-  double u = 0, distMiddleProj = Precision::Infinite(), distXYZ[4];
-  int iOkEdge = 0;
-  TopoDS_Edge edges[2];
+  TopoDS_Edge bestEdge;
+  double u = 0, distMiddleProj = Precision::Infinite(), distXYZ[4], f,l;
+
+  // get shapes under the nodes
+  TopoDS_Shape shape[2];
+  int nbShapes = 0;
   for ( int is2nd = 0; is2nd < 2; ++is2nd )
   {
-    // get an edge
     const SMDS_MeshNode* n = is2nd ? n2 : n1;
-    TopoDS_Shape shape = GetSubShapeByNode( n, GetMeshDS() );
-    if ( shape.IsNull() || shape.ShapeType() != TopAbs_EDGE )
-      continue;
+    TopoDS_Shape S = GetSubShapeByNode( n, GetMeshDS() );
+    if ( !S.IsNull() )
+      shape[ nbShapes++ ] = S;
+  }
+  // get EDGEs
+  vector< TopoDS_Shape > edges;
+  for ( int iS = 0; iS < nbShapes; ++iS )
+  {
+    switch ( shape[iS].ShapeType() ) {
+    case TopAbs_EDGE:
+    {
+      edges.push_back( shape[iS] );
+      break;
+    }
+    case TopAbs_VERTEX:
+    {
+      TopoDS_Shape edge;
+      if ( nbShapes == 2 && iS==0 && shape[1-iS].ShapeType() == TopAbs_VERTEX )
+        edge = GetCommonAncestor( shape[iS], shape[1-iS], *myMesh, TopAbs_EDGE );
 
-    // project to get U of projection and distance from middle to projection
-    TopoDS_Edge edge = edges[ is2nd ] = TopoDS::Edge( shape );
-    double node2MiddleDist = middle.Distance( XYZ(n) );
-    double foundU = GetNodeU( edge, n );
-    CheckNodeU( edge, n12, foundU, 2*BRep_Tool::Tolerance(edge), /*force=*/true, distXYZ );
-    if ( distXYZ[0] < node2MiddleDist )
+      if ( edge.IsNull() )
+      {
+        PShapeIteratorPtr eIt = GetAncestors( shape[iS], *myMesh, TopAbs_EDGE );
+        while( const TopoDS_Shape* e = eIt->next() )
+          edges.push_back( *e );
+      }
+      break;
+    }
+    case TopAbs_FACE:
     {
-      distMiddleProj = distXYZ[0];
-      u = foundU;
-      iOkEdge = is2nd;
+      if ( nbShapes == 1 || shape[1-iS].ShapeType() < TopAbs_EDGE )
+        for ( TopExp_Explorer e( shape[iS], TopAbs_EDGE ); e.More(); e.Next() )
+          edges.push_back( e.Current() );
+      break;
+    }
+    default:
+      continue;
     }
   }
-  if ( Precision::IsInfinite( distMiddleProj ))
+  // project to get U of projection and distance from middle to projection
+  for ( size_t iE = 0; iE < edges.size(); ++iE )
   {
-    // both projections failed; set n12 on the edge of n1 with U of a common vertex
-    TopoDS_Vertex vCommon;
-    if ( TopExp::CommonVertex( edges[0], edges[1], vCommon ))
-      u = BRep_Tool::Parameter( vCommon, edges[0] );
-    else
+    const TopoDS_Edge& edge = TopoDS::Edge( edges[ iE ]);
+    distXYZ[0] = distMiddleProj;
+    double testU = 0;
+    CheckNodeU( edge, n12, testU, 2 * BRep_Tool::Tolerance(edge), /*force=*/true, distXYZ );
+    if ( distXYZ[0] < distMiddleProj )
     {
-      double f,l, u0 = GetNodeU( edges[0], n1 );
-      BRep_Tool::Range( edges[0],f,l );
-      u = ( fabs(u0-f) < fabs(u0-l) ) ? f : l;
+      distMiddleProj = distXYZ[0];
+      u = testU;
+      bestEdge = edge;
     }
-    iOkEdge = 0;
-    distMiddleProj = 0;
   }
-
-  // move n12 to position of a successfull projection
-  double tol = BRep_Tool::Tolerance(edges[ iOkEdge ]);
-  if ( !force3d && distMiddleProj > 2*tol )
+  // {
+  //   // both projections failed; set n12 on the edge of n1 with U of a common vertex
+  //   TopoDS_Vertex vCommon;
+  //   if ( TopExp::CommonVertex( edges[0], edges[1], vCommon ))
+  //     u = BRep_Tool::Parameter( vCommon, edges[0] );
+  //   else
+  //   {
+  //     double f,l, u0 = GetNodeU( edges[0], n1 );
+  //     BRep_Tool::Range( edges[0],f,l );
+  //     u = ( fabs(u0-f) < fabs(u0-l) ) ? f : l;
+  //   }
+  //   iOkEdge = 0;
+  //   distMiddleProj = 0;
+  // }
+
+  if ( !bestEdge.IsNull() )
   {
-    TopLoc_Location loc; double f,l;
-    Handle(Geom_Curve) curve = BRep_Tool::Curve( edges[iOkEdge],loc,f,l );
-    gp_Pnt p = curve->Value( u );
-    GetMeshDS()->MoveNode( n12, p.X(), p.Y(), p.Z() );
-  }
-
-  //if ( mySetElemOnShape ) node is not elem!
-  {
-    int edgeID = GetMeshDS()->ShapeToIndex( edges[iOkEdge] );
-    if ( edgeID != n12->getshapeId() )
-      GetMeshDS()->UnSetNodeOnShape( n12 );
-    GetMeshDS()->SetNodeOnEdge(n12, edgeID, u);
+    // move n12 to position of a successfull projection
+    //double tol = BRep_Tool::Tolerance(edges[ iOkEdge ]);
+    if ( !force3d /*&& distMiddleProj > 2*tol*/ )
+    {
+      TopLoc_Location loc;
+      Handle(Geom_Curve) curve = BRep_Tool::Curve( bestEdge,loc,f,l );
+      gp_Pnt p = curve->Value( u ).Transformed( loc );
+      GetMeshDS()->MoveNode( n12, p.X(), p.Y(), p.Z() );
+    }
+    //if ( mySetElemOnShape ) node is not elem!
+    {
+      int edgeID = GetMeshDS()->ShapeToIndex( bestEdge );
+      if ( edgeID != n12->getshapeId() )
+        GetMeshDS()->UnSetNodeOnShape( n12 );
+      GetMeshDS()->SetNodeOnEdge(n12, edgeID, u);
+    }
   }
   myTLinkNodeMap.insert( make_pair( SMESH_TLink(n1,n2), n12 ));
 
@@ -3551,7 +3593,7 @@ namespace { // Structures used by FixQuadraticElements()
     }
     else if ( _faces.size() > 1 ) // not found, set NULL by the first face
     {
-      _faces.insert( ++_faces.begin(), 0 );
+      _faces.insert( ++_faces.begin(), (QFace*) 0 );
     }
   }
   //================================================================================
index 9dc255a252ac8657cf96b851189860b7b3083cb5..af13d4548c7fed9612a140ae4ccaa5081c251e63 100644 (file)
@@ -4018,11 +4018,12 @@ bool SMESH_Pattern::MakeMesh(SMESH_Mesh* theMesh,
           map< double, const SMDS_MeshNode* >::iterator u2n    = ++paramsOfNodes.begin();
           map< double, const SMDS_MeshNode* >::iterator u2nEnd = --paramsOfNodes.end();
           TPoint* p;
+          const double tolFact = ( paramsOfNodes.size() == points.size() ) ? 0.3 : 0.05;
           while ( u2n != u2nEnd && pItF != points.end() )
           {
             const double         u = u2n->first;
             const SMDS_MeshNode* n = u2n->second;
-            const double       tol = ( (++u2n)->first - u ) / 20;
+            const double       tol = ( (++u2n)->first - u ) * tolFact;
             do
             {
               p = ( isForward ? *pItF : *pItR );
index 0b9269fed84d62ef9e4fa8fcaec5780725ba78e8..8ec6a77b6b022b01f03b078248ad90c0f5601288 100644 (file)
@@ -2122,7 +2122,7 @@ TopoDS_Shape SMESH_subMesh::getCollection(SMESH_Gen * theGen,
     theAlgo->GetUsedHypothesis( *_father, _subShape, ignoreAuxiliaryHyps ); // copy
 
   // put in a compound all shapes with the same hypothesis assigned
-  // and a good ComputState
+  // and a good ComputeState
 
   TopoDS_Compound aCompound;
   BRep_Builder aBuilder;
index d360c4a6f2e1a073003a6d39dde6522c86a60f70..ee16256859428f94085d8cd6ac260c724a84a8c8 100644 (file)
@@ -30,6 +30,9 @@
 #include "SMESHGUI.h"
 #include "SMESHGUI_FilterUtils.h"
 #include "SMESHGUI_FilterDlg.h"
+#include "SMESHGUI_VTKUtils.h"
+
+#include <GEOMBase.h>
 
 // SALOME GUI includes
 #include <SUIT_Session.h>
@@ -37,8 +40,9 @@
 #include <SUIT_FileDlg.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
-
 #include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SALOME_ListIO.hxx>
 
 // Qt includes
 #include <QApplication>
@@ -233,13 +237,16 @@ QWidget* SMESHGUI_FilterLibraryDlg::createMainFrame (QWidget* theParent)
   connect(myDeleteBtn, SIGNAL(clicked()), this, SLOT(onDeleteBtnPressed()));
 
   connect(myName, SIGNAL(textChanged(const QString&)),
-           this, SLOT(onFilterNameChanged(const QString&)));
+          this, SLOT(onFilterNameChanged(const QString&)));
 
   connect(myTable, SIGNAL(EntityTypeChanged(const int)),
-           this, SLOT(onEntityTypeChanged(const int)));
+          this, SLOT(onEntityTypeChanged(const int)));
 
   connect(myTable, SIGNAL(NeedValidation()), this, SLOT(onNeedValidation()));
 
+  LightApp_SelectionMgr* selMgr = SMESH::GetSelectionMgr( mySMESHGUI );
+  connect( selMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
+
   return aMainFrame;
 }
 
@@ -1179,6 +1186,73 @@ void SMESHGUI_FilterLibraryDlg::onNeedValidation()
   }
 }
 
+
+//=======================================================================
+// name    : SMESHGUI_FilterLibraryDlg::onSelectionDone
+// Purpose : SLOT called when selection changed.
+//           If current cell corresponds to the threshold value of
+//           BelongToGeom criterion name of selected object is set in this cell
+//=======================================================================
+
+void SMESHGUI_FilterLibraryDlg::onSelectionDone()
+{
+  SALOME_ListIO aList;
+  if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
+    aSel->selectedObjects( aList );
+
+  int aRow, aCol;
+  if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol))
+    return;
+
+  const int type = myTable->GetCriterionType(aRow);
+  QList<int> types; 
+  types << SMESH::FT_BelongToGeom     << SMESH::FT_BelongToPlane 
+        << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
+        << SMESH::FT_LyingOnGeom      << SMESH::FT_CoplanarFaces
+        << SMESH::FT_ConnectedElements;
+  if ( !types.contains( type ))
+    return;
+
+  Handle(SALOME_InteractiveObject) anIO = aList.First();
+  switch ( type )
+  {
+  case SMESH::FT_CoplanarFaces: // get ID of a selected mesh face
+    {
+      QString aString;
+      int nbElems = SMESH::GetNameOfSelectedElements(SMESH::GetSelector(), anIO, aString);
+      if (nbElems == 1)
+        myTable->SetThreshold(aRow, aString);
+      break;
+    }
+  case SMESH::FT_ConnectedElements: // get either VERTEX or a node ID
+    {
+      GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
+      if (!anObj->_is_nil())
+      {
+        myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
+        myTable->SetID       (aRow, anIO->getEntry());
+      }
+      else
+      {
+        QString aString;
+        int nbElems = SMESH::GetNameOfSelectedElements(SMESH::GetSelector(), anIO, aString);
+        if (nbElems == 1)
+          myTable->SetThreshold(aRow, aString);
+      }
+      break;
+    }
+  default: // get a GEOM object
+    {
+      GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
+      if (!anObj->_is_nil())
+      {
+        myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
+        myTable->SetID       (aRow, anIO->getEntry());
+      }
+    }
+  }
+}
+
 //=================================================================================
 // function : keyPressEvent()
 // purpose  :
index 12158bef8a66e7c7919ccb974ad2bbf3a7399886..cc5d1f7ce6b32f9ef4fadde6c456c26b95556992 100644 (file)
@@ -98,6 +98,7 @@ private slots:
   void                        onFilterNameChanged( const QString& );
   void                        onEntityTypeChanged( const int );
   void                        onNeedValidation();
+  void                        onSelectionDone();
 
 private:
   void                        construct( const QList<int>&, const int ); 
index 9c63004b331ffc0b9ded4916c9a3bd6b2b1e5022..d1a2dd8b3a30611986d144ffa2520b93c7b7a52d 100644 (file)
@@ -331,7 +331,7 @@ void SMESHGUI_ShapeByMeshOp::commitOperation()
 
       TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
 
-      std::map<double, GEOM::GEOM_Object_wrap> aGeomObjectsMap;
+      std::map<int, GEOM::GEOM_Object_wrap> aGeomObjectsMap;
       GEOM::GEOM_Object_wrap aGeomObject;
 
       GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
@@ -343,7 +343,7 @@ void SMESHGUI_ShapeByMeshOp::commitOperation()
 
         if (aGeomObject->_is_nil()) continue;
 
-        double anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject);
+        int anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject);
         if (aShapesOp->IsDone() && !aGeomObjectsMap.count(anId) )
         {
           aGeomObjectsMap[anId] = aGeomObject;
@@ -372,13 +372,13 @@ void SMESHGUI_ShapeByMeshOp::commitOperation()
         aGeomObjects->length( aNumberOfGO );
 
         int i = 0;
-        std::map<double, GEOM::GEOM_Object_wrap>::iterator anIter;
+        std::map<int, GEOM::GEOM_Object_wrap>::iterator anIter;
         for (anIter = aGeomObjectsMap.begin(); anIter!=aGeomObjectsMap.end(); anIter++)
-          aGeomObjects[i++] = (*anIter).second.in();
+          aGeomObjects[i++] = GEOM::GEOM_Object::_duplicate( (*anIter).second.in() );
 
         //create geometry group
         aGeomObject = aGroupOp->CreateGroup(aMeshShape, aGroupType);
-        aGroupOp->UnionList(myGeomObj, aGeomObjects);
+        aGroupOp->UnionList(aGeomObject, aGeomObjects);
 
         if (!aGroupOp->IsDone())
           return;
index 1c85e046994b73f160fccc55b044ef8403bca546..f23cac0cab8bc5e0804e03d2c6c93535e676487a 100644 (file)
@@ -30,6 +30,7 @@
 #include "SMESH_OctreeNode.hxx"
 
 #include "SMDS_SetIterator.hxx"
+#include "SMESH_TypeDefs.hxx"
 #include <gp_Pnt.hxx>
 
 using namespace std;
@@ -167,7 +168,7 @@ void SMESH_OctreeNode::NodesAround (const SMDS_MeshNode * Node,
                                     list<const SMDS_MeshNode*>* Result,
                                     const double precision)
 {
-  gp_XYZ p(Node->X(), Node->Y(), Node->Z());
+  SMESH_TNodeXYZ p(Node);
   if (isInside(p, precision))
   {
     if (isLeaf())
@@ -191,7 +192,7 @@ void SMESH_OctreeNode::NodesAround (const SMDS_MeshNode * Node,
  *  \param node - node to find nodes closest to
  *  \param dist2Nodes - map of found nodes and their distances
  *  \param precision - radius of a sphere to check nodes inside
- *  \retval bool - true if an exact overlapping found
+ *  \retval bool - true if an exact overlapping found !!!
  */
 //================================================================================
 
@@ -204,7 +205,6 @@ bool SMESH_OctreeNode::NodesAround(const gp_XYZ &node,
   else if ( precision == 0. )
     precision = maxSize() / 2;
 
-  //gp_XYZ p(node->X(), node->Y(), node->Z());
   if (isInside(node, precision))
   {
     if (!isLeaf())
@@ -222,21 +222,20 @@ bool SMESH_OctreeNode::NodesAround(const gp_XYZ &node,
     }
     else if ( NbNodes() > 0 )
     {
-      size_t nbFoundBefore = dist2Nodes.size();
       double minDist = precision * precision;
-      gp_Pnt p1 ( node.X(), node.Y(), node.Z() );
       TIDSortedNodeSet::iterator nIt = myNodes.begin();
       for ( ; nIt != myNodes.end(); ++nIt )
       {
-        gp_Pnt p2 ( (*nIt)->X(), (*nIt)->Y(), (*nIt)->Z() );
-        double dist2 = p1.SquareDistance( p2 );
+        SMESH_TNodeXYZ p2( *nIt );
+        double dist2 = ( node - p2 ).SquareModulus();
         if ( dist2 < minDist )
-          dist2Nodes.insert( make_pair( minDist = dist2, *nIt ));
+          dist2Nodes.insert( make_pair( minDist = dist2, p2._node ));
       }
 //       if ( dist2Nodes.size() > 1 ) // leave only closest node in dist2Nodes
 //         dist2Nodes.erase( ++dist2Nodes.begin(), dist2Nodes.end());
 
-      return ( nbFoundBefore < dist2Nodes.size() );
+      // true if an exact overlapping found
+      return ( sqrt( minDist ) <= precision * 1e-12 );
     }
   }
   return false;
index ce0a35594f1a35befb4d9109ad41333536073ffd..778b72c3bf2fed3097d8cd286dde73066c6f18e7 100644 (file)
@@ -4629,6 +4629,19 @@ class Mesh:
     def GetSkew(self, elemId):
         return self._valueFromFunctor(SMESH.FT_Skew, elemId)
 
+    ## Return minimal and maximal value of a given functor.
+    #  @param funType a functor type, an item of SMESH.FunctorType enum
+    #         (one of SMESH.FunctorType._items)
+    #  @return tuple (min,max)
+    #  @ingroup l1_measurements
+    def GetMinMax(self, funType):
+        fun = self._getFunctor( funType )
+        if fun:
+            hist = fun.GetHistogram( 1, False )
+            if hist:
+                return hist[0].min, hist[0].max
+        return None
+
     pass # end of Mesh class
 
 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
index f52eea0ee710420f607d563f6040f4999c7f8ef3..f7516247a9982b25f97d0a02dfdf7c82a33515d8 100644 (file)
@@ -45,6 +45,7 @@
 #include <BRepBuilderAPI_Copy.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
 #include <BRepTools.hxx>
+#include <BRepTopAdaptor_FClass2d.hxx>
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 #include <Bnd_B3d.hxx>
@@ -87,7 +88,7 @@
 
 #include <limits>
 
-// #undef WITH_TBB
+//#undef WITH_TBB
 #ifdef WITH_TBB
 #include <tbb/parallel_for.h>
 //#include <tbb/enumerable_thread_specific.h>
@@ -452,8 +453,6 @@ namespace
         :_node(n), _intPoint(ip), _usedInFace(0) {} 
       const SMDS_MeshNode*    Node() const
       { return ( _intPoint && _intPoint->_node ) ? _intPoint->_node : _node; }
-      //const F_IntersectPoint* FaceIntPnt() const
-      //{ return static_cast< const F_IntersectPoint* >( _intPoint ); }
       const E_IntersectPoint* EdgeIntPnt() const
       { return static_cast< const E_IntersectPoint* >( _intPoint ); }
       bool IsUsedInFace( const _Face* polygon = 0 )
@@ -473,12 +472,12 @@ namespace
           _intPoint->Add( ip->_faceIDs );
         }
       }
-      int IsLinked( const B_IntersectPoint* other,
-                    int                     avoidFace=-1 ) const // returns id of a common face
+      TGeomID IsLinked( const B_IntersectPoint* other,
+                        TGeomID                 avoidFace=-1 ) const // returns id of a common face
       {
         return _intPoint ? _intPoint->HasCommonFace( other, avoidFace ) : 0;
       }
-      bool IsOnFace( int faceID ) const // returns true if faceID is found
+      bool IsOnFace( TGeomID faceID ) const // returns true if faceID is found
       {
         return _intPoint ? _intPoint->IsOnFace( faceID ) : false;
       }
@@ -491,6 +490,12 @@ namespace
           return eip->_point;
         return gp_Pnt( 1e100, 0, 0 );
       }
+      TGeomID ShapeID() const
+      {
+        if ( const E_IntersectPoint* eip = dynamic_cast< const E_IntersectPoint* >( _intPoint ))
+          return eip->_shapeID;
+        return 0;
+      }
     };
     // --------------------------------------------------------------------------------
     struct _Link // link connecting two _Node's
@@ -577,11 +582,29 @@ namespace
       vector< _OrientedLink > _links;       // links on GridLine's
       vector< _Link >         _polyLinks;   // links added to close a polygonal face
       vector< _Node* >        _eIntNodes;   // nodes at intersection with EDGEs
-      bool isPolyLink( const _OrientedLink& ol )
+      bool IsPolyLink( const _OrientedLink& ol )
       {
         return _polyLinks.empty() ? false :
           ( &_polyLinks[0] <= ol._link &&  ol._link <= &_polyLinks.back() );
       }
+      void AddPolyLink(_Node* n0, _Node* n1, _Face* faceToFindEqual=0)
+      {
+        if ( faceToFindEqual && faceToFindEqual != this ) {
+          for ( size_t iL = 0; iL < faceToFindEqual->_polyLinks.size(); ++iL )
+            if ( faceToFindEqual->_polyLinks[iL]._nodes[0] == n1 &&
+                 faceToFindEqual->_polyLinks[iL]._nodes[1] == n0 )
+            {
+              _links.push_back
+                ( _OrientedLink( & faceToFindEqual->_polyLinks[iL], /*reverse=*/true ));
+              return;
+            }
+        }
+        _Link l;
+        l._nodes[0] = n0;
+        l._nodes[1] = n1;
+        _polyLinks.push_back( l );
+        _links.push_back( _OrientedLink( &_polyLinks.back() ));
+      }
     };
     // --------------------------------------------------------------------------------
     struct _volumeDef // holder of nodes of a volume mesh element
@@ -592,6 +615,8 @@ namespace
       void set( const vector< _Node* >& nodes,
                 const vector< int >&    quant = vector< int >() )
       { _nodes = nodes; _quantities = quant; }
+      void set( _Node** nodes, int nb )
+      { _nodes.assign( nodes, nodes + nb ); }
     };
 
     // topology of a hexahedron
@@ -645,8 +670,15 @@ namespace
                           int ijk[], int dIJK[] );
     bool findChain( _Node* n1, _Node* n2, _Face& quad, vector<_Node*>& chainNodes );
     bool closePolygon( _Face* polygon, vector<_Node*>& chainNodes ) const;
+    bool findChainOnEdge( const vector< _OrientedLink >& splits,
+                          const _OrientedLink&           prevSplit,
+                          const _OrientedLink&           avoidSplit,
+                          size_t &                       iS,
+                          _Face&                         quad,
+                          vector<_Node*>&                chn);
     int  addElements(SMESH_MesherHelper& helper);
-    bool is1stNodeOut( _Link& link ) const;
+    bool isOutPoint( _Link& link, int iP, SMESH_MesherHelper& helper ) const;
+    void sortVertexNodes(vector<_Node*>& nodes, _Node* curNode, TGeomID face);
     bool isInHole() const;
     bool checkPolyhedronSize() const;
     bool addHexa ();
@@ -654,7 +686,7 @@ namespace
     bool addPenta();
     bool addPyra ();
     bool debugDumpLink( _Link* link );
-    _Node* FindEqualNode( vector< _Node* >&       nodes,
+    _Node* findEqualNode( vector< _Node* >&       nodes,
                           const E_IntersectPoint* ip,
                           const double            tol2 )
     {
@@ -664,6 +696,8 @@ namespace
           return nodes[i];
       return 0;
     }
+    bool isImplementEdges() const { return !_grid->_edgeIntP.empty(); }
+    bool isOutParam(const double uvw[3]) const;
   };
 
 #ifdef WITH_TBB
@@ -674,12 +708,11 @@ namespace
   struct ParallelHexahedron
   {
     vector< Hexahedron* >& _hexVec;
-    vector<int>&           _index;
-    ParallelHexahedron( vector< Hexahedron* >& hv, vector<int>& ind): _hexVec(hv), _index(ind) {}
+    ParallelHexahedron( vector< Hexahedron* >& hv ): _hexVec(hv) {}
     void operator() ( const tbb::blocked_range<size_t>& r ) const
     {
       for ( size_t i = r.begin(); i != r.end(); ++i )
-        if ( Hexahedron* hex = _hexVec[ _index[i]] )
+        if ( Hexahedron* hex = _hexVec[ ] )
           hex->ComputeElements();
     }
   };
@@ -1205,7 +1238,7 @@ namespace
   /*
    * Intersect a line with a plane
    */
-  void FaceLineIntersector::IntersectWithPlane   (const GridLine& gridLine)
+  void FaceLineIntersector::IntersectWithPlane(const GridLine& gridLine)
   {
     IntAna_IntConicQuad linPlane( gridLine._line, _plane, Precision::Angular());
     _w = linPlane.ParamOnConic(1);
@@ -1524,7 +1557,7 @@ namespace
       }
     }
   }
-  
+
   //================================================================================
   /*!
    * \brief Initializes its data by given grid cell
@@ -1543,7 +1576,6 @@ namespace
       _nbCornerNodes += bool( _hexNodes[iN]._node );
       _nbBndNodes    += bool( _hexNodes[iN]._intPoint );
     }
-
     _sideLength[0] = _grid->_coords[0][i+1] - _grid->_coords[0][i];
     _sideLength[1] = _grid->_coords[1][j+1] - _grid->_coords[1][j];
     _sideLength[2] = _grid->_coords[2][k+1] - _grid->_coords[2][k];
@@ -1556,8 +1588,11 @@ namespace
     {
       _intNodes.reserve( 3 * _nbBndNodes + _nbFaceIntNodes + _eIntPoints.size() );
 
-      _Link split;
+      // this method can be called in parallel, so use own helper
+      SMESH_MesherHelper helper( *_grid->_helper->GetMesh() );
+
       // create sub-links (_splits) by splitting links with _fIntPoints
+      _Link split;
       for ( int iLink = 0; iLink < 12; ++iLink )
       {
         _Link& link = _hexLinks[ iLink ];
@@ -1570,11 +1605,12 @@ namespace
 
         link._splits.clear();
         split._nodes[ 0 ] = link._nodes[0];
-        bool isOut = ( ! link._nodes[0]->Node() ); // is1stNodeOut( iLink );
+        bool isOut = ( ! link._nodes[0]->Node() );
         bool checkTransition;
         for ( size_t i = 0; i < link._fIntNodes.size(); ++i )
         {
-          if ( link._fIntNodes[i]->Node() ) // intersection non-coinsident with a grid node
+          const bool isGridNode = ( ! link._fIntNodes[i]->Node() );
+          if ( !isGridNode ) // intersection non-coincident with a grid node
           {
             if ( split._nodes[ 0 ]->Node() && !isOut )
             {
@@ -1584,21 +1620,21 @@ namespace
             split._nodes[ 0 ] = link._fIntNodes[i];
             checkTransition = true;
           }
-          else // FACE intersection coinsident with a grid node
+          else // FACE intersection coincident with a grid node (at link ends)
           {
-            checkTransition = ( link._nodes[0]->Node() );
+            checkTransition = ( i == 0 && link._nodes[0]->Node() );
           }
           if ( checkTransition )
           {
-            switch ( link._fIntPoints[i]->_transition ) {
-            case Trans_OUT: isOut = true; break;
-            case Trans_IN : isOut = false; break;
-            default:
-              if ( !link._fIntNodes[i]->Node() && i == 0 )
-                isOut = is1stNodeOut( link );
-              else
-                ; // isOut remains the same
-            }
+            if ( link._fIntPoints[i]->_faceIDs.size() > 1 || _eIntPoints.size() > 0 )
+              isOut = isOutPoint( link, i, helper );
+            else
+              switch ( link._fIntPoints[i]->_transition ) {
+              case Trans_OUT: isOut = true;  break;
+              case Trans_IN : isOut = false; break;
+              default:
+                isOut = isOutPoint( link, i, helper );
+              }
           }
         }
         if ( link._nodes[ 1 ]->Node() && split._nodes[ 0 ]->Node() && !isOut )
@@ -1621,7 +1657,7 @@ namespace
         case 1: // in a _Face
         {
           _Face& quad = _hexQuads[ facets[0] - SMESH_Block::ID_FirstF ];
-          equalNode = FindEqualNode( quad._eIntNodes, _eIntPoints[ iP ], tol2 );
+          equalNode = findEqualNode( quad._eIntNodes, _eIntPoints[ iP ], tol2 );
           if ( equalNode ) {
             equalNode->Add( _eIntPoints[ iP ] );
           }
@@ -1636,7 +1672,7 @@ namespace
           _Link& link = _hexLinks[ subEntity - SMESH_Block::ID_FirstE ];
           if ( link._splits.size() > 0 )
           {
-            equalNode = FindEqualNode( link._fIntNodes, _eIntPoints[ iP ], tol2 );
+            equalNode = findEqualNode( link._fIntNodes, _eIntPoints[ iP ], tol2 );
             if ( equalNode )
               equalNode->Add( _eIntPoints[ iP ] );
           }
@@ -1646,7 +1682,7 @@ namespace
             for ( int iF = 0; iF < 2; ++iF )
             {
               _Face& quad = _hexQuads[ facets[iF] - SMESH_Block::ID_FirstF ];
-              equalNode = FindEqualNode( quad._eIntNodes, _eIntPoints[ iP ], tol2 );
+              equalNode = findEqualNode( quad._eIntNodes, _eIntPoints[ iP ], tol2 );
               if ( equalNode ) {
                 equalNode->Add( _eIntPoints[ iP ] );
               }
@@ -1671,7 +1707,7 @@ namespace
             for ( int iF = 0; iF < 3; ++iF )
             {
               _Face& quad = _hexQuads[ facets[iF] - SMESH_Block::ID_FirstF ];
-              equalNode = FindEqualNode( quad._eIntNodes, _eIntPoints[ iP ], tol2 );
+              equalNode = findEqualNode( quad._eIntNodes, _eIntPoints[ iP ], tol2 );
               if ( equalNode ) {
                 equalNode->Add( _eIntPoints[ iP ] );
               }
@@ -1687,11 +1723,11 @@ namespace
         if ( nbFacets == 0 ||
              _grid->_shapes( _eIntPoints[ iP ]->_shapeID ).ShapeType() == TopAbs_VERTEX )
         {
-          equalNode = FindEqualNode( _vIntNodes, _eIntPoints[ iP ], tol2 );
+          equalNode = findEqualNode( _vIntNodes, _eIntPoints[ iP ], tol2 );
           if ( equalNode ) {
             equalNode->Add( _eIntPoints[ iP ] );
           }
-          else {
+          else if ( nbFacets == 0 ) {
             if ( _intNodes.empty() || _intNodes.back().EdgeIntPnt() != _eIntPoints[ iP ])
               _intNodes.push_back( _Node( 0, _eIntPoints[ iP ]));
             _vIntNodes.push_back( & _intNodes.back() );
@@ -1752,9 +1788,8 @@ namespace
     // Create polygons from quadrangles
     // --------------------------------
 
-    _Link                   polyLink;
     vector< _OrientedLink > splits;
-    vector<_Node*>          chainNodes, usedEdgeNodes;
+    vector<_Node*>          chainNodes;
     _Face*                  coplanarPolyg;
 
     bool hasEdgeIntersections = !_eIntPoints.empty();
@@ -1776,7 +1811,10 @@ namespace
       // polygon's boundary closed
 
       int nbSplits = splits.size();
-      if ( nbSplits < 2 && quad._eIntNodes.empty() )
+      if (( nbSplits == 1 ) &&
+          ( quad._eIntNodes.empty() ||
+            splits[0].FirstNode()->IsLinked( splits[0].LastNode()->_intPoint )))
+          //( quad._eIntNodes.empty() || _nbCornerNodes + nbIntersections > 6 ))
         nbSplits = 0;
 
 #ifdef _DEBUG_
@@ -1785,6 +1823,7 @@ namespace
           quad._eIntNodes[ iP ]->_usedInFace = 0;
 #endif
       int nbUsedEdgeNodes = 0;
+      _Face* prevPolyg = 0; // polygon previously created from this quad
 
       while ( nbSplits > 0 )
       {
@@ -1810,7 +1849,21 @@ namespace
           if ( !split ) continue;
 
           n1 = split.FirstNode();
-          if ( n1 != n2 )
+          if ( n1 == n2 &&
+               n1->_intPoint &&
+               n1->_intPoint->_faceIDs.size() > 1 )
+          {
+            // n1 is at intersection with EDGE
+            if ( findChainOnEdge( splits, polygon->_links.back(), split, iS, quad, chainNodes ))
+            {
+              for ( size_t i = 1; i < chainNodes.size(); ++i )
+                polygon->AddPolyLink( chainNodes[i-1], chainNodes[i], prevPolyg );
+              prevPolyg = polygon;
+              n2 = chainNodes.back();
+              continue;
+            }
+          }
+          else if ( n1 != n2 )
           {
             // try to connect to intersections with EDGEs
             if ( quad._eIntNodes.size() > nbUsedEdgeNodes  &&
@@ -1818,11 +1871,8 @@ namespace
             {
               for ( size_t i = 1; i < chainNodes.size(); ++i )
               {
-                polyLink._nodes[0] = chainNodes[i-1];
-                polyLink._nodes[1] = chainNodes[i];
-                polygon->_polyLinks.push_back( polyLink );
-                polygon->_links.push_back( _OrientedLink( &polygon->_polyLinks.back() ));
-                nbUsedEdgeNodes += ( polyLink._nodes[1]->IsUsedInFace( polygon ));
+                polygon->AddPolyLink( chainNodes[i-1], chainNodes[i] );
+                nbUsedEdgeNodes += ( chainNodes[i]->IsUsedInFace( polygon ));
               }
               if ( chainNodes.back() != n1 )
               {
@@ -1839,10 +1889,6 @@ namespace
                 if (( foundSplit = splits[ i ]) &&
                     ( n2->IsLinked( foundSplit.FirstNode()->_intPoint )))
                 {
-                  polyLink._nodes[0] = n2;
-                  polyLink._nodes[1] = foundSplit.FirstNode();
-                  polygon->_polyLinks.push_back( polyLink );
-                  polygon->_links.push_back( _OrientedLink( &polygon->_polyLinks.back() ));
                   iS = i - 1;
                 }
                 else
@@ -1851,20 +1897,22 @@ namespace
                 }
               if ( foundSplit )
               {
-                n2 = foundSplit.FirstNode();
+                if ( n2 != foundSplit.FirstNode() )
+                {
+                  polygon->AddPolyLink( n2, foundSplit.FirstNode() );
+                  n2 = foundSplit.FirstNode();
+                }
                 continue;
               }
               else
               {
                 if ( n2->IsLinked( nFirst->_intPoint ))
                   break;
-                polyLink._nodes[0] = n2;
-                polyLink._nodes[1] = n1;
-                polygon->_polyLinks.push_back( polyLink );
-                polygon->_links.push_back( _OrientedLink( &polygon->_polyLinks.back() ));
+                polygon->AddPolyLink( n2, n1, prevPolyg );
               }
             }
-          }
+          } // if ( n1 != n2 )
+
           polygon->_links.push_back( split );
           split._link = 0;
           --nbSplits;
@@ -1877,15 +1925,13 @@ namespace
           if ( !findChain( n2, nFirst, quad, chainNodes ))
           {
             if ( !closePolygon( polygon, chainNodes ))
-              chainNodes.push_back( nFirst );
+              if ( !isImplementEdges() )
+                chainNodes.push_back( nFirst );
           }
           for ( size_t i = 1; i < chainNodes.size(); ++i )
           {
-            polyLink._nodes[0] = chainNodes[i-1];
-            polyLink._nodes[1] = chainNodes[i];
-            polygon->_polyLinks.push_back( polyLink );
-            polygon->_links.push_back( _OrientedLink( &polygon->_polyLinks.back() ));
-            nbUsedEdgeNodes += bool( polyLink._nodes[1]->IsUsedInFace( polygon ));
+            polygon->AddPolyLink( chainNodes[i-1], chainNodes[i], prevPolyg );
+            nbUsedEdgeNodes += bool( chainNodes[i]->IsUsedInFace( polygon ));
           }
         }
 
@@ -1896,26 +1942,9 @@ namespace
         }
       } // while ( nbSplits > 0 )
 
-      // if ( quad._eIntNodes.size() > nbUsedEdgeNodes )
-      // {
-      //   // make _vIntNodes from not used _eIntNodes
-      //   const double tol = 0.05 * Min( Min( _sideLength[0], _sideLength[1] ), _sideLength[0] );
-      //   for ( size_t iP = 0; iP < quad._eIntNodes.size(); ++iP )
-      //   {
-      //     if ( quad._eIntNodes[ iP ]->IsUsedInFace() ) continue;
-      //     _Node* equalNode =
-      //       FindEqualNode( _vIntNodes, quad._eIntNodes[ iP ].EdgeIntPnt(), tol*tol );
-      //     if ( equalNode )
-      //       equalNode->Add( quad._eIntNodes[ iP ].EdgeIntPnt() );
-      //     else
-      //       _vIntNodes.push_back( quad._eIntNodes[ iP ]);
-      //   }
-      // }
-
       if ( polygon->_links.size() < 3 )
       {
         _polygons.pop_back();
-        //usedEdgeNodes.resize( usedEdgeNodes.size() - nbUsedEdgeNodes );
       }
     }  // loop on 6 hexahedron sides
 
@@ -1944,13 +1973,10 @@ namespace
       _Face& polygon = _polygons[ iP ];
       for ( size_t iL = 0; iL < polygon._links.size(); ++iL )
         if ( polygon._links[ iL ].NbFaces() < 2 )
-        {
           freeLinks.push_back( & polygon._links[ iL ]);
-          freeLinks.back()->FirstNode()->IsUsedInFace() == true;
-        }
     }
     int nbFreeLinks = freeLinks.size();
-    if ( nbFreeLinks > 0 && nbFreeLinks < 3 ) return;
+    if ( nbFreeLinks == 1 ) return;
 
     // put not used intersection nodes to _vIntNodes
     int nbVertexNodes = 0; // nb not used vertex nodes
@@ -1964,8 +1990,8 @@ namespace
         if ( _intNodes[ iN ].IsUsedInFace() ) continue;
         if ( dynamic_cast< const F_IntersectPoint* >( _intNodes[ iN ]._intPoint )) continue;
         _Node* equalNode =
-          FindEqualNode( _vIntNodes, _intNodes[ iN ].EdgeIntPnt(), tol*tol );
-        if ( !equalNode /*|| equalNode->IsUsedInFace()*/ )
+          findEqualNode( _vIntNodes, _intNodes[ iN ].EdgeIntPnt(), tol*tol );
+        if ( !equalNode )
         {
           _vIntNodes.push_back( &_intNodes[ iN ]);
           ++nbVertexNodes;
@@ -1974,8 +2000,10 @@ namespace
     }
 
     set<TGeomID> usedFaceIDs;
+    vector< TGeomID > faces;
     TGeomID curFace = 0;
     const size_t nbQuadPolygons = _polygons.size();
+    E_IntersectPoint ipTmp;
 
     // create polygons by making closed chains of free links
     size_t iPolygon = _polygons.size();
@@ -2017,37 +2045,38 @@ namespace
       {
         // get a remaining link to start from, one lying on minimal nb of FACEs
         {
-          vector< pair< TGeomID, int > > facesOfLink[3];
-          pair< TGeomID, int > faceOfLink( -1, -1 );
-          vector< TGeomID > faces;
+          typedef pair< TGeomID, int > TFaceOfLink;
+          TFaceOfLink faceOfLink( -1, -1 );
+          TFaceOfLink facesOfLink[3] = { faceOfLink, faceOfLink, faceOfLink };
           for ( size_t iL = 0; iL < freeLinks.size(); ++iL )
             if ( freeLinks[ iL ] )
             {
               faces = freeLinks[ iL ]->GetNotUsedFace( usedFaceIDs );
               if ( faces.size() == 1 )
               {
-                faceOfLink = make_pair( faces[0], iL );
+                faceOfLink = TFaceOfLink( faces[0], iL );
                 if ( !freeLinks[ iL ]->HasEdgeNodes() )
                   break;
-                facesOfLink[0].push_back( faceOfLink );
+                facesOfLink[0] = faceOfLink;
               }
-              else if ( facesOfLink[0].empty() )
+              else if ( facesOfLink[0].first < 0 )
               {
-                faceOfLink = make_pair(( faces.empty() ? -1 : faces[0]), iL );
-                facesOfLink[ 1 + faces.empty() ].push_back( faceOfLink );
+                faceOfLink = TFaceOfLink(( faces.empty() ? -1 : faces[0]), iL );
+                facesOfLink[ 1 + faces.empty() ] = faceOfLink;
               }
             }
-          for ( int i = 0; faceOfLink.second < 0 && i < 3; ++i )
-            if ( !facesOfLink[i].empty() )
-              faceOfLink = facesOfLink[i][0];
+          for ( int i = 0; faceOfLink.first < 0 && i < 3; ++i )
+            faceOfLink = facesOfLink[i];
 
           if ( faceOfLink.first < 0 ) // all faces used
           {
-            for ( size_t i = 0; i < facesOfLink[2].size() && faceOfLink.first < 1; ++i )
-            {
-              curLink = freeLinks[ facesOfLink[2][i].second ];
-              faceOfLink.first = curLink->FirstNode()->IsLinked( curLink->LastNode()->_intPoint );
-            }
+            for ( size_t iL = 0; iL < freeLinks.size() && faceOfLink.first < 1; ++iL )
+              if (( curLink = freeLinks[ iL ]))
+              {
+                faceOfLink.first = 
+                  curLink->FirstNode()->IsLinked( curLink->LastNode()->_intPoint );
+                faceOfLink.second = iL;
+              }
             usedFaceIDs.clear();
           }
           curFace = faceOfLink.first;
@@ -2103,28 +2132,30 @@ namespace
           if ( nbVertexNodes > 0 )
           {
             // add links with _vIntNodes if not already used
+            chainNodes.clear();
             for ( size_t iN = 0; iN < _vIntNodes.size(); ++iN )
               if ( !_vIntNodes[ iN ]->IsUsedInFace() &&
                    _vIntNodes[ iN ]->IsOnFace( curFace ))
               {
                 _vIntNodes[ iN ]->_usedInFace = &polygon;
-                --nbVertexNodes;
-                polyLink._nodes[0] = _vIntNodes[ iN ];
-                polyLink._nodes[1] = curNode;
-                polygon._polyLinks.push_back( polyLink );
-                polygon._links.push_back( _OrientedLink( &polygon._polyLinks.back() ));
-                freeLinks.push_back( &polygon._links.back() );
-                ++nbFreeLinks;
-                curNode = _vIntNodes[ iN ];
-                // TODO: to reorder _vIntNodes within polygon, if there are several ones
+                chainNodes.push_back( _vIntNodes[ iN ] );
               }
+            if ( chainNodes.size() > 1 )
+            {
+              sortVertexNodes( chainNodes, curNode, curFace );
+            }
+            for ( int i = 0; i < chainNodes.size(); ++i )
+            {
+              polygon.AddPolyLink( chainNodes[ i ], curNode );
+              curNode = chainNodes[ i ];
+              freeLinks.push_back( &polygon._links.back() );
+              ++nbFreeLinks;
+            }
+            nbVertexNodes -= chainNodes.size();
           }
           // if ( polygon._links.size() > 1 )
           {
-            polyLink._nodes[0] = polygon._links[0].LastNode();
-            polyLink._nodes[1] = curNode;
-            polygon._polyLinks.push_back( polyLink );
-            polygon._links.push_back( _OrientedLink( &polygon._polyLinks.back() ));
+            polygon.AddPolyLink( polygon._links[0].LastNode(), curNode );
             freeLinks.push_back( &polygon._links.back() );
             ++nbFreeLinks;
           }
@@ -2158,9 +2189,9 @@ namespace
           polygon._links[ iL ].AddFace( &polygon );
           polygon._links[ iL ].Reverse();
         }
-        if ( hasEdgeIntersections && iPolygon == _polygons.size() - 1 )
+        if ( /*hasEdgeIntersections &&*/ iPolygon == _polygons.size() - 1 )
         {
-          // check that a polygon does not lie in the plane of another polygon
+          // check that a polygon does not lie on a hexa side
           coplanarPolyg = 0;
           for ( size_t iL = 0; iL < polygon._links.size() && !coplanarPolyg; ++iL )
           {
@@ -2172,7 +2203,8 @@ namespace
             coplanarPolyg = polygon._links[ iL ]._link->_faces[0];
             for ( iL2 = iL + 1; iL2 < polygon._links.size(); ++iL2 )
               if ( polygon._links[ iL2 ]._link->_faces[0] == coplanarPolyg &&
-                   !coplanarPolyg->isPolyLink( polygon._links[ iL2 ]) &&
+                   !coplanarPolyg->IsPolyLink( polygon._links[ iL  ]) &&
+                   !coplanarPolyg->IsPolyLink( polygon._links[ iL2 ]) &&
                    coplanarPolyg < & _polygons[ nbQuadPolygons ])
                 break;
             if ( iL2 == polygon._links.size() )
@@ -2183,11 +2215,10 @@ namespace
             freeLinks.resize( freeLinks.size() - polygon._polyLinks.size() );
             nbFreeLinks -= polygon._polyLinks.size();
 
-            // an artificial E_IntersectPoint used to mark nodes of coplanarPolyg
+            // an E_IntersectPoint used to mark nodes of coplanarPolyg
             // as lying on curFace while they are not at intersection with geometry
-            E_IntersectPoint* ip = & _grid->_edgeIntP.back();
-            ip->_faceIDs.resize(1);
-            ip->_faceIDs[0] = curFace;
+            ipTmp._faceIDs.resize(1);
+            ipTmp._faceIDs[0] = curFace;
 
             // fill freeLinks with links not shared by coplanarPolyg and polygon
             for ( size_t iL = 0; iL < polygon._links.size(); ++iL )
@@ -2228,8 +2259,8 @@ namespace
                     for ( int iN = 0; iN < 2; ++iN )
                     {
                       _Node* n = freeLinks[ iL3 ]->_link->_nodes[ iN ];
-                      if ( n->_intPoint ) n->_intPoint->Add( ip->_faceIDs );
-                      else                n->_intPoint = ip;
+                      if ( n->_intPoint ) n->_intPoint->Add( ipTmp._faceIDs );
+                      else                n->_intPoint = &ipTmp;
                     }
                     break;
                   }
@@ -2264,13 +2295,28 @@ namespace
       return;
     }
 
+    for ( size_t i = 0; i < 8; ++i )
+      if ( _hexNodes[ i ]._intPoint == &ipTmp )
+        _hexNodes[ i ]._intPoint = 0;
+
     // create a classic cell if possible
-    const int nbNodes = _nbCornerNodes + nbIntersections;
+
+    int nbPolygons = 0;
+    for ( size_t iF = 0; iF < _polygons.size(); ++iF )
+      nbPolygons += (_polygons[ iF ]._links.size() > 0 );
+
+    //const int nbNodes = _nbCornerNodes + nbIntersections;
+    int nbNodes = 0;
+    for ( size_t i = 0; i < 8; ++i )
+      nbNodes += _hexNodes[ i ].IsUsedInFace();
+    for ( size_t i = 0; i < _intNodes.size(); ++i )
+      nbNodes += _intNodes[ i ].IsUsedInFace();
+
     bool isClassicElem = false;
-    if (      nbNodes == 8 && _polygons.size() == 6 ) isClassicElem = addHexa();
-    else if ( nbNodes == 4 && _polygons.size() == 4 ) isClassicElem = addTetra();
-    else if ( nbNodes == 6 && _polygons.size() == 5 ) isClassicElem = addPenta();
-    else if ( nbNodes == 5 && _polygons.size() == 5 ) isClassicElem = addPyra ();
+    if (      nbNodes == 8 && nbPolygons == 6 ) isClassicElem = addHexa();
+    else if ( nbNodes == 4 && nbPolygons == 4 ) isClassicElem = addTetra();
+    else if ( nbNodes == 6 && nbPolygons == 5 ) isClassicElem = addPenta();
+    else if ( nbNodes == 5 && nbPolygons == 5 ) isClassicElem = addPyra ();
     if ( !isClassicElem )
     {
       _volumeDefs._nodes.clear();
@@ -2279,6 +2325,7 @@ namespace
       for ( size_t iF = 0; iF < _polygons.size(); ++iF )
       {
         const size_t nbLinks = _polygons[ iF ]._links.size();
+        if ( nbLinks == 0 ) continue;
         _volumeDefs._quantities.push_back( nbLinks );
         for ( size_t iL = 0; iL < nbLinks; ++iL )
           _volumeDefs._nodes.push_back( _polygons[ iF ]._links[ iL ].FirstNode() );
@@ -2298,10 +2345,10 @@ namespace
                           _grid->_coords[1].size() - 1,
                           _grid->_coords[2].size() - 1 };
     const size_t nbGridCells = nbCells[0] * nbCells[1] * nbCells[2];
-    vector< Hexahedron* > intersectedHex( nbGridCells, 0 );
+    vector< Hexahedron* > allHexa( nbGridCells, 0 );
     int nbIntHex = 0;
 
-    // set intersection nodes from GridLine's to links of intersectedHex
+    // set intersection nodes from GridLine's to links of allHexa
     int i,j,k, iDirOther[3][2] = {{ 1,2 },{ 0,2 },{ 0,1 }};
     for ( int iDir = 0; iDir < 3; ++iDir )
     {
@@ -2329,7 +2376,7 @@ namespace
                  k < 0 || k >= nbCells[2] ) continue;
 
             const size_t hexIndex = _grid->CellIndex( i,j,k );
-            Hexahedron *& hex = intersectedHex[ hexIndex ];
+            Hexahedron *& hex = allHexa[ hexIndex ];
             if ( !hex)
             {
               hex = new Hexahedron( *this );
@@ -2347,18 +2394,17 @@ namespace
     }
 
     // implement geom edges into the mesh
-    addEdges( helper, intersectedHex, edge2faceIDsMap );
+    addEdges( helper, allHexa, edge2faceIDsMap );
 
     // add not split hexadrons to the mesh
     int nbAdded = 0;
-    vector<int> intHexInd( nbIntHex );
-    nbIntHex = 0;
-    for ( size_t i = 0; i < intersectedHex.size(); ++i )
+    vector< Hexahedron* > intHexa( nbIntHex, (Hexahedron*) NULL );
+    for ( size_t i = 0; i < allHexa.size(); ++i )
     {
-      Hexahedron * & hex = intersectedHex[ i ];
+      Hexahedron * & hex = allHexa[ i ];
       if ( hex )
       {
-        intHexInd[ nbIntHex++ ] = i;
+        intHexa.push_back( hex );
         if ( hex->_nbFaceIntNodes > 0 || hex->_eIntPoints.size() > 0 )
           continue; // treat intersected hex later
         this->init( hex->_i, hex->_j, hex->_k );
@@ -2379,11 +2425,7 @@ namespace
         mesh->SetMeshElementOnShape( el, helper.GetSubShapeID() );
         ++nbAdded;
         if ( hex )
-        {
-          delete hex;
-          intersectedHex[ i ] = 0;
-          --nbIntHex;
-        }
+          intHexa.pop_back();
       }
       else if ( _nbCornerNodes > 3  && !hex )
       {
@@ -2392,32 +2434,30 @@ namespace
         hex->_i = _i;
         hex->_j = _j;
         hex->_k = _k;
-        intHexInd.push_back(0);
-        intHexInd[ nbIntHex++ ] = i;
+        intHexa.push_back( hex );
       }
     }
 
     // add elements resulted from hexadron intersection
 #ifdef WITH_TBB
-    intHexInd.resize( nbIntHex );
-    tbb::parallel_for ( tbb::blocked_range<size_t>( 0, nbIntHex ),
-                        ParallelHexahedron( intersectedHex, intHexInd ),
+    tbb::parallel_for ( tbb::blocked_range<size_t>( 0, intHexa.size() ),
+                        ParallelHexahedron( intHexa ),
                         tbb::simple_partitioner()); // ComputeElements() is called here
-    for ( size_t i = 0; i < intHexInd.size(); ++i )
-      if ( Hexahedron * hex = intersectedHex[ intHexInd[ i ]] )
+    for ( size_t i = 0; i < intHexa.size(); ++i )
+      if ( Hexahedron * hex = intHexa[ i ] )
         nbAdded += hex->addElements( helper );
 #else
-    for ( size_t i = 0; i < intHexInd.size(); ++i )
-      if ( Hexahedron * hex = intersectedHex[ intHexInd[ i ]] )
+    for ( size_t i = 0; i < intHexa.size(); ++i )
+      if ( Hexahedron * hex = intHexa[ i ] )
       {
         hex->ComputeElements();
         nbAdded += hex->addElements( helper );
       }
 #endif
 
-    for ( size_t i = 0; i < intersectedHex.size(); ++i )
-      if ( intersectedHex[ i ] )
-        delete intersectedHex[ i ];
+    for ( size_t i = 0; i < allHexa.size(); ++i )
+      if ( allHexa[ i ] )
+        delete allHexa[ i ];
 
     return nbAdded;
   }
@@ -2522,33 +2562,34 @@ namespace
           double u2     = discret.Parameter( iP );
           double zProj2 = planes._zNorm * ( p2 - _grid->_origin );
           int    iZ2    = iZ1;
-          if ( Abs( zProj2 - zProj1 ) <= std::numeric_limits<double>::min() )
-            continue;
-          locateValue( iZ2, zProj2, planes._zProjs, dIJK[ iDirZ ], tol );
-
-          // treat intersections with planes between 2 end points of a segment
-          int dZ = ( iZ1 <= iZ2 ) ? +1 : -1;
-          int iZ = iZ1 + ( iZ1 < iZ2 );
-          for ( int i = 0, nb = Abs( iZ1 - iZ2 ); i < nb; ++i, iZ += dZ )
+          if ( Abs( zProj2 - zProj1 ) > std::numeric_limits<double>::min() )
           {
-            ip._point = findIntPoint( u1, zProj1, u2, zProj2,
-                                      planes._zProjs[ iZ ],
-                                      curve, planes._zNorm, _grid->_origin );
-            _grid->ComputeUVW( ip._point.XYZ(), ip._uvw );
-            locateValue( ijk[iDirX], ip._uvw[iDirX], _grid->_coords[iDirX], dIJK[iDirX], tol );
-            locateValue( ijk[iDirY], ip._uvw[iDirY], _grid->_coords[iDirY], dIJK[iDirY], tol );
-            ijk[ iDirZ ] = iZ;
-
-            // add ip to hex "above" the plane
-            _grid->_edgeIntP.push_back( ip );
-            dIJK[ iDirZ ] = 0;
-            bool added = addIntersection(_grid->_edgeIntP.back(), hexes, ijk, dIJK);
-
-            // add ip to hex "below" the plane
-            ijk[ iDirZ ] = iZ-1;
-            if ( !addIntersection( _grid->_edgeIntP.back(), hexes, ijk, dIJK ) &&
-                 !added)
-              _grid->_edgeIntP.pop_back();
+            locateValue( iZ2, zProj2, planes._zProjs, dIJK[ iDirZ ], tol );
+
+            // treat intersections with planes between 2 end points of a segment
+            int dZ = ( iZ1 <= iZ2 ) ? +1 : -1;
+            int iZ = iZ1 + ( iZ1 < iZ2 );
+            for ( int i = 0, nb = Abs( iZ1 - iZ2 ); i < nb; ++i, iZ += dZ )
+            {
+              ip._point = findIntPoint( u1, zProj1, u2, zProj2,
+                                        planes._zProjs[ iZ ],
+                                        curve, planes._zNorm, _grid->_origin );
+              _grid->ComputeUVW( ip._point.XYZ(), ip._uvw );
+              locateValue( ijk[iDirX], ip._uvw[iDirX], _grid->_coords[iDirX], dIJK[iDirX], tol );
+              locateValue( ijk[iDirY], ip._uvw[iDirY], _grid->_coords[iDirY], dIJK[iDirY], tol );
+              ijk[ iDirZ ] = iZ;
+
+              // add ip to hex "above" the plane
+              _grid->_edgeIntP.push_back( ip );
+              dIJK[ iDirZ ] = 0;
+              bool added = addIntersection(_grid->_edgeIntP.back(), hexes, ijk, dIJK);
+
+              // add ip to hex "below" the plane
+              ijk[ iDirZ ] = iZ-1;
+              if ( !addIntersection( _grid->_edgeIntP.back(), hexes, ijk, dIJK ) &&
+                   !added)
+                _grid->_edgeIntP.pop_back();
+            }
           }
           iZ1    = iZ2;
           p1     = p2;
@@ -2572,11 +2613,6 @@ namespace
       } // loop on 3 grid directions
     } // loop on EDGEs
 
-    // add an artificial E_IntersectPoint used in Hexahedron::ComputeElements()
-    ip._shapeID = -1;
-    ip._faceIDs.clear();
-    ip._node = 0;
-    _grid->_edgeIntP.push_back( ip );
   }
 
   //================================================================================
@@ -2705,12 +2741,7 @@ namespace
         Hexahedron* h = hexes[ hexIndex[i] ];
         // check if ip is really inside the hex
 #ifdef _DEBUG_
-        if (( _grid->_coords[0][ h->_i   ] - _grid->_tol > ip._uvw[0] ) ||
-            ( _grid->_coords[0][ h->_i+1 ] + _grid->_tol < ip._uvw[0] ) ||
-            ( _grid->_coords[1][ h->_j   ] - _grid->_tol > ip._uvw[1] ) ||
-            ( _grid->_coords[1][ h->_j+1 ] + _grid->_tol < ip._uvw[1] ) ||
-            ( _grid->_coords[2][ h->_k   ] - _grid->_tol > ip._uvw[2] ) ||
-            ( _grid->_coords[2][ h->_k+1 ] + _grid->_tol < ip._uvw[2] ))
+        if ( h->isOutParam( ip._uvw ))
           throw SALOME_Exception("ip outside a hex");
 #endif
         h->_eIntPoints.push_back( & ip );
@@ -2804,55 +2835,297 @@ namespace
   }
   //================================================================================
   /*!
-   * \brief Checks transition at the 1st node of a link
+   * \brief Finds nodes on the same EDGE as the first node of avoidSplit.
+   *
+   * This function is for a case where an EDGE lies on a quad which lies on a FACE
+   * so that a part of quad in ON and another part in IN
    */
-  bool Hexahedron::is1stNodeOut( _Link& link /*int iLink*/ ) const
+  bool Hexahedron::findChainOnEdge( const vector< _OrientedLink >& splits,
+                                    const _OrientedLink&           prevSplit,
+                                    const _OrientedLink&           avoidSplit,
+                                    size_t &                       iS,
+                                    _Face&                         quad,
+                                    vector<_Node*>&                chn )
   {
-    // new version is for the case: tangent transition at the 1st node
-    bool isOut = false;
-    if ( link._fIntNodes.size() > 1 )
+    if ( !isImplementEdges() )
+      return false;
+
+    _Node* pn1 = prevSplit.FirstNode();
+    _Node* pn2 = prevSplit.LastNode();
+    int avoidFace = pn1->IsLinked( pn2->_intPoint ); // FACE under the quad
+    if ( avoidFace < 1 && pn1->_intPoint )
+      return false;
+
+    _Node* n, *stopNode = avoidSplit.LastNode();
+
+    chn.clear();
+    if ( !quad._eIntNodes.empty() )
     {
-      // check transition at the next intersection
-      switch ( link._fIntPoints[1]->_transition ) {
-      case Trans_OUT: return false;
-      case Trans_IN : return true;
-      default: ; // tangent transition
-      }
+      chn.push_back( pn2 );
+      bool found;
+      do
+      {
+        found = false;
+        for ( size_t iP = 0; iP < quad._eIntNodes.size(); ++iP )
+          if (( !quad._eIntNodes[ iP ]->IsUsedInFace( &quad )) &&
+              ( chn.back()->IsLinked( quad._eIntNodes[ iP ]->_intPoint, avoidFace )) &&
+              ( !avoidFace || quad._eIntNodes[ iP ]->IsOnFace( avoidFace )))
+          {
+            chn.push_back( quad._eIntNodes[ iP ]);
+            found = quad._eIntNodes[ iP ]->_usedInFace = &quad;
+            break;
+          }
+      } while ( found );
+      pn2 = chn.back();
     }
-    if ( !link._nodes[1]->Node() )
+
+    int i;
+    for ( i = splits.size()-1; i >= 0; --i )
+    {
+      if ( !splits[i] )
+        continue;
+
+      n = splits[i].LastNode();
+      if ( n == stopNode )
+        break;
+      if (( n != pn1 ) &&
+          ( n->IsLinked( pn2->_intPoint, avoidFace )) &&
+          ( !avoidFace || n->IsOnFace( avoidFace )))
+        break;
+
+      n = splits[i].FirstNode();
+      if ( n == stopNode )
+        break;
+      if (( n->IsLinked( pn2->_intPoint, avoidFace )) &&
+          ( !avoidFace || n->IsOnFace( avoidFace )))
+        break;
+      n = 0;
+    }
+    if ( n && n != stopNode)
+    {
+      if ( chn.empty() )
+        chn.push_back( pn2 );
+      chn.push_back( n );
+      iS = i-1;
+      return true;
+    }
+    return false;
+  }
+  //================================================================================
+  /*!
+   * \brief Checks transition at the ginen intersection node of a link
+   */
+  bool Hexahedron::isOutPoint( _Link& link, int iP, SMESH_MesherHelper& helper ) const
+  {
+    bool isOut = false;
+
+    const bool moreIntPoints = ( iP+1 < link._fIntPoints.size() );
+
+    // get 2 _Node's
+    _Node* n1 = link._fIntNodes[ iP ];
+    if ( !n1->Node() )
+      n1 = link._nodes[0];
+    _Node* n2 = moreIntPoints ? link._fIntNodes[ iP+1 ] : 0;
+    if ( !n2 || !n2->Node() )
+      n2 = link._nodes[1];
+    if ( !n2->Node() )
       return true;
 
-    gp_Pnt p1 = link._nodes[0]->Point();
-    gp_Pnt p2 = link._nodes[1]->Point();
-    gp_Pnt testPnt = 0.8 * p1.XYZ() + 0.2 * p2.XYZ();
+    // get all FACEs under n1 and n2
+    set< TGeomID > faceIDs;
+    if ( moreIntPoints ) faceIDs.insert( link._fIntPoints[iP+1]->_faceIDs.begin(),
+                                         link._fIntPoints[iP+1]->_faceIDs.end() );
+    if ( n2->_intPoint ) faceIDs.insert( n2->_intPoint->_faceIDs.begin(),
+                                         n2->_intPoint->_faceIDs.end() );
+    if ( faceIDs.empty() )
+      return false; // n2 is inside
+    if ( n1->_intPoint ) faceIDs.insert( n1->_intPoint->_faceIDs.begin(),
+                                         n1->_intPoint->_faceIDs.end() );
+    faceIDs.insert( link._fIntPoints[iP]->_faceIDs.begin(),
+                    link._fIntPoints[iP]->_faceIDs.end() );
+
+    // get a point between 2 nodes
+    gp_Pnt p1      = n1->Point();
+    gp_Pnt p2      = n2->Point();
+    gp_Pnt pOnLink = 0.8 * p1.XYZ() + 0.2 * p2.XYZ();
 
-    TGeomID          faceID = link._fIntPoints[0]->_faceIDs[0];
-    const TopoDS_Face& face = TopoDS::Face( _grid->_shapes( faceID ));
     TopLoc_Location loc;
-    GeomAPI_ProjectPointOnSurf& proj =
-      _grid->_helper->GetProjector( face, loc, 0.1*_grid->_tol );
-    testPnt.Transform( loc );
-    proj.Perform( testPnt );
-    if ( proj.IsDone() &&
-         proj.NbPoints() > 0 &&
-         proj.LowerDistance() > _grid->_tol )
-    {
-      Quantity_Parameter u,v;
-      proj.LowerDistanceParameters( u,v );
-      gp_Dir normal;
-      if ( GeomLib::NormEstim( BRep_Tool::Surface( face, loc ),
-                               gp_Pnt2d( u,v ),
-                               0.1*_grid->_tol,
-                               normal ) < 3 )
-      {
-        if ( face.Orientation() == TopAbs_REVERSED )
-          normal.Reverse();
-        gp_Vec v( proj.NearestPoint(), testPnt );
-        return v * normal > 0;
+
+    set< TGeomID >::iterator faceID = faceIDs.begin();
+    for ( ; faceID != faceIDs.end(); ++faceID )
+    {
+      // project pOnLink on a FACE
+      if ( *faceID < 1 ) continue;
+      const TopoDS_Face& face = TopoDS::Face( _grid->_shapes( *faceID ));
+      GeomAPI_ProjectPointOnSurf& proj =
+        helper.GetProjector( face, loc, 0.1*_grid->_tol );
+      gp_Pnt testPnt = pOnLink.Transformed( loc.Transformation().Inverted() );
+      proj.Perform( testPnt );
+      if ( proj.IsDone() && proj.NbPoints() > 0 )       
+      {
+        Quantity_Parameter u,v;
+        proj.LowerDistanceParameters( u,v );
+
+        if ( proj.LowerDistance() <= 0.1 * _grid->_tol )
+        {
+          isOut = false;
+        }
+        else
+        {
+          // find isOut by normals
+          gp_Dir normal;
+          if ( GeomLib::NormEstim( BRep_Tool::Surface( face, loc ),
+                                   gp_Pnt2d( u,v ),
+                                   0.1*_grid->_tol,
+                                   normal ) < 3 )
+          {
+            if ( face.Orientation() == TopAbs_REVERSED )
+              normal.Reverse();
+            gp_Vec v( proj.NearestPoint(), testPnt );
+            isOut = ( v * normal > 0 );
+          }
+        }
+        if ( !isOut )
+        {
+          // classify a projection
+          if ( !n1->IsOnFace( *faceID ) || !n2->IsOnFace( *faceID ))
+          {
+            BRepTopAdaptor_FClass2d cls( face, Precision::Confusion() );
+            TopAbs_State state = cls.Perform( gp_Pnt2d( u,v ));
+            if ( state == TopAbs_OUT )
+            {
+              isOut = true;
+              continue;
+            }
+          }
+          return false;
+        }
       }
     }
     return isOut;
   }
+  //================================================================================
+  /*!
+   * \brief Sort nodes on a FACE
+   */
+  void Hexahedron::sortVertexNodes(vector<_Node*>& nodes, _Node* curNode, TGeomID faceID)
+  {
+    if ( nodes.size() > 20 ) return;
+
+    // get shapes under nodes
+    TGeomID nShapeIds[20], *nShapeIdsEnd = &nShapeIds[0] + nodes.size();
+    for ( size_t i = 0; i < nodes.size(); ++i )
+      if ( !( nShapeIds[i] = nodes[i]->ShapeID() ))
+        return;
+
+    // get shapes of the FACE
+    const TopoDS_Face&  face = TopoDS::Face( _grid->_shapes( faceID ));
+    list< TopoDS_Edge > edges;
+    list< int >         nbEdges;
+    int nbW = SMESH_Block::GetOrderedEdges (face, edges, nbEdges);
+    if ( nbW > 1 ) {
+      // select a WIRE
+      list< TopoDS_Edge >::iterator e = edges.begin(), eEnd = e;
+      list< int >::iterator nE = nbEdges.begin();
+      for ( ; nbW ; ++nE, --nbW )
+      {
+        std::advance( eEnd, *nE );
+        for ( ; e != eEnd; ++e )
+          for ( int i = 0; i < 2; ++i )
+          {
+            TGeomID id = i==0 ?
+              _grid->_shapes.FindIndex( *e ) :
+              _grid->_shapes.FindIndex( SMESH_MesherHelper::IthVertex( 0, *e ));
+            if (( id > 0 ) &&
+                ( std::find( &nShapeIds[0], nShapeIdsEnd, id ) != nShapeIdsEnd ))
+            {
+              edges.erase( eEnd, edges.end() ); // remove rest wires
+              e = eEnd;
+              nbW = 0;
+              break;
+            }
+          }
+        if ( nbW > 0 )
+          edges.erase( edges.begin(), eEnd ); // remove a current wire
+      }
+    }
+    // rotate edges to have the first one at least partially out of the hexa
+    list< TopoDS_Edge >::iterator e = edges.begin(), eMidOut = edges.end();
+    for ( ; e != edges.end(); ++e )
+    {
+      if ( !_grid->_shapes.FindIndex( *e ))
+        continue;
+      bool isOut = false;
+      gp_Pnt p;
+      double uvw[3], f,l;
+      for ( int i = 0; i < 2 && !isOut; ++i )
+      {
+        if ( i == 0 )
+        {
+          TopoDS_Vertex v = SMESH_MesherHelper::IthVertex( 0, *e );
+          p = BRep_Tool::Pnt( v );
+        }
+        else if ( eMidOut == edges.end() )
+        {
+          TopLoc_Location loc;
+          Handle(Geom_Curve) c = BRep_Tool::Curve( *e, loc, f, l);
+          if ( c.IsNull() ) break;
+          p = c->Value( 0.5 * ( f + l )).Transformed( loc );
+        }
+        else
+        {
+          continue;
+        }
+
+        _grid->ComputeUVW( p.XYZ(), uvw );
+        if ( isOutParam( uvw ))
+        {
+          if ( i == 0 )
+            isOut = true;
+          else
+            eMidOut = e;
+        }
+      }
+      if ( isOut )
+        break;
+    }
+    if ( e != edges.end() )
+      edges.splice( edges.end(), edges, edges.begin(), e );
+    else if ( eMidOut != edges.end() )
+      edges.splice( edges.end(), edges, edges.begin(), eMidOut );
+
+    // sort nodes accoring to the order of edges
+    _Node*  orderNodes   [20];
+    TGeomID orderShapeIDs[20];
+    int nbN = 0;
+    TGeomID id, *pID;
+    for ( e = edges.begin(); e != edges.end(); ++e )
+    {
+      if (( id = _grid->_shapes.FindIndex( SMESH_MesherHelper::IthVertex( 0, *e ))) &&
+          (( pID = std::find( &nShapeIds[0], nShapeIdsEnd, id )) != nShapeIdsEnd ))
+      {
+        orderShapeIDs[ nbN ] = id;
+        orderNodes   [ nbN++ ] = nodes[ pID - &nShapeIds[0] ];
+        *pID = -1;
+      }
+      if (( id = _grid->_shapes.FindIndex( *e )) &&
+          (( pID = std::find( &nShapeIds[0], nShapeIdsEnd, id )) != nShapeIdsEnd ))
+      {
+        orderShapeIDs[ nbN ] = id;
+        orderNodes   [ nbN++ ] = nodes[ pID - &nShapeIds[0] ];
+        *pID = -1;
+      }
+    }
+    if ( nbN != nodes.size() )
+      return;
+
+    bool reverse = ( orderNodes[0    ]->Point().SquareDistance( curNode->Point() ) >
+                     orderNodes[nbN-1]->Point().SquareDistance( curNode->Point() ));
+
+    for ( size_t i = 0; i < nodes.size(); ++i )
+      nodes[ i ] = orderNodes[ reverse ? nbN-1-i : i ];
+  }
+
   //================================================================================
   /*!
    * \brief Adds computed elements to the mesh
@@ -2966,6 +3239,8 @@ namespace
     for ( size_t iP = 0; iP < _polygons.size(); ++iP )
     {
       const _Face& polygon = _polygons[iP];
+      if ( polygon._links.empty() )
+        continue;
       gp_XYZ area (0,0,0);
       gp_XYZ p1 = polygon._links[ 0 ].FirstNode()->Point().XYZ();
       for ( size_t iL = 0; iL < polygon._links.size(); ++iL )
@@ -2988,27 +3263,34 @@ namespace
    */
   bool Hexahedron::addHexa()
   {
-    if ( _polygons[0]._links.size() != 4 ||
-         _polygons[1]._links.size() != 4 ||
-         _polygons[2]._links.size() != 4 ||
-         _polygons[3]._links.size() != 4 ||
-         _polygons[4]._links.size() != 4 ||
-         _polygons[5]._links.size() != 4   )
+    int nbQuad = 0, iQuad = -1;
+    for ( size_t i = 0; i < _polygons.size(); ++i )
+    {
+      if ( _polygons[i]._links.empty() )
+        continue;
+      if ( _polygons[i]._links.size() != 4 )
+        return false;
+      ++nbQuad;
+      if ( iQuad < 0 )
+        iQuad = i;
+    }
+    if ( nbQuad != 6 )
       return false;
+
     _Node* nodes[8];
     int nbN = 0;
     for ( int iL = 0; iL < 4; ++iL )
     {
       // a base node
-      nodes[iL] = _polygons[0]._links[iL].FirstNode();
+      nodes[iL] = _polygons[iQuad]._links[iL].FirstNode();
       ++nbN;
 
       // find a top node above the base node
-      _Link* link = _polygons[0]._links[iL]._link;
+      _Link* link = _polygons[iQuad]._links[iL]._link;
       if ( !link->_faces[0] || !link->_faces[1] )
         return debugDumpLink( link );
-      // a quadrangle sharing <link> with _polygons[0]
-      _Face* quad = link->_faces[ bool( link->_faces[0] == & _polygons[0] )];
+      // a quadrangle sharing <link> with _polygons[iQuad]
+      _Face* quad = link->_faces[ bool( link->_faces[0] == & _polygons[iQuad] )];
       for ( int i = 0; i < 4; ++i )
         if ( quad->_links[i]._link == link )
         {
@@ -3019,7 +3301,7 @@ namespace
         }
     }
     if ( nbN == 8 )
-      _volumeDefs.set( vector< _Node* >( nodes, nodes+8 ));
+      _volumeDefs.set( &nodes[0], 8 );
 
     return nbN == 8;
   }
@@ -3029,22 +3311,29 @@ namespace
    */
   bool Hexahedron::addTetra()
   {
+    int iTria = -1;
+    for ( size_t i = 0; i < _polygons.size() && iTria < 0; ++i )
+      if ( _polygons[i]._links.size() == 3 )
+        iTria = i;
+    if ( iTria < 0 )
+      return false;
+
     _Node* nodes[4];
-    nodes[0] = _polygons[0]._links[0].FirstNode();
-    nodes[1] = _polygons[0]._links[1].FirstNode();
-    nodes[2] = _polygons[0]._links[2].FirstNode();
+    nodes[0] = _polygons[iTria]._links[0].FirstNode();
+    nodes[1] = _polygons[iTria]._links[1].FirstNode();
+    nodes[2] = _polygons[iTria]._links[2].FirstNode();
 
-    _Link* link = _polygons[0]._links[0]._link;
+    _Link* link = _polygons[iTria]._links[0]._link;
     if ( !link->_faces[0] || !link->_faces[1] )
       return debugDumpLink( link );
 
     // a triangle sharing <link> with _polygons[0]
-    _Face* tria = link->_faces[ bool( link->_faces[0] == & _polygons[0] )];
+    _Face* tria = link->_faces[ bool( link->_faces[0] == & _polygons[iTria] )];
     for ( int i = 0; i < 3; ++i )
       if ( tria->_links[i]._link == link )
       {
         nodes[3] = tria->_links[(i+1)%3].LastNode();
-        _volumeDefs.set( vector< _Node* >( nodes, nodes+4 ));
+        _volumeDefs.set( &nodes[0], 4 );
         return true;
       }
 
@@ -3089,7 +3378,7 @@ namespace
         }
     }
     if ( nbN == 6 )
-      _volumeDefs.set( vector< _Node* >( nodes, nodes+6 ));
+      _volumeDefs.set( &nodes[0], 6 );
 
     return ( nbN == 6 );
   }
@@ -3124,7 +3413,7 @@ namespace
       if ( tria->_links[i]._link == link )
       {
         nodes[4] = tria->_links[(i+1)%3].LastNode();
-        _volumeDefs.set( vector< _Node* >( nodes, nodes+5 ));
+        _volumeDefs.set( &nodes[0], 5 );
         return true;
       }
 
@@ -3144,6 +3433,19 @@ namespace
 #endif
     return false;
   }
+  //================================================================================
+  /*!
+   * \brief Classify a point by grid paremeters
+   */
+  bool Hexahedron::isOutParam(const double uvw[3]) const
+  {
+    return (( _grid->_coords[0][ _i   ] - _grid->_tol > uvw[0] ) ||
+            ( _grid->_coords[0][ _i+1 ] + _grid->_tol < uvw[0] ) ||
+            ( _grid->_coords[1][ _j   ] - _grid->_tol > uvw[1] ) ||
+            ( _grid->_coords[1][ _j+1 ] + _grid->_tol < uvw[1] ) ||
+            ( _grid->_coords[2][ _k   ] - _grid->_tol > uvw[2] ) ||
+            ( _grid->_coords[2][ _k+1 ] + _grid->_tol < uvw[2] ));
+  }
 
   //================================================================================
   /*!
index 6aff7c2078072f33b097a32f716a5e43b500b2fe..e557bc60d6d549114405da755d186a0a3a8061f6 100644 (file)
@@ -280,7 +280,8 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
         {
           // find a pre-existing node
           dist2foundNodes.clear();
-          if ( existingNodeOcTr.NodesAround( SMESH_TNodeXYZ( *node ), dist2foundNodes, groupTol ))
+          existingNodeOcTr.NodesAround( SMESH_TNodeXYZ( *node ), dist2foundNodes, groupTol );
+          if ( !dist2foundNodes.empty() )
             (*n2nIt).second = dist2foundNodes.begin()->second;
         }
         if ( !n2nIt->second )
index 1bb30e342199dcdd8e732a3c6f2ffc12d211cfaf..cba69065d67dee60e14e6800bb5e3433fa2fe08f 100644 (file)
@@ -3848,7 +3848,7 @@ void StdMeshers_Quadrangle_2D::updateDegenUV(FaceQuadStruct::Ptr quad)
       uv1.v = uv2.v = 0.5 * ( uv1.v + uv2.v );
     }
 
-  else if ( quad->side.size() == 4 && myQuadType == QUAD_STANDARD)
+  else if ( quad->side.size() == 4 /*&& myQuadType == QUAD_STANDARD*/)
 
     // Set number of nodes on a degenerated side to be same as on an opposite side
     // ----------------------------------------------------------------------------
@@ -4076,7 +4076,8 @@ bool StdMeshers_Quadrangle_2D::check()
       const TopoDS_Edge& e1 = wire->Edge( iPrev );
       const TopoDS_Edge& e2 = wire->Edge( i );
       double angle = myHelper->GetAngle( e1, e2, geomFace );
-      if ( maxAngle < angle && angle < 0.9 * M_PI )
+      if (( maxAngle < angle ) &&
+          ( 5.* M_PI/180 < angle && angle < 175.* M_PI/180  ))
       {
         maxAngle = angle;
         iVertex = i;
index a012d0292b9cca955567585276c1b7a8f097fe90..1f6d46263460186259fe57f14cafee07b51facb4 100644 (file)
@@ -54,6 +54,7 @@
 #include <Geom2d_Line.hxx>
 #include <Geom2d_TrimmedCurve.hxx>
 #include <GeomAdaptor_Curve.hxx>
+#include <GeomLib.hxx>
 #include <Geom_Circle.hxx>
 #include <Geom_Curve.hxx>
 #include <Geom_Line.hxx>
@@ -1811,45 +1812,36 @@ bool _ViscousBuilder::setEdgeData(_LayerEdge&         edge,
       totalNbFaces++;
       F = TopoDS::Face( s );
 
-      // IDEA: if there is a problem with finding a normal,
-      // we can compute an area-weighted sum of normals of all faces sharing the node
       gp_XY uv = helper.GetNodeUV( F, node, 0, &normOK );
       Handle(Geom_Surface) surface = BRep_Tool::Surface( F );
-      surface->D1( uv.X(), uv.Y(), p, du,dv );
-      geomNorm = du ^ dv;
-      double size2 = geomNorm.SquareMagnitude();
-      if ( size2 < 1e-10 ) // singularity
       {
-        SMDS_ElemIteratorPtr fIt = node->GetInverseElementIterator(SMDSAbs_Face);
-        while ( fIt->more() )
+        gp_Dir normal;
+        if ( GeomLib::NormEstim( surface, uv, 1e-10, normal ) < 3 )
+        {
+          geomNorm = normal;
+          normOK = true;
+        }
+        else // hard singularity
         {
-          const SMDS_MeshElement* f = fIt->next();
-          if ( editor.FindShape( f ) == *id )
+          SMDS_ElemIteratorPtr fIt = node->GetInverseElementIterator(SMDSAbs_Face);
+          while ( fIt->more() )
           {
-            SMESH_MeshAlgos::FaceNormal( f, (gp_XYZ&) geomNorm.XYZ(), /*normalized=*/false );
-            size2 = geomNorm.SquareMagnitude();
-            break;
+            const SMDS_MeshElement* f = fIt->next();
+            if ( editor.FindShape( f ) == *id )
+            {
+              SMESH_MeshAlgos::FaceNormal( f, (gp_XYZ&) geomNorm.XYZ(), /*normalized=*/false );
+              if ( helper.IsReversedSubMesh( F ))
+                geomNorm.Reverse();
+              break;
+            }
           }
+          double size2 = geomNorm.SquareMagnitude();
+          if ( size2 > numeric_limits<double>::min() )
+            geomNorm /= sqrt( size2 );
+          else
+            normOK = false;
         }
-        // double ddu = 0, ddv = 0;
-        // if ( du.SquareMagnitude() > dv.SquareMagnitude() )
-        //   ddu = 1e-3;
-        // else
-        //   ddv = 1e-3;
-        // surface->D1( uv.X()+ddu, uv.Y()+ddv, p, du,dv );
-        // geomNorm = du ^ dv;
-        // size2 = geomNorm.SquareMagnitude();
-        // if ( size2 < 1e-10 )
-        // {
-        //   surface->D1( uv.X()-ddu, uv.Y()-ddv, p, du,dv );
-        //   geomNorm = du ^ dv;
-        //   size2 = geomNorm.SquareMagnitude();
-        // }
       }
-      if ( size2 > numeric_limits<double>::min() )
-        geomNorm /= sqrt( size2 );
-      else
-        normOK = false;
       if ( helper.GetSubShapeOri( data._solid, F ) != TopAbs_REVERSED )
         geomNorm.Reverse();
       edge._normal += geomNorm.XYZ();
@@ -4205,7 +4197,9 @@ void _ViscousBuilder::fixBadFaces(const TopoDS_Face&          F,
       trias [iSide].first  = badTrias[iTia];
       trias [iSide].second = SMESH_MeshAlgos::FindFaceInSet( n1, n2, emptySet, involvedFaces,
                                                              & i1, & i2 );
-      if ( ! trias[iSide].second || trias[iSide].second->NbCornerNodes() != 3 )
+      if (( ! trias[iSide].second ) ||
+          ( trias[iSide].second->NbCornerNodes() != 3 ) ||
+          ( ! sm->Contains( trias[iSide].second )))
         continue;
 
       // aspect ratio of an adjacent tria
diff --git a/src/Tools/padder/doc/images/padder_curvedgeom.png b/src/Tools/padder/doc/images/padder_curvedgeom.png
new file mode 100644 (file)
index 0000000..0e714d0
Binary files /dev/null and b/src/Tools/padder/doc/images/padder_curvedgeom.png differ
index a1b97eca4f4a92b927363e010377f33a7d38682b..e6ef09007ed936cb2f25808c3677087d62c3d930 100644 (file)
Binary files a/src/Tools/padder/doc/images/padder_sphererendering.png and b/src/Tools/padder/doc/images/padder_sphererendering.png differ
index 21a227997ace3079634793a5756de49ed1308880..3efd9ce852f141f572a93079a4b4dcf12246f855 100644 (file)
@@ -1,6 +1,6 @@
 /*!
 
-\page padder_userguide_page Use the padder SMESH Plugin
+\page padder_userguide_page Use the SpherePadder SMESH Plugin
 
 -# \ref S1_PADDER
 -# \ref S2_PADDER
@@ -135,15 +135,17 @@ SMESH and publish the resulting mesh in the SALOME study:
 \image html padder_image12.png
 
 Note that the final ED mesh contains as many groups as the input
-meshes. Their names have been specified in the input dialog. For the
-moment, the DE mesh is shown as a set of points of equal size:
+meshes. Their names have been specified in the input dialog. 
 
-\image html padder_image13.png
+A new functionality has been added to SpherePadder allowing to mesh
+curved geometries. Circular objects with concave boundaries such as 
+shown here:
 
-In the next version, the PointSprite (sphere-like) mode will be used
-to show the MED_BALL elements with their real diameters. Then the
-above example should look like on the following capture (realized in
-module GEOM for illustration):
+\image html padder_curvedgeom.png
+
+can be "padded" with spherical discrete elements. Henceforward, 
+the PointSprite (sphere-like) mode is used to show the MED_BALL 
+elements with their real diameters:
 
 \image html padder_sphererendering.png