Fix of the bug

This commit is contained in:
jgv 2022-09-14 21:39:42 +03:00 committed by jfa
parent 306a9dee53
commit 4cf5812a67
2 changed files with 162 additions and 7 deletions

View File

@ -26,6 +26,8 @@
#define PROXIMITY_ARG_POINT1 5 #define PROXIMITY_ARG_POINT1 5
#define PROXIMITY_ARG_POINT2 6 #define PROXIMITY_ARG_POINT2 6
#define PROXIMITY_ARG_VALUE 7 #define PROXIMITY_ARG_VALUE 7
#define PROXIMITY_ARG_STATUS1 8
#define PROXIMITY_ARG_STATUS2 9
class GEOMImpl_IProximity class GEOMImpl_IProximity
{ {
@ -61,12 +63,24 @@ public:
setPoint(PROXIMITY_ARG_POINT2, thePoint2); setPoint(PROXIMITY_ARG_POINT2, thePoint2);
} }
void SetStatusOfPoints(const Standard_Integer theStatus1, const Standard_Integer theStatus2)
{
setStatus(PROXIMITY_ARG_STATUS1, theStatus1);
setStatus(PROXIMITY_ARG_STATUS2, theStatus2);
}
void GetProximityPoints(gp_Pnt& thePoint1, gp_Pnt& thePoint2) void GetProximityPoints(gp_Pnt& thePoint1, gp_Pnt& thePoint2)
{ {
thePoint1 = getPoint(PROXIMITY_ARG_POINT1); thePoint1 = getPoint(PROXIMITY_ARG_POINT1);
thePoint2 = getPoint(PROXIMITY_ARG_POINT2); thePoint2 = getPoint(PROXIMITY_ARG_POINT2);
} }
void GetStatusOfPoints(Standard_Integer& theStatus1, Standard_Integer& theStatus2)
{
theStatus1 = getStatus(PROXIMITY_ARG_STATUS1);
theStatus2 = getStatus(PROXIMITY_ARG_STATUS2);
}
void SetValue(const Standard_Real theValue) void SetValue(const Standard_Real theValue)
{ {
_func->SetReal(PROXIMITY_ARG_VALUE, theValue); _func->SetReal(PROXIMITY_ARG_VALUE, theValue);
@ -87,12 +101,22 @@ private:
_func->SetRealArray(thePosition, aCoords); _func->SetRealArray(thePosition, aCoords);
} }
void setStatus(const Standard_Integer thePosition, const Standard_Integer theStatus)
{
_func->SetInteger(thePosition, theStatus);
}
gp_Pnt getPoint(const Standard_Integer thePosition) gp_Pnt getPoint(const Standard_Integer thePosition)
{ {
Handle(TColStd_HArray1OfReal) aCoords = _func->GetRealArray(thePosition); Handle(TColStd_HArray1OfReal) aCoords = _func->GetRealArray(thePosition);
return gp_Pnt(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3)); return gp_Pnt(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
} }
Standard_Integer getStatus(const Standard_Integer thePosition)
{
return _func->GetInteger(thePosition);
}
private: private:
Handle(GEOM_Function) _func; Handle(GEOM_Function) _func;
}; };

View File

@ -30,7 +30,9 @@
#include <Extrema_ExtPS.hxx> #include <Extrema_ExtPS.hxx>
#include <Extrema_GenLocateExtCS.hxx> #include <Extrema_GenLocateExtCS.hxx>
#include <Extrema_GenLocateExtSS.hxx> #include <Extrema_GenLocateExtSS.hxx>
#include <Extrema_GenLocateExtPS.hxx>
#include <Extrema_LocateExtCC.hxx> #include <Extrema_LocateExtCC.hxx>
#include <Extrema_LocateExtPC.hxx>
#include <TopExp_Explorer.hxx> #include <TopExp_Explorer.hxx>
#include <TopoDS.hxx> #include <TopoDS.hxx>
@ -138,6 +140,60 @@ namespace {
return aValue; 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, static Standard_Real extremaEF(const TopoDS_Edge& theEdge, const TopoDS_Face& theFace,
gp_Pnt& thePonE, gp_Pnt& thePonF) gp_Pnt& thePonE, gp_Pnt& thePonF)
{ {
@ -253,6 +309,8 @@ Standard_Integer GEOMImpl_ShapeProximityDriver::Execute(Handle(TFunction_Logbook
aValue = aCalcProx.Proximity(); aValue = aCalcProx.Proximity();
aProximity.SetProximityPoints(aCalcProx.ProximityPoint1(), aProximity.SetProximityPoints(aCalcProx.ProximityPoint1(),
aCalcProx.ProximityPoint2()); aCalcProx.ProximityPoint2());
aProximity.SetStatusOfPoints((Standard_Integer)aCalcProx.ProxPntStatus1(),
(Standard_Integer)aCalcProx.ProxPntStatus2());
} }
else else
Standard_ConstructionError::Raise("Failed to compute coarse proximity"); Standard_ConstructionError::Raise("Failed to compute coarse proximity");
@ -262,26 +320,99 @@ Standard_Integer GEOMImpl_ShapeProximityDriver::Execute(Handle(TFunction_Logbook
TopAbs_ShapeEnum aType1 = aShape1.ShapeType(); TopAbs_ShapeEnum aType1 = aShape1.ShapeType();
TopAbs_ShapeEnum aType2 = aShape2.ShapeType(); TopAbs_ShapeEnum aType2 = aShape2.ShapeType();
gp_Pnt aP1, aP2; gp_Pnt aPnt1, aPnt2;
aProximity.GetProximityPoints(aP1, aP2); BRepExtrema_ProximityDistTool::ProxPnt_Status aStatus1, aStatus2;
Standard_Integer intStatus1, intStatus2;
aProximity.GetProximityPoints(aPnt1, aPnt2);
aProximity.GetStatusOfPoints(intStatus1, intStatus2);
aStatus1 = (BRepExtrema_ProximityDistTool::ProxPnt_Status)intStatus1;
aStatus2 = (BRepExtrema_ProximityDistTool::ProxPnt_Status)intStatus2;
Standard_Real anExactValue = -1;
if (aType1 == TopAbs_EDGE) if (aType1 == TopAbs_EDGE)
{ {
if (aType2 == TopAbs_EDGE) if (aType2 == TopAbs_EDGE)
aValue = extremaEE(TopoDS::Edge(aShape1), TopoDS::Edge(aShape2), aP1, aP2); {
if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
{
anExactValue = extremaEE(TopoDS::Edge(aShape1), TopoDS::Edge(aShape2), aPnt1, aPnt2);
}
else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
{
anExactValue = extremaPE(aPnt1, TopoDS::Edge(aShape2), aPnt2);
}
else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER)
{
anExactValue = extremaPE(aPnt2, TopoDS::Edge(aShape1), aPnt1);
}
}
else if (aType2 == TopAbs_FACE) else if (aType2 == TopAbs_FACE)
aValue = extremaEF(TopoDS::Edge(aShape1), TopoDS::Face(aShape2), aP1, aP2); {
if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
{
anExactValue = extremaEF(TopoDS::Edge(aShape1), TopoDS::Face(aShape2), aPnt1, aPnt2);
}
else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
{
anExactValue = extremaPF(aPnt1, TopoDS::Face(aShape2), aPnt2);
}
else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER)
{
anExactValue = extremaPE(aPnt2, TopoDS::Edge(aShape1), aPnt1);
}
}
} }
else if (aType1 == TopAbs_FACE) else if (aType1 == TopAbs_FACE)
{ {
if (aType2 == TopAbs_EDGE) if (aType2 == TopAbs_EDGE)
aValue = extremaEF(TopoDS::Edge(aShape2), TopoDS::Face(aShape1), aP2, aP1); {
if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
{
anExactValue = extremaEF(TopoDS::Edge(aShape2), TopoDS::Face(aShape1), aPnt2, aPnt1);
}
else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
{
anExactValue = extremaPE(aPnt1, TopoDS::Edge(aShape2), aPnt2);
}
else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER)
{
anExactValue = extremaPF(aPnt2, TopoDS::Face(aShape1), aPnt1);
}
}
else if (aType2 == TopAbs_FACE) else if (aType2 == TopAbs_FACE)
aValue = extremaFF(TopoDS::Face(aShape1), TopoDS::Face(aShape2), aP1, aP2); {
if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
{
anExactValue = extremaFF(TopoDS::Face(aShape1), TopoDS::Face(aShape2), aPnt1, aPnt2);
}
else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
{
anExactValue = extremaPF(aPnt1, TopoDS::Face(aShape2), aPnt2);
}
else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER)
{
anExactValue = extremaPF(aPnt2, TopoDS::Face(aShape1), aPnt1);
}
}
} }
if (anExactValue != -1)
aValue = anExactValue;
if (aValue >= 0) if (aValue >= 0)
aProximity.SetProximityPoints(aP1, aP2); aProximity.SetProximityPoints(aPnt1, aPnt2);
else else
Standard_ConstructionError::Raise("Failed to compute precise proximity"); Standard_ConstructionError::Raise("Failed to compute precise proximity");
} }