From 5c95370148b4c8aa52cb2046795f9582589a1668 Mon Sep 17 00:00:00 2001 From: szv Date: Tue, 6 Mar 2012 14:43:10 +0400 Subject: [PATCH] 0022998: Various exceptions in HLR algorithms --- src/HLRBRep/HLRBRep.cxx | 157 ++++---- src/HLRBRep/HLRBRep_Curve.cxx | 20 +- src/HLRBRep/HLRBRep_HLRToShape.cxx | 40 +- src/HLRTopoBRep/HLRTopoBRep_DSFiller.cxx | 448 +++++++++++------------ 4 files changed, 337 insertions(+), 328 deletions(-) diff --git a/src/HLRBRep/HLRBRep.cxx b/src/HLRBRep/HLRBRep.cxx index 44b9cdb45a..21e8dd1f95 100755 --- a/src/HLRBRep/HLRBRep.cxx +++ b/src/HLRBRep/HLRBRep.cxx @@ -17,80 +17,99 @@ //======================================================================= TopoDS_Edge HLRBRep::MakeEdge (const HLRBRep_Curve& ec, - const Standard_Real U1, - const Standard_Real U2) + const Standard_Real U1, + const Standard_Real U2) { TopoDS_Edge Edg; - //gp_Pnt2d P,P1,P2; - Standard_Real sta3d = U1; - Standard_Real end3d = U2; - Standard_Real sta = ec.Parameter2d(U1); - Standard_Real end = ec.Parameter2d(U2); - - if (ec.GetType() == GeomAbs_Line) { - Edg = BRepLib_MakeEdge2d(ec.Line(),sta,end); - } - else if (ec.GetType() == GeomAbs_Circle) { - Edg = BRepLib_MakeEdge2d(ec.Circle(),sta,end); - } - else if (ec.GetType() == GeomAbs_Ellipse) { - Edg = BRepLib_MakeEdge2d(ec.Ellipse(),sta,end); - } - else if (ec.GetType() == GeomAbs_Hyperbola) { - Edg = BRepLib_MakeEdge2d(ec.Hyperbola(),sta,end); - } - else if (ec.GetType() == GeomAbs_Parabola) { - Edg = BRepLib_MakeEdge2d(ec.Parabola(),sta,end); - } - else if (ec.GetType() == GeomAbs_BezierCurve) { - TColgp_Array1OfPnt2d Poles(1,ec.NbPoles()); - if (ec.IsRational()) { - TColStd_Array1OfReal Weights(1,ec.NbPoles()); - ec.PolesAndWeights(Poles,Weights); - Edg = BRepLib_MakeEdge2d(new Geom2d_BezierCurve(Poles,Weights),sta,end); - } - else { - ec.Poles(Poles); - Edg = BRepLib_MakeEdge2d(new Geom2d_BezierCurve(Poles),sta,end); - } - } - else if (ec.GetType() == GeomAbs_BSplineCurve) { - TColgp_Array1OfPnt2d Poles(1,ec.NbPoles()); - TColStd_Array1OfReal knots(1,ec.NbKnots()); - TColStd_Array1OfInteger mults(1,ec.NbKnots()); - //-- ec.KnotsAndMultiplicities(knots,mults); - ec.Knots(knots); - ec.Multiplicities(mults); - if (ec.IsRational()) { - TColStd_Array1OfReal Weights(1,ec.NbPoles()); - ec.PolesAndWeights(Poles,Weights); - Edg = BRepLib_MakeEdge2d - (new Geom2d_BSplineCurve - (Poles,Weights,knots,mults,ec.Degree()),sta,end); + const Standard_Real sta = ec.Parameter2d(U1); + const Standard_Real end = ec.Parameter2d(U2); + + switch (ec.GetType()) + { + case GeomAbs_Line: + Edg = BRepLib_MakeEdge2d(ec.Line(),sta,end); + break; + + case GeomAbs_Circle: + Edg = BRepLib_MakeEdge2d(ec.Circle(),sta,end); + break; + + case GeomAbs_Ellipse: + Edg = BRepLib_MakeEdge2d(ec.Ellipse(),sta,end); + break; + + case GeomAbs_Hyperbola: + Edg = BRepLib_MakeEdge2d(ec.Hyperbola(),sta,end); + break; + + case GeomAbs_Parabola: + Edg = BRepLib_MakeEdge2d(ec.Parabola(),sta,end); + break; + + case GeomAbs_BezierCurve: { + TColgp_Array1OfPnt2d Poles(1,ec.NbPoles()); + Handle(Geom2d_BezierCurve) ec2d; + if (ec.IsRational()) { + TColStd_Array1OfReal Weights(1,ec.NbPoles()); + ec.PolesAndWeights(Poles,Weights); + ec2d = new Geom2d_BezierCurve(Poles,Weights); + } + else { + ec.Poles(Poles); + ec2d = new Geom2d_BezierCurve(Poles); + } + BRepLib_MakeEdge2d mke2d(ec2d,sta,end); + if (mke2d.IsDone()) + Edg = mke2d.Edge(); + break; } - else { - ec.Poles(Poles); - Edg = BRepLib_MakeEdge2d - (new Geom2d_BSplineCurve(Poles,knots,mults,ec.Degree()),sta,end); + + case GeomAbs_BSplineCurve: { + TColgp_Array1OfPnt2d Poles(1,ec.NbPoles()); + TColStd_Array1OfReal knots(1,ec.NbKnots()); + TColStd_Array1OfInteger mults(1,ec.NbKnots()); + //-- ec.KnotsAndMultiplicities(knots,mults); + ec.Knots(knots); + ec.Multiplicities(mults); + Handle(Geom2d_BSplineCurve) ec2d; + if (ec.IsRational()) { + TColStd_Array1OfReal Weights(1,ec.NbPoles()); + ec.PolesAndWeights(Poles,Weights); + ec2d = new Geom2d_BSplineCurve(Poles,Weights,knots,mults,ec.Degree()); + } + else { + ec.Poles(Poles); + ec2d = new Geom2d_BSplineCurve(Poles,knots,mults,ec.Degree()); + } + BRepLib_MakeEdge2d mke2d(ec2d,sta,end); + if (mke2d.IsDone()) + Edg = mke2d.Edge(); + break; } - } - else { - Standard_Integer nbPnt = 15; - TColgp_Array1OfPnt2d Poles(1,nbPnt); - TColStd_Array1OfReal knots(1,nbPnt); - TColStd_Array1OfInteger mults(1,nbPnt); - mults.Init(1); - mults(1 ) = 2; - mults(nbPnt) = 2; - Standard_Real step = (end3d-sta3d)/(nbPnt-1); - - for (Standard_Integer i = 1; i <= nbPnt; i++) { - Poles(i) = ec.Value(sta3d); - knots(i) = sta3d; - sta3d += step; + + default: { + const Standard_Integer nbPnt = 15; + TColgp_Array1OfPnt2d Poles(1,nbPnt); + TColStd_Array1OfReal knots(1,nbPnt); + TColStd_Array1OfInteger mults(1,nbPnt); + mults.Init(1); + mults(1 ) = 2; + mults(nbPnt) = 2; + const Standard_Real step = (U2-U1)/(nbPnt-1); + Standard_Real par3d = U1; + for (Standard_Integer i = 1; i < nbPnt; i++) { + Poles(i) = ec.Value(par3d); + knots(i) = par3d; + par3d += step; + } + Poles(nbPnt) = ec.Value(U2); + knots(nbPnt) = U2; + + Handle(Geom2d_BSplineCurve) ec2d = new Geom2d_BSplineCurve(Poles,knots,mults,1); + BRepLib_MakeEdge2d mke2d(ec2d,sta,end); + if (mke2d.IsDone()) + Edg = mke2d.Edge(); } - Edg = BRepLib_MakeEdge2d - (new Geom2d_BSplineCurve(Poles,knots,mults,1),sta,end); } return Edg; } diff --git a/src/HLRBRep/HLRBRep_Curve.cxx b/src/HLRBRep/HLRBRep_Curve.cxx index 169ded6d71..6adf29df31 100755 --- a/src/HLRBRep/HLRBRep_Curve.cxx +++ b/src/HLRBRep/HLRBRep_Curve.cxx @@ -50,18 +50,18 @@ HLRBRep_Curve::Parameter2d (const Standard_Real P3d) const // Res -> -------------------------------------------- // (-myOF + myOZ) (-myOF + myOZ + P3d myVZ) - if (myType == GeomAbs_Line) { - if (((HLRAlgo_Projector*) myProj)->Perspective()) { - const Standard_Real FmOZ = myOF - myOZ; - return myOF * P3d * (myVX * FmOZ + myOX * myVZ) / (FmOZ * (FmOZ - P3d * myVZ)); - } - return P3d * myVX; - } + switch (myType) + { + case GeomAbs_Line: + if (((HLRAlgo_Projector*) myProj)->Perspective()) { + const Standard_Real FmOZ = myOF - myOZ; + return myOF * P3d * (myVX * FmOZ + myOX * myVZ) / (FmOZ * (FmOZ - P3d * myVZ)); + } + return P3d * myVX; - else if (myType == GeomAbs_Ellipse) { - return P3d + myOX; + case GeomAbs_Ellipse: + return P3d + myOX; } - return P3d; } diff --git a/src/HLRBRep/HLRBRep_HLRToShape.cxx b/src/HLRBRep/HLRBRep_HLRToShape.cxx index 553f0912af..f333558e88 100755 --- a/src/HLRBRep/HLRBRep_HLRToShape.cxx +++ b/src/HLRBRep/HLRBRep_HLRToShape.cxx @@ -180,34 +180,40 @@ HLRBRep_HLRToShape::DrawEdge (const Standard_Boolean visible, TopoDS_Shape& Result, Standard_Boolean& added) const { - Standard_Boolean todraw; + Standard_Boolean todraw = Standard_False; if (inFace) todraw = Standard_True; else if (typ == 3) todraw = ed.Rg1Line() && !ed.RgNLine(); else if (typ == 4) todraw = ed.RgNLine(); else todraw =!ed.Rg1Line(); + if (todraw) { Standard_Real sta,end; Standard_ShortReal tolsta,tolend; BRep_Builder B; + TopoDS_Edge E; HLRAlgo_EdgeIterator It; - if (visible) { - - for (It.InitVisible(ed.Status()); - It.MoreVisible(); - It.NextVisible()) { - It.Visible(sta,tolsta,end,tolend); - B.Add(Result,HLRBRep::MakeEdge(ed.Geometry(),sta,end)); - added = Standard_True; + if (visible) + { + for (It.InitVisible(ed.Status()); It.MoreVisible(); It.NextVisible()) { + It.Visible(sta,tolsta,end,tolend); + E = HLRBRep::MakeEdge(ed.Geometry(),sta,end); + if (!E.IsNull()) + { + B.Add(Result,E); + added = Standard_True; + } } } - else { - - for (It.InitHidden(ed.Status()); - It.MoreHidden(); - It.NextHidden()) { - It.Hidden(sta,tolsta,end,tolend); - B.Add(Result,HLRBRep::MakeEdge(ed.Geometry(),sta,end)); - added = Standard_True; + else + { + for (It.InitHidden(ed.Status()); It.MoreHidden(); It.NextHidden()) { + It.Hidden(sta,tolsta,end,tolend); + E = HLRBRep::MakeEdge(ed.Geometry(),sta,end); + if (!E.IsNull()) + { + B.Add(Result,E); + added = Standard_True; + } } } } diff --git a/src/HLRTopoBRep/HLRTopoBRep_DSFiller.cxx b/src/HLRTopoBRep/HLRTopoBRep_DSFiller.cxx index cb0eb63570..3f691cc7ec 100755 --- a/src/HLRTopoBRep/HLRTopoBRep_DSFiller.cxx +++ b/src/HLRTopoBRep/HLRTopoBRep_DSFiller.cxx @@ -104,15 +104,14 @@ void HLRTopoBRep_DSFiller::InsertFace (const Standard_Integer FI, { // Insert the intersections of FO in DS - - Standard_Real tol = BRep_Tool::Tolerance(F); + const Standard_Real tol = BRep_Tool::Tolerance(F); TopTools_ListOfShape& IntL = DS.AddIntL(F); TopTools_ListOfShape& OutL = DS.AddOutL(F); - TopTools_MapOfShape VM; + TopoDS_Vertex VF,VL; - Standard_Real parF,parL; + /* + TopTools_MapOfShape VM; TopExp_Explorer ex(F,TopAbs_EDGE); - while (ex.More()) { const TopoDS_Edge& E = TopoDS::Edge(ex.Current()); if (BRep_Tool::IsClosed(E,F)) { @@ -122,100 +121,97 @@ void HLRTopoBRep_DSFiller::InsertFace (const Standard_Integer FI, } ex.Next(); } + */ - Standard_Integer CurLine; - Standard_Integer NbLines = FO.NbLines(); - - for (CurLine = 1; CurLine <= NbLines; CurLine++) { + const Standard_Integer NbLines = FO.NbLines(); + Standard_Integer CurLine = 1; + for (; CurLine <= NbLines; CurLine++) + { const Contap_TheLineOfContour& Line = FO.Line(CurLine); + const Standard_Integer NbPoints = Line.NbVertex(); Standard_Integer CurPoint; - Standard_Integer NbPoints = Line.NbVertex(); - - if (Line.TypeContour() == Contap_Restriction) { + if (Line.TypeContour() == Contap_Restriction) + { // OutLine on restriction - TopoDS_Edge E = - (*(BRepAdaptor_Curve2d*)&(Line.Arc()->Curve2d())).Edge(); + TopoDS_Edge E = (*(BRepAdaptor_Curve2d*)&(Line.Arc()->Curve2d())).Edge(); OutL.Append(E); TopExp::Vertices(E,VF,VL); // insert the Internal points. for (CurPoint = 1; CurPoint <= NbPoints; CurPoint++) { - Contap_ThePointOfContour P = Line.Vertex(CurPoint); - if (P.IsInternal()) { - if (P.Value().IsEqual(BRep_Tool::Pnt(VF),BRep_Tool::Tolerance(VF))) { - if (P.Value().IsEqual(BRep_Tool::Pnt(VL),BRep_Tool::Tolerance(VL))) { - InsertVertex(P,tol,E,DS); - } - } - } + Contap_ThePointOfContour P = Line.Vertex(CurPoint); + if (P.IsInternal()) { + if (P.Value().IsEqual(BRep_Tool::Pnt(VF),BRep_Tool::Tolerance(VF))) { + if (P.Value().IsEqual(BRep_Tool::Pnt(VL),BRep_Tool::Tolerance(VL))) { + InsertVertex(P,tol,E,DS); + } + } + } } } - else { + else + { for (CurPoint = 1; CurPoint <= NbPoints; CurPoint++) { - Standard_Boolean InsuffisantNumberOfPoints=Standard_False; - Contap_ThePointOfContour PF = Line.Vertex(CurPoint); - if (PF.IsInternal()) - VF = VL; - else - VF = MakeVertex(PF,tol,DS); - parF = PF.ParameterOnLine(); - - if (CurPoint <= NbPoints) { - CurPoint++; - Contap_ThePointOfContour PF = Line.Vertex(CurPoint); - VL = MakeVertex(PF,tol,DS); - parL = PF.ParameterOnLine(); - Handle(Geom_Curve) C; - Handle(Geom2d_Curve) C2d; - Standard_Real first = parF; - Standard_Real last = parL; - Standard_Real tol = BRep_Tool::Tolerance(F); - - - if( (last-first) > Precision::PConfusion()) { - - switch (Line.TypeContour()) { + + const Contap_ThePointOfContour PF = Line.Vertex(CurPoint); + if (PF.IsInternal() && CurPoint != 1) + VF = VL; + else + VF = MakeVertex(PF,tol,DS); + const Standard_Real parF = PF.ParameterOnLine(); + + if (CurPoint < NbPoints) { + const Contap_ThePointOfContour PL = Line.Vertex(CurPoint+1); + VL = MakeVertex(PL,tol,DS); + const Standard_Real parL = PL.ParameterOnLine(); + + if( (parL-parF) > Precision::PConfusion() ) { + + Handle(Geom_Curve) C; + Handle(Geom2d_Curve) C2d; + Standard_Real first = parF; + Standard_Real last = parL; + Standard_Boolean InsuffisantNumberOfPoints=Standard_False; + + switch (Line.TypeContour()) { - case Contap_Lin : - { - C = new Geom_Line(Line.Line()); - if (withPCurve) { - Handle(Geom_Surface) S = BRep_Tool::Surface(F); - Standard_Real Tol = 1e-7; - C2d = GeomProjLib::Curve2d(C,first,last,S,Tol); - } - } - break; + case Contap_Lin : + { + C = new Geom_Line(Line.Line()); + if (withPCurve) { + Handle(Geom_Surface) S = BRep_Tool::Surface(F); + Standard_Real Tol = 1e-7; + C2d = GeomProjLib::Curve2d(C,first,last,S,Tol); + } + } + break; - case Contap_Circle : - { - C = new Geom_Circle(Line.Circle()); - if (withPCurve) { - TopLoc_Location Loc; - Handle(Geom_Surface) S = - BRep_Tool::Surface(F,Loc); - if (!Loc.IsIdentity()) { - S = Handle(Geom_Surface)::DownCast - (S->Transformed(Loc.Transformation())); - } -// C2d = GeomProjLib::Curve2d(C,first,last,S,1e-7); - Standard_Real Tol = 1e-7; - C2d = GeomProjLib::Curve2d(C,first,last,S,Tol); - } - } - break; + case Contap_Circle : + { + C = new Geom_Circle(Line.Circle()); + if (withPCurve) { + TopLoc_Location Loc; + Handle(Geom_Surface) S = BRep_Tool::Surface(F,Loc); + if (!Loc.IsIdentity()) { + S = Handle(Geom_Surface)::DownCast(S->Transformed(Loc.Transformation())); + } + Standard_Real Tol = 1e-7; + C2d = GeomProjLib::Curve2d(C,first,last,S,Tol); + } + } + break; - case Contap_Walking : - { - // copy the points - Standard_Integer ipF = Standard_Integer(parF); - Standard_Integer ipL = Standard_Integer(parL); + case Contap_Walking : + { + // copy the points + Standard_Integer ipF = Standard_Integer(parF); + Standard_Integer ipL = Standard_Integer(parL); - if(ipL-ipF < 1) { - InsuffisantNumberOfPoints=Standard_True; - //cout<<"\n !! Pb ds HLRTopoBRep_DSFiller.cxx (Contour App Nbp <3)"<Maxx) Maxx=P.X(); - if(P.Y()>Maxy) Maxy=P.Y(); - if(P.Z()>Maxz) Maxz=P.Z(); - Points.SetValue(i,P); - } - mults(1)=mults(nbp)=2; - Handle(Geom_BSplineCurve) AppC; - Handle(Geom2d_BSplineCurve) AppC2d; - AppC = new Geom_BSplineCurve(Points,knots,mults,1); + if(withPCurve) { + TColgp_Array1OfPnt2d Points2d(1,nbp); + for(Standard_Integer i=1;i<=nbp;i++) { + Standard_Real u,v; + Line.Point(i+ipF-1).ParametersOnS2(u,v); + Points2d.SetValue(i,gp_Pnt2d(u,v)); + } + C2d = new Geom2d_BSplineCurve(Points2d,knots,mults,1); + } + first = 1; + last = nbp; + } + else { + const Standard_Integer nbp = ipL - ipF + 1; + TColStd_Array1OfReal knots(1,nbp); + TColStd_Array1OfInteger mults(1,nbp); + TColgp_Array1OfPnt Points(1,nbp); + + Standard_Real Maxx,Maxy,Maxz,Maxu,Maxv; + Standard_Real Minx,Miny,Minz,Minu,Minv; + Maxx=Maxy=Maxz=Maxu=Maxv=-RealLast(); + Minx=Miny=Minz=Minu=Minv=RealLast(); - if(withPCurve) { - TColgp_Array1OfPnt2d Points2d(1,nbp); - for(Standard_Integer i=1;i<=nbp;i++) { - Standard_Real u,v; - Line.Point(i+ipF-1).ParametersOnS2(u,v); - gp_Pnt2d P2d(u,v); - if(uMaxu) Maxu=u; - if(v>Maxv) Maxv=v; - Points2d.SetValue(i,P2d); - } - AppC2d = new Geom2d_BSplineCurve(Points2d,knots,mults,1); - } - first = 1; - last = nbp; + for(Standard_Integer i=1;i<=nbp;i++) { + knots.SetValue(i,(Standard_Real)i); + mults.SetValue(i,1); + const gp_Pnt& P= Line.Point(i+ipF-1).Value(); + if(P.X()Maxx) Maxx=P.X(); + if(P.Y()>Maxy) Maxy=P.Y(); + if(P.Z()>Maxz) Maxz=P.Z(); + Points.SetValue(i,P); + } + mults(1)=mults(nbp)=2; + Handle(Geom_BSplineCurve) AppC; + Handle(Geom2d_BSplineCurve) AppC2d; + AppC = new Geom_BSplineCurve(Points,knots,mults,1); + + if(withPCurve) { + TColgp_Array1OfPnt2d Points2d(1,nbp); + for(Standard_Integer i=1;i<=nbp;i++) { + Standard_Real u,v; + Line.Point(i+ipF-1).ParametersOnS2(u,v); + if(uMaxu) Maxu=u; + if(v>Maxv) Maxv=v; + Points2d.SetValue(i,gp_Pnt2d(u,v)); + } + AppC2d = new Geom2d_BSplineCurve(Points2d,knots,mults,1); + } + first = 1; + last = nbp; - Handle(BRepApprox_ApproxLine) AppLine; - Handle(Geom2d_BSplineCurve) CNull; - AppLine = new BRepApprox_ApproxLine(AppC,AppC2d,CNull); + Handle(BRepApprox_ApproxLine) AppLine; + Handle(Geom2d_BSplineCurve) CNull; + AppLine = new BRepApprox_ApproxLine(AppC,AppC2d,CNull); - Standard_Integer dmin=4,dmax=8,niter=0; - Standard_Boolean tg= Standard_False; - BRepApprox_Approx Approx; - Standard_Real TOL3d,TOL2d,TOL=0.0001; - - Maxx-=Minx; Maxy-=Miny; Maxz-=Minz; - Maxu-=Minu; Maxv-=Minv; - if(Maxy>Maxx) Maxx=Maxy; - if(Maxz>Maxx) Maxx=Maxy; - if(Maxv>Maxu) Maxu=Maxv; - - TOL3d=TOL*Maxx; if(TOL3d<1e-12) TOL3d=1e-12; else if(TOL3d>0.1) TOL3d=0.1; - TOL2d=TOL*Maxu; if(TOL2d<1e-12) TOL2d=1e-12; else if(TOL2d>0.1) TOL2d=0.1; + Standard_Integer dmin=4,dmax=8,niter=0; + Standard_Boolean tg= Standard_False; + BRepApprox_Approx Approx; + Standard_Real TOL3d,TOL2d,TOL=0.0001; + + Maxx-=Minx; Maxy-=Miny; Maxz-=Minz; + Maxu-=Minu; Maxv-=Minv; + if(Maxy>Maxx) Maxx=Maxy; + if(Maxz>Maxx) Maxx=Maxy; + if(Maxv>Maxu) Maxu=Maxv; + + TOL3d=TOL*Maxx; if(TOL3d<1e-12) TOL3d=1e-12; else if(TOL3d>0.1) TOL3d=0.1; + TOL2d=TOL*Maxu; if(TOL2d<1e-12) TOL2d=1e-12; else if(TOL2d>0.1) TOL2d=0.1; - //-- cout<<"\nHLRTopoBRep_DSFiller : nbp="<