+
+ //================================================================================
+ /*!
+ * \brief triangulate the srcFace in 2D
+ * \param [in] srcWires - boundary of the src FACE
+ */
+ //================================================================================
+
+ Morph::Morph(const TSideVector& srcWires):
+ _delaunay( srcWires, /*checkUV=*/true )
+ {
+ _srcSubMesh = srcWires[0]->GetMesh()->GetSubMesh( srcWires[0]->Face() );
+ }
+
+ //================================================================================
+ /*!
+ * \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 src boundary nodes
+ 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 != _delaunay.GetBndNodes().size() )
+ return false;
+
+ std::vector< gp_XY > tgtUV( nbP );
+ for ( size_t iW = 0, iP = 0; iW < tgtWires.size(); ++iW )
+ {
+ const UVPtStructVec& tgtPnt = tgtWires[iW]->GetUVPtStruct();
+ for ( int i = 0, nb = tgtPnt.size() - 1; i < nb; ++i, ++iP )
+ {
+ tgtUV[ iP ] = tgtPnt[i].UV();
+ }
+ }
+
+ SMESHDS_Mesh* tgtMesh = tgtHelper.GetMeshDS();
+ const SMDS_MeshNode *srcNode, *tgtNode;
+
+ // un-mark internal src nodes in order iterate them using _delaunay
+ smIdType 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]; // nodes of a delaunay triangle
+
+ _delaunay.InitTraversal( nbSrcNodes );
+
+ while (( srcNode = _delaunay.NextNode( bc, nodeIDs )))
+ {
+ // compute new coordinates for a corresponding tgt node
+ gp_XY uvNew( 0., 0. ), nodeUV;
+ for ( int i = 0; i < 3; ++i )
+ uvNew += bc[i] * tgtUV[ nodeIDs[i]];
+ 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 ( SMDS_FacePositionPtr pos = tgtNode->GetPosition() )
+ pos->SetParameters( uvNew.X(), uvNew.Y() );
+
+ --nbSrcNodes;
+ }
+
+ return nbSrcNodes == 0;
+
+ } // Morph::Perform
+
+ //=======================================================================
+ //function : Delaunay
+ //purpose : construct from face sides
+ //=======================================================================
+
+ Delaunay::Delaunay( const TSideVector& wires, bool checkUV ):
+ SMESH_Delaunay( SideVector2UVPtStructVec( wires ),
+ TopoDS::Face( wires[0]->FaceHelper()->GetSubShape() ),
+ wires[0]->FaceHelper()->GetSubShapeID() )
+ {
+ _wire = wires[0]; // keep a wire to assure _helper to keep alive
+ _helper = _wire->FaceHelper();
+ _checkUVPtr = checkUV ? & _checkUV : 0;
+ }
+
+ //=======================================================================
+ //function : Delaunay
+ //purpose : construct from UVPtStructVec's
+ //=======================================================================
+
+ Delaunay::Delaunay( const std::vector< const UVPtStructVec* > & boundaryNodes,
+ SMESH_MesherHelper& faceHelper,
+ bool checkUV):
+ SMESH_Delaunay( boundaryNodes,
+ TopoDS::Face( faceHelper.GetSubShape() ),
+ faceHelper.GetSubShapeID() )
+ {
+ _helper = & faceHelper;
+ _checkUVPtr = checkUV ? & _checkUV : 0;
+ }
+
+ //=======================================================================
+ //function : getNodeUV
+ //purpose :
+ //=======================================================================
+
+ gp_XY Delaunay::getNodeUV( const TopoDS_Face& face, const SMDS_MeshNode* node ) const
+ {
+ return _helper->GetNodeUV( face, node, 0, _checkUVPtr );
+ }
+
+
+} // namespace StdMeshers_ProjectionUtils