From: aml Date: Mon, 7 Apr 2014 08:09:39 +0000 (+0400) Subject: 0024538: BRepFill_CompatibleWires.cxx, implementation of function PlaneOfWire() is... X-Git-Tag: V6_8_0_beta~408 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=927513c009db592f7762dbccc48df42590013203;p=occt-copy.git 0024538: BRepFill_CompatibleWires.cxx, implementation of function PlaneOfWire() is suboptimal Implementation improvements and refactoring in PlaneOfWire() function. --- diff --git a/src/BRepFill/BRepFill_CompatibleWires.cxx b/src/BRepFill/BRepFill_CompatibleWires.cxx index 1e26734c2a..dc3248a145 100644 --- a/src/BRepFill/BRepFill_CompatibleWires.cxx +++ b/src/BRepFill/BRepFill_CompatibleWires.cxx @@ -138,42 +138,61 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P) BRepLib_FindSurface findPlanarSurf; Handle(Geom_Surface) S; TopLoc_Location L; - + GProp_GProps GP; - BRepGProp::LinearProperties(W,GP); - gp_Pnt Bary = GP.CentreOfMass(); + gp_Pnt Bary; + Standard_Boolean isBaryDefined = Standard_False; // shielding for particular cases : only one edge circle or ellipse // on a closed wire ! - Standard_Integer nbEdges = 0; - BRepTools_WireExplorer anExp; - anExp.Init(W); + Standard_Boolean wClosed = W.Closed(); - if (!wClosed) { + if (!wClosed) + { // it is checked if the vertices are the same. TopoDS_Vertex V1, V2; TopExp::Vertices(W,V1,V2); if ( V1.IsSame(V2)) wClosed = Standard_True; } - TopoDS_Edge Edge = TopoDS::Edge(anExp.Current()); - Standard_Real first, last; - Handle(Geom_Curve) curv = BRep_Tool::Curve(Edge, first, last); - if (wClosed) { - GeomAdaptor_Curve AdC; - AdC.Load(curv); - for(; anExp.More(); anExp.Next()) { + + if (wClosed) + { + Standard_Integer nbEdges = 0; + TopoDS_Iterator anIter; + anIter.Initialize(W); + for(; anIter.More(); anIter.Next()) nbEdges ++; + + if(nbEdges == 1) + { + GeomAdaptor_Curve AdC; + Standard_Real first, last; + anIter.Initialize(W); + AdC.Load(BRep_Tool::Curve(TopoDS::Edge(anIter.Value()), first, last)); + + if (AdC.GetType() == GeomAbs_Circle) + { + Bary = AdC.Circle().Location(); + isBaryDefined = Standard_True; + } + + if (AdC.GetType() == GeomAbs_Ellipse) + { + Bary = AdC.Ellipse().Location(); + isBaryDefined = Standard_True; + } } - if ( nbEdges==1 && AdC.GetType() == GeomAbs_Circle ) { - Bary = AdC.Circle().Location(); - } - if ( nbEdges==1 && AdC.GetType() == GeomAbs_Ellipse ) { - Bary = AdC.Ellipse().Location(); - } + } + + if (!isBaryDefined) + { + BRepGProp::LinearProperties(W,GP); + Bary = GP.CentreOfMass(); } findPlanarSurf.Init(W, -1, Standard_True); - if ( findPlanarSurf.Found()) { + if ( findPlanarSurf.Found()) + { S = findPlanarSurf.Surface(); L = findPlanarSurf.Location(); if (!L.IsIdentity()) S = Handle(Geom_Surface):: @@ -181,7 +200,8 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P) P = (Handle(Geom_Plane)::DownCast(S))->Pln(); P.SetLocation(Bary); } - else { + else + { // wire not plane ! GProp_PrincipalProps Pp = GP.PrincipalProperties(); gp_Vec Vec; @@ -189,28 +209,35 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P) Pp.RadiusOfGyration(R1,R2,R3); Standard_Real RMax = Max(Max(R1,R2),R3); if ( ( Abs(RMax-R1)=R2 && R1>=R3) { - Vec = Pp.FirstAxisOfInertia(); + else + { + if (R1>=R2 && R1>=R3) + { + Vec = Pp.FirstAxisOfInertia(); } - else if (R2>=R1 && R2>=R3) { - Vec = Pp.SecondAxisOfInertia(); + else if (R2>=R1 && R2>=R3) + { + Vec = Pp.SecondAxisOfInertia(); } - else if (R3>=R1 && R3>=R2) { - Vec = Pp.ThirdAxisOfInertia(); + else if (R3>=R1 && R3>=R2) + { + Vec = Pp.ThirdAxisOfInertia(); } gp_Dir NDir(Vec); - if (R3<=R2 && R3<=R1) { - Vec = Pp.ThirdAxisOfInertia(); + if (R3<=R2 && R3<=R1) + { + Vec = Pp.ThirdAxisOfInertia(); } - else if (R2<=R1 && R2<=R3) { - Vec = Pp.SecondAxisOfInertia(); + else if (R2<=R1 && R2<=R3) + { + Vec = Pp.SecondAxisOfInertia(); } - else if (R1<=R2 && R1<=R3) { - Vec = Pp.FirstAxisOfInertia(); + else if (R1<=R2 && R1<=R3) + { + Vec = Pp.FirstAxisOfInertia(); } gp_Dir XDir(Vec); gp_Ax3 repere(Bary,NDir,XDir);