Salome HOME
23422: EDF 14312 - Strange behavior of Viscous Layer Surface offset + smooth
[modules/smesh.git] / src / StdMeshers / StdMeshers_ProjectionUtils.cxx
index 51a6398690b0a87fddc2df6443ec7cd0dc8019a6..e7051db9b8efa3751ed70d85c13137066fb2c113 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 #include "StdMeshers_ProjectionUtils.hxx"
 
-#include "StdMeshers_ProjectionSource1D.hxx"
-#include "StdMeshers_ProjectionSource2D.hxx"
-#include "StdMeshers_ProjectionSource3D.hxx"
-
 #include "SMDS_EdgePosition.hxx"
+#include "SMDS_FacePosition.hxx"
+#include "SMESHDS_Mesh.hxx"
 #include "SMESH_Algo.hxx"
 #include "SMESH_Block.hxx"
 #include "SMESH_Gen.hxx"
 #include "SMESH_HypoFilter.hxx"
 #include "SMESH_Hypothesis.hxx"
 #include "SMESH_Mesh.hxx"
+#include "SMESH_MeshAlgos.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_subMesh.hxx"
 #include "SMESH_subMeshEventListener.hxx"
-#include "SMESH_MeshAlgos.hxx"
+#include "StdMeshers_ProjectionSource1D.hxx"
+#include "StdMeshers_ProjectionSource2D.hxx"
+#include "StdMeshers_ProjectionSource3D.hxx"
 
 #include "utilities.h"
 
 #include <BRepAdaptor_Surface.hxx>
+#include <BRepMesh_Delaun.hxx>
 #include <BRepTools.hxx>
 #include <BRepTools_WireExplorer.hxx>
 #include <BRep_Builder.hxx>
@@ -124,6 +126,10 @@ namespace {
     const char* type[] ={"COMPOUND","COMPSOLID","SOLID","SHELL","FACE","WIRE","EDGE","VERTEX"};
     BRepTools::Write( shape, SMESH_Comment("/tmp/") << type[shape.ShapeType()] << "_"
                       << shape.TShape().operator->() << ".brep");
+    if ( !theMeshDS[0] ) {
+      show_shape( TopoDS_Shape(), "avoid warning: show_shape() defined but not used");
+      show_list( "avoid warning: show_list() defined but not used", list< TopoDS_Edge >() );
+    }
 #endif
     return false;
   }
@@ -410,9 +416,8 @@ namespace {
                      const gp_Pnt2d&    uv,
                      const double&      tol2d )
   {
-    TopoDS_Vertex VV[2];
-    TopExp::Vertices( edge, VV[0], VV[1], true);
-    gp_Pnt2d v1UV = BRep_Tool::Parameters( VV[vIndex], face);
+    TopoDS_Vertex V = SMESH_MesherHelper::IthVertex( vIndex, edge, /*CumOri=*/true );
+    gp_Pnt2d v1UV = BRep_Tool::Parameters( V, face);
     double dist2d = v1UV.Distance( uv );
     return dist2d < tol2d;
   }
@@ -739,8 +744,8 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
         int nbE = FindFaceAssociation( face1, VV1, face2, VV2, edges1, edges2, isVCloseness );
         if ( !nbE ) RETURN_BAD_RESULT("FindFaceAssociation() failed");
         InsertAssociation( face1, face2, theMap ); // assoc faces
-        MESSAGE("Assoc FACE " << theMesh1->GetMeshDS()->ShapeToIndex( face1 )<<
-                " to "        << theMesh2->GetMeshDS()->ShapeToIndex( face2 ));
+        // MESSAGE("Assoc FACE " << theMesh1->GetMeshDS()->ShapeToIndex( face1 )<<
+        //         " to "        << theMesh2->GetMeshDS()->ShapeToIndex( face2 ));
         if ( nbE == 2 && (edge1.IsSame( edges1.front())) != (edge2.IsSame( edges2.front())))
         {
           reverseEdges( edges2, nbE );
@@ -844,8 +849,8 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
       }
       // Associate shells
       //
-      int nbFaces1 = SMESH_MesherHelper:: Count( shell1, TopAbs_FACE, 0 );
-      int nbFaces2 = SMESH_MesherHelper:: Count( shell2, TopAbs_FACE, 0 );
+      int nbFaces1 = SMESH_MesherHelper::Count( shell1, TopAbs_FACE, 0 );
+      int nbFaces2 = SMESH_MesherHelper::Count( shell2, TopAbs_FACE, 0 );
       if ( nbFaces1 != nbFaces2 )
         RETURN_BAD_RESULT("Different nb of faces found for shells");
       if ( nbFaces1 > 0 ) {
@@ -951,14 +956,14 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
             v2e[0].UnBind( V[0] );
             v2e[1].UnBind( V[1] );
             InsertAssociation( e0, e1, theMap );
-            MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0 )<<
-                    " to "        << theMesh2->GetMeshDS()->ShapeToIndex( e1 ));
+            // MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0 )<<
+            //         " to "        << theMesh2->GetMeshDS()->ShapeToIndex( e1 ));
             V[0] = GetNextVertex( e0, V[0] );
             V[1] = GetNextVertex( e1, V[1] );
             if ( !V[0].IsNull() ) {
               InsertAssociation( V[0], V[1], theMap );
-              MESSAGE("Assoc vertex " << theMesh1->GetMeshDS()->ShapeToIndex( V[0] )<<
-                      " to "          << theMesh2->GetMeshDS()->ShapeToIndex( V[1] ));
+              // MESSAGE("Assoc vertex " << theMesh1->GetMeshDS()->ShapeToIndex( V[0] )<<
+              //         " to "          << theMesh2->GetMeshDS()->ShapeToIndex( V[1] ));
             }
           }
           else if ( nbE0 == 2 )
@@ -985,12 +990,12 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
             InsertAssociation( e0b, e1b, theMap );
             InsertAssociation( e0n, e1n, theMap );
             InsertAssociation( v0n, v1n, theMap );
-            MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0b )<<
-                    " to "        << theMesh2->GetMeshDS()->ShapeToIndex( e1b ));
-            MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0n )<<
-                    " to "        << theMesh2->GetMeshDS()->ShapeToIndex( e1n ));
-            MESSAGE("Assoc vertex " << theMesh1->GetMeshDS()->ShapeToIndex( v0n )<<
-                    " to "          << theMesh2->GetMeshDS()->ShapeToIndex( v1n ));
+            // MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0b )<<
+            //         " to "        << theMesh2->GetMeshDS()->ShapeToIndex( e1b ));
+            // MESSAGE("Assoc edge " << theMesh1->GetMeshDS()->ShapeToIndex( e0n )<<
+            //         " to "        << theMesh2->GetMeshDS()->ShapeToIndex( e1n ));
+            // MESSAGE("Assoc vertex " << theMesh1->GetMeshDS()->ShapeToIndex( v0n )<<
+            //         " to "          << theMesh2->GetMeshDS()->ShapeToIndex( v1n ));
             v2e[0].UnBind( V[0] );
             v2e[1].UnBind( V[1] );
             V[0] = v0n;
@@ -1107,8 +1112,8 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
         for ( ; eIt1 != edges1.end(); ++eIt1, ++eIt2 )
         {
           InsertAssociation( *eIt1, *eIt2, theMap );
-          VV1[0] = TopExp::FirstVertex( *eIt1, true );
-          VV2[0] = TopExp::FirstVertex( *eIt2, true );
+          VV1[0] = SMESH_MesherHelper::IthVertex( 0, *eIt1, true );
+          VV2[0] = SMESH_MesherHelper::IthVertex( 0, *eIt2, true );
           InsertAssociation( VV1[0], VV2[0], theMap );
         }
         InsertAssociation( theShape1, theShape2, theMap );
@@ -1339,10 +1344,10 @@ bool StdMeshers_ProjectionUtils::FindSubShapeAssociation(const TopoDS_Shape& the
 
   InsertAssociation( VV1[ 0 ], VV2[ 0 ], theMap );
   InsertAssociation( VV1[ 1 ], VV2[ 1 ], theMap );
-  MESSAGE("Initial assoc VERT " << theMesh1->GetMeshDS()->ShapeToIndex( VV1[ 0 ] )<<
-          " to "                << theMesh2->GetMeshDS()->ShapeToIndex( VV2[ 0 ] )<<
-          "\nand         VERT " << theMesh1->GetMeshDS()->ShapeToIndex( VV1[ 1 ] )<<
-          " to "                << theMesh2->GetMeshDS()->ShapeToIndex( VV2[ 1 ] ));
+  // MESSAGE("Initial assoc VERT " << theMesh1->GetMeshDS()->ShapeToIndex( VV1[ 0 ] )<<
+  //         " to "                << theMesh2->GetMeshDS()->ShapeToIndex( VV2[ 0 ] )<<
+  //         "\nand         VERT " << theMesh1->GetMeshDS()->ShapeToIndex( VV1[ 1 ] )<<
+  //         " to "                << theMesh2->GetMeshDS()->ShapeToIndex( VV2[ 1 ] ));
   if ( theShape1.ShapeType() == TopAbs_EDGE ) {
     InsertAssociation( theShape1, theShape2, theMap );
     return true;
@@ -1586,7 +1591,7 @@ int StdMeshers_ProjectionUtils::FindFaceAssociation(const TopoDS_Face&    face1,
           std::advance( edge2End, *nbE2 );
           if ( *nbE1 == *nbE2 && iW2 >= iW1 )
           {
-            // rotate edge2 untill coincidence with edge1 in 2D
+            // rotate edge2 until coincides with edge1 in 2D
             int i = *nbE2;
             bool sameUV = false;
             while ( !( sameUV = sameVertexUV( *edge2Beg, face2, 0, v0f1UV, vTolUV )) && --i > 0 )
@@ -1635,7 +1640,7 @@ int StdMeshers_ProjectionUtils::FindFaceAssociation(const TopoDS_Face&    face1,
               break;
             }
           }
-          // prepare to the next wire loop
+          // prepare for the next wire loop
           edge2Beg = edge2End;
         }
         edge1Beg = edge1End;
@@ -1868,7 +1873,7 @@ StdMeshers_ProjectionUtils::GetPropagationEdge( SMESH_Mesh*                 aMes
             int prevChainSize = aChain.Extent();
             if ( aChain.Add(anOppE) > prevChainSize ) { // ... anOppE is not in aChain
               // Add found edge to the chain oriented so that to
-              // have it co-directed with a forward MainEdge
+              // have it co-directed with a fromEdge
               TopAbs_Orientation ori = anE.Orientation();
               if ( anOppE.Orientation() == fourEdges[found].Orientation() )
                 ori = TopAbs::Reverse( ori );
@@ -1931,7 +1936,7 @@ FindMatchingNodesOnFaces( const TopoDS_Face&     face1,
 
   helper1.SetSubShape( face1 );
   helper2.SetSubShape( face2 );
-  if ( helper1.HasSeam() != helper2.HasSeam() )
+  if ( helper1.HasRealSeam() != helper2.HasRealSeam() )
     RETURN_BAD_RESULT("Different faces' geometry");
 
   // Data to call SMESH_MeshEditor::FindMatchingNodes():
@@ -2321,7 +2326,7 @@ bool StdMeshers_ProjectionUtils::MakeComputed(SMESH_subMesh * sm, const int iter
 
   string algoType = algo->GetName();
   if ( algoType.substr(0, 11) != "Projection_")
-    return gen->Compute( *mesh, shape, /*shapeOnly=*/true );
+    return gen->Compute( *mesh, shape, SMESH_Gen::SHAPE_ONLY );
 
   // try to compute source mesh
 
@@ -2362,7 +2367,7 @@ bool StdMeshers_ProjectionUtils::MakeComputed(SMESH_subMesh * sm, const int iter
     srcMesh = mesh;
 
   if ( MakeComputed( srcMesh->GetSubMesh( srcShape ), iterationNb + 1 ) &&
-       gen->Compute( *mesh, shape, /*shapeOnly=*/true ))
+       gen->Compute( *mesh, shape, SMESH_Gen::SHAPE_ONLY ))
     return sm->IsMeshComputed();
 
   return false;
@@ -2384,7 +2389,7 @@ std::string StdMeshers_ProjectionUtils::SourceNotComputedError( SMESH_subMesh *
   if ( !sm || sm->GetAlgoState() != SMESH_subMesh::NO_ALGO )
     return usualMessage; // algo is OK, anything else is KO.
 
-  // Try to find a type of all-dimentional algorithm that would compute the
+  // Try to find a type of all-dimensional algorithm that would compute the
   // given sub-mesh if it could be launched before projection
   const TopoDS_Shape shape = sm->GetSubShape();
   const int       shapeDim = SMESH_Gen::GetShapeDim( shape );
@@ -2565,7 +2570,7 @@ namespace StdMeshers_ProjectionUtils
 
   //================================================================================
   /*!
-   * \brief Computes transformation beween two sets of 2D points using
+   * \brief Computes transformation between two sets of 2D points using
    *        a least square approximation
    *
    * See "Surface Mesh Projection For Hexahedral Mesh Generation By Sweeping"
@@ -2648,7 +2653,7 @@ namespace StdMeshers_ProjectionUtils
 
   //================================================================================
   /*!
-   * \brief Computes transformation beween two sets of 3D points using
+   * \brief Computes transformation between two sets of 3D points using
    *        a least square approximation
    *
    * See "Surface Mesh Projection For Hexahedral Mesh Generation By Sweeping"
@@ -2784,4 +2789,320 @@ namespace StdMeshers_ProjectionUtils
     }
     return true;
   }
-}
+
+  //================================================================================
+  /*!
+   * \brief Add in-FACE nodes surrounding a given node to a queue
+   */
+  //================================================================================
+
+  typedef list< pair< const SMDS_MeshNode*, const BRepMesh_Triangle* > > TNodeTriaList;
+
+  void addCloseNodes( const SMDS_MeshNode*     srcNode,
+                      const BRepMesh_Triangle* bmTria,
+                      const int                srcFaceID,
+                      TNodeTriaList &          noTriQueue )
+  {
+    // find in-FACE nodes
+    SMDS_ElemIteratorPtr elems = srcNode->GetInverseElementIterator(SMDSAbs_Face);
+    while ( elems->more() )
+    {
+      const SMDS_MeshElement* elem = elems->next();
+      if ( elem->getshapeId() == srcFaceID )
+      {
+        for ( int i = 0, nb = elem->NbNodes(); i < nb; ++i )
+        {
+          const SMDS_MeshNode* n = elem->GetNode( i );
+          if ( !n->isMarked() )
+            noTriQueue.push_back( make_pair( n, bmTria ));
+        }
+      }
+    }
+  }
+
+  //================================================================================
+  /*!
+   * \brief Find a delauney triangle containing a given 2D point and return
+   *        barycentric coordinates within the found triangle
+   */
+  //================================================================================
+
+  const BRepMesh_Triangle* findTriangle( const gp_XY&                            uv,
+                                         const BRepMesh_Triangle*                bmTria,
+                                         Handle(BRepMesh_DataStructureOfDelaun)& triaDS,
+                                         double                                  bc[3] )
+  {
+    int   nodeIDs[3];
+    gp_XY nodeUVs[3];
+    int   linkIDs[3];
+    Standard_Boolean ori[3];
+
+    while ( bmTria )
+    {
+      // check bmTria
+
+      triaDS->ElementNodes( *bmTria, nodeIDs );
+      nodeUVs[0] = triaDS->GetNode( nodeIDs[0] ).Coord();
+      nodeUVs[1] = triaDS->GetNode( nodeIDs[1] ).Coord();
+      nodeUVs[2] = triaDS->GetNode( nodeIDs[2] ).Coord();
+
+      SMESH_MeshAlgos::GetBarycentricCoords( uv,
+                                             nodeUVs[0], nodeUVs[1], nodeUVs[2],
+                                             bc[0], bc[1] );
+      if ( bc[0] >= 0 && bc[1] >= 0 && bc[0] + bc[1] <= 1 )
+      {
+        bc[2] = 1 - bc[0] - bc[1];
+        return bmTria;
+      }
+
+      // look for a neighbor triangle, which is adjacent to a link intersected
+      // by a segment( triangle center -> uv )
+
+      gp_XY gc = ( nodeUVs[0] + nodeUVs[1] + nodeUVs[2] ) / 3.;
+      gp_XY seg = uv - gc;
+
+      bmTria->Edges( linkIDs, ori );
+      int triaID = triaDS->IndexOf( *bmTria );
+      bmTria = 0;
+
+      for ( int i = 0; i < 3; ++i )
+      {
+        const BRepMesh_PairOfIndex & triIDs = triaDS->ElementsConnectedTo( linkIDs[i] );
+        if ( triIDs.Extent() < 2 )
+          continue; // no neighbor triangle
+
+        // check if a link intersects gc2uv
+        const BRepMesh_Edge & link = triaDS->GetLink( linkIDs[i] );
+        const BRepMesh_Vertex & n1 = triaDS->GetNode( link.FirstNode() );
+        const BRepMesh_Vertex & n2 = triaDS->GetNode( link.LastNode() );
+        gp_XY uv1 = n1.Coord();
+        gp_XY lin = n2.Coord() - uv1; // link direction
+
+        double crossSegLin = seg ^ lin;
+        if ( Abs( crossSegLin ) < std::numeric_limits<double>::min() )
+          continue; // parallel
+
+        double uSeg = ( uv1 - gc ) ^ lin / crossSegLin;
+        if ( 0. <= uSeg && uSeg <= 1. )
+        {
+          bmTria = & triaDS->GetElement( triIDs.Index( 1 + ( triIDs.Index(1) == triaID )));
+          break;
+        }
+      }
+    }
+    return bmTria;
+  }
+
+  //================================================================================
+  /*!
+   * \brief triangulate the srcFace in 2D
+   *  \param [in] srcWires - boundary of the src FACE
+   */
+  //================================================================================
+
+  Morph::Morph(const TSideVector& srcWires)
+  {
+    _srcSubMesh = srcWires[0]->GetMesh()->GetSubMesh( srcWires[0]->Face() );
+
+    // compute _scale
+    {
+      BRepAdaptor_Surface surf( srcWires[0]->Face() );
+      const int nbDiv = 100;
+      const double uRange = surf.LastUParameter() - surf.FirstUParameter();
+      const double vRange = surf.LastVParameter() - surf.FirstVParameter();
+      const double dU = uRange / nbDiv;
+      const double dV = vRange / nbDiv;
+      double u = surf.FirstUParameter(), v = surf.FirstVParameter();
+      gp_Pnt p0U = surf.Value( u, v ), p0V = p0U;
+      double lenU = 0, lenV = 0;
+      for ( ; u < surf.LastUParameter(); u += dU, v += dV )
+      {
+        gp_Pnt p1U = surf.Value( u, surf.FirstVParameter() );
+        lenU += p1U.Distance( p0U );
+        p0U = p1U;
+        gp_Pnt p1V = surf.Value( surf.FirstUParameter(), v );
+        lenV += p1V.Distance( p0V );
+        p0V = p1V;
+      }
+      _scale.SetCoord( lenU / uRange, lenV / vRange );
+    }
+
+    // count boundary points
+    int iP = 1, nbP = 0;
+    for ( size_t iW = 0; iW < srcWires.size(); ++iW )
+      nbP += srcWires[iW]->NbPoints() - 1; // 1st and last points coincide
+
+    _bndSrcNodes.resize( nbP + 1 ); _bndSrcNodes[0] = 0;
+
+    // fill boundary points
+    BRepMesh::Array1OfVertexOfDelaun srcVert( 1, 1 + nbP );
+    BRepMesh_Vertex v( 0, 0, BRepMesh_Frontier );
+    for ( size_t iW = 0; iW < srcWires.size(); ++iW )
+    {
+      const UVPtStructVec& srcPnt = srcWires[iW]->GetUVPtStruct();
+      for ( int i = 0, nb = srcPnt.size() - 1;  i < nb;  ++i, ++iP )
+      {
+        _bndSrcNodes[ iP ]  = srcPnt[i].node;
+        srcPnt[i].node->setIsMarked( true );
+
+        v.ChangeCoord() = srcPnt[i].UV().Multiplied( _scale );
+        srcVert( iP )   = v;
+      }
+    }
+    // triangulate the srcFace in 2D
+    BRepMesh_Delaun delauney( srcVert );
+    _triaDS = delauney.Result();
+  }
+
+  //================================================================================
+  /*!
+   * \brief Move non-marked target nodes
+   *  \param [in,out] tgtHelper - helper
+   *  \param [in] tgtWires - boundary nodes of the target FACE; must be in the
+   *         same order as the nodes in srcWires given in the constructor
+   *  \param [in] src2tgtNodes - map of src -> tgt nodes
+   *  \param [in] moveAll - to move all nodes; if \c false, move only non-marked nodes
+   *  \return bool - Ok or not
+   */
+  //================================================================================
+
+  bool Morph::Perform(SMESH_MesherHelper&           tgtHelper,
+                      const TSideVector&            tgtWires,
+                      Handle(ShapeAnalysis_Surface) tgtSurface,
+                      const TNodeNodeMap&           src2tgtNodes,
+                      const bool                    moveAll)
+  {
+    // get tgt boundary points corresponding to _bndSrcNodes
+    size_t nbP = 0;
+    for ( size_t iW = 0; iW < tgtWires.size(); ++iW )
+      nbP += tgtWires[iW]->NbPoints() - 1; // 1st and last points coincide
+    if ( nbP != _bndSrcNodes.size() - 1 )
+      return false;
+
+    BRepMesh::Array1OfVertexOfDelaun tgtVert( 1, 1 + nbP );
+    BRepMesh_Vertex v( 0, 0, BRepMesh_Frontier );
+    for ( size_t iW = 0, iP = 1; iW < tgtWires.size(); ++iW )
+    {
+      const UVPtStructVec& tgtPnt = tgtWires[iW]->GetUVPtStruct();
+      for ( int i = 0, nb = tgtPnt.size() - 1;  i < nb;  ++i, ++iP )
+      {
+        v.ChangeCoord() = tgtPnt[i].UV().Multiplied( _scale );
+        tgtVert( iP )   = v;
+      }
+    }
+
+    const TopoDS_Face& srcFace = TopoDS::Face( _srcSubMesh->GetSubShape() );
+    const int        srcFaceID = _srcSubMesh->GetId();
+    SMESHDS_Mesh* tgtMesh = tgtHelper.GetMeshDS();
+    const SMDS_MeshNode *srcNode, *tgtNode;
+    const BRepMesh_Triangle *bmTria;
+
+    // initialize a queue of nodes with starting triangles
+    TNodeTriaList noTriQueue;
+    size_t iBndSrcN = 1;
+    for ( ; iBndSrcN < _bndSrcNodes.size() &&  noTriQueue.empty();  ++iBndSrcN )
+    {
+      // get a triangle
+      const BRepMesh::ListOfInteger & linkIds = _triaDS->LinksConnectedTo( iBndSrcN );
+      const BRepMesh_PairOfIndex &    triaIds = _triaDS->ElementsConnectedTo( linkIds.First() );
+      const BRepMesh_Triangle&           tria = _triaDS->GetElement( triaIds.Index(1) );
+
+      addCloseNodes( _bndSrcNodes[ iBndSrcN ], &tria, srcFaceID, noTriQueue );
+    }
+
+    // un-mark internal src nodes; later we will mark moved nodes
+    int nbSrcNodes = 0;
+    SMDS_NodeIteratorPtr nIt = _srcSubMesh->GetSubMeshDS()->GetNodes();
+    if ( !nIt || !nIt->more() ) return true;
+    if ( moveAll )
+    {
+      nbSrcNodes = _srcSubMesh->GetSubMeshDS()->NbNodes();
+      while ( nIt->more() )
+        nIt->next()->setIsMarked( false );
+    }
+    else
+    {
+      while ( nIt->more() )
+        nbSrcNodes += int( !nIt->next()->isMarked() );
+    }
+
+    // Move tgt nodes
+
+    double bc[3]; // barycentric coordinates
+    int    nodeIDs[3];
+    bool   checkUV = true;
+    const SMDS_FacePosition* pos;
+
+    while ( nbSrcNodes > 0 )
+    {
+      while ( !noTriQueue.empty() )
+      {
+        srcNode = noTriQueue.front().first;
+        bmTria  = noTriQueue.front().second;
+        noTriQueue.pop_front();
+        if ( srcNode->isMarked() )
+          continue;
+        --nbSrcNodes;
+        srcNode->setIsMarked( true );
+
+        // find a delauney triangle containing the src node
+        gp_XY uv = tgtHelper.GetNodeUV( srcFace, srcNode, NULL, &checkUV );
+        uv *= _scale;
+        bmTria = findTriangle( uv, bmTria, _triaDS, bc );
+        if ( !bmTria )
+          continue;
+
+        // compute new coordinates for a corresponding tgt node
+        gp_XY uvNew( 0., 0. ), nodeUV;
+        _triaDS->ElementNodes( *bmTria, nodeIDs );
+        for ( int i = 0; i < 3; ++i )
+          uvNew += bc[i] * tgtVert( nodeIDs[i]).Coord();
+        uvNew.SetCoord( uvNew.X() / _scale.X(), uvNew.Y() / _scale.Y() );
+        gp_Pnt xyz = tgtSurface->Value( uvNew );
+
+        // find and move tgt node
+        TNodeNodeMap::const_iterator n2n = src2tgtNodes.find( srcNode );
+        if ( n2n == src2tgtNodes.end() ) continue;
+        tgtNode = n2n->second;
+        tgtMesh->MoveNode( tgtNode, xyz.X(), xyz.Y(), xyz.Z() );
+
+        if (( pos = dynamic_cast< const SMDS_FacePosition* >( tgtNode->GetPosition() )))
+          const_cast<SMDS_FacePosition*>( pos )->SetParameters( uvNew.X(), uvNew.Y() );
+
+        addCloseNodes( srcNode, bmTria, srcFaceID, noTriQueue );
+      }
+
+      if ( nbSrcNodes > 0 )
+      {
+        // assure that all src nodes are visited
+        for ( ; iBndSrcN < _bndSrcNodes.size() &&  noTriQueue.empty();  ++iBndSrcN )
+        {
+          const BRepMesh::ListOfInteger & linkIds = _triaDS->LinksConnectedTo( iBndSrcN );
+          const BRepMesh_PairOfIndex &    triaIds = _triaDS->ElementsConnectedTo( linkIds.First() );
+          const BRepMesh_Triangle&           tria = _triaDS->GetElement( triaIds.Index(1) );
+          addCloseNodes( _bndSrcNodes[ iBndSrcN ], &tria, srcFaceID, noTriQueue );
+        }
+        if ( noTriQueue.empty() )
+        {
+          SMDS_NodeIteratorPtr nIt = _srcSubMesh->GetSubMeshDS()->GetNodes();
+          while ( nIt->more() )
+          {
+            srcNode = nIt->next();
+            if ( !srcNode->isMarked() )
+              noTriQueue.push_back( make_pair( srcNode, bmTria ));
+          }
+        }
+      }
+    }
+
+    return true;
+
+  } // Morph::Perform
+
+gp_XY Morph::GetBndUV(const int iNode) const
+{
+    return _triaDS->GetNode( iNode ).Coord();
+  }
+
+
+} // namespace StdMeshers_ProjectionUtils