1 // Copyright (C) 2007-2008 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.
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
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : StdMeshers_MEFISTO_2D.cxx
24 // Moved here from SMESH_MEFISTO_2D.cxx
25 // Author : Paul RASCLE, EDF
28 #include "StdMeshers_MEFISTO_2D.hxx"
30 #include "SMESH_Gen.hxx"
31 #include "SMESH_Mesh.hxx"
32 #include "SMESH_subMesh.hxx"
33 #include "SMESH_Block.hxx"
34 #include "SMESH_MesherHelper.hxx"
35 #include "SMESH_Comment.hxx"
37 #include "StdMeshers_FaceSide.hxx"
38 #include "StdMeshers_MaxElementArea.hxx"
39 #include "StdMeshers_LengthFromEdges.hxx"
44 #include "SMDS_MeshElement.hxx"
45 #include "SMDS_MeshNode.hxx"
46 #include "SMDS_EdgePosition.hxx"
47 #include "SMDS_FacePosition.hxx"
49 #include "utilities.h"
51 #include <BRepTools.hxx>
52 #include <BRep_Tool.hxx>
53 #include <Geom_Curve.hxx>
54 #include <Geom2d_Curve.hxx>
55 #include <Geom_Surface.hxx>
56 #include <Precision.hxx>
58 #include <TopExp_Explorer.hxx>
59 #include <TopTools_ListIteratorOfListOfShape.hxx>
60 #include <TopTools_ListOfShape.hxx>
61 #include <TopTools_MapOfShape.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Iterator.hxx>
66 #include <gp_Pnt2d.hxx>
68 #include <BRep_Tool.hxx>
69 #include <GProp_GProps.hxx>
70 #include <BRepGProp.hxx>
74 //=============================================================================
78 //=============================================================================
80 StdMeshers_MEFISTO_2D::StdMeshers_MEFISTO_2D(int hypId, int studyId, SMESH_Gen * gen):
81 SMESH_2D_Algo(hypId, studyId, gen)
83 MESSAGE("StdMeshers_MEFISTO_2D::StdMeshers_MEFISTO_2D");
85 _shapeType = (1 << TopAbs_FACE);
86 _compatibleHypothesis.push_back("MaxElementArea");
87 _compatibleHypothesis.push_back("LengthFromEdges");
91 _hypMaxElementArea = NULL;
92 _hypLengthFromEdges = NULL;
96 //=============================================================================
100 //=============================================================================
102 StdMeshers_MEFISTO_2D::~StdMeshers_MEFISTO_2D()
104 MESSAGE("StdMeshers_MEFISTO_2D::~StdMeshers_MEFISTO_2D");
107 //=============================================================================
111 //=============================================================================
113 bool StdMeshers_MEFISTO_2D::CheckHypothesis
115 const TopoDS_Shape& aShape,
116 SMESH_Hypothesis::Hypothesis_Status& aStatus)
118 _hypMaxElementArea = NULL;
119 _hypLengthFromEdges = NULL;
123 list <const SMESHDS_Hypothesis * >::const_iterator itl;
124 const SMESHDS_Hypothesis *theHyp;
126 const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
127 int nbHyp = hyps.size();
130 aStatus = SMESH_Hypothesis::HYP_OK; //SMESH_Hypothesis::HYP_MISSING;
131 return true; // (PAL13464) can work with no hypothesis, LengthFromEdges is default one
135 theHyp = (*itl); // use only the first hypothesis
137 string hypName = theHyp->GetName();
141 if (hypName == "MaxElementArea")
143 _hypMaxElementArea = static_cast<const StdMeshers_MaxElementArea *>(theHyp);
144 ASSERT(_hypMaxElementArea);
145 _maxElementArea = _hypMaxElementArea->GetMaxArea();
147 aStatus = SMESH_Hypothesis::HYP_OK;
150 else if (hypName == "LengthFromEdges")
152 _hypLengthFromEdges = static_cast<const StdMeshers_LengthFromEdges *>(theHyp);
153 ASSERT(_hypLengthFromEdges);
155 aStatus = SMESH_Hypothesis::HYP_OK;
158 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
163 if (_maxElementArea > 0)
165 //_edgeLength = 2 * sqrt(_maxElementArea); // triangles : minorant
166 _edgeLength = sqrt(2. * _maxElementArea/sqrt(3.0));
170 isOk = (_hypLengthFromEdges != NULL); // **** check mode
172 aStatus = SMESH_Hypothesis::HYP_BAD_PARAMETER;
178 //=============================================================================
182 //=============================================================================
184 bool StdMeshers_MEFISTO_2D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
186 MESSAGE("StdMeshers_MEFISTO_2D::Compute");
188 TopoDS_Face F = TopoDS::Face(aShape.Oriented(TopAbs_FORWARD));
190 // helper builds quadratic mesh if necessary
191 SMESH_MesherHelper helper(aMesh);
193 _quadraticMesh = myTool->IsQuadraticSubMesh(aShape);
194 const bool ignoreMediumNodes = _quadraticMesh;
196 // get all edges of a face
198 TWireVector wires = StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, problem );
199 int nbWires = wires.size();
200 if ( problem && !problem->IsOK() ) return error( problem );
201 if ( nbWires == 0 ) return error( "Problem in StdMeshers_FaceSide::GetFaceWires()");
202 if ( wires[0]->NbSegments() < 3 ) // ex: a circle with 2 segments
203 return error(COMPERR_BAD_INPUT_MESH,
204 SMESH_Comment("Too few segments: ")<<wires[0]->NbSegments());
206 // compute average edge length
207 if (!_hypMaxElementArea)
211 for ( int iW = 0; iW < nbWires; ++iW )
213 StdMeshers_FaceSidePtr wire = wires[ iW ];
214 _edgeLength += wire->Length();
215 nbSegments += wire->NbSegments();
218 _edgeLength /= nbSegments;
221 if (/*_hypLengthFromEdges &&*/ _edgeLength < DBL_MIN )
224 Z nblf; //nombre de lignes fermees (enveloppe en tete)
225 Z *nudslf = NULL; //numero du dernier sommet de chaque ligne fermee
227 Z nbpti = 0; //nombre points internes futurs sommets de la triangulation
236 Z nutysu = 1; // 1: il existe un fonction areteideale_()
237 // Z nutysu=0; // 0: on utilise aretmx
238 R aretmx = _edgeLength; // longueur max aretes future triangulation
242 nudslf = new Z[1 + nblf];
247 // count nb of input points
248 for ( int iW = 0; iW < nbWires; ++iW )
250 nbpnt += wires[iW]->NbPoints() - 1;
251 nudslf[iw++] = nbpnt;
254 uvslf = new R2[nudslf[nblf]];
256 double scalex, scaley;
257 ComputeScaleOnFace(aMesh, F, scalex, scaley);
259 // correspondence mefisto index --> Nodes
260 vector< const SMDS_MeshNode*> mefistoToDS(nbpnt, (const SMDS_MeshNode*)0);
264 // fill input points UV
265 if ( LoadPoints(wires, uvslf, mefistoToDS, scalex, scaley) )
268 aptrte(nutysu, aretmx,
269 nblf, nudslf, uvslf, nbpti, uvpti, nbst, uvst, nbt, nust, ierr);
273 MESSAGE("... End Triangulation Generated Triangle Number " << nbt);
274 MESSAGE(" Node Number " << nbst);
275 StoreResult(nbst, uvst, nbt, nust, mefistoToDS, scalex, scaley);
280 error(ierr,"Error in Triangulation (aptrte())");
283 if (nudslf != NULL) delete[]nudslf;
284 if (uvslf != NULL) delete[]uvslf;
285 if (uvst != NULL) delete[]uvst;
286 if (nust != NULL) delete[]nust;
292 //=============================================================================
296 //=============================================================================
298 bool StdMeshers_MEFISTO_2D::Evaluate(SMESH_Mesh & aMesh,
299 const TopoDS_Shape & aShape,
300 MapShapeNbElems& aResMap)
302 MESSAGE("StdMeshers_MEFISTO_2D::Evaluate");
304 TopoDS_Face F = TopoDS::Face(aShape.Oriented(TopAbs_FORWARD));
308 bool IsQuadratic = false;
310 TopExp_Explorer exp(F,TopAbs_EDGE);
311 for(; exp.More(); exp.Next()) {
312 TopoDS_Edge E = TopoDS::Edge(exp.Current());
313 MapShapeNbElemsItr anIt = aResMap.find( aMesh.GetSubMesh(E) );
314 if( anIt == aResMap.end() ) continue;
315 std::vector<int> aVec = (*anIt).second;
316 int nbe = Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
319 IsQuadratic = ( aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge] );
324 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,a,b);
327 double dp = (b-a)/nbe;
328 for(int i=1; i<=nbe; i++) {
331 aLen += P1.Distance(P2);
336 aLen = aLen/NbSeg; // middle length
338 aLen = Precision::Infinite();
340 _edgeLength = Precision::Infinite();
341 double tmpLength = Min( _edgeLength, aLen );
344 BRepGProp::SurfaceProperties(aShape,G);
345 double anArea = G.Mass();
347 int nbFaces = Precision::IsInfinite( tmpLength ) ? 0 :
348 (int)( anArea/(tmpLength*tmpLength*sqrt(3.)/4) );
349 int nbNodes = (int) ( nbFaces*3 - (NbSeg-1)*2 ) / 6;
351 std::vector<int> aVec(SMDSEntity_Last);
352 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
354 aVec[SMDSEntity_Quad_Triangle] = nbFaces;
355 aVec[SMDSEntity_Node] = (int)( nbNodes + nbFaces*3 - (NbSeg-1) );
358 aVec[SMDSEntity_Node] = nbNodes;
359 aVec[SMDSEntity_Triangle] = nbFaces;
361 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
362 aResMap.insert(std::make_pair(sm,aVec));
368 //=======================================================================
369 //function : fixOverlappedLinkUV
370 //purpose : prevent failure due to overlapped adjacent links
371 //=======================================================================
373 static bool fixOverlappedLinkUV( R2& uv0, const R2& uv1, const R2& uv2 )
375 gp_XY v1( uv0.x - uv1.x, uv0.y - uv1.y );
376 gp_XY v2( uv2.x - uv1.x, uv2.y - uv1.y );
378 double tol2 = DBL_MIN * DBL_MIN;
379 double sqMod1 = v1.SquareModulus();
380 if ( sqMod1 <= tol2 ) return false;
381 double sqMod2 = v2.SquareModulus();
382 if ( sqMod2 <= tol2 ) return false;
386 // check sinus >= 1.e-3
387 const double minSin = 1.e-3;
388 if ( dot > 0 && 1 - dot * dot / ( sqMod1 * sqMod2 ) < minSin * minSin ) {
389 MESSAGE(" ___ FIX UV ____" << uv0.x << " " << uv0.y);
390 v1.SetCoord( -v1.Y(), v1.X() );
391 double delta = sqrt( sqMod1 ) * minSin;
401 // MESSAGE(" -> " << uv0.x << " " << uv0.y << " ");
402 // MESSAGE("v1( " << v1.X() << " " << v1.Y() << " ) " <<
403 // "v2( " << v2.X() << " " << v2.Y() << " ) ");
404 // MESSAGE("SIN: " << sqrt(1 - dot * dot / (sqMod1 * sqMod2)));
405 // v1.SetCoord( uv0.x - uv1.x, uv0.y - uv1.y );
406 // v2.SetCoord( uv2.x - uv1.x, uv2.y - uv1.y );
407 // gp_XY v3( uv2.x - uv0.x, uv2.y - uv0.y );
408 // sqMod1 = v1.SquareModulus();
409 // sqMod2 = v2.SquareModulus();
411 // double sin = sqrt(1 - dot * dot / (sqMod1 * sqMod2));
412 // MESSAGE("NEW SIN: " << sin);
419 //=======================================================================
420 //function : fixCommonVertexUV
422 //=======================================================================
424 static bool fixCommonVertexUV (R2 & theUV,
425 const TopoDS_Vertex& theV,
426 const TopoDS_Face& theF,
427 const TopTools_IndexedDataMapOfShapeListOfShape & theVWMap,
428 SMESH_Mesh & theMesh,
429 const double theScaleX,
430 const double theScaleY,
431 const bool theCreateQuadratic)
433 if( !theVWMap.Contains( theV )) return false;
435 // check if there is another wire sharing theV
436 const TopTools_ListOfShape& WList = theVWMap.FindFromKey( theV );
437 TopTools_ListIteratorOfListOfShape aWIt;
438 TopTools_MapOfShape aWires;
439 for ( aWIt.Initialize( WList ); aWIt.More(); aWIt.Next() )
440 aWires.Add( aWIt.Value() );
441 if ( aWires.Extent() < 2 ) return false;
443 TopoDS_Shape anOuterWire = BRepTools::OuterWire(theF);
444 TopoDS_Shape anInnerWire;
445 for ( aWIt.Initialize( WList ); aWIt.More() && anInnerWire.IsNull(); aWIt.Next() )
446 if ( !anOuterWire.IsSame( aWIt.Value() ))
447 anInnerWire = aWIt.Value();
449 TopTools_ListOfShape EList;
450 list< double > UList;
452 // find edges of theW sharing theV
453 // and find 2d normal to them at theV
455 TopoDS_Iterator itE( anInnerWire );
456 for ( ; itE.More(); itE.Next() )
458 const TopoDS_Edge& E = TopoDS::Edge( itE.Value() );
459 TopoDS_Iterator itV( E );
460 for ( ; itV.More(); itV.Next() )
462 const TopoDS_Vertex & V = TopoDS::Vertex( itV.Value() );
463 if ( !V.IsSame( theV ))
466 Standard_Real u = BRep_Tool::Parameter( V, E );
467 UList.push_back( u );
469 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, theF, f, l);
473 gp_Vec2d n( d1.Y() * theScaleX, -d1.X() * theScaleY);
474 if ( E.Orientation() == TopAbs_REVERSED )
480 // define step size by which to move theUV
482 gp_Pnt2d nextUV; // uv of next node on edge, most distant of the four
483 gp_Pnt2d thisUV( theUV.x, theUV.y );
484 double maxDist = -DBL_MAX;
485 TopTools_ListIteratorOfListOfShape aEIt (EList);
486 list< double >::iterator aUIt = UList.begin();
487 for ( ; aEIt.More(); aEIt.Next(), aUIt++ )
489 const TopoDS_Edge& E = TopoDS::Edge( aEIt.Value() );
491 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, theF, f, l);
493 double umin = DBL_MAX, umax = -DBL_MAX;
494 SMDS_NodeIteratorPtr nIt = theMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
495 if ( !nIt->more() ) // no nodes on edge, only on vertices
501 while ( nIt->more() ) {
502 const SMDS_MeshNode* node = nIt->next();
503 // check if node is medium
504 if ( theCreateQuadratic && SMESH_MesherHelper::IsMedium( node, SMDSAbs_Edge ))
506 const SMDS_EdgePosition* epos =
507 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
508 double u = epos->GetUParameter();
515 bool isFirstCommon = ( *aUIt == f );
516 gp_Pnt2d uv = C2d->Value( isFirstCommon ? umin : umax );
517 double dist = thisUV.SquareDistance( uv );
518 if ( dist > maxDist ) {
524 uv0.x = thisUV.X(); uv0.y = thisUV.Y();
525 uv1.x = nextUV.X(); uv1.y = nextUV.Y();
526 uv2.x = thisUV.X(); uv2.y = thisUV.Y();
528 uv1.x *= theScaleX; uv1.y *= theScaleY;
530 if ( fixOverlappedLinkUV( uv0, uv1, uv2 ))
532 double step = thisUV.Distance( gp_Pnt2d( uv0.x, uv0.y ));
534 // move theUV along the normal by the step
538 MESSAGE("--fixCommonVertexUV move(" << theUV.x << " " << theUV.x
539 << ") by (" << N.X() << " " << N.Y() << ")"
540 << endl << "--- MAX DIST " << maxDist);
550 //=============================================================================
554 //=============================================================================
556 bool StdMeshers_MEFISTO_2D::LoadPoints(TWireVector & wires,
558 vector<const SMDS_MeshNode*>& mefistoToDS,
562 // to avoid passing same uv points for a vertex common to 2 wires
564 TopTools_IndexedDataMapOfShapeListOfShape VWMap;
565 if ( wires.size() > 1 )
567 F = TopoDS::Face( myTool->GetSubShape() );
568 TopExp::MapShapesAndAncestors( F, TopAbs_VERTEX, TopAbs_WIRE, VWMap );
570 for ( int iW = 0; iW < wires.size(); ++iW )
571 nbVertices += wires[ iW ]->NbEdges();
572 if ( nbVertices == VWMap.Extent() )
573 VWMap.Clear(); // wires have no common vertices
578 for ( int iW = 0; iW < wires.size(); ++iW )
580 const vector<UVPtStruct>& uvPtVec = wires[ iW ]->GetUVPtStruct();
581 if ( uvPtVec.size() != wires[ iW ]->NbPoints() ) {
582 return error(COMPERR_BAD_INPUT_MESH,SMESH_Comment("Unexpected nb of points on wire ")
583 << iW << ": " << uvPtVec.size()<<" != "<<wires[ iW ]->NbPoints()
584 << ", probably because of invalid node parameters on geom edges");
586 if ( m + uvPtVec.size()-1 > mefistoToDS.size() ) {
587 MESSAGE("Wrong mefistoToDS.size: "<<mefistoToDS.size()<<" < "<<m + uvPtVec.size()-1);
588 return error("Internal error");
591 list< int > mOnVertex;
592 vector<UVPtStruct>::const_iterator uvPt = uvPtVec.begin();
593 for ( ++uvPt; uvPt != uvPtVec.end(); ++uvPt )
595 // bind mefisto ID to node
596 mefistoToDS[m] = uvPt->node;
598 uvslf[m].x = uvPt->u * scalex;
599 uvslf[m].y = uvPt->v * scaley;
600 if ( uvPt->node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
601 mOnVertex.push_back( m );
605 int mFirst = mOnVertex.front(), mLast = m - 1;
606 list< int >::iterator mIt = mOnVertex.begin();
607 for ( ; mIt != mOnVertex.end(); ++mIt)
610 if ( iW && !VWMap.IsEmpty()) { // except outer wire
611 // avoid passing same uv point for a vertex common to 2 wires
612 int vID = mefistoToDS[m]->GetPosition()->GetShapeId();
613 TopoDS_Vertex V = TopoDS::Vertex( myTool->GetMeshDS()->IndexToShape( vID ));
614 if ( fixCommonVertexUV( uvslf[m], V, F, VWMap, *myTool->GetMesh(),
615 scalex, scaley, _quadraticMesh )) {
616 myNodesOnCommonV.push_back( mefistoToDS[m] );
620 // prevent failure on overlapped adjacent links,
621 // check only links ending in vertex nodes
622 int mB = m - 1, mA = m + 1; // indices Before and After
623 if ( mB < mFirst ) mB = mLast;
624 if ( mA > mLast ) mA = mFirst;
625 fixOverlappedLinkUV (uvslf[ mB ], uvslf[ m ], uvslf[ mA ]);
632 //=============================================================================
636 //=============================================================================
638 void StdMeshers_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh & aMesh,
639 const TopoDS_Face & aFace,
643 TopoDS_Wire W = BRepTools::OuterWire(aFace);
645 double xmin = 1.e300; // min & max of face 2D parametric coord.
646 double xmax = -1.e300;
647 double ymin = 1.e300;
648 double ymax = -1.e300;
653 TopExp_Explorer wexp(W, TopAbs_EDGE);
654 for ( ; wexp.More(); wexp.Next())
656 const TopoDS_Edge & E = TopoDS::Edge( wexp.Current() );
658 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, aFace, f, l);
659 if ( C2d.IsNull() ) continue;
660 double du = (l - f) / double (nbp);
661 for (int i = 0; i <= nbp; i++)
663 double param = f + double (i) * du;
664 gp_Pnt2d p = C2d->Value(param);
673 // MESSAGE(" "<< f<<" "<<l<<" "<<param<<" "<<xmin<<" "<<xmax<<" "<<ymin<<" "<<ymax);
680 double xmoy = (xmax + xmin) / 2.;
681 double ymoy = (ymax + ymin) / 2.;
682 double xsize = xmax - xmin;
683 double ysize = ymax - ymin;
686 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace,L); // 3D surface
690 gp_Pnt PX0 = S->Value(xmin, ymoy);
691 gp_Pnt PY0 = S->Value(xmoy, ymin);
692 double dx = xsize / double (nbp);
693 double dy = ysize / double (nbp);
694 for (int i = 1; i <= nbp; i++)
696 double x = xmin + double (i) * dx;
697 gp_Pnt PX = S->Value(x, ymoy);
698 double y = ymin + double (i) * dy;
699 gp_Pnt PY = S->Value(xmoy, y);
700 length_x += PX.Distance(PX0);
701 length_y += PY.Distance(PY0);
705 scalex = length_x / xsize;
706 scaley = length_y / ysize;
709 double xyratio = xsize*scalex/(ysize*scaley);
710 const double maxratio = 1.e2;
712 if (xyratio > maxratio) {
714 scaley *= xyratio / maxratio;
717 else if (xyratio < 1./maxratio) {
719 scalex *= 1 / xyratio / maxratio;
726 //=============================================================================
730 //=============================================================================
732 void StdMeshers_MEFISTO_2D::StoreResult(Z nbst, R2 * uvst, Z nbt, Z * nust,
733 vector< const SMDS_MeshNode*>&mefistoToDS,
734 double scalex, double scaley)
736 SMESHDS_Mesh * meshDS = myTool->GetMeshDS();
737 int faceID = myTool->GetSubShapeID();
739 TopoDS_Face F = TopoDS::Face( myTool->GetSubShape() );
740 Handle(Geom_Surface) S = BRep_Tool::Surface( F );
742 Z n = mefistoToDS.size(); // nb input points
743 mefistoToDS.resize( nbst );
744 for ( ; n < nbst; n++)
748 double u = uvst[n][0] / scalex;
749 double v = uvst[n][1] / scaley;
750 gp_Pnt P = S->Value(u, v);
752 SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
753 meshDS->SetNodeOnFace(node, faceID, u, v);
755 //MESSAGE(P.X()<<" "<<P.Y()<<" "<<P.Z());
756 mefistoToDS[n] = node;
757 //MESSAGE("NEW: "<<n<<" "<<mefistoToDS[n+1]);
763 // triangle points must be in trigonometric order if face is Forward
764 // else they must be put clockwise
766 bool triangleIsWellOriented = ( F.Orientation() == TopAbs_FORWARD );
768 for (n = 1; n <= nbt; n++)
770 const SMDS_MeshNode * n1 = mefistoToDS[ nust[m++] - 1 ];
771 const SMDS_MeshNode * n2 = mefistoToDS[ nust[m++] - 1 ];
772 const SMDS_MeshNode * n3 = mefistoToDS[ nust[m++] - 1 ];
774 SMDS_MeshElement * elt;
775 if (triangleIsWellOriented)
776 elt = myTool->AddFace(n1, n2, n3);
778 elt = myTool->AddFace(n1, n3, n2);
780 meshDS->SetMeshElementOnShape(elt, faceID);
784 // remove bad elements built on vertices shared by wires
786 list<const SMDS_MeshNode*>::iterator itN = myNodesOnCommonV.begin();
787 for ( ; itN != myNodesOnCommonV.end(); itN++ )
789 const SMDS_MeshNode* node = *itN;
790 SMDS_ElemIteratorPtr invElemIt = node->GetInverseElementIterator();
791 while ( invElemIt->more() )
793 const SMDS_MeshElement* elem = invElemIt->next();
794 SMDS_ElemIteratorPtr itN = elem->nodesIterator();
796 while ( itN->more() )
797 if ( itN->next() == node)
800 MESSAGE( "RM bad element " << elem->GetID());
801 meshDS->RemoveElement( elem );