1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_Projection_2D.cxx
26 // Created : Fri Oct 20 11:37:07 2006
27 // Author : Edward AGAPOV (eap)
29 #include "StdMeshers_Projection_2D.hxx"
31 #include "StdMeshers_ProjectionSource2D.hxx"
32 #include "StdMeshers_ProjectionUtils.hxx"
33 #include "StdMeshers_FaceSide.hxx"
35 #include "SMDS_EdgePosition.hxx"
36 #include "SMDS_FacePosition.hxx"
37 #include "SMESHDS_Hypothesis.hxx"
38 #include "SMESHDS_SubMesh.hxx"
39 #include "SMESH_Block.hxx"
40 #include "SMESH_Comment.hxx"
41 #include "SMESH_Gen.hxx"
42 #include "SMESH_Mesh.hxx"
43 #include "SMESH_MesherHelper.hxx"
44 #include "SMESH_Pattern.hxx"
45 #include "SMESH_subMesh.hxx"
46 #include "SMESH_subMeshEventListener.hxx"
48 #include "utilities.h"
50 #include <BRepAdaptor_Surface.hxx>
51 #include <BRep_Tool.hxx>
52 #include <Bnd_B2d.hxx>
53 #include <GeomAPI_ProjectPointOnSurf.hxx>
54 #include <GeomLib_IsPlanarSurface.hxx>
56 #include <TopExp_Explorer.hxx>
57 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TopTools_MapOfShape.hxx>
61 #include <TopoDS_Solid.hxx>
64 #include <gp_GTrsf.hxx>
69 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
71 namespace TAssocTool = StdMeshers_ProjectionUtils;
72 //typedef StdMeshers_ProjectionUtils TAssocTool;
74 //=======================================================================
75 //function : StdMeshers_Projection_2D
77 //=======================================================================
79 StdMeshers_Projection_2D::StdMeshers_Projection_2D(int hypId, int studyId, SMESH_Gen* gen)
80 :SMESH_2D_Algo(hypId, studyId, gen)
82 _name = "Projection_2D";
83 _compatibleHypothesis.push_back("ProjectionSource2D");
87 //================================================================================
91 //================================================================================
93 StdMeshers_Projection_2D::~StdMeshers_Projection_2D()
96 //=======================================================================
97 //function : CheckHypothesis
99 //=======================================================================
101 bool StdMeshers_Projection_2D::CheckHypothesis(SMESH_Mesh& theMesh,
102 const TopoDS_Shape& theShape,
103 SMESH_Hypothesis::Hypothesis_Status& theStatus)
105 list <const SMESHDS_Hypothesis * >::const_iterator itl;
107 const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(theMesh, theShape);
108 if ( hyps.size() == 0 )
110 theStatus = HYP_MISSING;
111 return false; // can't work with no hypothesis
114 if ( hyps.size() > 1 )
116 theStatus = HYP_ALREADY_EXIST;
120 const SMESHDS_Hypothesis *theHyp = hyps.front();
122 string hypName = theHyp->GetName();
126 if (hypName == "ProjectionSource2D")
128 _sourceHypo = static_cast<const StdMeshers_ProjectionSource2D *>(theHyp);
130 // Check hypo parameters
132 SMESH_Mesh* srcMesh = _sourceHypo->GetSourceMesh();
133 SMESH_Mesh* tgtMesh = & theMesh;
138 if ( _sourceHypo->HasVertexAssociation() )
141 TopoDS_Shape edge = TAssocTool::GetEdgeByVertices
142 ( srcMesh, _sourceHypo->GetSourceVertex(1), _sourceHypo->GetSourceVertex(2) );
143 if ( edge.IsNull() ||
144 !SMESH_MesherHelper::IsSubShape( edge, srcMesh ) ||
145 !SMESH_MesherHelper::IsSubShape( edge, _sourceHypo->GetSourceFace() ))
147 theStatus = HYP_BAD_PARAMETER;
148 error("Invalid source vertices");
149 SCRUTE((edge.IsNull()));
150 SCRUTE((SMESH_MesherHelper::IsSubShape( edge, srcMesh )));
151 SCRUTE((SMESH_MesherHelper::IsSubShape( edge, _sourceHypo->GetSourceFace() )));
156 edge = TAssocTool::GetEdgeByVertices
157 ( tgtMesh, _sourceHypo->GetTargetVertex(1), _sourceHypo->GetTargetVertex(2) );
158 if ( edge.IsNull() || !SMESH_MesherHelper::IsSubShape( edge, tgtMesh ))
160 theStatus = HYP_BAD_PARAMETER;
161 error("Invalid target vertices");
162 SCRUTE((edge.IsNull()));
163 SCRUTE((SMESH_MesherHelper::IsSubShape( edge, tgtMesh )));
166 else if ( !_sourceHypo->IsCompoundSource() &&
167 !SMESH_MesherHelper::IsSubShape( edge, theShape ))
169 theStatus = HYP_BAD_PARAMETER;
170 error("Invalid target vertices");
171 SCRUTE((SMESH_MesherHelper::IsSubShape( edge, theShape )));
175 // check a source face
176 if ( !SMESH_MesherHelper::IsSubShape( _sourceHypo->GetSourceFace(), srcMesh ) ||
177 ( srcMesh == tgtMesh && theShape == _sourceHypo->GetSourceFace() ))
179 theStatus = HYP_BAD_PARAMETER;
180 error("Invalid source face");
181 SCRUTE((SMESH_MesherHelper::IsSubShape( _sourceHypo->GetSourceFace(), srcMesh )));
182 SCRUTE((srcMesh == tgtMesh));
183 SCRUTE(( theShape == _sourceHypo->GetSourceFace() ));
188 theStatus = HYP_INCOMPATIBLE;
190 return ( theStatus == HYP_OK );
195 //================================================================================
197 * \brief define if a node is new or old
198 * \param node - node to check
199 * \retval bool - true if the node existed before Compute() is called
201 //================================================================================
203 bool isOldNode( const SMDS_MeshNode* node )
205 // old nodes are shared by edges and new ones are shared
206 // only by faces created by mapper
207 //if ( is1DComputed )
209 bool isOld = node->NbInverseElements(SMDSAbs_Edge) > 0;
214 // SMDS_ElemIteratorPtr invFace = node->GetInverseElementIterator(SMDSAbs_Face);
215 // bool isNew = invFace->more();
220 //================================================================================
222 * \brief Class to remove mesh built by pattern mapper on edges
223 * and vertices in the case of failure of projection algo.
224 * It does it's job at destruction
226 //================================================================================
231 MeshCleaner( SMESH_subMesh* faceSubMesh ): sm(faceSubMesh) {}
232 ~MeshCleaner() { Clean(sm); }
233 void Release() { sm = 0; } // mesh will not be removed
234 static void Clean( SMESH_subMesh* sm, bool withSub=true )
236 if ( !sm || !sm->GetSubMeshDS() ) return;
237 // PAL16567, 18920. Remove face nodes as well
238 // switch ( sm->GetSubShape().ShapeType() ) {
239 // case TopAbs_VERTEX:
240 // case TopAbs_EDGE: {
241 SMDS_NodeIteratorPtr nIt = sm->GetSubMeshDS()->GetNodes();
242 SMESHDS_Mesh* mesh = sm->GetFather()->GetMeshDS();
243 while ( nIt->more() ) {
244 const SMDS_MeshNode* node = nIt->next();
245 if ( !isOldNode( node ) )
246 mesh->RemoveNode( node );
248 // do not break but iterate over DependsOn()
251 if ( !withSub ) return;
252 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(false,false);
253 while ( smIt->more() )
254 Clean( smIt->next(), false );
259 //================================================================================
261 * \brief find new nodes belonging to one free border of mesh on face
262 * \param sm - submesh on edge or vertex containg nodes to choose from
263 * \param face - the face bound by the submesh
264 * \param u2nodes - map to fill with nodes
265 * \param seamNodes - set of found nodes
266 * \retval bool - is a success
268 //================================================================================
270 bool getBoundaryNodes ( SMESH_subMesh* sm,
271 const TopoDS_Face& face,
272 map< double, const SMDS_MeshNode* > & u2nodes,
273 set< const SMDS_MeshNode* > & seamNodes)
277 if ( !sm || !sm->GetSubMeshDS() )
278 RETURN_BAD_RESULT("Null submesh");
280 SMDS_NodeIteratorPtr nIt = sm->GetSubMeshDS()->GetNodes();
281 switch ( sm->GetSubShape().ShapeType() ) {
283 case TopAbs_VERTEX: {
284 while ( nIt->more() ) {
285 const SMDS_MeshNode* node = nIt->next();
286 if ( isOldNode( node ) ) continue;
287 u2nodes.insert( make_pair( 0., node ));
288 seamNodes.insert( node );
295 // Get submeshes of sub-vertices
296 const map< int, SMESH_subMesh * >& subSM = sm->DependsOn();
297 if ( subSM.size() != 2 )
298 RETURN_BAD_RESULT("there must be 2 submeshes of sub-vertices"
299 " but we have " << subSM.size());
300 SMESH_subMesh* smV1 = subSM.begin()->second;
301 SMESH_subMesh* smV2 = subSM.rbegin()->second;
302 if ( !smV1->IsMeshComputed() || !smV2->IsMeshComputed() )
303 RETURN_BAD_RESULT("Empty vertex submeshes");
305 const SMDS_MeshNode* nV1 = 0;
306 const SMDS_MeshNode* nE = 0;
308 // Look for nV1 - a new node on V1
309 nIt = smV1->GetSubMeshDS()->GetNodes();
310 while ( nIt->more() && !nE ) {
311 const SMDS_MeshNode* node = nIt->next();
312 if ( isOldNode( node ) ) continue;
315 // Find nE - a new node connected to nV1 and belonging to edge submesh;
316 SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
317 SMDS_ElemIteratorPtr vElems = nV1->GetInverseElementIterator(SMDSAbs_Face);
318 while ( vElems->more() && !nE ) {
319 const SMDS_MeshElement* elem = vElems->next();
320 int nbNodes = elem->NbNodes();
321 if ( elem->IsQuadratic() )
323 int iV1 = elem->GetNodeIndex( nV1 );
324 // try next after nV1
325 int iE = SMESH_MesherHelper::WrapIndex( iV1 + 1, nbNodes );
326 if ( smDS->Contains( elem->GetNode( iE ) ))
327 nE = elem->GetNode( iE );
329 // try node before nV1
330 iE = SMESH_MesherHelper::WrapIndex( iV1 - 1, nbNodes );
331 if ( smDS->Contains( elem->GetNode( iE )))
332 nE = elem->GetNode( iE );
334 if ( nE && elem->IsQuadratic() ) { // find medium node between nV1 and nE
335 if ( Abs( iV1 - iE ) == 1 )
336 nE = elem->GetNode( Min ( iV1, iE ) + nbNodes );
338 nE = elem->GetNode( elem->NbNodes() - 1 );
343 RETURN_BAD_RESULT("No new node found on V1");
345 RETURN_BAD_RESULT("new node on edge not found");
347 // Get the whole free border of a face
348 list< const SMDS_MeshNode* > bordNodes;
349 list< const SMDS_MeshElement* > bordFaces;
350 if ( !SMESH_MeshEditor::FindFreeBorder (nV1, nE, nV1, bordNodes, bordFaces ))
351 RETURN_BAD_RESULT("free border of a face not found by nodes " <<
352 nV1->GetID() << " " << nE->GetID() );
354 // Insert nodes of the free border to the map until node on V2 encountered
355 SMESHDS_SubMesh* v2smDS = smV2->GetSubMeshDS();
356 list< const SMDS_MeshNode* >::iterator bordIt = bordNodes.begin();
357 bordIt++; // skip nV1
358 for ( ; bordIt != bordNodes.end(); ++bordIt ) {
359 const SMDS_MeshNode* node = *bordIt;
360 if ( v2smDS->Contains( node ))
362 if ( node->GetPosition()->GetTypeOfPosition() != SMDS_TOP_EDGE )
363 RETURN_BAD_RESULT("Bad node position type: node " << node->GetID() <<
364 " pos type " << node->GetPosition()->GetTypeOfPosition());
365 const SMDS_EdgePosition* pos =
366 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
367 u2nodes.insert( make_pair( pos->GetUParameter(), node ));
368 seamNodes.insert( node );
370 if ( u2nodes.size() != seamNodes.size() )
371 RETURN_BAD_RESULT("Bad node params on edge " << sm->GetId() <<
372 ", " << u2nodes.size() << " != " << seamNodes.size() );
377 RETURN_BAD_RESULT ("Unexpected submesh type");
379 } // bool getBoundaryNodes()
381 //================================================================================
383 * \brief Check if two consecutive EDGEs are connected in 2D
384 * \param [in] E1 - a well oriented non-seam EDGE
385 * \param [in] E2 - a possibly well oriented seam EDGE
386 * \param [in] F - a FACE
387 * \return bool - result
389 //================================================================================
391 bool are2dConnected( const TopoDS_Edge & E1,
392 const TopoDS_Edge & E2,
393 const TopoDS_Face & F )
396 Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface( E1, F, f, l );
397 gp_Pnt2d uvFirst1 = c1->Value( f );
398 gp_Pnt2d uvLast1 = c1->Value( l );
400 Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface( E2, F, f, l );
401 gp_Pnt2d uvFirst2 = c2->Value( E2.Orientation() == TopAbs_REVERSED ? l : f );
402 double tol2 = Max( Precision::PConfusion() * Precision::PConfusion(),
403 1e-5 * uvLast1.SquareDistance( uvFirst1 ));
405 return (( uvFirst2.SquareDistance( uvFirst1 ) < tol2 ) ||
406 ( uvFirst2.SquareDistance( uvLast1 ) < tol2 ));
409 //================================================================================
411 * \brief Compose TSideVector for both FACEs keeping matching order of EDGEs
412 * and fill src2tgtNodes map
414 //================================================================================
416 TError getWires(const TopoDS_Face& tgtFace,
417 const TopoDS_Face& srcFace,
418 SMESH_Mesh * tgtMesh,
419 SMESH_Mesh * srcMesh,
420 const TAssocTool::TShapeShapeMap& shape2ShapeMap,
421 TSideVector& srcWires,
422 TSideVector& tgtWires,
423 TAssocTool::TNodeNodeMap& src2tgtNodes,
426 SMESHDS_Mesh* tgtMeshDS = tgtMesh->GetMeshDS();
427 SMESHDS_Mesh* srcMeshDS = srcMesh->GetMeshDS();
429 src2tgtNodes.clear();
431 // get ordered src EDGEs
433 srcWires = StdMeshers_FaceSide::GetFaceWires( srcFace, *srcMesh,/*skipMediumNodes=*/0, err);
434 if ( err && !err->IsOK() || srcWires.empty() )
437 SMESH_MesherHelper srcHelper( *srcMesh );
438 srcHelper.SetSubShape( srcFace );
440 // make corresponding sequence of tgt EDGEs
441 tgtWires.resize( srcWires.size() );
442 for ( size_t iW = 0; iW < srcWires.size(); ++iW )
444 StdMeshers_FaceSidePtr srcWire = srcWires[iW];
446 list< TopoDS_Edge > tgtEdges;
447 TopTools_IndexedMapOfShape edgeMap; // to detect seam edges
448 for ( int iE = 0; iE < srcWire->NbEdges(); ++iE )
450 TopoDS_Edge srcE = srcWire->Edge( iE );
451 TopoDS_Edge tgtE = TopoDS::Edge( shape2ShapeMap( srcE, /*isSrc=*/true));
452 TopoDS_Shape srcEbis = shape2ShapeMap( tgtE, /*isSrc=*/false );
453 if ( srcE.Orientation() != srcEbis.Orientation() )
455 // reverse a seam edge encountered for the second time
456 const int index = edgeMap.Add( tgtE );
457 if ( index < edgeMap.Extent() ) // E is a seam
459 // check which of edges to reverse, E or one already being in tgtEdges
460 if ( are2dConnected( tgtEdges.back(), tgtE, tgtFace ))
462 list< TopoDS_Edge >::iterator eIt = tgtEdges.begin();
463 std::advance( eIt, index-1 );
464 if ( are2dConnected( tgtEdges.back(), *eIt, tgtFace ))
472 if ( srcWire->NbEdges() == 1 && tgtMesh == srcMesh ) // circle
474 // try to verify ori by propagation
475 pair<int,TopoDS_Edge> nE =
476 StdMeshers_ProjectionUtils::GetPropagationEdge( srcMesh, tgtE, srcE );
477 if ( !nE.second.IsNull() )
480 tgtEdges.push_back( tgtE );
483 tgtWires[ iW ].reset( new StdMeshers_FaceSide( tgtFace, tgtEdges, tgtMesh,
484 /*theIsForward = */ true,
485 /*theIgnoreMediumNodes = */false));
486 StdMeshers_FaceSidePtr tgtWire = tgtWires[ iW ];
488 // Fill map of src to tgt nodes with nodes on edges
490 for ( int iE = 0; iE < srcWire->NbEdges(); ++iE )
492 if ( srcMesh->GetSubMesh( srcWire->Edge(iE) )->IsEmpty() ||
493 tgtMesh->GetSubMesh( tgtWire->Edge(iE) )->IsEmpty() )
495 // add nodes on VERTEXes for a case of not meshes EDGEs
496 const SMDS_MeshNode* srcN = srcWire->VertexNode( iE );
497 const SMDS_MeshNode* tgtN = tgtWire->VertexNode( iE );
499 src2tgtNodes.insert( make_pair( srcN, tgtN ));
503 const bool skipMedium = true, isFwd = true;
504 StdMeshers_FaceSide srcEdge( srcFace, srcWire->Edge(iE), srcMesh, isFwd, skipMedium);
505 StdMeshers_FaceSide tgtEdge( tgtFace, tgtWire->Edge(iE), tgtMesh, isFwd, skipMedium);
507 vector< const SMDS_MeshNode* > srcNodes = srcEdge.GetOrderedNodes();
508 vector< const SMDS_MeshNode* > tgtNodes = tgtEdge.GetOrderedNodes();
510 if (( srcNodes.size() != tgtNodes.size() ) && tgtNodes.size() > 0 )
511 return SMESH_ComputeError::New( COMPERR_BAD_INPUT_MESH,
512 "Different number of nodes on edges");
513 if ( !tgtNodes.empty() )
515 vector< const SMDS_MeshNode* >::iterator tn = tgtNodes.begin();
516 //if ( srcWire->Edge(iE).Orientation() == tgtWire->Edge(iE).Orientation() )
518 vector< const SMDS_MeshNode* >::iterator sn = srcNodes.begin();
519 for ( ; tn != tgtNodes.end(); ++tn, ++sn)
520 src2tgtNodes.insert( make_pair( *sn, *tn ));
524 // vector< const SMDS_MeshNode* >::reverse_iterator sn = srcNodes.rbegin();
525 // for ( ; tn != tgtNodes.end(); ++tn, ++sn)
526 // src2tgtNodes.insert( make_pair( *sn, *tn ));
531 } // loop on EDGEs of a WIRE
538 //================================================================================
540 * \brief Preform projection in case if tgtFace.IsPartner( srcFace ) and in case
541 * if projection by 3D transformation is possible
543 //================================================================================
545 bool projectPartner(const TopoDS_Face& tgtFace,
546 const TopoDS_Face& srcFace,
547 const TSideVector& tgtWires,
548 const TSideVector& srcWires,
549 const TAssocTool::TShapeShapeMap& shape2ShapeMap,
550 TAssocTool::TNodeNodeMap& src2tgtNodes,
551 const bool is1DComputed)
553 SMESH_Mesh * tgtMesh = tgtWires[0]->GetMesh();
554 SMESH_Mesh * srcMesh = srcWires[0]->GetMesh();
555 SMESHDS_Mesh* tgtMeshDS = tgtMesh->GetMeshDS();
556 SMESHDS_Mesh* srcMeshDS = srcMesh->GetMeshDS();
557 SMESH_MesherHelper helper( *tgtMesh );
559 const double tol = 1.e-7 * srcMeshDS->getMaxDim();
561 // transformation to get location of target nodes from source ones
562 StdMeshers_ProjectionUtils::TrsfFinder3D trsf;
563 bool trsfIsOK = false;
564 if ( tgtFace.IsPartner( srcFace ))
566 gp_GTrsf srcTrsf = srcFace.Location().Transformation();
567 gp_GTrsf tgtTrsf = tgtFace.Location().Transformation();
568 gp_GTrsf t = srcTrsf.Inverted().Multiplied( tgtTrsf );
571 gp_Pnt srcP = BRep_Tool::Pnt( srcWires[0]->FirstVertex() );
572 gp_Pnt tgtP = BRep_Tool::Pnt( tgtWires[0]->FirstVertex() );
573 trsfIsOK = ( tgtP.Distance( trsf.Transform( srcP )) < tol );
576 trsf.Set( tgtTrsf.Inverted().Multiplied( srcTrsf ));
577 trsfIsOK = ( tgtP.Distance( trsf.Transform( srcP )) < tol );
582 // Try to find the 3D transformation
584 const int totNbSeg = 50;
585 vector< gp_XYZ > srcPnts, tgtPnts;
586 srcPnts.reserve( totNbSeg );
587 tgtPnts.reserve( totNbSeg );
588 gp_XYZ srcBC( 0,0,0 ), tgtBC( 0,0,0 );
589 for ( size_t iW = 0; iW < srcWires.size(); ++iW )
591 const double minSegLen = srcWires[iW]->Length() / totNbSeg;
592 for ( int iE = 0; iE < srcWires[iW]->NbEdges(); ++iE )
594 int nbSeg = Max( 1, int( srcWires[iW]->EdgeLength( iE ) / minSegLen ));
595 double srcU = srcWires[iW]->FirstParameter( iE );
596 double tgtU = tgtWires[iW]->FirstParameter( iE );
597 double srcDu = ( srcWires[iW]->LastParameter( iE )- srcU ) / nbSeg;
598 double tgtDu = ( tgtWires[iW]->LastParameter( iE )- tgtU ) / nbSeg;
599 for ( size_t i = 0; i < nbSeg; ++i )
601 srcPnts.push_back( srcWires[iW]->Value3d( srcU ).XYZ() );
602 tgtPnts.push_back( tgtWires[iW]->Value3d( tgtU ).XYZ() );
605 srcBC += srcPnts.back();
606 tgtBC += tgtPnts.back();
610 if ( !trsf.Solve( srcPnts, tgtPnts ))
615 const int nbTestPnt = 20;
616 const size_t iStep = Max( 1, int( srcPnts.size() / nbTestPnt ));
618 gp_Pnt trsfTgt = trsf.Transform( srcBC / srcPnts.size() );
619 trsfIsOK = ( trsfTgt.SquareDistance( tgtBC / tgtPnts.size() ) < tol*tol );
620 for ( size_t i = 0; ( i < srcPnts.size() && trsfIsOK ); i += iStep )
622 gp_Pnt trsfTgt = trsf.Transform( srcPnts[i] );
623 trsfIsOK = ( trsfTgt.SquareDistance( tgtPnts[i] ) < tol*tol );
625 // check an in-FACE point
628 BRepAdaptor_Surface srcSurf( srcFace );
630 srcSurf.Value( 0.321 * ( srcSurf.FirstUParameter() + srcSurf.LastUParameter() ),
631 0.123 * ( srcSurf.FirstVParameter() + srcSurf.LastVParameter() ));
632 gp_Pnt tgtTrsfP = trsf.Transform( srcP );
634 GeomAPI_ProjectPointOnSurf& proj = helper.GetProjector( tgtFace, loc, 0.1*tol );
635 if ( !loc.IsIdentity() )
636 tgtTrsfP.Transform( loc.Transformation().Inverted() );
637 proj.Perform( tgtTrsfP );
638 trsfIsOK = ( proj.IsDone() &&
639 proj.NbPoints() > 0 &&
640 proj.LowerDistance() < tol );
648 // prepare the helper to adding quadratic elements if necessary
649 //helper.SetSubShape( tgtFace );
650 helper.IsQuadraticSubMesh( tgtFace );
652 SMESHDS_SubMesh* srcSubDS = srcMeshDS->MeshElements( srcFace );
653 if ( !is1DComputed && srcSubDS->NbElements() )
654 helper.SetIsQuadratic( srcSubDS->GetElements()->next()->IsQuadratic() );
656 SMESH_MesherHelper srcHelper( *srcMesh );
657 srcHelper.SetSubShape( srcFace );
659 const SMDS_MeshNode* nullNode = 0;
660 TAssocTool::TNodeNodeMap::iterator srcN_tgtN;
662 // indices of nodes to create properly oriented faces
663 bool isReverse = ( !trsf.IsIdentity() );
664 int tri1 = 1, tri2 = 2, quad1 = 1, quad3 = 3;
666 std::swap( tri1, tri2 ), std::swap( quad1, quad3 );
668 SMDS_ElemIteratorPtr elemIt = srcSubDS->GetElements();
669 vector< const SMDS_MeshNode* > tgtNodes;
670 while ( elemIt->more() ) // loop on all mesh faces on srcFace
672 const SMDS_MeshElement* elem = elemIt->next();
673 const int nbN = elem->NbCornerNodes();
674 tgtNodes.resize( nbN );
675 helper.SetElementsOnShape( false );
676 for ( int i = 0; i < nbN; ++i ) // loop on nodes of the source element
678 const SMDS_MeshNode* srcNode = elem->GetNode(i);
679 srcN_tgtN = src2tgtNodes.insert( make_pair( srcNode, nullNode )).first;
680 if ( srcN_tgtN->second == nullNode )
683 gp_Pnt tgtP = trsf.Transform( SMESH_TNodeXYZ( srcNode ));
684 SMDS_MeshNode* n = helper.AddNode( tgtP.X(), tgtP.Y(), tgtP.Z() );
685 srcN_tgtN->second = n;
686 switch ( srcNode->GetPosition()->GetTypeOfPosition() )
690 gp_Pnt2d srcUV = srcHelper.GetNodeUV( srcFace, srcNode );
691 tgtMeshDS->SetNodeOnFace( n, helper.GetSubShapeID(), srcUV.X(), srcUV.Y() );
696 const TopoDS_Shape & srcE = srcMeshDS->IndexToShape( srcNode->getshapeId() );
697 const TopoDS_Shape & tgtE = shape2ShapeMap( srcE, /*isSrc=*/true );
698 double srcU = srcHelper.GetNodeU( TopoDS::Edge( srcE ), srcNode );
699 tgtMeshDS->SetNodeOnEdge( n, TopoDS::Edge( tgtE ), srcU );
702 case SMDS_TOP_VERTEX:
704 const TopoDS_Shape & srcV = srcMeshDS->IndexToShape( srcNode->getshapeId() );
705 const TopoDS_Shape & tgtV = shape2ShapeMap( srcV, /*isSrc=*/true );
706 tgtMeshDS->SetNodeOnVertex( n, TopoDS::Vertex( tgtV ));
712 tgtNodes[i] = srcN_tgtN->second;
715 helper.SetElementsOnShape( true );
718 case 3: helper.AddFace(tgtNodes[0], tgtNodes[tri1], tgtNodes[tri2]); break;
719 case 4: helper.AddFace(tgtNodes[0], tgtNodes[quad1], tgtNodes[2], tgtNodes[quad3]); break;
721 if ( isReverse ) std::reverse( tgtNodes.begin(), tgtNodes.end() );
722 helper.AddPolygonalFace( tgtNodes );
726 // check node positions
728 if ( !tgtFace.IsPartner( srcFace ) )
730 SMESH_MesherHelper edgeHelper( *tgtMesh );
731 edgeHelper.ToFixNodeParameters( true );
732 helper.ToFixNodeParameters( true );
736 const double tol2d = 1e-12;
737 srcN_tgtN = src2tgtNodes.begin();
738 for ( ; srcN_tgtN != src2tgtNodes.end(); ++srcN_tgtN )
740 const SMDS_MeshNode* n = srcN_tgtN->second;
741 switch ( n->GetPosition()->GetTypeOfPosition() )
745 if ( nbOkPos > 10 ) break;
746 gp_XY uv = helper.GetNodeUV( tgtFace, n ), uvBis = uv;
747 if (( helper.CheckNodeUV( tgtFace, n, uv, tol )) &&
748 (( uv - uvBis ).SquareModulus() < tol2d ))
751 nbOkPos = -((int) src2tgtNodes.size() );
756 const TopoDS_Edge & tgtE = TopoDS::Edge( tgtMeshDS->IndexToShape( n->getshapeId() ));
757 edgeHelper.SetSubShape( tgtE );
758 edgeHelper.GetNodeU( tgtE, n, 0, &toCheck );
768 } // bool projectPartner()
770 //================================================================================
772 * \brief Preform projection in case if the faces are similar in 2D space
774 //================================================================================
776 bool projectBy2DSimilarity(const TopoDS_Face& tgtFace,
777 const TopoDS_Face& srcFace,
778 const TSideVector& tgtWires,
779 const TSideVector& srcWires,
780 const TAssocTool::TShapeShapeMap& shape2ShapeMap,
781 TAssocTool::TNodeNodeMap& src2tgtNodes,
782 const bool is1DComputed)
784 SMESH_Mesh * tgtMesh = tgtWires[0]->GetMesh();
785 SMESH_Mesh * srcMesh = srcWires[0]->GetMesh();
787 // WARNING: we can have problems if the FACE is symmetrical in 2D,
788 // then the projection can be mirrored relating to what is expected
790 // 1) Find 2D transformation
792 StdMeshers_ProjectionUtils::TrsfFinder2D trsf;
794 // get 2 pairs of corresponding UVs
795 gp_Pnt2d srcP0 = srcWires[0]->Value2d(0.0);
796 gp_Pnt2d srcP1 = srcWires[0]->Value2d(0.333);
797 gp_Pnt2d tgtP0 = tgtWires[0]->Value2d(0.0);
798 gp_Pnt2d tgtP1 = tgtWires[0]->Value2d(0.333);
800 // make transformation
801 gp_Trsf2d fromTgtCS, toSrcCS; // from/to global CS
802 gp_Ax2d srcCS( srcP0, gp_Vec2d( srcP0, srcP1 ));
803 gp_Ax2d tgtCS( tgtP0, gp_Vec2d( tgtP0, tgtP1 ));
804 toSrcCS .SetTransformation( srcCS );
805 fromTgtCS.SetTransformation( tgtCS );
807 trsf.Set( fromTgtCS * toSrcCS );
809 // check transformation
810 bool trsfIsOK = true;
811 const double tol = 1e-5 * gp_Vec2d( srcP0, srcP1 ).Magnitude();
812 for ( double u = 0.12; ( u < 1. && trsfIsOK ); u += 0.1 )
814 gp_Pnt2d srcUV = srcWires[0]->Value2d( u );
815 gp_Pnt2d tgtUV = tgtWires[0]->Value2d( u );
816 gp_Pnt2d tgtUV2 = trsf.Transform( srcUV );
817 trsfIsOK = ( tgtUV.Distance( tgtUV2 ) < tol );
820 // Find trsf using a least-square approximation
824 const int totNbSeg = 50;
825 vector< gp_XY > srcPnts, tgtPnts;
826 srcPnts.resize( totNbSeg );
827 tgtPnts.resize( totNbSeg );
828 for ( size_t iW = 0; iW < srcWires.size(); ++iW )
830 const double minSegLen = srcWires[iW]->Length() / totNbSeg;
831 for ( int iE = 0; iE < srcWires[iW]->NbEdges(); ++iE )
833 int nbSeg = Max( 1, int( srcWires[iW]->EdgeLength( iE ) / minSegLen ));
834 double srcU = srcWires[iW]->FirstParameter( iE );
835 double tgtU = tgtWires[iW]->FirstParameter( iE );
836 double srcDu = ( srcWires[iW]->LastParameter( iE )- srcU ) / nbSeg;
837 double tgtDu = ( tgtWires[iW]->LastParameter( iE )- tgtU ) / nbSeg;
838 for ( size_t i = 0; i < nbSeg; ++i, srcU += srcDu, tgtU += tgtDu )
840 srcPnts.push_back( srcWires[iW]->Value2d( srcU ).XY() );
841 tgtPnts.push_back( tgtWires[iW]->Value2d( tgtU ).XY() );
845 if ( !trsf.Solve( srcPnts, tgtPnts ))
851 const int nbTestPnt = 10;
852 const size_t iStep = Max( 1, int( srcPnts.size() / nbTestPnt ));
853 for ( size_t i = 0; ( i < srcPnts.size() && trsfIsOK ); i += iStep )
855 gp_Pnt2d trsfTgt = trsf.Transform( srcPnts[i] );
856 trsfIsOK = ( trsfTgt.Distance( tgtPnts[i] ) < tol );
861 } // "Find transformation" block
865 SMESHDS_SubMesh* srcSubDS = srcMesh->GetMeshDS()->MeshElements( srcFace );
867 SMESH_MesherHelper helper( *tgtMesh );
868 helper.SetSubShape( tgtFace );
870 helper.IsQuadraticSubMesh( tgtFace );
872 helper.SetIsQuadratic( srcSubDS->GetElements()->next()->IsQuadratic() );
873 helper.SetElementsOnShape( true );
874 Handle(Geom_Surface) tgtSurface = BRep_Tool::Surface( tgtFace );
875 SMESHDS_Mesh* tgtMeshDS = tgtMesh->GetMeshDS();
877 SMESH_MesherHelper srcHelper( *srcMesh );
878 srcHelper.SetSubShape( srcFace );
880 const SMDS_MeshNode* nullNode = 0;
881 TAssocTool::TNodeNodeMap::iterator srcN_tgtN;
883 SMDS_ElemIteratorPtr elemIt = srcSubDS->GetElements();
884 vector< const SMDS_MeshNode* > tgtNodes;
886 while ( elemIt->more() ) // loop on all mesh faces on srcFace
888 const SMDS_MeshElement* elem = elemIt->next();
889 const int nbN = elem->NbCornerNodes();
890 tgtNodes.resize( nbN );
891 for ( int i = 0; i < nbN; ++i ) // loop on nodes of the source element
893 const SMDS_MeshNode* srcNode = elem->GetNode(i);
894 srcN_tgtN = src2tgtNodes.insert( make_pair( srcNode, nullNode )).first;
895 if ( srcN_tgtN->second == nullNode )
898 gp_Pnt2d srcUV = srcHelper.GetNodeUV( srcFace, srcNode,
899 elem->GetNode( helper.WrapIndex(i+1,nbN)), &uvOK);
900 gp_Pnt2d tgtUV = trsf.Transform( srcUV );
901 gp_Pnt tgtP = tgtSurface->Value( tgtUV.X(), tgtUV.Y() );
902 SMDS_MeshNode* n = tgtMeshDS->AddNode( tgtP.X(), tgtP.Y(), tgtP.Z() );
903 switch ( srcNode->GetPosition()->GetTypeOfPosition() )
905 case SMDS_TOP_FACE: {
906 tgtMeshDS->SetNodeOnFace( n, helper.GetSubShapeID(), tgtUV.X(), tgtUV.Y() );
909 case SMDS_TOP_EDGE: {
910 TopoDS_Shape srcEdge = srcHelper.GetSubShapeByNode( srcNode, srcHelper.GetMeshDS() );
911 TopoDS_Edge tgtEdge = TopoDS::Edge( shape2ShapeMap( srcEdge, /*isSrc=*/true ));
912 double U = Precision::Infinite();
913 helper.CheckNodeU( tgtEdge, n, U, Precision::PConfusion());
914 tgtMeshDS->SetNodeOnEdge( n, TopoDS::Edge( tgtEdge ), U );
917 case SMDS_TOP_VERTEX: {
918 TopoDS_Shape srcV = srcHelper.GetSubShapeByNode( srcNode, srcHelper.GetMeshDS() );
919 TopoDS_Shape tgtV = shape2ShapeMap( srcV, /*isSrc=*/true );
920 tgtMeshDS->SetNodeOnVertex( n, TopoDS::Vertex( tgtV ));
924 srcN_tgtN->second = n;
926 tgtNodes[i] = srcN_tgtN->second;
928 // create a new face (with reversed orientation)
931 case 3: helper.AddFace(tgtNodes[0], tgtNodes[2], tgtNodes[1]); break;
932 case 4: helper.AddFace(tgtNodes[0], tgtNodes[3], tgtNodes[2], tgtNodes[1]); break;
934 } // loop on all mesh faces on srcFace
939 //================================================================================
941 * \brief Preform projection in case of quadrilateral faces
943 //================================================================================
945 bool projectQuads(const TopoDS_Face& tgtFace,
946 const TopoDS_Face& srcFace,
947 const TSideVector& tgtWires,
948 const TSideVector& srcWires,
949 const TAssocTool::TShapeShapeMap& shape2ShapeMap,
950 TAssocTool::TNodeNodeMap& src2tgtNodes,
951 const bool is1DComputed)
953 SMESH_Mesh * tgtMesh = tgtWires[0]->GetMesh();
954 SMESH_Mesh * srcMesh = srcWires[0]->GetMesh();
955 SMESHDS_Mesh * tgtMeshDS = tgtMesh->GetMeshDS();
956 SMESHDS_Mesh * srcMeshDS = srcMesh->GetMeshDS();
958 if ( srcWires[0]->NbEdges() != 4 )
962 for ( int iE = 0; iE < 4; ++iE )
964 SMESHDS_SubMesh* sm = srcMeshDS->MeshElements( srcWires[0]->Edge( iE ));
965 if ( !sm ) return false;
966 if ( sm->NbNodes() + sm->NbElements() == 0 ) return false;
968 if ( BRepAdaptor_Surface( tgtFace ).GetType() != GeomAbs_Plane )
970 // if ( BRepAdaptor_Surface( tgtFace ).GetType() == GeomAbs_Plane &&
971 // BRepAdaptor_Surface( srcFace ).GetType() == GeomAbs_Plane )
972 // return false; // too easy
974 // load EDGEs to SMESH_Block
977 TopTools_IndexedMapOfOrientedShape blockSubShapes;
979 const TopoDS_Solid& box = srcMesh->PseudoShape();
980 TopoDS_Shell shell = TopoDS::Shell( TopExp_Explorer( box, TopAbs_SHELL ).Current() );
982 block.LoadBlockShapes( shell, v, v, blockSubShapes ); // fill all since operator[] is missing
984 const SMESH_Block::TShapeID srcFaceBID = SMESH_Block::ID_Fxy0;
985 const SMESH_Block::TShapeID tgtFaceBID = SMESH_Block::ID_Fxy1;
986 vector< int > edgeBID;
987 block.GetFaceEdgesIDs( srcFaceBID, edgeBID ); // u0, u1, 0v, 1v
988 blockSubShapes.Substitute( edgeBID[0], srcWires[0]->Edge(0) );
989 blockSubShapes.Substitute( edgeBID[1], srcWires[0]->Edge(2) );
990 blockSubShapes.Substitute( edgeBID[2], srcWires[0]->Edge(3) );
991 blockSubShapes.Substitute( edgeBID[3], srcWires[0]->Edge(1) );
992 block.GetFaceEdgesIDs( tgtFaceBID, edgeBID ); // u0, u1, 0v, 1v
993 blockSubShapes.Substitute( edgeBID[0], tgtWires[0]->Edge(0) );
994 blockSubShapes.Substitute( edgeBID[1], tgtWires[0]->Edge(2) );
995 blockSubShapes.Substitute( edgeBID[2], tgtWires[0]->Edge(3) );
996 blockSubShapes.Substitute( edgeBID[3], tgtWires[0]->Edge(1) );
997 block.LoadFace( srcFace, srcFaceBID, blockSubShapes );
998 block.LoadFace( tgtFace, tgtFaceBID, blockSubShapes );
1000 // remember connectivity of new faces in terms of ( node-or-XY )
1002 typedef std::pair< const SMDS_MeshNode*, gp_XYZ > TNodeOrXY; // node-or-XY
1003 typedef std::vector< TNodeOrXY* > TFaceConn; // face connectivity
1004 std::vector< TFaceConn > newFacesVec; // connectivity of all faces
1005 std::map< const SMDS_MeshNode*, TNodeOrXY > srcNode2tgtNXY; // src node -> node-or-XY
1007 TAssocTool::TNodeNodeMap::iterator srcN_tgtN;
1008 std::map< const SMDS_MeshNode*, TNodeOrXY >::iterator srcN_tgtNXY;
1009 std::pair< std::map< const SMDS_MeshNode*, TNodeOrXY >::iterator, bool > n2n_isNew;
1010 TNodeOrXY nullNXY( (SMDS_MeshNode*)NULL, gp_XYZ(0,0,0) );
1012 SMESHDS_SubMesh* srcSubDS = srcMeshDS->MeshElements( srcFace );
1013 newFacesVec.resize( srcSubDS->NbElements() );
1016 SMDS_ElemIteratorPtr elemIt = srcSubDS->GetElements();
1017 while ( elemIt->more() ) // loop on all mesh faces on srcFace
1019 const SMDS_MeshElement* elem = elemIt->next();
1020 TFaceConn& tgtNodes = newFacesVec[ iFaceSrc++ ];
1022 const int nbN = elem->NbCornerNodes();
1023 tgtNodes.resize( nbN );
1024 for ( int i = 0; i < nbN; ++i ) // loop on nodes of the source element
1026 const SMDS_MeshNode* srcNode = elem->GetNode(i);
1027 n2n_isNew = srcNode2tgtNXY.insert( make_pair( srcNode, nullNXY ));
1028 TNodeOrXY & tgtNodeOrXY = n2n_isNew.first->second;
1029 if ( n2n_isNew.second ) // new src node encounters
1031 srcN_tgtN = src2tgtNodes.find( srcNode );
1032 if ( srcN_tgtN != src2tgtNodes.end() )
1034 tgtNodeOrXY.first = srcN_tgtN->second; // tgt node exists
1038 // find XY of src node withing the quadrilateral srcFace
1039 if ( !block.ComputeParameters( SMESH_TNodeXYZ( srcNode ),
1040 tgtNodeOrXY.second, srcFaceBID ))
1044 tgtNodes[ i ] = & tgtNodeOrXY;
1048 // as all XY are computed, create tgt nodes and faces
1050 SMESH_MesherHelper helper( *tgtMesh );
1051 helper.SetSubShape( tgtFace );
1053 helper.IsQuadraticSubMesh( tgtFace );
1055 helper.SetIsQuadratic( srcSubDS->GetElements()->next()->IsQuadratic() );
1056 helper.SetElementsOnShape( true );
1057 Handle(Geom_Surface) tgtSurface = BRep_Tool::Surface( tgtFace );
1059 SMESH_MesherHelper srcHelper( *srcMesh );
1060 srcHelper.SetSubShape( srcFace );
1062 vector< const SMDS_MeshNode* > tgtNodes;
1065 for ( size_t iFaceTgt = 0; iFaceTgt < newFacesVec.size(); ++iFaceTgt )
1067 TFaceConn& tgtConn = newFacesVec[ iFaceTgt ];
1068 tgtNodes.resize( tgtConn.size() );
1069 for ( size_t iN = 0; iN < tgtConn.size(); ++iN )
1071 const SMDS_MeshNode* & tgtN = tgtConn[ iN ]->first;
1072 if ( !tgtN ) // create a node
1074 if ( !block.FaceUV( tgtFaceBID, tgtConn[iN]->second, uv ))
1076 gp_Pnt p = tgtSurface->Value( uv.X(), uv.Y() );
1077 tgtN = helper.AddNode( p.X(), p.Y(), p.Z(), uv.X(), uv.Y() );
1079 tgtNodes[ tgtNodes.size() - iN - 1] = tgtN; // reversed orientation
1081 switch ( tgtNodes.size() )
1083 case 3: helper.AddFace(tgtNodes[0], tgtNodes[1], tgtNodes[2]); break;
1084 case 4: helper.AddFace(tgtNodes[0], tgtNodes[1], tgtNodes[2], tgtNodes[3]); break;
1086 if ( tgtNodes.size() > 4 )
1087 helper.AddPolygonalFace( tgtNodes );
1092 } // bool projectQuads(...)
1094 //================================================================================
1096 * \brief Fix bad faces by smoothing
1098 //================================================================================
1100 bool fixDistortedFaces( SMESH_MesherHelper& helper,
1101 TSideVector& tgtWires )
1103 SMESH_subMesh* faceSM = helper.GetMesh()->GetSubMesh( helper.GetSubShape() );
1105 if ( helper.IsDistorted2D( faceSM, /*checkUV=*/false ))
1107 SMESH_MeshEditor editor( helper.GetMesh() );
1108 SMESHDS_SubMesh* smDS = faceSM->GetSubMeshDS();
1109 const TopoDS_Face& F = TopoDS::Face( faceSM->GetSubShape() );
1111 TIDSortedElemSet faces;
1112 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1113 for ( faceIt = smDS->GetElements(); faceIt->more(); )
1114 faces.insert( faces.end(), faceIt->next() );
1116 // choose smoothing algo
1117 //SMESH_MeshEditor:: SmoothMethod algo = SMESH_MeshEditor::CENTROIDAL;
1118 bool isConcaveBoundary = false;
1119 for ( size_t iW = 0; iW < tgtWires.size() && !isConcaveBoundary; ++iW )
1121 TopoDS_Edge prevEdge = tgtWires[iW]->Edge( tgtWires[iW]->NbEdges() - 1 );
1122 for ( int iE = 0; iE < tgtWires[iW]->NbEdges() && !isConcaveBoundary; ++iE )
1124 double angle = helper.GetAngle( prevEdge, tgtWires[iW]->Edge( iE ),
1125 F, tgtWires[iW]->FirstVertex( iE ));
1126 isConcaveBoundary = ( angle < -5. * M_PI / 180. );
1128 prevEdge = tgtWires[iW]->Edge( iE );
1131 SMESH_MeshEditor:: SmoothMethod algo =
1132 isConcaveBoundary ? SMESH_MeshEditor::CENTROIDAL : SMESH_MeshEditor::LAPLACIAN;
1134 // smooth in 2D or 3D?
1135 TopLoc_Location loc;
1136 Handle(Geom_Surface) surface = BRep_Tool::Surface( F, loc );
1137 bool isPlanar = GeomLib_IsPlanarSurface( surface ).IsPlanar();
1140 set<const SMDS_MeshNode*> fixedNodes;
1141 editor.Smooth( faces, fixedNodes, algo, /*nbIterations=*/ 10,
1142 /*theTgtAspectRatio=*/1.0, /*the2D=*/!isPlanar);
1144 helper.ToFixNodeParameters( true );
1146 return !helper.IsDistorted2D( faceSM, /*checkUV=*/true );
1154 //=======================================================================
1155 //function : Compute
1157 //=======================================================================
1159 bool StdMeshers_Projection_2D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
1161 _src2tgtNodes.clear();
1163 MESSAGE("Projection_2D Compute");
1167 SMESH_Mesh * srcMesh = _sourceHypo->GetSourceMesh();
1168 SMESH_Mesh * tgtMesh = & theMesh;
1172 SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
1173 SMESH_MesherHelper helper( theMesh );
1175 // ---------------------------
1176 // Make sub-shapes association
1177 // ---------------------------
1179 TopoDS_Face tgtFace = TopoDS::Face( theShape.Oriented(TopAbs_FORWARD));
1180 TopoDS_Shape srcShape = _sourceHypo->GetSourceFace().Oriented(TopAbs_FORWARD);
1182 TAssocTool::TShapeShapeMap shape2ShapeMap;
1183 TAssocTool::InitVertexAssociation( _sourceHypo, shape2ShapeMap );
1184 if ( !TAssocTool::FindSubShapeAssociation( tgtFace, tgtMesh, srcShape, srcMesh,
1186 !shape2ShapeMap.IsBound( tgtFace ))
1188 if ( srcShape.ShapeType() == TopAbs_FACE )
1190 int nbE1 = helper.Count( tgtFace, TopAbs_EDGE, /*ignoreSame=*/true );
1191 int nbE2 = helper.Count( srcShape, TopAbs_EDGE, /*ignoreSame=*/true );
1193 return error(COMPERR_BAD_SHAPE,
1194 SMESH_Comment("Different number of edges in source and target faces: ")
1195 << nbE2 << " and " << nbE1 );
1197 return error(COMPERR_BAD_SHAPE,"Topology of source and target faces seems different" );
1199 TopoDS_Face srcFace = TopoDS::Face( shape2ShapeMap( tgtFace ).Oriented(TopAbs_FORWARD));
1202 // if ( srcMesh == tgtMesh )
1204 // TopoDS_Shape solid =
1205 // helper.GetCommonAncestor( srcFace, tgtFace, *tgtMesh, TopAbs_SOLID );
1206 // if ( !solid.IsNull() )
1208 // srcFace.Orientation( helper.GetSubShapeOri( solid, srcFace ));
1209 // tgtFace.Orientation( helper.GetSubShapeOri( solid, tgtFace ));
1211 // else if ( helper.NbAncestors( srcFace, *tgtMesh, TopAbs_SOLID ) == 1 &&
1212 // helper.NbAncestors( tgtFace, *tgtMesh, TopAbs_SOLID ) == 1 )
1214 // srcFace.Orientation( helper.GetSubShapeOri( tgtMesh->GetShapeToMesh(), srcFace ));
1215 // tgtFace.Orientation( helper.GetSubShapeOri( tgtMesh->GetShapeToMesh(), tgtFace ));
1218 // ----------------------------------------------
1219 // Assure that mesh on a source Face is computed
1220 // ----------------------------------------------
1222 SMESH_subMesh* srcSubMesh = srcMesh->GetSubMesh( srcFace );
1223 SMESH_subMesh* tgtSubMesh = tgtMesh->GetSubMesh( tgtFace );
1225 string srcMeshError;
1226 if ( tgtMesh == srcMesh ) {
1227 if ( !TAssocTool::MakeComputed( srcSubMesh ))
1228 srcMeshError = TAssocTool::SourceNotComputedError( srcSubMesh, this );
1231 if ( !srcSubMesh->IsMeshComputed() )
1232 srcMeshError = TAssocTool::SourceNotComputedError();
1234 if ( !srcMeshError.empty() )
1235 return error(COMPERR_BAD_INPUT_MESH, srcMeshError );
1241 // get ordered src and tgt EDGEs
1242 TSideVector srcWires, tgtWires;
1243 bool is1DComputed = false; // if any tgt EDGE is meshed
1244 TError err = getWires( tgtFace, srcFace, tgtMesh, srcMesh,
1245 shape2ShapeMap, srcWires, tgtWires, _src2tgtNodes, is1DComputed );
1246 if ( err && !err->IsOK() )
1247 return error( err );
1249 bool projDone = false;
1253 // try to project from the same face with different location
1254 projDone = projectPartner( tgtFace, srcFace, tgtWires, srcWires,
1255 shape2ShapeMap, _src2tgtNodes, is1DComputed );
1259 // projection in case if the faces are similar in 2D space
1260 projDone = projectBy2DSimilarity( tgtFace, srcFace, tgtWires, srcWires,
1261 shape2ShapeMap, _src2tgtNodes, is1DComputed);
1265 // projection in case of quadrilateral faces
1266 // projDone = projectQuads( tgtFace, srcFace, tgtWires, srcWires,
1267 // shape2ShapeMap, _src2tgtNodes, is1DComputed);
1270 helper.SetSubShape( tgtFace );
1272 // it will remove mesh built on edges and vertices in failure case
1273 MeshCleaner cleaner( tgtSubMesh );
1277 _src2tgtNodes.clear();
1278 // --------------------
1279 // Prepare to mapping
1280 // --------------------
1282 // Check if node projection to a face is needed
1284 SMDS_ElemIteratorPtr faceIt = srcSubMesh->GetSubMeshDS()->GetElements();
1285 set< const SMDS_MeshNode* > faceNodes;
1286 for ( ; faceNodes.size() < 3 && faceIt->more(); ) {
1287 const SMDS_MeshElement* face = faceIt->next();
1288 SMDS_ElemIteratorPtr nodeIt = face->nodesIterator();
1289 while ( nodeIt->more() ) {
1290 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
1291 if ( node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE &&
1292 faceNodes.insert( node ).second )
1293 uvBox.Add( helper.GetNodeUV( srcFace, node ));
1296 bool toProjectNodes = false;
1297 if ( faceNodes.size() == 1 )
1298 toProjectNodes = ( uvBox.IsVoid() || uvBox.CornerMin().IsEqual( gp_XY(0,0), 1e-12 ));
1299 else if ( faceNodes.size() > 1 )
1300 toProjectNodes = ( uvBox.IsVoid() || uvBox.SquareExtent() < DBL_MIN );
1302 // Find the corresponding source and target vertex
1303 // and <theReverse> flag needed to call mapper.Apply()
1305 TopoDS_Vertex srcV1, tgtV1;
1306 bool reverse = false;
1308 TopExp_Explorer vSrcExp( srcFace, TopAbs_VERTEX );
1309 srcV1 = TopoDS::Vertex( vSrcExp.Current() );
1310 tgtV1 = TopoDS::Vertex( shape2ShapeMap( srcV1, /*isSrc=*/true ));
1312 list< TopoDS_Edge > tgtEdges, srcEdges;
1313 list< int > nbEdgesInWires;
1314 SMESH_Block::GetOrderedEdges( tgtFace, tgtEdges, nbEdgesInWires, tgtV1 );
1315 SMESH_Block::GetOrderedEdges( srcFace, srcEdges, nbEdgesInWires, srcV1 );
1317 if ( nbEdgesInWires.front() > 1 ) // possible to find out orientation
1319 TopoDS_Edge srcE1 = srcEdges.front(), tgtE1 = tgtEdges.front();
1320 TopoDS_Shape srcE1bis = shape2ShapeMap( tgtE1 );
1321 reverse = ( ! srcE1.IsSame( srcE1bis ));
1323 //_sourceHypo->HasVertexAssociation() &&
1324 nbEdgesInWires.front() > 2 &&
1325 helper.IsRealSeam( tgtEdges.front() ))
1327 // projection to a face with seam EDGE; pb is that GetOrderedEdges()
1328 // always puts a seam EDGE first (if possible) and as a result
1329 // we can't use only theReverse flag to correctly associate source
1330 // and target faces in the mapper. Thus we select srcV1 so that
1331 // GetOrderedEdges() to return EDGEs in a needed order
1332 TopoDS_Face tgtFaceBis = tgtFace;
1333 TopTools_MapOfShape checkedVMap( tgtEdges.size() );
1334 checkedVMap.Add ( srcV1 );
1335 for ( vSrcExp.Next(); vSrcExp.More(); )
1337 tgtFaceBis.Reverse();
1339 SMESH_Block::GetOrderedEdges( tgtFaceBis, tgtEdges, nbEdgesInWires, tgtV1 );
1341 list< TopoDS_Edge >::iterator edgeS = srcEdges.begin(), edgeT = tgtEdges.begin();
1342 for ( ; edgeS != srcEdges.end() && ok ; ++edgeS, ++edgeT )
1343 ok = edgeT->IsSame( shape2ShapeMap( *edgeS, /*isSrc=*/true ));
1351 while ( vSrcExp.More() && !checkedVMap.Add( vSrcExp.Current() ))
1356 srcV1 = TopoDS::Vertex( vSrcExp.Current() );
1357 tgtV1 = TopoDS::Vertex( shape2ShapeMap( srcV1, /*isSrc=*/true ));
1359 SMESH_Block::GetOrderedEdges( srcFace, srcEdges, nbEdgesInWires, srcV1 );
1363 // for the case: project to a closed face from a non-closed face w/o vertex assoc;
1364 // avoid projecting to a seam from two EDGEs with different nb nodes on them
1365 // ( test mesh_Projection_2D_01/B1 )
1366 if ( !_sourceHypo->HasVertexAssociation() &&
1367 nbEdgesInWires.front() > 2 &&
1368 helper.IsRealSeam( tgtEdges.front() ))
1370 TopoDS_Shape srcEdge1 = shape2ShapeMap( tgtEdges.front() );
1371 list< TopoDS_Edge >::iterator srcEdge2 =
1372 std::find( srcEdges.begin(), srcEdges.end(), srcEdge1);
1373 list< TopoDS_Edge >::iterator srcEdge3 =
1374 std::find( srcEdges.begin(), srcEdges.end(), srcEdge1.Reversed());
1375 if ( srcEdge2 == srcEdges.end() || srcEdge3 == srcEdges.end() ) // srcEdge1 is not a seam
1377 // find srcEdge2 which also will be projected to tgtEdges.front()
1378 for ( srcEdge2 = srcEdges.begin(); srcEdge2 != srcEdges.end(); ++srcEdge2 )
1379 if ( !srcEdge1.IsSame( *srcEdge2 ) &&
1380 tgtEdges.front().IsSame( shape2ShapeMap( *srcEdge2, /*isSrc=*/true )))
1382 // compare nb nodes on srcEdge1 and srcEdge2
1383 if ( srcEdge2 != srcEdges.end() )
1385 int nbN1 = 0, nbN2 = 0;
1386 if ( SMESHDS_SubMesh* sm = srcMesh->GetMeshDS()->MeshElements( srcEdge1 ))
1387 nbN1 = sm->NbNodes();
1388 if ( SMESHDS_SubMesh* sm = srcMesh->GetMeshDS()->MeshElements( *srcEdge2 ))
1389 nbN2 = sm->NbNodes();
1391 srcV1 = helper.IthVertex( 1, srcEdges.front() );
1396 else if ( nbEdgesInWires.front() == 1 )
1398 // TODO::Compare orientation of curves in a sole edge
1399 //RETURN_BAD_RESULT("Not implemented case");
1403 RETURN_BAD_RESULT("Bad result from SMESH_Block::GetOrderedEdges()");
1406 // Load pattern from the source face
1407 SMESH_Pattern mapper;
1408 mapper.Load( srcMesh, srcFace, toProjectNodes, srcV1 );
1409 if ( mapper.GetErrorCode() != SMESH_Pattern::ERR_OK )
1410 return error(COMPERR_BAD_INPUT_MESH,"Can't load mesh pattern from the source face");
1412 // --------------------
1413 // Perform 2D mapping
1414 // --------------------
1416 // Compute mesh on a target face
1418 mapper.Apply( tgtFace, tgtV1, reverse );
1419 if ( mapper.GetErrorCode() != SMESH_Pattern::ERR_OK ) {
1420 // std::ofstream file("/tmp/Pattern.smp" );
1421 // mapper.Save( file );
1422 return error("Can't apply source mesh pattern to the face");
1427 const bool toCreatePolygons = false, toCreatePolyedrs = false;
1428 mapper.MakeMesh( tgtMesh, toCreatePolygons, toCreatePolyedrs );
1429 if ( mapper.GetErrorCode() != SMESH_Pattern::ERR_OK )
1430 return error("Can't make mesh by source mesh pattern");
1432 // -------------------------------------------------------------------------
1433 // mapper doesn't take care of nodes already existing on edges and vertices,
1434 // so we must merge nodes created by it with existing ones
1435 // -------------------------------------------------------------------------
1437 SMESH_MeshEditor::TListOfListOfNodes groupsOfNodes;
1439 // Make groups of nodes to merge
1441 // loop on EDGE and VERTEX sub-meshes of a target FACE
1442 SMESH_subMeshIteratorPtr smIt = tgtSubMesh->getDependsOnIterator(/*includeSelf=*/false,
1443 /*complexShapeFirst=*/false);
1444 while ( smIt->more() )
1446 SMESH_subMesh* sm = smIt->next();
1447 SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
1448 if ( !smDS || smDS->NbNodes() == 0 )
1450 //if ( !is1DComputed && sm->GetSubShape().ShapeType() == TopAbs_EDGE )
1453 if ( helper.IsDegenShape( sm->GetId() ) ) // to merge all nodes on degenerated
1455 if ( sm->GetSubShape().ShapeType() == TopAbs_EDGE )
1457 groupsOfNodes.push_back( list< const SMDS_MeshNode* >() );
1458 SMESH_subMeshIteratorPtr smDegenIt
1459 = sm->getDependsOnIterator(/*includeSelf=*/true,/*complexShapeFirst=*/false);
1460 while ( smDegenIt->more() )
1461 if (( smDS = smDegenIt->next()->GetSubMeshDS() ))
1463 SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
1464 while ( nIt->more() )
1465 groupsOfNodes.back().push_back( nIt->next() );
1468 continue; // do not treat sm of degen VERTEX
1471 // Sort new and old nodes of a submesh separately
1473 bool isSeam = helper.IsRealSeam( sm->GetId() );
1475 enum { NEW_NODES = 0, OLD_NODES };
1476 map< double, const SMDS_MeshNode* > u2nodesMaps[2], u2nodesOnSeam;
1477 map< double, const SMDS_MeshNode* >::iterator u_oldNode, u_newNode, u_newOnSeam, newEnd;
1478 set< const SMDS_MeshNode* > seamNodes;
1480 // mapper changed, no more "mapper puts on a seam edge nodes from 2 edges"
1481 if ( isSeam && ! getBoundaryNodes ( sm, tgtFace, u2nodesOnSeam, seamNodes ))
1482 ;//RETURN_BAD_RESULT("getBoundaryNodes() failed");
1484 SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
1485 while ( nIt->more() )
1487 const SMDS_MeshNode* node = nIt->next();
1488 bool isOld = isOldNode( node );
1490 if ( !isOld && isSeam ) { // new node on a seam edge
1491 if ( seamNodes.count( node ) )
1492 continue; // node is already in the map
1495 // sort nodes on edges by their position
1496 map< double, const SMDS_MeshNode* > & pos2nodes = u2nodesMaps[isOld ? OLD_NODES : NEW_NODES];
1497 switch ( node->GetPosition()->GetTypeOfPosition() )
1499 case SMDS_TOP_VERTEX: {
1500 if ( !is1DComputed && !pos2nodes.empty() )
1501 u2nodesMaps[isOld ? NEW_NODES : OLD_NODES].insert( make_pair( 0, node ));
1503 pos2nodes.insert( make_pair( 0, node ));
1506 case SMDS_TOP_EDGE: {
1507 const SMDS_EdgePosition* pos =
1508 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
1509 pos2nodes.insert( make_pair( pos->GetUParameter(), node ));
1513 RETURN_BAD_RESULT("Wrong node position type: "<<
1514 node->GetPosition()->GetTypeOfPosition());
1517 const bool mergeNewToOld =
1518 ( u2nodesMaps[ NEW_NODES ].size() == u2nodesMaps[ OLD_NODES ].size() );
1519 const bool mergeSeamToNew =
1520 ( u2nodesMaps[ NEW_NODES ].size() == u2nodesOnSeam.size() );
1522 if ( !mergeNewToOld )
1523 if ( u2nodesMaps[ NEW_NODES ].size() > 0 &&
1524 u2nodesMaps[ OLD_NODES ].size() > 0 )
1526 u_oldNode = u2nodesMaps[ OLD_NODES ].begin();
1527 newEnd = u2nodesMaps[ OLD_NODES ].end();
1528 for ( ; u_oldNode != newEnd; ++u_oldNode )
1529 SMESH_Algo::addBadInputElement( u_oldNode->second );
1530 return error( COMPERR_BAD_INPUT_MESH,
1531 SMESH_Comment( "Existing mesh mismatches the projected 2D mesh on " )
1532 << ( sm->GetSubShape().ShapeType() == TopAbs_EDGE ? "edge" : "vertex" )
1533 << " #" << sm->GetId() );
1535 if ( isSeam && !mergeSeamToNew ) {
1536 const TopoDS_Shape& seam = sm->GetSubShape();
1537 if ( u2nodesMaps[ NEW_NODES ].size() > 0 &&
1538 u2nodesOnSeam.size() > 0 &&
1539 seam.ShapeType() == TopAbs_EDGE )
1541 int nbE1 = helper.Count( tgtFace, TopAbs_EDGE, /*ignoreSame=*/true );
1542 int nbE2 = helper.Count( srcFace, TopAbs_EDGE, /*ignoreSame=*/true );
1543 if ( nbE1 != nbE2 ) // 2 EDGEs are mapped to a seam EDGE
1545 // find the 2 EDGEs of srcFace
1546 TopTools_DataMapIteratorOfDataMapOfShapeShape src2tgtIt( shape2ShapeMap._map2to1 );
1547 for ( ; src2tgtIt.More(); src2tgtIt.Next() )
1548 if ( seam.IsSame( src2tgtIt.Value() ))
1549 SMESH_Algo::addBadInputElements
1550 ( srcMesh->GetMeshDS()->MeshElements( src2tgtIt.Key() ));
1551 return error( COMPERR_BAD_INPUT_MESH,
1552 "Different number of nodes on two edges projected to a seam edge" );
1557 // Make groups of nodes to merge
1559 u_oldNode = u2nodesMaps[ OLD_NODES ].begin();
1560 u_newNode = u2nodesMaps[ NEW_NODES ].begin();
1561 newEnd = u2nodesMaps[ NEW_NODES ].end();
1562 u_newOnSeam = u2nodesOnSeam.begin();
1563 if ( mergeNewToOld )
1564 for ( ; u_newNode != newEnd; ++u_newNode, ++u_oldNode )
1566 groupsOfNodes.push_back( list< const SMDS_MeshNode* >() );
1567 groupsOfNodes.back().push_back( u_oldNode->second );
1568 groupsOfNodes.back().push_back( u_newNode->second );
1569 if ( mergeSeamToNew )
1570 groupsOfNodes.back().push_back( (u_newOnSeam++)->second );
1572 else if ( mergeSeamToNew )
1573 for ( ; u_newNode != newEnd; ++u_newNode, ++u_newOnSeam )
1575 groupsOfNodes.push_back( list< const SMDS_MeshNode* >() );
1576 groupsOfNodes.back().push_back( u_newNode->second );
1577 groupsOfNodes.back().push_back( u_newOnSeam->second );
1580 } // loop on EDGE and VERTEX submeshes of a target FACE
1584 SMESH_MeshEditor editor( tgtMesh );
1585 int nbFaceBeforeMerge = tgtSubMesh->GetSubMeshDS()->NbElements();
1586 editor.MergeNodes( groupsOfNodes );
1587 int nbFaceAtferMerge = tgtSubMesh->GetSubMeshDS()->NbElements();
1588 if ( nbFaceBeforeMerge != nbFaceAtferMerge && !helper.HasDegeneratedEdges() )
1589 return error(COMPERR_BAD_INPUT_MESH, "Probably invalid node parameters on geom faces");
1591 // ----------------------------------------------------------------
1592 // The mapper can't create quadratic elements, so convert if needed
1593 // ----------------------------------------------------------------
1595 faceIt = srcSubMesh->GetSubMeshDS()->GetElements();
1596 bool srcIsQuad = faceIt->next()->IsQuadratic();
1597 faceIt = tgtSubMesh->GetSubMeshDS()->GetElements();
1598 bool tgtIsQuad = faceIt->next()->IsQuadratic();
1599 if ( srcIsQuad && !tgtIsQuad )
1601 TIDSortedElemSet tgtFaces;
1602 faceIt = tgtSubMesh->GetSubMeshDS()->GetElements();
1603 while ( faceIt->more() )
1604 tgtFaces.insert( tgtFaces.end(), faceIt->next() );
1606 editor.ConvertToQuadratic(/*theForce3d=*/false, tgtFaces, false);
1609 } // end of projection using Pattern mapping
1612 if ( !projDone || is1DComputed )
1613 // ----------------------------------------------------------------
1614 // The mapper can create distorted faces by placing nodes out of the FACE
1615 // boundary, also bad face can be created if EDGEs already discretized
1616 // --> fix bad faces by smoothing
1617 // ----------------------------------------------------------------
1618 if ( !fixDistortedFaces( helper, tgtWires ))
1619 return error("Invalid mesh generated");
1621 // ---------------------------
1622 // Check elements orientation
1623 // ---------------------------
1625 TopoDS_Face face = TopoDS::Face( theShape );
1626 if ( !theMesh.IsMainShape( tgtFace ))
1628 // find the main shape
1629 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
1630 switch ( mainShape.ShapeType() ) {
1632 case TopAbs_SOLID: break;
1634 TopTools_ListIteratorOfListOfShape ancestIt = theMesh.GetAncestors( face );
1635 for ( ; ancestIt.More(); ancestIt.Next() ) {
1636 TopAbs_ShapeEnum type = ancestIt.Value().ShapeType();
1637 if ( type == TopAbs_SOLID ) {
1638 mainShape = ancestIt.Value();
1640 } else if ( type == TopAbs_SHELL ) {
1641 mainShape = ancestIt.Value();
1645 // find tgtFace in the main solid or shell to know it's true orientation.
1646 TopExp_Explorer exp( mainShape, TopAbs_FACE );
1647 for ( ; exp.More(); exp.Next() ) {
1648 if ( tgtFace.IsSame( exp.Current() )) {
1649 face = TopoDS::Face( exp.Current() );
1655 if ( helper.IsReversedSubMesh( face ))
1657 SMESH_MeshEditor editor( tgtMesh );
1658 SMDS_ElemIteratorPtr eIt = meshDS->MeshElements( face )->GetElements();
1659 while ( eIt->more() ) {
1660 const SMDS_MeshElement* e = eIt->next();
1661 if ( e->GetType() == SMDSAbs_Face && !editor.Reorient( e ))
1662 RETURN_BAD_RESULT("Pb of SMESH_MeshEditor::Reorient()");
1666 cleaner.Release(); // not to remove mesh
1672 //=======================================================================
1673 //function : Evaluate
1675 //=======================================================================
1677 bool StdMeshers_Projection_2D::Evaluate(SMESH_Mesh& theMesh,
1678 const TopoDS_Shape& theShape,
1679 MapShapeNbElems& aResMap)
1684 SMESH_Mesh * srcMesh = _sourceHypo->GetSourceMesh();
1685 SMESH_Mesh * tgtMesh = & theMesh;
1689 // ---------------------------
1690 // Make sub-shapes association
1691 // ---------------------------
1693 TopoDS_Face tgtFace = TopoDS::Face( theShape.Oriented(TopAbs_FORWARD));
1694 TopoDS_Shape srcShape = _sourceHypo->GetSourceFace().Oriented(TopAbs_FORWARD);
1696 TAssocTool::TShapeShapeMap shape2ShapeMap;
1697 TAssocTool::InitVertexAssociation( _sourceHypo, shape2ShapeMap );
1698 if ( !TAssocTool::FindSubShapeAssociation( tgtFace, tgtMesh, srcShape, srcMesh,
1700 !shape2ShapeMap.IsBound( tgtFace ))
1701 return error(COMPERR_BAD_SHAPE,"Topology of source and target faces seems different" );
1703 TopoDS_Face srcFace = TopoDS::Face( shape2ShapeMap( tgtFace ).Oriented(TopAbs_FORWARD));
1705 // -------------------------------------------------------
1706 // Assure that mesh on a source Face is computed/evaluated
1707 // -------------------------------------------------------
1709 std::vector<int> aVec;
1711 SMESH_subMesh* srcSubMesh = srcMesh->GetSubMesh( srcFace );
1712 if ( srcSubMesh->IsMeshComputed() )
1714 aVec.resize( SMDSEntity_Last, 0 );
1715 aVec[SMDSEntity_Node] = srcSubMesh->GetSubMeshDS()->NbNodes();
1717 SMDS_ElemIteratorPtr elemIt = srcSubMesh->GetSubMeshDS()->GetElements();
1718 while ( elemIt->more() )
1719 aVec[ elemIt->next()->GetEntityType() ]++;
1723 MapShapeNbElems tmpResMap;
1724 MapShapeNbElems& srcResMap = (srcMesh == tgtMesh) ? aResMap : tmpResMap;
1725 if ( !_gen->Evaluate( *srcMesh, srcShape, srcResMap ))
1726 return error(COMPERR_BAD_INPUT_MESH,"Source mesh not evaluatable");
1727 aVec = srcResMap[ srcSubMesh ];
1729 return error(COMPERR_BAD_INPUT_MESH,"Source mesh is wrongly evaluated");
1732 SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1733 aResMap.insert(std::make_pair(sm,aVec));
1739 //=============================================================================
1741 * \brief Sets a default event listener to submesh of the source face
1742 * \param subMesh - submesh where algo is set
1744 * This method is called when a submesh gets HYP_OK algo_state.
1745 * After being set, event listener is notified on each event of a submesh.
1746 * Arranges that CLEAN event is translated from source submesh to
1749 //=============================================================================
1751 void StdMeshers_Projection_2D::SetEventListener(SMESH_subMesh* subMesh)
1753 TAssocTool::SetEventListener( subMesh,
1754 _sourceHypo->GetSourceFace(),
1755 _sourceHypo->GetSourceMesh() );