1 // Copyright (C) 2007-2020 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 : implementation of SMESH idl descriptions
24 // File : StdMeshers_MEFISTO_2D.cxx
25 // Moved here from SMESH_MEFISTO_2D.cxx
26 // Author : Paul RASCLE, EDF
29 #include "StdMeshers_MEFISTO_2D.hxx"
31 #include "SMDS_EdgePosition.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMDS_MeshNode.hxx"
34 #include "SMESHDS_Mesh.hxx"
35 #include "SMESH_Comment.hxx"
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MesherHelper.hxx"
39 #include "SMESH_subMesh.hxx"
40 #include "StdMeshers_FaceSide.hxx"
41 #include "StdMeshers_LengthFromEdges.hxx"
42 #include "StdMeshers_MaxElementArea.hxx"
43 #include "StdMeshers_ViscousLayers2D.hxx"
45 #include "utilities.h"
50 #include <BRepGProp.hxx>
51 #include <BRepTools.hxx>
52 #include <BRep_Tool.hxx>
53 #include <GProp_GProps.hxx>
54 #include <Geom2d_Curve.hxx>
55 #include <Geom_Curve.hxx>
56 #include <Geom_Surface.hxx>
57 #include <Precision.hxx>
59 #include <TopExp_Explorer.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <TopTools_ListOfShape.hxx>
62 #include <TopTools_MapOfShape.hxx>
64 #include <TopoDS_Edge.hxx>
65 #include <TopoDS_Face.hxx>
66 #include <TopoDS_Iterator.hxx>
67 #include <TopoDS_Wire.hxx>
68 #include <gp_Pnt2d.hxx>
73 //#define DUMP_POINTS // to print coordinates of MEFISTO input
76 //=============================================================================
80 //=============================================================================
82 StdMeshers_MEFISTO_2D::StdMeshers_MEFISTO_2D(int hypId, SMESH_Gen * gen):
83 SMESH_2D_Algo(hypId, gen)
86 _shapeType = (1 << TopAbs_FACE);
87 _compatibleHypothesis.push_back("MaxElementArea");
88 _compatibleHypothesis.push_back("LengthFromEdges");
89 _compatibleHypothesis.push_back("ViscousLayers2D");
93 _hypMaxElementArea = NULL;
94 _hypLengthFromEdges = NULL;
98 //=============================================================================
102 //=============================================================================
104 StdMeshers_MEFISTO_2D::~StdMeshers_MEFISTO_2D()
108 //=============================================================================
112 //=============================================================================
114 bool StdMeshers_MEFISTO_2D::CheckHypothesis
116 const TopoDS_Shape& aShape,
117 SMESH_Hypothesis::Hypothesis_Status& aStatus)
119 _hypMaxElementArea = NULL;
120 _hypLengthFromEdges = NULL;
124 if ( !error( StdMeshers_ViscousLayers2D::CheckHypothesis( aMesh, aShape, aStatus )))
127 list <const SMESHDS_Hypothesis * >::const_iterator itl;
128 const SMESHDS_Hypothesis *theHyp;
130 const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
131 int nbHyp = hyps.size();
134 aStatus = SMESH_Hypothesis::HYP_OK; //SMESH_Hypothesis::HYP_MISSING;
135 return true; // (PAL13464) can work with no hypothesis, LengthFromEdges is default one
139 theHyp = (*itl); // use only the first hypothesis
141 string hypName = theHyp->GetName();
145 if (hypName == "MaxElementArea")
147 _hypMaxElementArea = static_cast<const StdMeshers_MaxElementArea *>(theHyp);
148 ASSERT(_hypMaxElementArea);
149 _maxElementArea = _hypMaxElementArea->GetMaxArea();
151 aStatus = SMESH_Hypothesis::HYP_OK;
154 else if (hypName == "LengthFromEdges")
156 _hypLengthFromEdges = static_cast<const StdMeshers_LengthFromEdges *>(theHyp);
157 ASSERT(_hypLengthFromEdges);
159 aStatus = SMESH_Hypothesis::HYP_OK;
162 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
167 if (_maxElementArea > 0)
169 //_edgeLength = 2 * sqrt(_maxElementArea); // triangles : minorant
170 _edgeLength = sqrt(2. * _maxElementArea/sqrt(3.0));
174 isOk = (_hypLengthFromEdges != NULL); // **** check mode
176 aStatus = SMESH_Hypothesis::HYP_BAD_PARAMETER;
182 //=============================================================================
186 //=============================================================================
188 bool StdMeshers_MEFISTO_2D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
190 TopoDS_Face F = TopoDS::Face(aShape.Oriented(TopAbs_FORWARD));
192 // helper builds quadratic mesh if necessary
193 SMESH_MesherHelper helper(aMesh);
195 _quadraticMesh = _helper->IsQuadraticSubMesh(aShape);
196 const bool skipMediumNodes = _quadraticMesh;
198 // build viscous layers if required
199 SMESH_ProxyMesh::Ptr proxyMesh = StdMeshers_ViscousLayers2D::Compute( aMesh, F );
203 // get all edges of a face
206 StdMeshers_FaceSide::GetFaceWires( F, aMesh, skipMediumNodes, problem, _helper, proxyMesh );
207 int nbWires = wires.size();
208 if ( problem && !problem->IsOK() ) return error( problem );
209 if ( nbWires == 0 ) return error( "Problem in StdMeshers_FaceSide::GetFaceWires()");
210 if ( wires[0]->NbSegments() < 3 ) // ex: a circle with 2 segments
211 return error(COMPERR_BAD_INPUT_MESH,
212 SMESH_Comment("Too few segments: ")<<wires[0]->NbSegments());
214 // compute average edge length
215 if (!_hypMaxElementArea)
219 for ( int iW = 0; iW < nbWires; ++iW )
221 StdMeshers_FaceSidePtr wire = wires[ iW ];
222 _edgeLength += wire->Length();
223 nbSegments += wire->NbSegments();
226 _edgeLength /= nbSegments;
229 if (/*_hypLengthFromEdges &&*/ _edgeLength < DBL_MIN )
232 Z nblf; //nombre de lignes fermees (enveloppe en tete)
233 Z *nudslf = NULL; //numero du dernier sommet de chaque ligne fermee
235 Z nbpti = 0; //nombre points internes futurs sommets de la triangulation
244 Z nutysu = 1; // 1: il existe un fonction areteideale_()
245 // Z nutysu=0; // 0: on utilise aretmx
246 R aretmx = _edgeLength; // longueur max aretes future triangulation
247 if ( _hypMaxElementArea )
252 nudslf = new Z[1 + nblf];
257 // count nb of input points
258 for ( int iW = 0; iW < nbWires; ++iW )
260 nbpnt += wires[iW]->NbPoints() - 1;
261 nudslf[iw++] = nbpnt;
264 uvslf = new R2[nudslf[nblf]];
266 double scalex, scaley;
267 ComputeScaleOnFace(aMesh, F, scalex, scaley);
269 // correspondence mefisto index --> Nodes
270 vector< const SMDS_MeshNode*> mefistoToDS(nbpnt, (const SMDS_MeshNode*)0);
274 // fill input points UV
275 if ( LoadPoints(wires, uvslf, mefistoToDS, scalex, scaley) )
278 aptrte(nutysu, aretmx,
279 nblf, nudslf, uvslf, nbpti, uvpti, nbst, uvst, nbt, nust, ierr);
283 StoreResult(nbst, uvst, nbt, nust, mefistoToDS, scalex, scaley);
288 error(ierr,"Error in Triangulation (aptrte())");
291 if (nudslf != NULL) delete[]nudslf;
292 if (uvslf != NULL) delete[]uvslf;
293 if (uvst != NULL) delete[]uvst;
294 if (nust != NULL) delete[]nust;
300 //=============================================================================
304 //=============================================================================
306 bool StdMeshers_MEFISTO_2D::Evaluate(SMESH_Mesh & aMesh,
307 const TopoDS_Shape & aShape,
308 MapShapeNbElems& aResMap)
310 TopoDS_Face F = TopoDS::Face(aShape.Oriented(TopAbs_FORWARD));
314 bool IsQuadratic = false;
316 TopExp_Explorer exp(F,TopAbs_EDGE);
317 for(; exp.More(); exp.Next()) {
318 TopoDS_Edge E = TopoDS::Edge(exp.Current());
319 MapShapeNbElemsItr anIt = aResMap.find( aMesh.GetSubMesh(E) );
320 if( anIt == aResMap.end() ) continue;
321 std::vector<int> aVec = (*anIt).second;
322 int nbe = Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
325 IsQuadratic = ( aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge] );
330 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,a,b);
333 double dp = (b-a)/nbe;
334 for(int i=1; i<=nbe; i++) {
337 aLen += P1.Distance(P2);
342 std::vector<int> aResVec(SMDSEntity_Last);
343 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
344 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
345 aResMap.insert(std::make_pair(sm,aResVec));
346 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
347 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
348 "Submesh can not be evaluated",this));
351 aLen = aLen/NbSeg; // middle length
353 _edgeLength = Precision::Infinite();
354 double tmpLength = Min( _edgeLength, aLen );
357 BRepGProp::SurfaceProperties(aShape,G);
358 double anArea = G.Mass();
360 int nbFaces = Precision::IsInfinite( tmpLength ) ? 0 :
361 (int)( anArea/(tmpLength*tmpLength*sqrt(3.)/4) );
362 int nbNodes = (int) ( nbFaces*3 - (NbSeg-1)*2 ) / 6;
364 std::vector<int> aVec(SMDSEntity_Last);
365 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
367 aVec[SMDSEntity_Quad_Triangle] = nbFaces;
368 aVec[SMDSEntity_Node] = (int)( nbNodes + nbFaces*3 - (NbSeg-1) );
371 aVec[SMDSEntity_Node] = nbNodes;
372 aVec[SMDSEntity_Triangle] = nbFaces;
374 SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
375 aResMap.insert(std::make_pair(sm,aVec));
381 //=======================================================================
382 //function : fixOverlappedLinkUV
383 //purpose : prevent failure due to overlapped adjacent links
384 //=======================================================================
386 static bool fixOverlappedLinkUV( R2& uv0, const R2& uv1, const R2& uv2 )
388 gp_XY v1( uv0.x - uv1.x, uv0.y - uv1.y );
389 gp_XY v2( uv2.x - uv1.x, uv2.y - uv1.y );
391 double tol2 = DBL_MIN * DBL_MIN;
392 double sqMod1 = v1.SquareModulus();
393 if ( sqMod1 <= tol2 ) return false;
394 double sqMod2 = v2.SquareModulus();
395 if ( sqMod2 <= tol2 ) return false;
399 // check sinus >= 1.e-3
400 const double minSin = 1.e-3;
401 if ( dot > 0 && 1 - dot * dot / ( sqMod1 * sqMod2 ) < minSin * minSin ) {
402 MESSAGE(" ___ FIX UV ____" << uv0.x << " " << uv0.y);
403 v1.SetCoord( -v1.Y(), v1.X() );
404 double delta = sqrt( sqMod1 ) * minSin;
414 // MESSAGE(" -> " << uv0.x << " " << uv0.y << " ");
415 // MESSAGE("v1( " << v1.X() << " " << v1.Y() << " ) " <<
416 // "v2( " << v2.X() << " " << v2.Y() << " ) ");
417 // MESSAGE("SIN: " << sqrt(1 - dot * dot / (sqMod1 * sqMod2)));
418 // v1.SetCoord( uv0.x - uv1.x, uv0.y - uv1.y );
419 // v2.SetCoord( uv2.x - uv1.x, uv2.y - uv1.y );
420 // gp_XY v3( uv2.x - uv0.x, uv2.y - uv0.y );
421 // sqMod1 = v1.SquareModulus();
422 // sqMod2 = v2.SquareModulus();
424 // double sin = sqrt(1 - dot * dot / (sqMod1 * sqMod2));
425 // MESSAGE("NEW SIN: " << sin);
432 //=======================================================================
433 //function : fixCommonVertexUV
435 //=======================================================================
437 static bool fixCommonVertexUV (R2 & theUV,
438 const TopoDS_Vertex& theV,
439 const TopoDS_Face& theF,
440 const TopTools_IndexedDataMapOfShapeListOfShape & theVWMap,
441 SMESH_Mesh & theMesh,
442 const double theScaleX,
443 const double theScaleY,
444 const bool theCreateQuadratic)
446 if( !theVWMap.Contains( theV )) return false;
448 // check if there is another wire sharing theV
449 const TopTools_ListOfShape& WList = theVWMap.FindFromKey( theV );
450 TopTools_ListIteratorOfListOfShape aWIt;
451 TopTools_MapOfShape aWires;
452 for ( aWIt.Initialize( WList ); aWIt.More(); aWIt.Next() )
453 aWires.Add( aWIt.Value() );
454 if ( aWires.Extent() < 2 ) return false;
456 TopoDS_Shape anOuterWire = BRepTools::OuterWire(theF);
457 TopoDS_Shape anInnerWire;
458 for ( aWIt.Initialize( WList ); aWIt.More() && anInnerWire.IsNull(); aWIt.Next() )
459 if ( !anOuterWire.IsSame( aWIt.Value() ))
460 anInnerWire = aWIt.Value();
462 TopTools_ListOfShape EList;
463 list< double > UList;
465 // find edges of theW sharing theV
466 // and find 2d normal to them at theV
468 TopoDS_Iterator itE( anInnerWire );
469 for ( ; itE.More(); itE.Next() )
471 const TopoDS_Edge& E = TopoDS::Edge( itE.Value() );
472 TopoDS_Iterator itV( E );
473 for ( ; itV.More(); itV.Next() )
475 const TopoDS_Vertex & V = TopoDS::Vertex( itV.Value() );
476 if ( !V.IsSame( theV ))
479 Standard_Real u = BRep_Tool::Parameter( V, E );
480 UList.push_back( u );
482 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, theF, f, l);
486 gp_Vec2d n( d1.Y() * theScaleX, -d1.X() * theScaleY);
487 if ( E.Orientation() == TopAbs_REVERSED )
493 // define step size by which to move theUV
495 gp_Pnt2d nextUV; // uv of next node on edge, most distant of the four
496 gp_Pnt2d thisUV( theUV.x, theUV.y );
497 double maxDist = -DBL_MAX;
498 TopTools_ListIteratorOfListOfShape aEIt (EList);
499 list< double >::iterator aUIt = UList.begin();
500 for ( ; aEIt.More(); aEIt.Next(), aUIt++ )
502 const TopoDS_Edge& E = TopoDS::Edge( aEIt.Value() );
504 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, theF, f, l);
506 double umin = DBL_MAX, umax = -DBL_MAX;
507 SMDS_NodeIteratorPtr nIt = theMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
508 if ( !nIt->more() ) // no nodes on edge, only on vertices
514 while ( nIt->more() ) {
515 const SMDS_MeshNode* node = nIt->next();
516 // check if node is medium
517 if ( theCreateQuadratic && SMESH_MesherHelper::IsMedium( node, SMDSAbs_Edge ))
519 SMDS_EdgePositionPtr epos = node->GetPosition();
520 double u = epos->GetUParameter();
527 bool isFirstCommon = ( *aUIt == f );
528 gp_Pnt2d uv = C2d->Value( isFirstCommon ? umin : umax );
529 double dist = thisUV.SquareDistance( uv );
530 if ( dist > maxDist ) {
536 uv0.x = thisUV.X(); uv0.y = thisUV.Y();
537 uv1.x = nextUV.X(); uv1.y = nextUV.Y();
538 uv2.x = thisUV.X(); uv2.y = thisUV.Y();
540 uv1.x *= theScaleX; uv1.y *= theScaleY;
542 if ( fixOverlappedLinkUV( uv0, uv1, uv2 ))
544 double step = thisUV.Distance( gp_Pnt2d( uv0.x, uv0.y ));
546 // move theUV along the normal by the step
550 MESSAGE("--fixCommonVertexUV move(" << theUV.x << " " << theUV.x
551 << ") by (" << N.X() << " " << N.Y() << ")"
552 << endl << "--- MAX DIST " << maxDist);
562 //=============================================================================
566 //=============================================================================
568 bool StdMeshers_MEFISTO_2D::LoadPoints(TWireVector & wires,
570 vector<const SMDS_MeshNode*>& mefistoToDS,
574 // to avoid passing same uv points for a vertex common to 2 wires
576 TopTools_IndexedDataMapOfShapeListOfShape VWMap;
577 if ( wires.size() > 1 )
579 F = TopoDS::Face( _helper->GetSubShape() );
580 TopExp::MapShapesAndAncestors( F, TopAbs_VERTEX, TopAbs_WIRE, VWMap );
582 for ( size_t iW = 0; iW < wires.size(); ++iW )
583 nbVertices += wires[ iW ]->NbEdges();
584 if ( nbVertices == VWMap.Extent() )
585 VWMap.Clear(); // wires have no common vertices
590 for ( size_t iW = 0; iW < wires.size(); ++iW )
592 const vector<UVPtStruct>& uvPtVec = wires[ iW ]->GetUVPtStruct();
593 if ((int) uvPtVec.size() != wires[ iW ]->NbPoints() ) {
594 return error(COMPERR_BAD_INPUT_MESH,SMESH_Comment("Unexpected nb of points on wire ")
595 << iW << ": " << uvPtVec.size()<<" != "<<wires[ iW ]->NbPoints()
596 << ", probably because of invalid node parameters on geom edges");
598 if ( m + uvPtVec.size()-1 > mefistoToDS.size() ) {
599 MESSAGE("Wrong mefistoToDS.size: "<<mefistoToDS.size()<<" < "<<m + uvPtVec.size()-1);
600 return error("Internal error");
603 list< int > mOnVertex;
604 vector<UVPtStruct>::const_iterator uvPt = uvPtVec.begin();
605 for ( ++uvPt; uvPt != uvPtVec.end(); ++uvPt )
607 // bind mefisto ID to node
608 mefistoToDS[m] = uvPt->node;
610 uvslf[m].x = uvPt->u * scalex;
611 uvslf[m].y = uvPt->v * scaley;
612 switch ( uvPt->node->GetPosition()->GetTypeOfPosition())
614 case SMDS_TOP_VERTEX:
615 mOnVertex.push_back( m );
618 // In order to detect degenerated faces easily, we replace
619 // nodes on a degenerated edge by node on the vertex of that edge
620 if ( _helper->IsDegenShape( uvPt->node->getshapeId() ))
622 int edgeID = uvPt->node->getshapeId();
623 SMESH_subMesh* edgeSM = _helper->GetMesh()->GetSubMeshContaining( edgeID );
624 SMESH_subMeshIteratorPtr smIt = edgeSM->getDependsOnIterator( /*includeSelf=*/0,
625 /*complexShapeFirst=*/0);
628 SMESH_subMesh* vertexSM = smIt->next();
629 SMDS_NodeIteratorPtr nIt = vertexSM->GetSubMeshDS()->GetNodes();
631 mefistoToDS[m] = nIt->next();
640 int mFirst = mOnVertex.front(), mLast = m - 1;
641 list< int >::iterator mIt = mOnVertex.begin();
642 for ( ; mIt != mOnVertex.end(); ++mIt)
645 if ( iW && !VWMap.IsEmpty()) { // except outer wire
646 // avoid passing same uv point for a vertex common to 2 wires
647 int vID = mefistoToDS[m]->getshapeId();
648 TopoDS_Vertex V = TopoDS::Vertex( _helper->GetMeshDS()->IndexToShape( vID ));
649 if ( fixCommonVertexUV( uvslf[m], V, F, VWMap, *_helper->GetMesh(),
650 scalex, scaley, _quadraticMesh )) {
651 myNodesOnCommonV.push_back( mefistoToDS[m] );
655 // prevent failure on overlapped adjacent links,
656 // check only links ending in vertex nodes
657 int mB = m - 1, mA = m + 1; // indices Before and After
658 if ( mB < mFirst ) mB = mLast;
659 if ( mA > mLast ) mA = mFirst;
660 fixOverlappedLinkUV (uvslf[ mB ], uvslf[ m ], uvslf[ mA ]);
665 cout << "MEFISTO INPUT************" << endl;
666 for ( int i =0; i < m; ++i )
667 cout << i << ": \t" << uvslf[i].x << ", " << uvslf[i].y
668 << " Node " << mefistoToDS[i]->GetID()<< endl;
674 //=============================================================================
678 //=============================================================================
680 void StdMeshers_MEFISTO_2D::ComputeScaleOnFace(SMESH_Mesh & aMesh,
681 const TopoDS_Face & aFace,
685 TopoDS_Wire W = BRepTools::OuterWire(aFace);
687 double xmin = 1.e300; // min & max of face 2D parametric coord.
688 double xmax = -1.e300;
689 double ymin = 1.e300;
690 double ymax = -1.e300;
695 TopExp_Explorer wexp(W, TopAbs_EDGE);
696 for ( ; wexp.More(); wexp.Next())
698 const TopoDS_Edge & E = TopoDS::Edge( wexp.Current() );
700 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, aFace, f, l);
701 if ( C2d.IsNull() ) continue;
702 double du = (l - f) / double (nbp);
703 for (int i = 0; i <= nbp; i++)
705 double param = f + double (i) * du;
706 gp_Pnt2d p = C2d->Value(param);
717 double xmoy = (xmax + xmin) / 2.;
718 double ymoy = (ymax + ymin) / 2.;
719 double xsize = xmax - xmin;
720 double ysize = ymax - ymin;
723 Handle(Geom_Surface) S = BRep_Tool::Surface(aFace,L); // 3D surface
727 gp_Pnt PX0 = S->Value(xmin, ymoy);
728 gp_Pnt PY0 = S->Value(xmoy, ymin);
729 double dx = xsize / double (nbp);
730 double dy = ysize / double (nbp);
731 for (int i = 1; i <= nbp; i++)
733 double x = xmin + double (i) * dx;
734 gp_Pnt PX = S->Value(x, ymoy);
735 double y = ymin + double (i) * dy;
736 gp_Pnt PY = S->Value(xmoy, y);
737 length_x += PX.Distance(PX0);
738 length_y += PY.Distance(PY0);
742 scalex = length_x / xsize;
743 scaley = length_y / ysize;
744 double xyratio = xsize*scalex/(ysize*scaley);
745 const double maxratio = 1.e2;
746 if (xyratio > maxratio) {
747 scaley *= xyratio / maxratio;
749 else if (xyratio < 1./maxratio) {
750 scalex *= 1 / xyratio / maxratio;
756 // bool isDegenTria( const SMDS_MeshNode * nn[3] )
758 // SMESH_TNodeXYZ p1( nn[0] );
759 // SMESH_TNodeXYZ p2( nn[1] );
760 // SMESH_TNodeXYZ p3( nn[2] );
761 // gp_XYZ vec1 = p2 - p1;
762 // gp_XYZ vec2 = p3 - p1;
763 // gp_XYZ cross = vec1 ^ vec2;
764 // const double eps = 1e-100;
765 // return ( fabs( cross.X() ) < eps &&
766 // fabs( cross.Y() ) < eps &&
767 // fabs( cross.Z() ) < eps );
771 //=============================================================================
775 //=============================================================================
777 void StdMeshers_MEFISTO_2D::StoreResult(Z nbst, R2 * uvst, Z nbt, Z * nust,
778 vector< const SMDS_MeshNode*>&mefistoToDS,
779 double scalex, double scaley)
781 _helper->SetElementsOnShape( true );
783 TopoDS_Face F = TopoDS::Face( _helper->GetSubShape() );
784 Handle(Geom_Surface) S = BRep_Tool::Surface( F );
786 //const size_t nbInputNodes = mefistoToDS.size();
788 Z n = mefistoToDS.size(); // nb input points
789 mefistoToDS.resize( nbst );
790 for ( ; n < nbst; n++)
794 double u = uvst[n][0] / scalex;
795 double v = uvst[n][1] / scaley;
796 gp_Pnt P = S->Value(u, v);
798 mefistoToDS[n] = _helper->AddNode( P.X(), P.Y(), P.Z(), 0, u, v );
804 // triangle points must be in trigonometric order if face is Forward
805 // else they must be put clockwise
808 if ( F.Orientation() != TopAbs_FORWARD )
811 const SMDS_MeshNode * nn[3];
812 for (n = 1; n <= nbt; n++)
814 // const bool allNodesAreOld = ( nust[m + 0] <= nbInputNodes &&
815 // nust[m + 1] <= nbInputNodes &&
816 // nust[m + 2] <= nbInputNodes );
817 nn[ 0 ] = mefistoToDS[ nust[m++] - 1 ];
818 nn[ 1 ] = mefistoToDS[ nust[m++] - 1 ];
819 nn[ 2 ] = mefistoToDS[ nust[m++] - 1 ];
822 // avoid creating degenetrated faces
823 bool isDegen = ( _helper->HasDegeneratedEdges() &&
824 ( nn[0] == nn[1] || nn[1] == nn[2] || nn[2] == nn[0] ));
826 // It was an attempt to fix a problem of a zero area face whose all nodes
827 // are on one staight EDGE. But omitting this face makes a hole in the mesh :(
828 // if ( !isDegen && allNodesAreOld )
829 // isDegen = isDegenTria( nn );
832 _helper->AddFace( nn[0], nn[i1], nn[i2] );
835 // remove bad elements built on vertices shared by wires
837 list<const SMDS_MeshNode*>::iterator itN = myNodesOnCommonV.begin();
838 for ( ; itN != myNodesOnCommonV.end(); itN++ )
840 const SMDS_MeshNode* node = *itN;
841 SMDS_ElemIteratorPtr invElemIt = node->GetInverseElementIterator();
842 while ( invElemIt->more() )
844 const SMDS_MeshElement* elem = invElemIt->next();
845 SMDS_ElemIteratorPtr itN = elem->nodesIterator();
847 while ( itN->more() )
848 if ( itN->next() == node)
851 MESSAGE( "RM bad element " << elem->GetID());
852 _helper->GetMeshDS()->RemoveElement( elem );