From 911230cb3094a7c526e4a2569451e9b01c2932b8 Mon Sep 17 00:00:00 2001 From: jfa Date: Wed, 2 Nov 2022 19:14:06 +0300 Subject: [PATCH] Debug --- .../Test/TestMeasurementDistance.py | 8 +- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 145 ++++++++++++++++-- 2 files changed, 139 insertions(+), 14 deletions(-) diff --git a/src/FeaturesPlugin/Test/TestMeasurementDistance.py b/src/FeaturesPlugin/Test/TestMeasurementDistance.py index c29bd6126..603efbae9 100644 --- a/src/FeaturesPlugin/Test/TestMeasurementDistance.py +++ b/src/FeaturesPlugin/Test/TestMeasurementDistance.py @@ -96,7 +96,7 @@ REF_DATA = [(model.selection("VERTEX", "PartSet/Origin"), (model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face]"), model.selection("EDGE", "([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face])([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face])([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face])([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face])"), 0, - 60), + 100.0), (model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face]"), model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchArc_1_2][Extrusion_2_1/To_Face]"), 16.00781059, @@ -104,7 +104,7 @@ REF_DATA = [(model.selection("VERTEX", "PartSet/Origin"), (model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face]"), model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchArc_1_2"), 8.412291828, - 165.748725311), + "NA"), (model.selection("VERTEX", "Sketch_1/SketchCircle_1_2__cc"), model.selection("FACE", "Plane_1"), 35.35533906, @@ -116,11 +116,11 @@ REF_DATA = [(model.selection("VERTEX", "PartSet/Origin"), (model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2"), model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchArc_1_2"), 0, - 165.748725311), + 165.799606), (model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2"), model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"), 27.63932023, - 27.61462299114), + 40.0), (model.selection("SOLID", "Extrusion_1_1"), model.selection("FACE", "Extrusion_2_1/To_Face"), 12.5, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index 7620db463..b2c92a1e9 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -62,7 +62,9 @@ #include #include +#include #include +#include #include #include @@ -424,6 +426,60 @@ static Standard_Real extremaEE(const TopoDS_Edge& theEdge1, return aValue; } +static Standard_Real extremaPE(const gp_Pnt& thePoint, + const TopoDS_Edge& theEdge, + gp_Pnt& thePointOnEdge) +{ + BRepAdaptor_Curve aCurve (theEdge); + + TopLoc_Location aLoc; + Standard_Real aTol = BRep_Tool::Tolerance(theEdge); + Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D (theEdge, aLoc); + if (!aPoly.IsNull()) + aTol = Max (aTol, aPoly->Deflection()); + + Standard_Real aParam = paramOnCurve (aCurve, thePointOnEdge, 2*aTol); + + Standard_Real aValue = -1.0; + Extrema_LocateExtPC anExtr (thePoint, aCurve, aParam, Precision::PConfusion()); + if (anExtr.IsDone()) + { + aValue = Sqrt(anExtr.SquareDistance()); + + Extrema_POnCurv aPointOnCurve = anExtr.Point(); + thePointOnEdge = aPointOnCurve.Value(); + } + return aValue; +} + +static Standard_Real extremaPF(const gp_Pnt& thePoint, + const TopoDS_Face& theFace, + gp_Pnt& thePointOnFace) +{ + BRepAdaptor_Surface aSurf (theFace); + + TopLoc_Location aLoc; + Standard_Real aTol = BRep_Tool::Tolerance(theFace); + Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation (theFace, aLoc); + if (!aTria.IsNull()) + aTol = Max (aTol, aTria->Deflection()); + + Standard_Real aU, aV; + paramsOnSurf(aSurf, thePointOnFace, 2*aTol, aU, aV); + + Standard_Real aValue = -1.0; + Extrema_GenLocateExtPS anExtr (aSurf); + anExtr.Perform (thePoint, aU, aV); + if (anExtr.IsDone()) + { + aValue = Sqrt(anExtr.SquareDistance()); + + Extrema_POnSurf aPointOnSurf = anExtr.Point(); + thePointOnFace = aPointOnSurf.Value(); + } + return aValue; +} + static Standard_Real extremaEF(const TopoDS_Edge& theEdge, const TopoDS_Face& theFace, const gp_Pnt& thePonE, @@ -489,7 +545,7 @@ double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1, double GeomAlgoAPI_ShapeTools::shapeProximity(const GeomShapePtr& theShape1, const GeomShapePtr& theShape2) { - double aResult = Precision::Infinite(); + double aResult = -1.0; if (!theShape1.get() || !theShape2.get()) return aResult; @@ -509,26 +565,95 @@ double GeomAlgoAPI_ShapeTools::shapeProximity(const GeomShapePtr& theShape1, aResult = aDist.Proximity(); // refine the result - const gp_Pnt& aPonS1 = aDist.ProximityPoint1(); - const gp_Pnt& aPonS2 = aDist.ProximityPoint2(); + gp_Pnt aPnt1 = aDist.ProximityPoint1(); + gp_Pnt aPnt2 = aDist.ProximityPoint2(); + + BRepExtrema_ProximityDistTool::ProxPnt_Status aStatus1 = aDist.ProxPntStatus1(); + BRepExtrema_ProximityDistTool::ProxPnt_Status aStatus2 = aDist.ProxPntStatus2(); + + double aValue = -1.0; - double anExtrema = -1.0; if (aType1 == TopAbs_EDGE) { if (aType2 == TopAbs_EDGE) - anExtrema = extremaEE(TopoDS::Edge(aShape1), TopoDS::Edge(aShape2), aPonS1, aPonS2); + { + if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaEE(TopoDS::Edge(aShape1), TopoDS::Edge(aShape2), aPnt1, aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaPE(aPnt1, TopoDS::Edge(aShape2), aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER) + { + aValue = extremaPE(aPnt2, TopoDS::Edge(aShape1), aPnt1); + } + } else if (aType2 == TopAbs_FACE) - anExtrema = extremaEF(TopoDS::Edge(aShape1), TopoDS::Face(aShape2), aPonS1, aPonS2); + { + if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaEF(TopoDS::Edge(aShape1), TopoDS::Face(aShape2), aPnt1, aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaPF(aPnt1, TopoDS::Face(aShape2), aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER) + { + aValue = extremaPE(aPnt2, TopoDS::Edge(aShape1), aPnt1); + } + } } else if (aType1 == TopAbs_FACE) { if (aType2 == TopAbs_EDGE) - anExtrema = extremaEF(TopoDS::Edge(aShape2), TopoDS::Face(aShape1), aPonS2, aPonS1); + { + if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaEF(TopoDS::Edge(aShape2), TopoDS::Face(aShape1), aPnt2, aPnt1); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaPE(aPnt1, TopoDS::Edge(aShape2), aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER) + { + aValue = extremaPF(aPnt2, TopoDS::Face(aShape1), aPnt1); + } + } else if (aType2 == TopAbs_FACE) - anExtrema = extremaFF(TopoDS::Face(aShape1), TopoDS::Face(aShape2), aPonS1, aPonS2); + { + if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaFF(TopoDS::Face(aShape1), TopoDS::Face(aShape2), aPnt1, aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaPF(aPnt1, TopoDS::Face(aShape2), aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER) + { + aValue = extremaPF(aPnt2, TopoDS::Face(aShape1), aPnt1); + } + } } - if (anExtrema > 0.0) - aResult = anExtrema; + + if (aValue > 0.0) + aResult = aValue; } return aResult; } -- 2.39.2