From 57fe037f726a70b5190a8965272ed75324fa2d11 Mon Sep 17 00:00:00 2001 From: jgv Date: Tue, 19 Sep 2017 15:40:36 +0300 Subject: [PATCH] Next version --- src/BRepOffset/BRepOffset_Tool.cxx | 2 +- .../BRepOffsetAPI_PatchFaces.cxx | 497 +++++++++++++++--- .../BRepOffsetAPI_PatchFaces.hxx | 16 +- src/BRepOffsetAPI/FILES | 2 + 4 files changed, 434 insertions(+), 83 deletions(-) diff --git a/src/BRepOffset/BRepOffset_Tool.cxx b/src/BRepOffset/BRepOffset_Tool.cxx index 2a6ccc4ee6..c6f8275ccf 100644 --- a/src/BRepOffset/BRepOffset_Tool.cxx +++ b/src/BRepOffset/BRepOffset_Tool.cxx @@ -2865,7 +2865,7 @@ static Standard_Boolean EnlargeGeometry(Handle(Geom_Surface)& S, const Standard_Boolean GlobalEnlargeVfirst, const Standard_Boolean GlobalEnlargeVlast) { - const Standard_Real coeff = 4.; + const Standard_Real coeff = 2.; //4.; const Standard_Real TolApex = 1.e-5; Standard_Boolean SurfaceChange = Standard_False; diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx b/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx index b04935a394..b5050c3ac8 100644 --- a/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx +++ b/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -38,10 +40,82 @@ #include #include #include -#include -#include +#include +#include +//#include +//#include +//#include +static void IntersectIn2d(const TopoDS_Edge& theEdge1, + const TopoDS_Edge& theEdge2, + const TopoDS_Face& theFace, + const gp_Pnt2d& theP2dRef, + Standard_Real& theParamOnFirst, + Standard_Real& theParamOnSecond, + gp_Pnt& thePntSol, + gp_Pnt& thePntOnSecond) +{ + BRepAdaptor_Curve BAprevcurve(theEdge1); + BRepAdaptor_Curve BAcurcurve(theEdge2); + BRepAdaptor_Curve2d BAprevcurve2d(theEdge1, theFace); + BRepAdaptor_Curve2d BAcurcurve2d(theEdge2, theFace); + //Geom2dInt_GInter Inters2d(BAprevcurve2d, BAcurcurve2d, + // Precision::PConfusion(), Precision::PConfusion()); + Extrema_ExtCC2d ExtrCC(BAprevcurve2d, BAcurcurve2d); + Standard_Real ParOnPrev[6], ParOnCur[6], dist[6], SumDist[6]; + gp_Pnt2d Pnt2d[6]; + ParOnPrev[1] = ParOnPrev[2] = BAprevcurve2d.FirstParameter(); + ParOnPrev[3] = ParOnPrev[4] = BAprevcurve2d.LastParameter(); + ParOnCur[1] = ParOnCur[3] = BAcurcurve2d.FirstParameter(); + ParOnCur[2] = ParOnCur[4] = BAcurcurve2d.LastParameter(); + + ExtrCC.TrimmedSquareDistances(dist[1], dist[2], dist[3], dist[4], + Pnt2d[1], Pnt2d[2], Pnt2d[3], Pnt2d[4]); + SumDist[1] = theP2dRef.SquareDistance(Pnt2d[1]) + theP2dRef.SquareDistance(Pnt2d[3]); //first-first + SumDist[2] = theP2dRef.SquareDistance(Pnt2d[1]) + theP2dRef.SquareDistance(Pnt2d[4]); //first-last + SumDist[3] = theP2dRef.SquareDistance(Pnt2d[2]) + theP2dRef.SquareDistance(Pnt2d[3]); //last-first + SumDist[4] = theP2dRef.SquareDistance(Pnt2d[2]) + theP2dRef.SquareDistance(Pnt2d[4]); //last-last + SumDist[5] = RealLast(); + Standard_Integer imin = 0; + if (ExtrCC.IsDone()) + { + for (Standard_Integer i = 1; i <= ExtrCC.NbExt(); i++) + { + Extrema_POnCurv2d P2d1, P2d2; + ExtrCC.Points(i, P2d1, P2d2); + Standard_Real aSumDist = theP2dRef.SquareDistance(P2d1.Value()) + theP2dRef.SquareDistance(P2d2.Value()); + if (aSumDist < SumDist[5]) + { + SumDist[5] = aSumDist; + imin = i; + } + } + if (imin != 0) + { + Extrema_POnCurv2d P2d1min, P2d2min; + ExtrCC.Points(imin, P2d1min, P2d2min); + ParOnPrev[5] = P2d1min.Parameter(); + ParOnCur[5] = P2d2min.Parameter(); + } + } + if (imin == 0) + { + imin = 1; + for (Standard_Integer i = 2; i <= 4; i++) + if (SumDist[i] < SumDist[imin]) + imin = i; + } + else + imin = 5; + + theParamOnFirst = ParOnPrev[imin]; + theParamOnSecond = ParOnCur[imin]; + gp_Pnt PntOnFirst = BAprevcurve.Value(theParamOnFirst); + thePntOnSecond = BAcurcurve.Value(theParamOnSecond); + thePntSol.SetXYZ((PntOnFirst.XYZ() + thePntOnSecond.XYZ())/2); +} + static TopoDS_Edge MakeNewEdgeWithOldPcurvesOnNewSurfaces(const TopoDS_Edge& theEdge, const TopoDS_Face& theOldFace1, const TopoDS_Face& theNewFace1, @@ -87,6 +161,22 @@ static void UpdateEdgeByProjectionOfPCurve(TopoDS_Edge& anEdge, Standard_Real TolReached = SAS->Gap(); //BB.UpdateEdge(anEdge, NullPCurve, aFace, 0.); BB.UpdateEdge(anEdge, NewPCurve, aBoundedNewFace, TolReached); + //Check + Standard_Integer NCONTROL = 23; + BRepAdaptor_Curve BAcurve(anEdge); + BRepAdaptor_Curve BAcurveonsu(anEdge, aBoundedNewFace); + for (Standard_Integer i = 0; i < NCONTROL; i++) + { + Standard_Real prm = ((NCONTROL-1-i)*fpar + i*lpar)/(NCONTROL-1); + gp_Pnt Pnt1 = BAcurve.Value(prm); + gp_Pnt Pnt2 = BAcurveonsu.Value(prm); + Standard_Real aDist = Pnt1.Distance(Pnt2); + if (aDist > TolReached) + TolReached = aDist; + } + BB.UpdateEdge(anEdge, TolReached); + /////// + TopoDS_Vertex V1, V2; TopExp::Vertices(anEdge, V1, V2); BB.UpdateVertex(V1, TolReached); @@ -132,6 +222,86 @@ static void ProjectVertexOnNewEdge(const TopoDS_Vertex& theVertex, theTolReached = sqrt(dist[imin]); } +static Standard_Boolean IsPCurveUiso(const Handle(Geom2d_Curve)& thePCurve, + Standard_Real theFirstPar, + Standard_Real theLastPar) +{ + gp_Pnt2d FirstP2d = thePCurve->Value(theFirstPar); + gp_Pnt2d LastP2d = thePCurve->Value(theLastPar); + + Standard_Real DeltaU = Abs(FirstP2d.X() - LastP2d.X()); + Standard_Real DeltaV = Abs(FirstP2d.Y() - LastP2d.Y()); + + return (DeltaU < DeltaV); +} + +static TopoDS_Edge GetSeamEdge(const TopoDS_Edge& theEdge, + const TopoDS_Face& theFace, + const TopoDS_Face& theNewFace) +{ + TopoDS_Edge aSeamEdge; + + Standard_Real fpar, lpar; + Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, fpar, lpar); + Standard_Boolean IsUiso = IsPCurveUiso(aPCurve, fpar, lpar); + + TopExp_Explorer Explo(theNewFace, TopAbs_EDGE); + for (; Explo.More(); Explo.Next()) + { + const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current()); + if (BRepTools::IsReallyClosed(anEdge, theNewFace)) + { + Standard_Real NewFirst, NewLast; + Handle(Geom2d_Curve) aNewPCurve = BRep_Tool::CurveOnSurface(anEdge, theNewFace, + NewFirst, NewLast); + Standard_Boolean IsNewUiso = IsPCurveUiso(aNewPCurve, NewFirst, NewLast); + if (IsNewUiso == IsUiso) + { + aSeamEdge = anEdge; + break; + } + } + } + + TopoDS_Edge aNewEdge = TopoDS::Edge(aSeamEdge.EmptyCopied()); + return aNewEdge; +} + +static Standard_Boolean IsPCurveFirst(const TopoDS_Edge& theEdge, + const TopoDS_Face& theFace) +{ + Standard_Real fpar, lpar; + Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(theEdge, theFace, fpar, lpar); + TopoDS_Edge RevEdge = TopoDS::Edge(theEdge.Reversed()); + Handle(Geom2d_Curve) AnotherPCurve = BRep_Tool::CurveOnSurface(RevEdge, theFace, fpar, lpar); + Standard_Boolean IsUiso = IsPCurveUiso(aPCurve, fpar, lpar); + + gp_Pnt2d aP2d = aPCurve->Value(fpar); + gp_Pnt2d AnotherP2d = AnotherPCurve->Value(fpar); + + Standard_Integer IndCoord = (IsUiso)? 1 : 2; // U or V + + Standard_Real aCoord = aP2d.Coord(IndCoord); + Standard_Real AnotherCoord = AnotherP2d.Coord(IndCoord); + + return (aCoord < AnotherCoord); +} + +static void CorrectOrientationOfSeam(const TopoDS_Edge& theEdge, + const TopoDS_Face& theFace, + TopoDS_Edge& theNewEdge, + const TopoDS_Face& theNewFace) +{ + if (!BRepTools::IsReallyClosed(theEdge, theFace)) //only for seam + return; + + Standard_Boolean IsFirstPCurve = IsPCurveFirst(theEdge, theFace); + Standard_Boolean IsFirstNewPCurve = IsPCurveFirst(theNewEdge, theNewFace); + if (IsFirstPCurve != IsFirstNewPCurve) + theNewEdge.Reverse(); +} + +/* static TopoDS_Edge GetGeneratedEdge(const TopoDS_Edge& anEdge, const TopoDS_Face& aFace, const TopoDS_Face& aNewFace) @@ -159,6 +329,7 @@ static TopoDS_Edge GetGeneratedEdge(const TopoDS_Edge& anEdge, BB.Remove(aNewEdge, V2); return aNewEdge; } +*/ static TopAbs_Orientation OrientationInEdge(const TopoDS_Vertex& theVertex, const TopoDS_Edge& theEdge) @@ -366,8 +537,10 @@ void BRepOffsetAPI_PatchFaces::Build() if (Lfaces.Extent() == 1) //seam edge { cout< 0) + { + Standard_Integer imin = 1; + for (Standard_Integer i = 2; i <= Projector.NbExt(); i++) + if (Projector.SquareDistance(i) < Projector.SquareDistance(imin)) + imin = i; + Param[3] = Projector.Point(imin).Parameter(); + dist[3] = Projector.SquareDistance(imin); + Pnt2d[3] = Projector.Point(imin).Value(); + } + + Standard_Integer imin = 1; + for (Standard_Integer i = 2; i <= 3; i++) + if (dist[i] < dist[imin]) + imin = i; + + theParam = Param[imin]; + //BRepAdaptor_Surface BAnewsurf(theNewFace, Standard_False); + //thePnt = BAnewsurf.Value(Pnt[imin].X(), Pnt[imin].Y()); + thePnt2d = Pnt2d[imin]; + BRepAdaptor_Curve BAcurve(theEdge); + BRepAdaptor_Curve BAnewcurve(theNewEdge); + thePnt = BAnewcurve.Value(theParam); + gp_Pnt PointOnEdge = BAcurve.Value(ParamOnEdge); + theTolReached = PointOnEdge.Distance(thePnt); //sqrt(dist[imin]); +} diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx b/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx index 31d205bebb..6c437da676 100644 --- a/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx +++ b/src/BRepOffsetAPI/BRepOffsetAPI_PatchFaces.hxx @@ -67,7 +67,10 @@ private: TopoDS_Edge& thePrevNewEdge, const TopoDS_Edge& theCurEdge, TopoDS_Edge& theCurNewEdge, - TopoDS_Vertex& theCurVertex); + TopoDS_Vertex& theCurVertex, + const TopoDS_Face& theFace, + const TopoDS_Face& theNewFace, + TopoDS_Face& theBoundedNewFace); Standard_EXPORT void PutVertexToEdge(const TopoDS_Vertex& theVertex, const TopoDS_Vertex& theProVertex, @@ -75,6 +78,15 @@ private: const TopoDS_Edge& theProEdge, const Standard_Real theParamOnEdge); + Standard_EXPORT void ProjectVertexOnNewEdge_2d(const TopoDS_Vertex& theVertex, + const TopoDS_Edge& theEdge, + const TopoDS_Face& theFace, + const TopoDS_Edge& theNewEdge, + const TopoDS_Face& theNewFace, + Standard_Real& theParam, + gp_Pnt& thePnt, + gp_Pnt2d& thePnt2d, + Standard_Real& theTolReached); TopoDS_Shape myInitialShape; @@ -82,7 +94,7 @@ private: TopTools_IndexedDataMapOfShapeShape myFaceNewFace; TopTools_DataMapOfShapeShape myNewFaceBoundedFace; TopTools_DataMapOfShapeShape myEdgeNewEdge; - TopTools_DataMapOfOrientedShapeShape myOrientedEdgeNewEdge; + //TopTools_DataMapOfOrientedShapeShape myOrientedEdgeNewEdge; TopTools_DataMapOfShapeShape myVertexNewVertex; TopTools_MapOfShape myTangentEdges; diff --git a/src/BRepOffsetAPI/FILES b/src/BRepOffsetAPI/FILES index 4680ffd109..0d84a8f527 100644 --- a/src/BRepOffsetAPI/FILES +++ b/src/BRepOffsetAPI/FILES @@ -27,3 +27,5 @@ BRepOffsetAPI_SequenceOfSequenceOfShape.hxx BRepOffsetAPI_Sewing.hxx BRepOffsetAPI_ThruSections.cxx BRepOffsetAPI_ThruSections.hxx +BRepOffsetAPI_PatchFaces.cxx +BRepOffsetAPI_PatchFaces.hxx -- 2.39.5