From 71d14d3014b78fe9485aeb13a6832aea01fafa03 Mon Sep 17 00:00:00 2001 From: sneeraj Date: Thu, 7 Mar 2013 20:49:23 +0530 Subject: [PATCH] 0023820: Wrong result of projection algorithm when a polygon geometry is projected on a set of multiple faces --- src/BRepAlgo/BRepAlgo_NormalProjection.cxx | 89 ++++++++++++---------- src/ProjLib/ProjLib_CompProjectedCurve.cxx | 71 ++++++++++++----- 2 files changed, 102 insertions(+), 58 deletions(-) diff --git a/src/BRepAlgo/BRepAlgo_NormalProjection.cxx b/src/BRepAlgo/BRepAlgo_NormalProjection.cxx index acb9e17b96..03921efb61 100755 --- a/src/BRepAlgo/BRepAlgo_NormalProjection.cxx +++ b/src/BRepAlgo/BRepAlgo_NormalProjection.cxx @@ -480,46 +480,55 @@ void BRepAlgo_NormalProjection::SetDefaultParams() InitChron(chr_booltool); #endif if(!Degenerated){ - BRepAlgo_BooleanOperations BoolTool; - BoolTool.Shapes2d(Faces->Value(j),prj); - BoolTool.Common(); - Handle(TopOpeBRepBuild_HBuilder) HB; - TopTools_ListOfShape LS; - TopTools_ListIteratorOfListOfShape Iter; - HB = BoolTool.Builder(); - LS.Clear(); - if (HB->IsSplit(prj, TopAbs_IN)) - LS = HB->Splits(prj, TopAbs_IN); - Iter.Initialize(LS); - if(Iter.More()) { -#ifdef DEBUG - cout << " BooleanOperations :" << Iter.More()<<" solutions " << endl; -#endif - for(; Iter.More(); Iter.Next()) { - BB.Add(myRes, Iter.Value()); - myAncestorMap.Bind(Iter.Value(), Edges->Value(i)); - myCorresp.Bind(Iter.Value(),Faces->Value(j)); - } - } - - else { - - BRepTopAdaptor_FClass2d classifier(TopoDS::Face(Faces->Value(j)), - Precision::Confusion()); - gp_Pnt2d Puv; - Standard_Real f = PCur2d->FirstParameter(); - Standard_Real l = PCur2d->LastParameter(); - Standard_Real pmil = (f + l )/2; - PCur2d->D0(pmil, Puv); - TopAbs_State state; - state = classifier.Perform(Puv); - if(state == TopAbs_IN || state == TopAbs_ON) { - BB.Add(myRes, prj); - DescenList.Append(prj); - myAncestorMap.Bind(prj, Edges->Value(i)); - myCorresp.Bind(prj, Faces->Value(j)); - } - } + + // {Fix for Issue 0023820 ... introducing try-catch so that result of the previous iteration is kept + try + { + BRepAlgo_BooleanOperations BoolTool; + BoolTool.Shapes2d(Faces->Value(j),prj); + BoolTool.Common(); + Handle(TopOpeBRepBuild_HBuilder) HB; + TopTools_ListOfShape LS; + TopTools_ListIteratorOfListOfShape Iter; + HB = BoolTool.Builder(); + LS.Clear(); + if (HB->IsSplit(prj, TopAbs_IN)) + LS = HB->Splits(prj, TopAbs_IN); + Iter.Initialize(LS); + + if(Iter.More()) { + #ifdef DEBUG + cout << " BooleanOperations :" << Iter.More()<<" solutions " << endl; + #endif + for(; Iter.More(); Iter.Next()) { + BB.Add(myRes, Iter.Value()); + myAncestorMap.Bind(Iter.Value(), Edges->Value(i)); + myCorresp.Bind(Iter.Value(),Faces->Value(j)); + } + } + else { + + BRepTopAdaptor_FClass2d classifier(TopoDS::Face(Faces->Value(j)), + Precision::Confusion()); + gp_Pnt2d Puv; + Standard_Real f = PCur2d->FirstParameter(); + Standard_Real l = PCur2d->LastParameter(); + Standard_Real pmil = (f + l )/2; + PCur2d->D0(pmil, Puv); + TopAbs_State state; + state = classifier.Perform(Puv); + + if(state == TopAbs_IN || state == TopAbs_ON) { + BB.Add(myRes, prj); + DescenList.Append(prj); + myAncestorMap.Bind(prj, Edges->Value(i)); + myCorresp.Bind(prj, Faces->Value(j)); + } + } + } + catch (Standard_Failure) { + continue; + } } else { #ifdef DEB diff --git a/src/ProjLib/ProjLib_CompProjectedCurve.cxx b/src/ProjLib/ProjLib_CompProjectedCurve.cxx index 5d32f2514a..7926653144 100755 --- a/src/ProjLib/ProjLib_CompProjectedCurve.cxx +++ b/src/ProjLib/ProjLib_CompProjectedCurve.cxx @@ -579,9 +579,24 @@ static Standard_Boolean InitialPoint(const gp_Pnt& Point, FirstU = myCurve->FirstParameter(); LastU = myCurve->LastParameter(); + + // {Fix for Issue 0023820 ... + // Taking derivative of the curve in the parametric space of the curve + gp_Pnt Pt; + gp_Vec V; + + myCurve->D1(FirstU, Pt, V); + Standard_Real VD1 = V.Magnitude(); + // ... Fix for Issue 0023820} + const Standard_Real MinStep = 0.01*(LastU - FirstU), MaxStep = 0.1*(LastU - FirstU); - SearchStep = 10*MinStep; + + // {Fix for Issue 0023820 ... + // The step is taken to be minimum of the two values given below. + // The 2nd variable gives the 1/10th of the rate of change of parameter + SearchStep = Min(10*MinStep, 0.1/VD1); + // ... Fix for Issue 0023820} Step = SearchStep; //Initialization of aPrjPS @@ -833,19 +848,19 @@ static Standard_Boolean InitialPoint(const gp_Pnt& Point, if (t == LastU) {t = LastU + 1; break;}//return; //Computation of WalkStep - d2CurvOnSurf(Triple.X(), Triple.Y(), Triple.Z(), D1, D2, myCurve, mySurface); - MagnD1 = D1.Magnitude(); - MagnD2 = D2.Magnitude(); - if(MagnD2 < Precision::Confusion() ) WalkStep = MaxStep; - else WalkStep = Min(MaxStep, Max(MinStep, 0.1*MagnD1/MagnD2)); - - Step = WalkStep; - t += Step; - if (t > (LastU-MinStep/2) ) - { - Step =Step+LastU-t; - t = LastU; - } + d2CurvOnSurf(Triple.X(), Triple.Y(), Triple.Z(), D1, D2, myCurve, mySurface); + MagnD1 = D1.Magnitude(); + MagnD2 = D2.Magnitude(); + if(MagnD2 < Precision::Confusion() ) WalkStep = MaxStep; + else WalkStep = Min(MaxStep, Max(MinStep, 0.1*MagnD1/MagnD2)); + + Step = WalkStep; + t += Step; + if (t > (LastU-MinStep/2) ) + { + Step =Step+LastU-t; + t = LastU; + } DecStep=Step; } } @@ -1410,8 +1425,19 @@ gp_Vec2d ProjLib_CompProjectedCurve::DN(const Standard_Real t, gp_Pnt2d(Tol, myTolV), gp_Pnt2d(Tl, mySurface->FirstVParameter()), gp_Pnt2d(Tr, mySurface->LastVParameter())); - TUdisc.Append(Solver.Solution().X()); - } + + // {Fix for Issue 0023820 ... + // Continue and preserve the projection result of the previous iteration + try + { + TUdisc.Append(Solver.Solution().X()); + } + catch (Standard_Failure) + { + ; // just continue + } + // ... Fix for Issue 0023820} + } } } for(i = 2; i <= TUdisc.Length(); i++) @@ -1464,8 +1490,17 @@ gp_Vec2d ProjLib_CompProjectedCurve::DN(const Standard_Real t, gp_Pnt2d(Tol, myTolV), gp_Pnt2d(Tl, mySurface->FirstUParameter()), gp_Pnt2d(Tr, mySurface->LastUParameter())); - TVdisc.Append(Solver.Solution().X()); - } + + // We Want to preserve the previous projection result and continue + try + { + TVdisc.Append(Solver.Solution().X()); + } + catch (Standard_Failure) + { + + } + } } } for(i = 2; i <= TVdisc.Length(); i++) -- 2.39.5