Salome HOME
Merge branch 'V9_3_BR'
authorvsr <vsr@opencascade.com>
Mon, 6 May 2019 11:10:42 +0000 (14:10 +0300)
committervsr <vsr@opencascade.com>
Mon, 6 May 2019 11:10:53 +0000 (14:10 +0300)
CMakeLists.txt
src/SMESH/SMESH_Algo.cxx
src/SMESH/SMESH_Algo.hxx
src/SMESH/SMESH_MesherHelper.cxx
src/SMESH/SMESH_ProxyMesh.cxx
src/SMESH/SMESH_ProxyMesh.hxx
src/SMESHUtils/SMESH_MAT2d.cxx
src/SMESH_SWIG/smeshBuilder.py
src/StdMeshers/StdMeshers_CompositeHexa_3D.cxx
src/StdMeshers/StdMeshers_CompositeHexa_3D.hxx
src/StdMeshers/StdMeshers_QuadToTriaAdaptor.cxx

index 37fa5d94d0e5d668111108b86d8037c71626f093..95d1ef7e281d3731fc87536266c0f48930c1ea0c 100644 (file)
@@ -37,7 +37,7 @@ SET(${PROJECT_NAME_UC}_MINOR_VERSION 3)
 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 0)
+SET(${PROJECT_NAME_UC}_VERSION_DEV 1)
 
 # Common CMake macros
 # ===================
index 4de1879f1c231c776c864765bf238f28eebaab66..12371ea6488133d8b66f26169916684ad54a74c4 100644 (file)
@@ -1268,3 +1268,33 @@ bool SMESH_2D_Algo::FixInternalNodes(const SMESH_ProxyMesh& mesh,
   }
   return true;
 }
+
+//=======================================================================
+//function : IsApplicableToShape
+//purpose  : Return true if the algorithm can mesh a given shape
+//=======================================================================
+
+bool SMESH_1D_Algo::IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const
+{
+  return ( !shape.IsNull() && TopExp_Explorer( shape, TopAbs_EDGE ).More() );
+}
+
+//=======================================================================
+//function : IsApplicableToShape
+//purpose  : Return true if the algorithm can mesh a given shape
+//=======================================================================
+
+bool SMESH_2D_Algo::IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const
+{
+  return ( !shape.IsNull() && TopExp_Explorer( shape, TopAbs_FACE ).More() );
+}
+
+//=======================================================================
+//function : IsApplicableToShape
+//purpose  : Return true if the algorithm can mesh a given shape
+//=======================================================================
+
+bool SMESH_3D_Algo::IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const
+{
+  return ( !shape.IsNull() && TopExp_Explorer( shape, TopAbs_SOLID ).More() );
+}
index 2cc313af40c8bd8443f26b1659b9b8b59d5b7dc3..e35a47120a5ed43ac99bc37d1ccdaf92f8a6df3a 100644 (file)
@@ -482,12 +482,28 @@ class SMESH_EXPORT SMESH_1D_Algo: public SMESH_Algo
 {
 public:
   SMESH_1D_Algo(int hypId, SMESH_Gen* gen);
+  /*!
+   * \brief Return true if the algorithm can mesh a given shape
+   *  \param [in] aShape - shape to check
+   *  \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
+   *              else, returns OK if at least one shape is OK
+   *  \retval bool - \c true by default
+   */
+  virtual bool IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const;
 };
 
 class SMESH_EXPORT SMESH_2D_Algo: public SMESH_Algo
 {
 public:
   SMESH_2D_Algo(int hypId, SMESH_Gen* gen);
+  /*!
+   * \brief Return true if the algorithm can mesh a given shape
+   *  \param [in] aShape - shape to check
+   *  \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
+   *              else, returns OK if at least one shape is OK
+   *  \retval bool - \c true by default
+   */
+  virtual bool IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const;
   /*!
    * \brief Method in which an algorithm generating a structured mesh
    *        fixes positions of in-face nodes after there movement
@@ -501,6 +517,14 @@ class SMESH_EXPORT SMESH_3D_Algo: public SMESH_Algo
 {
 public:
   SMESH_3D_Algo(int hypId, SMESH_Gen* gen);
+  /*!
+   * \brief Return true if the algorithm can mesh a given shape
+   *  \param [in] aShape - shape to check
+   *  \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
+   *              else, returns OK if at least one shape is OK
+   *  \retval bool - \c true by default
+   */
+  virtual bool IsApplicableToShape(const TopoDS_Shape & shape, bool toCheckAll) const;
 };
 
 #endif
index eceb92e3657040b6f37d0ec777c370f534dce5bf..390278faaa18f6717b8668e5d3fd45013ea5f5b2 100644 (file)
@@ -1673,30 +1673,8 @@ const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1,
   // get positions of the given nodes on shapes
   if ( pos.second == TopAbs_FACE )
   {
-    F = TopoDS::Face(meshDS->IndexToShape( faceID = pos.first ));
+    F = TopoDS::Face( meshDS->IndexToShape( faceID = pos.first ));
     uv[0] = GetNodeUV(F,n1,n2, force3d ? 0 : &uvOK[0]);
-    if (( !force3d ) &&
-        ( HasDegeneratedEdges() || GetSurface( F )->HasSingularities( 1e-7 )))
-    {
-      // IPAL52850 (degen VERTEX not at singularity)
-      // project middle point to a surface
-      SMESH_TNodeXYZ p1( n1 ), p2( n2 );
-      gp_Pnt pMid = 0.5 * ( p1 + p2 );
-      Handle(ShapeAnalysis_Surface) projector = GetSurface( F );
-      gp_Pnt2d uvMid;
-      if ( uvOK[0] )
-        uvMid = projector->NextValueOfUV( uv[0], pMid, BRep_Tool::Tolerance( F ));
-      else
-        uvMid = projector->ValueOfUV( pMid, getFaceMaxTol( F ));
-      if ( projector->Gap() * projector->Gap() < ( p1 - p2 ).SquareModulus() / 4 )
-      {
-        gp_Pnt pProj = projector->Value( uvMid );
-        n12  = meshDS->AddNode( pProj.X(), pProj.Y(), pProj.Z() );
-        meshDS->SetNodeOnFace( n12, faceID, uvMid.X(), uvMid.Y() );
-        myTLinkNodeMap.insert( make_pair ( link, n12 ));
-        return n12;
-      }
-    }
     uv[1] = GetNodeUV(F,n2,n1, force3d ? 0 : &uvOK[1]);
   }
   else if ( pos.second == TopAbs_EDGE )
@@ -1729,26 +1707,43 @@ const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1,
     // nodes, else - medium between corresponding 3d points
     if( ! F.IsNull() )
     {
-      //if ( uvOK[0] && uvOK[1] )
+      if ( IsDegenShape( n1->getshapeId() )) {
+        if ( myParIndex & U_periodic ) uv[0].SetCoord( 1, uv[1].Coord( 1 ));
+        else                           uv[0].SetCoord( 2, uv[1].Coord( 2 ));
+      }
+      else if ( IsDegenShape( n2->getshapeId() )) {
+        if ( myParIndex & U_periodic ) uv[1].SetCoord( 1, uv[0].Coord( 1 ));
+        else                           uv[1].SetCoord( 2, uv[0].Coord( 2 ));
+      }
+      TopLoc_Location loc;
+      Handle(Geom_Surface) S = BRep_Tool::Surface(F,loc);
+      gp_XY UV = GetMiddleUV( S, uv[0], uv[1] );
+      gp_Pnt P = S->Value( UV.X(), UV.Y() ).Transformed(loc);
+
+      SMESH_TNodeXYZ p1( n1 ), p2( n2 );
+      gp_Pnt pMid = 0.5 * ( p1 + p2 );
+      double distMid = pMid.SquareDistance( P );
+      double dist12  = ( p1 - p2 ).SquareModulus();
+      Handle(ShapeAnalysis_Surface) surfInfo = GetSurface( F );
+      if ( distMid > dist12 ||
+           HasDegeneratedEdges() ||
+           surfInfo->HasSingularities( 1e-7 ) )
       {
-        if ( IsDegenShape( n1->getshapeId() )) {
-          if ( myParIndex & U_periodic ) uv[0].SetCoord( 1, uv[1].Coord( 1 ));
-          else                           uv[0].SetCoord( 2, uv[1].Coord( 2 ));
-        }
-        else if ( IsDegenShape( n2->getshapeId() )) {
-          if ( myParIndex & U_periodic ) uv[1].SetCoord( 1, uv[0].Coord( 1 ));
-          else                           uv[1].SetCoord( 2, uv[0].Coord( 2 ));
-        }
-        TopLoc_Location loc;
-        Handle(Geom_Surface) S = BRep_Tool::Surface(F,loc);
-        gp_XY UV = GetMiddleUV( S, uv[0], uv[1] );
-        gp_Pnt P = S->Value( UV.X(), UV.Y() ).Transformed(loc);
-        n12 = meshDS->AddNode(P.X(), P.Y(), P.Z());
-        // if ( mySetElemOnShape ) node is not elem!
-        meshDS->SetNodeOnFace(n12, faceID, UV.X(), UV.Y());
-        myTLinkNodeMap.insert(make_pair(link,n12));
-        return n12;
+        // IPAL52850 (degen VERTEX not at singularity)
+        // project middle point to a surface
+        gp_Pnt2d uvMid;
+        if ( uvOK[0] )
+          uvMid = surfInfo->NextValueOfUV( uv[0], pMid, BRep_Tool::Tolerance( F ));
+        else
+          uvMid = surfInfo->ValueOfUV( pMid, getFaceMaxTol( F ));
+        if ( surfInfo->Gap() * surfInfo->Gap() < distMid )
+          P = surfInfo->Value( uvMid );
       }
+      n12 = meshDS->AddNode(P.X(), P.Y(), P.Z());
+      // if ( mySetElemOnShape ) node is not elem!
+      meshDS->SetNodeOnFace(n12, faceID, UV.X(), UV.Y());
+      myTLinkNodeMap.insert(make_pair(link,n12));
+      return n12;
     }
     else if ( !E.IsNull() )
     {
index 2a12b362b407497ae1d7d4829d68c188d72dc7d5..36d745f6511da3613a1464192e2f194a56204559 100644 (file)
@@ -32,6 +32,9 @@
 #include <TopExp.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 
+#include <boost/container/flat_set.hpp>
+#include <boost/make_shared.hpp>
+
 //================================================================================
 /*!
  * \brief Constructor; mesh must be set by a descendant class
@@ -169,14 +172,24 @@ SMESH_ProxyMesh::SubMesh* SMESH_ProxyMesh::newSubmesh(int index) const
 //================================================================================
 
 const SMESHDS_SubMesh* SMESH_ProxyMesh::GetSubMesh(const TopoDS_Shape& shape) const
+{
+  return GetSubMesh( shapeIndex( shape ));
+}
+
+//================================================================================
+/*!
+ * \brief Return a sub-mesh by a shape ID; it can be a proxy sub-mesh
+ */
+//================================================================================
+
+const SMESHDS_SubMesh* SMESH_ProxyMesh::GetSubMesh(const int shapeID) const
 {
   const SMESHDS_SubMesh* sm = 0;
 
-  size_t i = shapeIndex(shape);
-  if ( i < _subMeshes.size() )
-    sm = _subMeshes[i];
+  if ( 0 < shapeID && shapeID < (int)_subMeshes.size() )
+    sm = _subMeshes[ shapeID ];
   if ( !sm )
-    sm = GetMeshDS()->MeshElements( i );
+    sm = GetMeshDS()->MeshElements( shapeID );
 
   return sm;
 }
@@ -272,6 +285,62 @@ namespace
       return res;
     }
   };
+
+  //================================================================================
+  /*!
+   * \brief Iterator returning unique elements from a vector and another iterator
+   */
+  //================================================================================
+
+  class TUniqueIterator : public SMDS_ElemIterator
+  {
+    typedef boost::container::flat_set< const SMDS_MeshElement* >                 TElemSet;
+    typedef SMDS_SetIterator< const SMDS_MeshElement*, TElemSet::const_iterator > TSetIterator;
+
+    TElemSet      _uniqueElems;
+    TSetIterator* _iterator;
+
+  public:
+    TUniqueIterator( const std::vector< const SMDS_MeshElement* >& elems,
+                     const SMDS_ElemIteratorPtr&                   elemIterator )
+      : _uniqueElems( elems.begin(), elems.end() )
+    {
+      if ( elemIterator )
+        while ( elemIterator->more() )
+          _uniqueElems.insert( elemIterator->next() );
+
+      _iterator = new TSetIterator( _uniqueElems.begin(), _uniqueElems.end() );
+    }
+    ~TUniqueIterator()
+    {
+      delete _iterator;
+    }
+    virtual bool more()
+    {
+      return _iterator->more();
+    }
+    virtual const SMDS_MeshElement* next()
+    {
+      return _iterator->next();
+    }
+  };
+
+  //================================================================================
+  /*!
+   * \brief Return iterator on 2 element iterators
+   */
+  //================================================================================
+
+  SMDS_ElemIteratorPtr iteratorOn2Iterators( SMDS_ElemIteratorPtr it1, SMDS_ElemIteratorPtr it2 )
+  {
+    std::vector< SMDS_ElemIteratorPtr > iters; iters.reserve(2);
+    if ( it1 ) iters.push_back( it1 );
+    if ( it2 ) iters.push_back( it2 );
+
+    typedef std::vector< SMDS_ElemIteratorPtr >                                 TElemIterVector;
+    typedef SMDS_IteratorOnIterators<const SMDS_MeshElement *, TElemIterVector> TItersIter;
+    return SMDS_ElemIteratorPtr( new TItersIter( iters ));
+  }
 }
 
 //================================================================================
@@ -324,13 +393,7 @@ SMDS_ElemIteratorPtr SMESH_ProxyMesh::GetFaces() const
   // ... else elements filtered using allowedTypes are additionally returned
   SMDS_ElemIteratorPtr facesIter = GetMeshDS()->elementsIterator(SMDSAbs_Face);
   SMDS_ElemIteratorPtr filterIter( new TFilteringIterator( _allowedTypes, facesIter ));
-  std::vector< SMDS_ElemIteratorPtr > iters(2);
-  iters[0] = proxyIter;
-  iters[1] = filterIter;
-    
-  typedef std::vector< SMDS_ElemIteratorPtr >                                 TElemIterVector;
-  typedef SMDS_IteratorOnIterators<const SMDS_MeshElement *, TElemIterVector> TItersIter;
-  return SMDS_ElemIteratorPtr( new TItersIter( iters ));
+  return iteratorOn2Iterators( proxyIter, filterIter );
 }
 
 //================================================================================
@@ -476,8 +539,14 @@ void SMESH_ProxyMesh::removeTmpElement( const SMDS_MeshElement* elem )
     std::set< const SMDS_MeshElement* >::iterator i = _elemsInMesh.find( elem );
     if ( i != _elemsInMesh.end() )
     {
+      std::vector< const SMDS_MeshNode* > nodes( elem->begin_nodes(), elem->end_nodes() );
+
       GetMeshDS()->RemoveFreeElement( elem, 0 );
       _elemsInMesh.erase( i );
+
+      for ( size_t i = 0; i < nodes.size(); ++i )
+        if ( nodes[i]->GetID() > 0 && nodes[i]->NbInverseElements() == 0 )
+          GetMeshDS()->RemoveFreeNode( nodes[i], 0, false );
     }
   }
   else
@@ -524,6 +593,52 @@ bool SMESH_ProxyMesh::IsTemporary(const SMDS_MeshElement* elem ) const
   return ( elem->GetID() < 1 ) || _elemsInMesh.count( elem );
 }
 
+//================================================================================
+/*!
+ * \brief Return iterator on inverse elements of a node that may be a proxy one
+ */
+//================================================================================
+
+SMDS_ElemIteratorPtr SMESH_ProxyMesh::GetInverseElementIterator(const SMDS_MeshNode* node,
+                                                                SMDSAbs_ElementType  type) const
+{
+  typedef std::vector< const SMDS_MeshElement* > TElemVec;
+  TElemVec *elemVecPtr;
+
+  TNodeElemVecMap& inverseElements = const_cast< TNodeElemVecMap& >( _inverseElements );
+  if ( inverseElements.IsEmpty() && NbProxySubMeshes() > 0 )
+  {
+    TElemVec elemVec;
+    for ( size_t i = 0; i < _subMeshes.size(); ++i )
+      if ( _subMeshes[i] )
+        for ( size_t j = 0; j < _subMeshes[i]->_elements.size(); ++j )
+        {
+          const SMDS_MeshElement* e = _subMeshes[i]->_elements[j];
+          for ( SMDS_NodeIteratorPtr nIt = e->nodeIterator(); nIt->more(); )
+          {
+            const SMDS_MeshNode* n = nIt->next();
+            elemVecPtr = inverseElements.ChangeSeek( n );
+            if ( !elemVecPtr )
+              elemVecPtr = inverseElements.Bound( n, elemVec );
+            elemVecPtr->push_back( e );
+          }
+        }
+  }
+
+  SMDS_ElemIteratorPtr iter = node->GetInverseElementIterator( type );
+
+  if (( elemVecPtr = inverseElements.ChangeSeek( node )))
+  {
+    if ( iter->more() )
+      iter = boost::make_shared< TUniqueIterator >( *elemVecPtr, iter );
+    else
+      iter = boost::make_shared< SMDS_ElementVectorIterator> ( elemVecPtr->begin(),
+                                                               elemVecPtr->end() );
+  }
+
+  return iter;
+}
+
 //================================================================================
 /*!
  * \brief SubMesh Constructor
index aa692414a8cd826a27cf7f732357f5817b4a6556..4df1d9bb04923db8944426a2725883269c57855e 100644 (file)
@@ -31,6 +31,7 @@
 #include "SMESH_TypeDefs.hxx"
 
 #include <TopoDS_Shape.hxx>
+#include <NCollection_DataMap.hxx>
 
 #include <map>
 #include <vector>
@@ -103,23 +104,26 @@ public:
   SMESH_ProxyMesh(const SMESH_Mesh& mesh);
   virtual ~SMESH_ProxyMesh();
 
-  // Returns the submesh of a shape; it can be a proxy sub-mesh
+  // Returns a sub-mesh of a shape; it can be a proxy sub-mesh
   const SMESHDS_SubMesh* GetSubMesh(const TopoDS_Shape& shape) const;
 
-  // Returns the proxy sub-mesh of a shape; it can be NULL
+  // Return a sub-mesh by a shape ID; it can be a proxy sub-mesh
+  const SMESHDS_SubMesh* GetSubMesh(const int shapeID) const;
+
+  // Return a proxy sub-mesh of a shape; it can be NULL
   const SubMesh*         GetProxySubMesh(const TopoDS_Shape& shape) const;
 
-  // Returns the proxy node of a node; the input node is returned if no proxy exists
+  // Return a proxy node of a node; the input node is returned if no proxy exists
   const SMDS_MeshNode*   GetProxyNode( const SMDS_MeshNode* node ) const;
 
-  // Returns number of proxy sub-meshes
+  // Return number of proxy sub-meshes
   int                    NbProxySubMeshes() const;
 
-  // Returns iterator on all faces of the mesh taking into account substitutions.
+  // Return iterator on all faces of the mesh taking into account substitutions.
   // To be used in case of mesh without shape
   SMDS_ElemIteratorPtr   GetFaces() const;
 
-  // Returns iterator on all faces on the face taking into account substitutions
+  // Return iterator on all faces on the face taking into account substitutions
   SMDS_ElemIteratorPtr   GetFaces(const TopoDS_Shape& face) const;
 
   // Return total nb of faces taking into account substitutions
@@ -127,6 +131,10 @@ public:
 
   bool                   IsTemporary(const SMDS_MeshElement* elem ) const;
 
+  // Return iterator on inverse elements of a node that may be a proxy one
+  SMDS_ElemIteratorPtr   GetInverseElementIterator(const SMDS_MeshNode* node,
+                                                   SMDSAbs_ElementType  type) const;
+
 
 
   SMESH_Mesh*            GetMesh() const { return const_cast<SMESH_Mesh*>( _mesh ); }
@@ -143,13 +151,13 @@ public:
 
   virtual SubMesh* newSubmesh(int index=0) const;
 
-  // returns a proxy sub-mesh; zero index is for the case of mesh w/o shape
+  // Return a proxy sub-mesh; zero index is for the case of mesh w/o shape
   SubMesh* findProxySubMesh(int shapeIndex=0) const;
 
-  // returns a proxy sub-mesh; it is created if not yet exists
+  // Return a proxy sub-mesh; it is created if not yet exists
   SubMesh* getProxySubMesh(int shapeIndex);
 
-  // returns a proxy sub-mesh; it is created if not yet exists
+  // Return a proxy sub-mesh; it is created if not yet exists
   SubMesh* getProxySubMesh(const TopoDS_Shape& shape=TopoDS_Shape());
 
   // move proxy sub-mesh from other proxy mesh to this, returns true if sub-mesh found
@@ -184,6 +192,12 @@ public:
   // tmp elements residing the _mesh, to be deleted at destruction
   std::set< const SMDS_MeshElement* > _elemsInMesh;
 
+  // inverse elements of proxy nodes
+  typedef NCollection_DataMap< const SMDS_MeshNode*,
+                               std::vector< const SMDS_MeshElement* >,
+                               SMESH_Hasher                         > TNodeElemVecMap;
+  TNodeElemVecMap  _inverseElements;
+
   // Complex submesh used to iterate over elements in other sub-meshes
   mutable SubMesh* _subContainer;
 };
index f925422c3fa6f62801183e815dbb46b1f32c8940..5469f476c6a70c901c0b5af5caf315739ce038bf 100644 (file)
@@ -673,14 +673,12 @@ namespace
     // make 'scale' such that to have coordinates precise enough when converted to int
 
     gp_XY uvMin = uvBox.CornerMin(), uvMax = uvBox.CornerMax();
-    uvMin.ChangeCoord(1) = uvMin.X() * scale[0];
-    uvMin.ChangeCoord(2) = uvMin.Y() * scale[1];
-    uvMax.ChangeCoord(1) = uvMax.X() * scale[0];
-    uvMax.ChangeCoord(2) = uvMax.Y() * scale[1];
+    uvMin *= gp_XY( scale[0], scale[1] );
+    uvMax *= gp_XY( scale[0], scale[1] );
     double vMax[2] = { Max( Abs( uvMin.X() ), Abs( uvMax.X() )),
                        Max( Abs( uvMin.Y() ), Abs( uvMax.Y() )) };
     int iMax = ( vMax[0] > vMax[1] ) ? 0 : 1;
-    const double precision = Min( 1e-5, minSegLen * 1e-2 );
+    const double precision = Min( 1e-5, Min( minSegLen * 1e-2, vMax[iMax] * 1e-5 ));
     double preciScale = Min( vMax[iMax] / precision,
                              std::numeric_limits<int>::max() / vMax[iMax] );
     preciScale /= scale[iMax];
index cce91ec022011a54b7855874462c7cc220faec09..26332db27bb2578d9d632387de69fdf54881b496 100644 (file)
@@ -4490,8 +4490,8 @@ class Mesh(metaclass = MeshMeta):
         Reorient faces contained in *the2DObject*.
 
         Parameters:
-                the2DObject: is a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>` or list of IDs of 2D elements
-                theDirection: is a desired direction of normal of *theFace*.
+                the2DObject: a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>` or list of IDs of 2D elements
+                theDirection: a desired direction of normal of *theFace*.
                         It can be either a GEOM vector or a list of coordinates [x,y,z].
                 theFaceOrPoint: defines a face of *the2DObject* whose normal will be
                         compared with theDirection. It can be either ID of face or a point
index 310d135ddea256f087a589b84b94193ad99cd062..b0f10f8d0d174ec23abf4ef64c1425175b8cb0c5 100644 (file)
 #include "SMESH_Block.hxx"
 #include "SMESH_Comment.hxx"
 #include "SMESH_ComputeError.hxx"
+#include "SMESH_HypoFilter.hxx"
 #include "SMESH_Mesh.hxx"
 #include "SMESH_MeshAlgos.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_subMesh.hxx"
+#include "StdMeshers_ViscousLayers.hxx"
 
 #include <BRepAdaptor_Surface.hxx>
 #include <BRep_Tool.hxx>
@@ -118,8 +120,9 @@ public:
   bool Contain( const TopoDS_Vertex& vertex ) const;
   void AppendSide( const _FaceSide& side );
   void SetBottomSide( int i );
-  int GetNbSegments(SMESH_Mesh& mesh) const;
-  bool StoreNodes(SMESH_Mesh& mesh, vector<const SMDS_MeshNode*>& myGrid, bool reverse );
+  int GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges=0) const;
+  bool StoreNodes(SMESH_ProxyMesh& mesh, vector<const SMDS_MeshNode*>& myGrid,
+                  bool reverse, bool isProxy, const SMESHDS_SubMesh* smToCheckEdges=0 );
   void SetID(EQuadSides id) { myID = id; }
   static inline const TopoDS_TShape* ptr(const TopoDS_Shape& theShape)
   { return theShape.TShape().operator->(); }
@@ -150,7 +153,7 @@ public:
 public: //** Methods to find and orient faces of 6 sides of the box **//
   
   //!< initialization
-  bool Init(const TopoDS_Face& f, SMESH_Mesh& mesh );
+  bool Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh );
 
   //!< try to unite self with other face
   bool AddContinuousFace( const _QuadFaceGrid& f, const TopTools_MapOfShape& internalEdges );
@@ -180,16 +183,16 @@ public: //** Methods to find and orient faces of 6 sides of the box **//
 public: //** Loading and access to mesh **//
 
   //!< Load nodes of a mesh
-  bool LoadGrid( SMESH_Mesh& mesh );
+  bool LoadGrid( SMESH_ProxyMesh& mesh );
 
   //!< Computes normalized parameters of nodes of myGrid
   void ComputeIJK( int i1, int i2, double v3 );
 
   //!< Return number of segments on the hirizontal sides
-  int GetNbHoriSegments(SMESH_Mesh& mesh, bool withBrothers=false) const;
+  int GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
 
   //!< Return number of segments on the vertical sides
-  int GetNbVertSegments(SMESH_Mesh& mesh, bool withBrothers=false) const;
+  int GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
 
   //!< Return edge on the hirizontal bottom sides
   int GetHoriEdges(vector<TopoDS_Edge> & edges) const;
@@ -230,9 +233,9 @@ private:
   bool error(const SMESH_ComputeErrorPtr& err)
   { myError = err; return ( !myError || myError->IsOK() ); }
 
-  bool loadCompositeGrid(SMESH_Mesh& mesh);
+  bool loadCompositeGrid(SMESH_ProxyMesh& mesh);
 
-  bool fillGrid(SMESH_Mesh&                    theMesh,
+  bool fillGrid(SMESH_ProxyMesh&               theMesh,
                 vector<const SMDS_MeshNode*> & theGrid,
                 const _Indexer&                theIndexer,
                 int                            theX,
@@ -298,10 +301,10 @@ namespace
    */
   //================================================================================
 
-  bool isContinuousMesh(TopoDS_Edge        E1,
-                        TopoDS_Edge        E2,
-                        const TopoDS_Face& F,
-                        const SMESH_Mesh&  mesh)
+  bool isContinuousMesh(TopoDS_Edge            E1,
+                        TopoDS_Edge            E2,
+                        const TopoDS_Face&     F,
+                        const SMESH_ProxyMesh& mesh)
   {
     if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
       E1.Orientation( TopAbs_FORWARD );
@@ -314,11 +317,13 @@ namespace
     const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
     if ( !n ) return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
 
-    SMESHDS_SubMesh* sm = mesh.GetSubMeshContaining( F )->GetSubMeshDS();
+    n = mesh.GetProxyNode( n );
+
+    const SMESHDS_SubMesh* sm = mesh.GetSubMesh( F );
     if ( !sm ) return false;
 
     int nbQuads = 0;
-    SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
+    SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
     if ( !fIt->more() )
       return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
     while ( fIt->more() )
@@ -362,11 +367,11 @@ namespace
    */
   //================================================================================
 
-  void getBlockCorners( SMESH_Mesh&          mesh,
+  void getBlockCorners( SMESH_ProxyMesh&     mesh,
                         const TopoDS_Shape&  shape,
                         TopTools_MapOfShape& cornerVV)
   {
-    set<int> faceIDs; // ids of FACEs in the shape
+    std::set<int> faceIDs; // ids of FACEs in the shape
     TopExp_Explorer exp;
     for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
       faceIDs.insert( mesh.GetMeshDS()->ShapeToIndex( exp.Current() ));
@@ -380,13 +385,20 @@ namespace
       const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
       if ( !n ) continue;
 
+      const SMDS_MeshNode* nProxy = mesh.GetProxyNode( n );
+      bool isProxy = ( nProxy != n );
+      n = nProxy;
+
       int nbQuads = 0;
-      SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
+      SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
       while ( fIt->more() )
       {
         const SMDS_MeshElement* f = fIt->next();
         if ( !faceIDs.count( f->getshapeId() )) continue;
 
+        if ( isProxy && !mesh.GetSubMesh( f->getshapeId() )->Contains( f ))
+          continue;
+
         if ( f->NbCornerNodes() == 4 )
           ++nbQuads;
         else
@@ -486,6 +498,51 @@ namespace
 
     return true;
   } // getInternalEdges()
+
+  //================================================================================
+  /*!
+   * \brief Find a face including two given nodes
+   */
+  //================================================================================
+
+  const SMDS_MeshElement* FindFaceByNodes( const SMDS_MeshNode* n1,
+                                           const SMDS_MeshNode* n2,
+                                           TIDSortedElemSet     avoidSet,
+                                           SMESH_ProxyMesh&     mesh)
+  {
+    SMDS_ElemIteratorPtr faceIt = mesh.GetInverseElementIterator( n1, SMDSAbs_Face );
+    while ( faceIt->more() )
+    {
+      const SMDS_MeshElement* f = faceIt->next();
+      if ( !avoidSet.count( f ) && f->GetNodeIndex( n2 ) >= 0 )
+        return f;
+    }
+    return 0;
+  }
+
+  //================================================================================
+  /*!
+   * \brief Check that a segment bounds a face belonging to smOfFaces
+   */
+  //================================================================================
+
+  bool IsSegmentOnSubMeshBoundary( const SMDS_MeshNode*   n1,
+                                   const SMDS_MeshNode*   n2,
+                                   const SMESHDS_SubMesh* smOfFaces,
+                                   SMESH_ProxyMesh&       mesh)
+  {
+    TIDSortedElemSet avoidSet;
+    bool faceFound = false;
+
+    while ( const SMDS_MeshElement* f = FindFaceByNodes( n1, n2, avoidSet, mesh ))
+    {
+      if (( faceFound = smOfFaces->Contains( f )))
+        break;
+      avoidSet.insert( f );
+    }
+    return faceFound;
+  }
+
 } // namespace
 
 //================================================================================
@@ -497,6 +554,7 @@ namespace
 bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
                                                 list< _QuadFaceGrid >& boxFaces,
                                                 SMESH_Mesh&            mesh,
+                                                SMESH_ProxyMesh&       proxyMesh,
                                                 _QuadFaceGrid * &      fBottom,
                                                 _QuadFaceGrid * &      fTop,
                                                 _QuadFaceGrid * &      fFront,
@@ -505,7 +563,7 @@ bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
                                                 _QuadFaceGrid * &      fRight)
 {
   TopTools_MapOfShape cornerVertices;
-  getBlockCorners( mesh, shape, cornerVertices );
+  getBlockCorners( proxyMesh, shape, cornerVertices );
   if ( cornerVertices.Extent() != 8 )
     return error( COMPERR_BAD_INPUT_MESH, "Can't find 8 corners of a block by 2D mesh" );
   TopTools_MapOfShape internalEdges;
@@ -518,7 +576,7 @@ bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
   for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFaces )
   {
     _QuadFaceGrid f;
-    if ( !f.Init( TopoDS::Face( exp.Current() ), mesh ))
+    if ( !f.Init( TopoDS::Face( exp.Current() ), proxyMesh ))
       return error (COMPERR_BAD_SHAPE);
 
     _QuadFaceGrid* prevContinuous = 0;
@@ -547,7 +605,7 @@ bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
     boxFaces.resize( 6 );
     boxFace = boxFaces.begin();
     for ( exp.Init( shape, TopAbs_FACE); exp.More(); exp.Next(), ++boxFace )
-      boxFace->Init( TopoDS::Face( exp.Current() ), mesh );
+      boxFace->Init( TopoDS::Face( exp.Current() ), proxyMesh );
   }
   // ----------------------------------------
   // Find out position of faces within a box
@@ -612,12 +670,22 @@ bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh&         theMesh,
   _quadraticMesh = helper.IsQuadraticSubMesh( theShape );
   helper.SetElementsOnShape( true );
 
+  // get Viscous Mesh
+  SMESH_ProxyMesh::Ptr proxyMesh;
+  SMESH_HypoFilter vlFilter( SMESH_HypoFilter::HasName( StdMeshers_ViscousLayers::GetHypType() ));
+  const SMESH_Hypothesis *          hyp = theMesh.GetHypothesis( theShape, vlFilter, true );
+  const StdMeshers_ViscousLayers* vlHyp = static_cast< const StdMeshers_ViscousLayers* >( hyp );
+  if ( vlHyp )
+    proxyMesh = vlHyp->Compute( theMesh, theShape, /*toMakeN2NMap=*/true );
+  else
+    proxyMesh.reset( new SMESH_ProxyMesh( theMesh ));
+
   // -------------------------
   // Try to find 6 side faces
   // -------------------------
   list< _QuadFaceGrid > boxFaceContainer;
   _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
-  if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh,
+  if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh,
                        fBottom, fTop, fFront, fBack, fLeft, fRight))
     return false;
 
@@ -626,12 +694,12 @@ bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh&         theMesh,
   // ------------------------------------------
 
   // let faces load their grids
-  if ( !fBottom->LoadGrid( theMesh )) return error( fBottom->GetError() );
-  if ( !fBack  ->LoadGrid( theMesh )) return error( fBack  ->GetError() );
-  if ( !fLeft  ->LoadGrid( theMesh )) return error( fLeft  ->GetError() );
-  if ( !fFront ->LoadGrid( theMesh )) return error( fFront ->GetError() );
-  if ( !fRight ->LoadGrid( theMesh )) return error( fRight ->GetError() );
-  if ( !fTop   ->LoadGrid( theMesh )) return error( fTop   ->GetError() );
+  if ( !fBottom->LoadGrid( *proxyMesh )) return error( fBottom->GetError() );
+  if ( !fBack  ->LoadGrid( *proxyMesh )) return error( fBack  ->GetError() );
+  if ( !fLeft  ->LoadGrid( *proxyMesh )) return error( fLeft  ->GetError() );
+  if ( !fFront ->LoadGrid( *proxyMesh )) return error( fFront ->GetError() );
+  if ( !fRight ->LoadGrid( *proxyMesh )) return error( fRight ->GetError() );
+  if ( !fTop   ->LoadGrid( *proxyMesh )) return error( fTop   ->GetError() );
 
   // compute normalized parameters of nodes on sides (PAL23189)
   fBottom->ComputeIJK( COO_X, COO_Y, /*z=*/0. );
@@ -641,9 +709,9 @@ bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh&         theMesh,
   fRight ->ComputeIJK( COO_Y, COO_Z, /*x=*/1. );
   fTop   ->ComputeIJK( COO_X, COO_Y, /*z=*/1. );
 
-  int x, xSize = fBottom->GetNbHoriSegments(theMesh) + 1, X = xSize - 1;
-  int y, ySize = fBottom->GetNbVertSegments(theMesh) + 1, Y = ySize - 1;
-  int z, zSize = fFront ->GetNbVertSegments(theMesh) + 1, Z = zSize - 1;
+  int x, xSize = fBottom->GetNbHoriSegments(*proxyMesh) + 1, X = xSize - 1;
+  int y, ySize = fBottom->GetNbVertSegments(*proxyMesh) + 1, Y = ySize - 1;
+  int z, zSize = fFront ->GetNbVertSegments(*proxyMesh) + 1, Z = zSize - 1;
   _Indexer colIndex( xSize, ySize );
   vector< vector< const SMDS_MeshNode* > > columns( colIndex.size() );
 
@@ -798,12 +866,14 @@ bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh&         theMesh,
                                            const TopoDS_Shape& theShape,
                                            MapShapeNbElems&    aResMap)
 {
+  SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
+
   // -------------------------
   // Try to find 6 side faces
   // -------------------------
   list< _QuadFaceGrid > boxFaceContainer;
   _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
-  if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh,
+  if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh,
                        fBottom, fTop, fFront, fBack, fLeft, fRight))
     return false;
 
@@ -889,7 +959,7 @@ _QuadFaceGrid::_QuadFaceGrid():
  */
 //================================================================================
 
-bool _QuadFaceGrid::Init(const TopoDS_Face& f, SMESH_Mesh& mesh)
+bool _QuadFaceGrid::Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh)
 {
   myFace         = f;
   mySides        = _FaceSide();
@@ -1144,7 +1214,7 @@ void _QuadFaceGrid::ReverseEdges()
  */
 //================================================================================
 
-bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
+bool _QuadFaceGrid::LoadGrid( SMESH_ProxyMesh& mesh )
 {
   if ( !myChildren.empty() )
   {
@@ -1166,24 +1236,33 @@ bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
   if ( !myGrid.empty() )
     return true;
 
-  SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace )->GetSubMeshDS();
+  const SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace );
+
   // check that all faces are quadrangular
   SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
   while ( fIt->more() )
     if ( fIt->next()->NbNodes() % 4 > 0 )
       return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
-  
-  myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
-  myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT   )->GetNbSegments( mesh );
+
+  bool isProxy, isTmpElem;
+  if ( faceSubMesh && faceSubMesh->NbElements() > 0 )
+  {
+    isProxy   = dynamic_cast< const SMESH_ProxyMesh::SubMesh* >( faceSubMesh );
+    isTmpElem = mesh.IsTemporary( faceSubMesh->GetElements()->next() );
+  }
+  const SMESHDS_SubMesh* smToCheckEdges = ( isProxy && !isTmpElem ) ? faceSubMesh : 0;
+
+  myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh, smToCheckEdges );
+  myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT   )->GetNbSegments( mesh, smToCheckEdges );
 
   myGrid.resize( myIndexer.size() );
 
   // store nodes bound to the bottom edge
-  mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse );
+  mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse, isProxy, smToCheckEdges );
 
   // store the rest nodes row by row
 
-  TIDSortedElemSet emptySet, avoidSet;
+  TIDSortedElemSet avoidSet;
   const SMDS_MeshElement* firstQuad = 0; // most left face above the last row of found nodes
 
   size_t nbFoundNodes = myIndexer._xSize;
@@ -1202,10 +1281,10 @@ bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
     //     o---o  o  o  o  o
     //n1down    n2down
     //
-    firstQuad = SMESH_MeshAlgos::FindFaceInSet( n1down, n2down, emptySet, avoidSet);
+    firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh );
     while ( firstQuad && !faceSubMesh->Contains( firstQuad )) {
       avoidSet.insert( firstQuad );
-      firstQuad = SMESH_MeshAlgos::FindFaceInSet( n1down, n2down, emptySet, avoidSet);
+      firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh);
     }
     if ( !firstQuad || !faceSubMesh->Contains( firstQuad ))
       return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
@@ -1235,7 +1314,7 @@ bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
     {
       // next face
       avoidSet.clear(); avoidSet.insert( quad );
-      quad = SMESH_MeshAlgos::FindFaceInSet( n1down, n1up, emptySet, avoidSet );
+      quad = FindFaceByNodes( n1down, n1up, avoidSet, mesh );
       if ( !quad || quad->NbNodes() % 4 > 0)
         return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
 
@@ -1352,7 +1431,7 @@ bool _QuadFaceGrid::locateChildren()
  */
 //================================================================================
 
-bool _QuadFaceGrid::loadCompositeGrid(SMESH_Mesh& mesh)
+bool _QuadFaceGrid::loadCompositeGrid(SMESH_ProxyMesh& mesh)
 {
   // Find out mutual location of children: find their right and up brothers
   if ( !locateChildren() )
@@ -1361,13 +1440,13 @@ bool _QuadFaceGrid::loadCompositeGrid(SMESH_Mesh& mesh)
   // Load nodes according to mutual location of children
 
   // grid size
-  myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments(mesh, /*withBrothers=*/true);
-  myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments(mesh, /*withBrothers=*/true);
+  myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments( mesh, /*withBrothers=*/true );
+  myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments( mesh, /*withBrothers=*/true );
 
   myGrid.resize( myIndexer.size() );
 
   int fromX = myReverse ? myIndexer._xSize : 0;
-  if (!myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
+  if ( !myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
     return error( myLeftBottomChild->GetError() );
 
   DumpGrid();
@@ -1429,7 +1508,7 @@ void _QuadFaceGrid::setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers )
  */
 //================================================================================
 
-bool _QuadFaceGrid::fillGrid(SMESH_Mesh&                    theMesh,
+bool _QuadFaceGrid::fillGrid(SMESH_ProxyMesh&               theMesh,
                              vector<const SMDS_MeshNode*> & theGrid,
                              const _Indexer&                theIndexer,
                              int                            theX,
@@ -1472,7 +1551,7 @@ bool _QuadFaceGrid::fillGrid(SMESH_Mesh&                    theMesh,
  */
 //================================================================================
 
-int _QuadFaceGrid::GetNbHoriSegments(SMESH_Mesh& mesh, bool withBrothers) const
+int _QuadFaceGrid::GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
 {
   int nbSegs = 0;
   if ( myLeftBottomChild )
@@ -1481,7 +1560,7 @@ int _QuadFaceGrid::GetNbHoriSegments(SMESH_Mesh& mesh, bool withBrothers) const
   }
   else
   {
-    nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments(mesh);
+    nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
     if ( withBrothers && myRightBrother )
       nbSegs += myRightBrother->GetNbHoriSegments( mesh, withBrothers );
   }
@@ -1494,7 +1573,7 @@ int _QuadFaceGrid::GetNbHoriSegments(SMESH_Mesh& mesh, bool withBrothers) const
  */
 //================================================================================
 
-int _QuadFaceGrid::GetNbVertSegments(SMESH_Mesh& mesh, bool withBrothers) const
+int _QuadFaceGrid::GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
 {
   int nbSegs = 0;
   if ( myLeftBottomChild )
@@ -1503,7 +1582,7 @@ int _QuadFaceGrid::GetNbVertSegments(SMESH_Mesh& mesh, bool withBrothers) const
   }
   else
   {
-    nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh);
+    nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh,0);
     if ( withBrothers && myUpBrother )
       nbSegs += myUpBrother->GetNbVertSegments( mesh, withBrothers );
   }
@@ -1914,30 +1993,46 @@ void _FaceSide::SetBottomSide( int i )
 //purpose  : 
 //=======================================================================
 
-int _FaceSide::GetNbSegments(SMESH_Mesh& mesh) const
+int _FaceSide::GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges) const
 {
   int nb = 0;
   if ( myChildren.empty() )
   {
-    nb = mesh.GetSubMesh(myEdge)->GetSubMeshDS()->NbElements();
+    nb = mesh.GetSubMesh(myEdge)->NbElements();
+
+    if ( smToCheckEdges )
+    {
+      // check that segments bound faces belonging to smToCheckEdges
+      SMDS_ElemIteratorPtr segIt = mesh.GetSubMesh(myEdge)->GetElements();
+      while ( segIt->more() )
+      {
+        const SMDS_MeshElement* seg = segIt->next();
+        if ( !IsSegmentOnSubMeshBoundary( mesh.GetProxyNode( seg->GetNode(0) ),
+                                          mesh.GetProxyNode( seg->GetNode(1) ),
+                                          smToCheckEdges, mesh ))
+          --nb;
+      }
+    }
   }
   else
   {
     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
     for ( ; side != sideEnd; ++side )
-      nb += side->GetNbSegments(mesh);
+      nb += side->GetNbSegments( mesh, smToCheckEdges );
   }
   return nb;
 }
 
 //=======================================================================
 //function : StoreNodes
-//purpose  : 
+//purpose  :
 //=======================================================================
 
-bool _FaceSide::StoreNodes(SMESH_Mesh&                   mesh,
+bool _FaceSide::StoreNodes(SMESH_ProxyMesh&              mesh,
                            vector<const SMDS_MeshNode*>& myGrid,
-                           bool                          reverse )
+                           bool                          reverse,
+                           bool                          isProxy,
+                           const SMESHDS_SubMesh*        smToCheckEdges)
 {
   list< TopoDS_Edge > edges;
   if ( myChildren.empty() )
@@ -1957,7 +2052,8 @@ bool _FaceSide::StoreNodes(SMESH_Mesh&                   mesh,
   list< TopoDS_Edge >::iterator edge = edges.begin(), eEnd = edges.end();
   for ( ; edge != eEnd; ++edge )
   {
-    map< double, const SMDS_MeshNode* > nodes;
+    typedef map< double, const SMDS_MeshNode* > TParamNodeMap;
+    TParamNodeMap nodes;
     bool ok = SMESH_Algo::GetSortedNodesOnEdge( mesh.GetMeshDS(),
                                                 *edge,
                                                 /*ignoreMediumNodes=*/true,
@@ -1971,17 +2067,46 @@ bool _FaceSide::StoreNodes(SMESH_Mesh&                   mesh,
          !nodes.rbegin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
       nodes.erase( --nodes.end() );
 
+    if ( isProxy )
+    {
+      TParamNodeMap::iterator u_node, nEnd = nodes.end();
+      for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
+        u_node->second = mesh.GetProxyNode( u_node->second );
+    }
+
+    if ( smToCheckEdges ) // erase nodes of segments not bounding faces of smToCheckEdges
+    {
+      {
+        TParamNodeMap::iterator u_node1, u_node2 = nodes.begin(), nEnd = nodes.end();
+        for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
+          if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
+                                           smToCheckEdges, mesh ))
+            break;
+          else
+            nodes.erase( u_node1 );
+      }
+      {
+        TParamNodeMap::reverse_iterator u_node1, u_node2 = nodes.rbegin(), nEnd = nodes.rend();
+        for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
+          if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
+                                           smToCheckEdges, mesh ))
+            break;
+          else
+            nodes.erase( --( u_node1.base() ));
+      }
+    }
+
     bool forward = ( edge->Orientation() == TopAbs_FORWARD );
     if ( reverse ) forward = !forward;
     if ( forward )
     {
-      map< double, const SMDS_MeshNode* >::iterator u_node, nEnd = nodes.end();
+      TParamNodeMap::iterator u_node, nEnd = nodes.end();
       for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
         myGrid[ nbNodes++ ] = u_node->second;
     }
-    else 
+    else
     {
-      map< double, const SMDS_MeshNode* >::reverse_iterator u_node, nEnd = nodes.rend();
+      TParamNodeMap::reverse_iterator u_node, nEnd = nodes.rend();
       for ( u_node = nodes.rbegin(); u_node != nEnd; ++u_node )
         myGrid[ nbNodes++ ] = u_node->second;
     }
index e0528fa20bc18fa12ee0e3d27ba98830feaf88a9..a7986de3bfa00afca09e5a4e558b259891c8c328 100644 (file)
@@ -28,6 +28,7 @@
 #include "SMESH_Algo.hxx"
 
 class SMESH_Mesh;
+class SMESH_ProxyMesh;
 class StdMeshers_FaceSide;
 class TopoDS_Edge;
 class TopoDS_Face;
@@ -60,6 +61,7 @@ private:
   bool findBoxFaces( const TopoDS_Shape&         shape,
                      std::list< _QuadFaceGrid >& boxFaceContainer,
                      SMESH_Mesh&                 mesh,
+                     SMESH_ProxyMesh&            proxyMesh,
                      _QuadFaceGrid * &           fBottom,
                      _QuadFaceGrid * &           fTop,
                      _QuadFaceGrid * &           fFront,
index 993956225671935b01875ccd63d12b396849b14a..f0d50dc0f321a45ae71992d52cff279c1dcab037 100644 (file)
@@ -258,6 +258,7 @@ namespace
           meshDS->RemoveFreeNode( nodesToRemove[i], sm, /*fromGroups=*/false);
       }
     }
+    return;
   }
 
   //================================================================================
@@ -319,7 +320,7 @@ void StdMeshers_QuadToTriaAdaptor::MergePiramids( const SMDS_MeshElement*     Pr
                                                   set<const SMDS_MeshNode*> & nodesToMove)
 {
   // cout << endl << "Merge " << PrmI->GetID() << " " << PrmJ->GetID() << " "
-  //      << PrmI->GetNode(4) << PrmJ->GetNode(4) << endl;
+  //      << PrmI->GetNode(4)->GetID() << " " << PrmJ->GetNode(4)->GetID() << endl;
   const SMDS_MeshNode* Nrem = PrmJ->GetNode(4); // node to remove
   //int nbJ = Nrem->NbInverseElements( SMDSAbs_Volume );
   SMESH_TNodeXYZ Pj( Nrem );
@@ -338,6 +339,9 @@ void StdMeshers_QuadToTriaAdaptor::MergePiramids( const SMDS_MeshElement*     Pr
   typedef SMDS_StdIterator< const SMDS_MeshElement*, SMDS_ElemIteratorPtr > TStdElemIterator;
   TStdElemIterator itEnd;
 
+  typedef std::map< const SMDS_MeshNode*, const SMDS_MeshNode* > TNNMap;
+  TNNMap mediumReplaceMap;
+
   // find and remove coincided faces of merged pyramids
   vector< const SMDS_MeshElement* > inverseElems
     // copy inverse elements to avoid iteration on changing container
@@ -355,6 +359,11 @@ void StdMeshers_QuadToTriaAdaptor::MergePiramids( const SMDS_MeshElement*     Pr
     }
     if ( FJEqual )
     {
+      if ( FJEqual->NbNodes() == 6 ) // find medium nodes to replace
+      {
+        mediumReplaceMap.insert( std::make_pair( FJEqual->GetNode(3), FI->GetNode(5) ));
+        mediumReplaceMap.insert( std::make_pair( FJEqual->GetNode(5), FI->GetNode(3) ));
+      }
       removeTmpElement( FI );
       removeTmpElement( FJEqual );
       myRemovedTrias.insert( FI );
@@ -370,12 +379,27 @@ void StdMeshers_QuadToTriaAdaptor::MergePiramids( const SMDS_MeshElement*     Pr
     const SMDS_MeshElement* elem = inverseElems[i];
     nodes.assign( elem->begin_nodes(), elem->end_nodes() );
     nodes[ elem->GetType() == SMDSAbs_Volume ? PYRAM_APEX : TRIA_APEX ] = CommonNode;
+    if ( !mediumReplaceMap.empty() )
+      for ( size_t iN = elem->NbCornerNodes(); iN < nodes.size(); ++iN )
+      {
+        TNNMap::iterator n2n = mediumReplaceMap.find( nodes[iN] );
+        if ( n2n != mediumReplaceMap.end() )
+          nodes[iN] = n2n->second;
+      }
     GetMeshDS()->ChangeElementNodes( elem, &nodes[0], nodes.size());
   }
   ASSERT( Nrem->NbInverseElements() == 0 );
   GetMeshDS()->RemoveFreeNode( Nrem,
                                GetMeshDS()->MeshElements( Nrem->getshapeId()),
                                /*fromGroups=*/false);
+  if ( !mediumReplaceMap.empty() )
+    for ( TNNMap::iterator n2n = mediumReplaceMap.begin(); n2n != mediumReplaceMap.end(); ++n2n )
+    {
+      const SMDS_MeshNode* remNode = n2n->first;
+      if ( !remNode->IsNull() && remNode->NbInverseElements() == 0 )
+        GetMeshDS()->RemoveFreeNode( remNode, 0, /*fromGroups=*/false);
+    }
+  return;
 }
 
 //================================================================================
@@ -390,7 +414,7 @@ void StdMeshers_QuadToTriaAdaptor::MergeAdjacent(const SMDS_MeshElement*    PrmI
 {
   TIDSortedElemSet adjacentPyrams;
   bool mergedPyrams = false;
-  for ( int k=0; k<4; k++ ) // loop on 4 base nodes of PrmI
+  for ( int k = 0; k < 4; k++ ) // loop on 4 base nodes of PrmI
   {
     const SMDS_MeshNode*   n = PrmI->GetNode(k);
     SMDS_ElemIteratorPtr vIt = n->GetInverseElementIterator( SMDSAbs_Volume );
@@ -414,6 +438,7 @@ void StdMeshers_QuadToTriaAdaptor::MergeAdjacent(const SMDS_MeshElement*    PrmI
     for (prm = adjacentPyrams.begin(); prm != adjacentPyrams.end(); ++prm)
       MergeAdjacent( *prm, nodesToMove, true );
   }
+  return;
 }
 
 //================================================================================
@@ -474,7 +499,7 @@ static gp_Pnt FindBestPoint(const gp_Pnt& P1, const gp_Pnt& P2,
 //           and a segment [PC,P]
 //=======================================================================
 
-static bool HasIntersection3(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint,
+static bool HasIntersection3(const gp_Pnt& P,  const gp_Pnt& PC, gp_Pnt&       Pint,
                              const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3)
 {
   const double EPSILON = 1e-6;
@@ -522,7 +547,27 @@ static bool HasIntersection3(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint,
 
   Pint = orig + dir * t;
 
-  return ( t > 0.  &&  t < segLen );
+  bool hasInt = ( t > 0.  &&  t < segLen );
+
+  if ( hasInt && det < EPSILON ) // t is inaccurate, additionally check
+  {
+    gp_XYZ triNorm = edge1 ^ edge2;
+    gp_XYZ int0vec = Pint.XYZ() - vert0;
+    gp_XYZ in      = triNorm ^ edge1; // dir inside triangle from edge1
+    double dot     = int0vec * in;
+    if ( dot < 0 && dot / triNorm.Modulus() < -EPSILON )
+      return false;
+    in  = edge2 ^ triNorm;
+    dot = int0vec * in;
+    if ( dot < 0 && dot / triNorm.Modulus() < -EPSILON )
+      return false;
+    gp_XYZ int1vec = Pint.XYZ() - vert1;
+    in  = triNorm ^ ( vert2 - vert1 );
+    dot = int1vec * in;
+    if ( dot < 0 && dot / triNorm.Modulus() < -EPSILON )
+      return false;
+  }
+  return hasInt;
 }
 
 //=======================================================================
@@ -817,7 +862,6 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh&         aMesh,
   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
   SMESH_MesherHelper helper(aMesh);
   helper.IsQuadraticSubMesh(aShape);
-  helper.SetElementsOnShape( true );
 
   if ( myElemSearcher ) delete myElemSearcher;
   vector< SMDS_ElemIteratorPtr > itVec;
@@ -877,10 +921,11 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh&         aMesh,
             // degenerate face
             // add triangles to result map
             SMDS_MeshFace* NewFace;
+            helper.SetElementsOnShape( false );
             if(!isRev)
-              NewFace = meshDS->AddFace( FNodes[0], FNodes[1], FNodes[2] );
+              NewFace = helper.AddFace( FNodes[0], FNodes[1], FNodes[2] );
             else
-              NewFace = meshDS->AddFace( FNodes[0], FNodes[2], FNodes[1] );
+              NewFace = helper.AddFace( FNodes[0], FNodes[2], FNodes[1] );
             storeTmpElement( NewFace );
             trias.push_back ( NewFace );
             quads.push_back( face );
@@ -916,20 +961,25 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh&         aMesh,
               if ( !LimitHeight( PCbest, PC, PN, FNodes, aMesh, face, /*UseApexRay=*/true, aShape ))
                 return false;
             }
-            // create node for PCbest
+            // create node at PCbest
+            helper.SetElementsOnShape( true );
             SMDS_MeshNode* NewNode = helper.AddNode( PCbest.X(), PCbest.Y(), PCbest.Z() );
 
+            // create a pyramid
+            SMDS_MeshVolume* aPyram;
+            if ( isRev )
+              aPyram = helper.AddVolume( FNodes[0], FNodes[3], FNodes[2], FNodes[1], NewNode );
+            else
+              aPyram = helper.AddVolume( FNodes[0], FNodes[1], FNodes[2], FNodes[3], NewNode );
+            myPyramids.push_back(aPyram);
+
             // add triangles to result map
-            for(i=0; i<4; i++)
+            helper.SetElementsOnShape( false );
+            for ( i = 0; i < 4; i++ )
             {
-              trias.push_back ( meshDS->AddFace( NewNode, FNodes[i], FNodes[i+1] ));
+              trias.push_back ( helper.AddFace( NewNode, FNodes[i], FNodes[i+1] ));
               storeTmpElement( trias.back() );
             }
-            // create a pyramid
-            if ( isRev ) swap( FNodes[1], FNodes[3]);
-            SMDS_MeshVolume* aPyram =
-              helper.AddVolume( FNodes[0], FNodes[1], FNodes[2], FNodes[3], NewNode );
-            myPyramids.push_back(aPyram);
 
             quads.push_back( face );
             hasNewTrias = true;
@@ -1018,7 +1068,6 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh)
   vector<const SMDS_MeshElement*> myPyramids;
   SMESH_MesherHelper helper(aMesh);
   helper.IsQuadraticSubMesh(aMesh.GetShapeToMesh());
-  helper.SetElementsOnShape( true );
 
   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
   SMESH_ProxyMesh::SubMesh* prxSubMesh = getProxySubMesh();
@@ -1116,10 +1165,11 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh)
           IsRev = true;
         }
       }
+      helper.SetElementsOnShape( false );
       if(!IsRev)
-        NewFace = meshDS->AddFace( FNodes[0], FNodes[1], FNodes[2] );
+        NewFace = helper.AddFace( FNodes[0], FNodes[1], FNodes[2] );
       else
-        NewFace = meshDS->AddFace( FNodes[0], FNodes[2], FNodes[1] );
+        NewFace = helper.AddFace( FNodes[0], FNodes[2], FNodes[1] );
       storeTmpElement( NewFace );
       prxSubMesh->AddElement( NewFace );
       continue;
@@ -1238,25 +1288,28 @@ bool StdMeshers_QuadToTriaAdaptor::Compute(SMESH_Mesh& aMesh)
         return false;
 
       // create node for Papex
+      helper.SetElementsOnShape( true );
       SMDS_MeshNode* NewNode = helper.AddNode( Papex.X(), Papex.Y(), Papex.Z() );
 
+      // create a pyramid
+      SMDS_MeshVolume* aPyram;
+      if(isRev)
+        aPyram = helper.AddVolume( FNodes[0], FNodes[1], FNodes[2], FNodes[3], NewNode );
+      else
+        aPyram = helper.AddVolume( FNodes[0], FNodes[3], FNodes[2], FNodes[1], NewNode );
+      myPyramids.push_back(aPyram);
+
       // add triangles to result map
+      helper.SetElementsOnShape( false );
       for ( i = 0; i < 4; i++) {
         SMDS_MeshFace* NewFace;
         if(isRev)
-          NewFace = meshDS->AddFace( NewNode, FNodes[i], FNodes[i+1] );
+          NewFace = helper.AddFace( NewNode, FNodes[i], FNodes[i+1] );
         else
-          NewFace = meshDS->AddFace( NewNode, FNodes[i+1], FNodes[i] );
+          NewFace = helper.AddFace( NewNode, FNodes[i+1], FNodes[i] );
         storeTmpElement( NewFace );
         prxSubMesh->AddElement( NewFace );
       }
-      // create a pyramid
-      SMDS_MeshVolume* aPyram;
-      if(isRev)
-        aPyram = helper.AddVolume( FNodes[0], FNodes[1], FNodes[2], FNodes[3], NewNode );
-      else
-        aPyram = helper.AddVolume( FNodes[0], FNodes[3], FNodes[2], FNodes[1], NewNode );
-      myPyramids.push_back(aPyram);
     }
   } // end loop on all faces