]> OCCT Git - occt.git/commitdiff
0033394: Modeling Algorithms - Wrong usage of BRepClass_FaceClassifier with 3d tolerance
authorastromko <astromko@opencascade.com>
Wed, 3 Apr 2024 10:52:56 +0000 (11:52 +0100)
committerjfa <jfa@opencascade.com>
Fri, 21 Feb 2025 11:43:49 +0000 (11:43 +0000)
Added the function Tolerance2d().
Now 2d-tolerance is used instead of 3d-tolerance where it's necessary.

src/BRep/BRep_Tool.cxx
src/BRep/BRep_Tool.hxx
src/BRepExtrema/BRepExtrema_DistanceSS.cxx
src/BRepExtrema/BRepExtrema_ExtFF.cxx
src/BRepExtrema/BRepExtrema_ExtPF.cxx
tests/bugs/modalg_8/bug33394 [new file with mode: 0644]

index a6e5fb8893dd2f6fed195b93cdd0ba98be376386..51ea88a3dff0751803453c18cb15706b8a61f6e3 100644 (file)
@@ -18,6 +18,7 @@
 #include <BRep_CurveOnClosedSurface.hxx>
 #include <BRep_CurveOnSurface.hxx>
 #include <BRep_CurveRepresentation.hxx>
+#include <BRep_GCurve.hxx>
 #include <BRep_Polygon3D.hxx>
 #include <BRep_PolygonOnSurface.hxx>
 #include <BRep_PolygonOnTriangulation.hxx>
@@ -25,6 +26,7 @@
 #include <BRep_TFace.hxx>
 #include <BRep_Tool.hxx>
 #include <BRep_TVertex.hxx>
+#include <BRepAdaptor_Surface.hxx>
 #include <ElSLib.hxx>
 #include <Geom2d_Curve.hxx>
 #include <Geom2d_TrimmedCurve.hxx>
@@ -60,7 +62,6 @@
 #include <TopoDS_Vertex.hxx>
 #include <TopTools_MapOfShape.hxx>
 #include <TopTools_ShapeMapHasher.hxx>
-#include <BRep_GCurve.hxx>
 
 // modified by NIZNHY-PKV Fri Oct 17 14:13:29 2008f
 static Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS);
@@ -1724,3 +1725,13 @@ Standard_Real BRep_Tool::MaxTolerance(const TopoDS_Shape&    theShape,
 
   return aTol;
 }
+
+//=======================================================================
+//function : Tolerance2d
+//purpose  : 
+//=======================================================================
+Standard_Real BRep_Tool::Tolerance2d(const TopoDS_Face& theFace, const Standard_Real theTolerance)
+{
+  BRepAdaptor_Surface aAdaptorSurface(theFace);
+  return Max(aAdaptorSurface.UResolution(theTolerance), aAdaptorSurface.VResolution(theTolerance));
+}
index 1415b57a0c5007c0e5e9a948a05ca257a3d942d6..e2cac8e95ec7f8e79cf3f211e698fc8dd738d2a8 100644 (file)
@@ -381,6 +381,13 @@ public:
   //@param theSubShape - Search subshape, only Face, Edge or Vertex are supported.
   Standard_EXPORT static Standard_Real MaxTolerance(const TopoDS_Shape&    theShape,
                                                     const TopAbs_ShapeEnum theSubShape);
+
+  //! Returns the 2d tolerance.
+  //@param theFace      - the input face to find 2d tolerance
+  //@param theTolerance - the input tolerance to calculate 2d tolerance.
+  Standard_EXPORT static Standard_Real Tolerance2d(const TopoDS_Face&  theFace,
+                                                   const Standard_Real theTolerance);
+
 };
 
 #endif // _BRep_Tool_HeaderFile
index ad0aa4450b189d1f6aeab3b0d514efa8944cf066..9acc7b53b72b16a559b1c329ff97c1ce96a17626 100644 (file)
@@ -462,9 +462,8 @@ static void PERFORM_C0(const TopoDS_Edge&         S1,
       Standard_Real Udeb, Ufin;
       BRep_Tool::Range(Eother, Udeb, Ufin);
 
-      gp_Pnt                   P1, Pt;
-      Standard_Integer         i, ii;
-      BRepClass_FaceClassifier classifier;
+      gp_Pnt           P1, Pt;
+      Standard_Integer i, ii;
       for (i = 1; i <= arrInter.Length(); i++)
       {
         const Standard_Real aParameter = arrInter(i);
@@ -796,7 +795,7 @@ void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex&       theS1,
       Standard_Real            U, V;
       gp_Pnt                   Pt, P1 = BRep_Tool::Pnt(theS1);
       BRepClass_FaceClassifier classifier;
-      const Standard_Real      tol = BRep_Tool::Tolerance(theS2);
+      const Standard_Real      tol2d = BRep_Tool::Tolerance2d(theS2, BRep_Tool::Tolerance(theS2));
 
       for (i = 1; i <= NbExtrema; i++)
       {
@@ -808,7 +807,7 @@ void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex&       theS1,
             // Check if the parameter does not correspond to a vertex
             Ext.Parameter(i, U, V);
             const gp_Pnt2d PUV(U, V);
-            classifier.Perform(theS2, PUV, tol);
+            classifier.Perform(theS2, PUV, tol2d);
             if (classifier.State() == TopAbs_IN)
             {
               if (myDstRef > Dstmin)
@@ -947,7 +946,7 @@ void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge&         theS1,
     if ((Dstmin < myDstRef - myEps) || (fabs(Dstmin - myDstRef) < myEps))
     {
       Standard_Real       U, V;
-      const Standard_Real tol = BRep_Tool::Tolerance(theS2);
+      const Standard_Real tol2d = BRep_Tool::Tolerance2d(theS2, BRep_Tool::Tolerance(theS2));
 
       gp_Pnt                  Pt1, Pt2;
       constexpr Standard_Real epsP = Precision::PConfusion();
@@ -966,7 +965,7 @@ void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge&         theS1,
             {
               Ext.ParameterOnFace(i, U, V);
               const gp_Pnt2d PUV(U, V);
-              classifier.Perform(theS2, PUV, tol);
+              classifier.Perform(theS2, PUV, tol2d);
               if (classifier.State() == TopAbs_IN)
               {
                 if (myDstRef > Dstmin)
@@ -999,7 +998,7 @@ void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge&         theS1,
 
     gp_Pnt              Pt;
     Standard_Real       U, V;
-    const Standard_Real tol = BRep_Tool::Tolerance(theS2);
+    const Standard_Real tol2d = BRep_Tool::Tolerance2d(theS2, BRep_Tool::Tolerance(theS2));
 
     Standard_Integer i;
     for (i = 1; i <= arrInter.Length(); i++)
@@ -1032,7 +1031,7 @@ void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge&         theS1,
               // Check if the parameter does not correspond to a vertex
               ExtPF.Parameter(ii, U, V);
               const gp_Pnt2d PUV(U, V);
-              classifier.Perform(theS2, PUV, tol);
+              classifier.Perform(theS2, PUV, tol2d);
               if (classifier.State() == TopAbs_IN)
               {
                 if (myDstRef > Dstmin)
@@ -1096,8 +1095,8 @@ void BRepExtrema_DistanceSS::Perform(const TopoDS_Face&         theS1,
     Dstmin = sqrt(Dstmin);
     if ((Dstmin < myDstRef - myEps) || (fabs(Dstmin - myDstRef) < myEps))
     {
-      const Standard_Real tol1 = BRep_Tool::Tolerance(theS1);
-      const Standard_Real tol2 = BRep_Tool::Tolerance(theS2);
+      const Standard_Real tol2d1 = BRep_Tool::Tolerance2d(theS1, BRep_Tool::Tolerance(theS1));
+      const Standard_Real tol2d2 = BRep_Tool::Tolerance2d(theS2, BRep_Tool::Tolerance(theS2));
 
       gp_Pnt                   Pt1, Pt2;
       gp_Pnt2d                 PUV;
@@ -1115,12 +1114,12 @@ void BRepExtrema_DistanceSS::Perform(const TopoDS_Face&         theS1,
             // Check if the parameter does not correspond to a vertex
             Ext.ParameterOnFace1(i, U1, V1);
             PUV.SetCoord(U1, V1);
-            classifier.Perform(theS1, PUV, tol1);
+            classifier.Perform(theS1, PUV, tol2d1);
             if (classifier.State() == TopAbs_IN)
             {
               Ext.ParameterOnFace2(i, U2, V2);
               PUV.SetCoord(U2, V2);
-              classifier.Perform(theS2, PUV, tol2);
+              classifier.Perform(theS2, PUV, tol2d2);
               if (classifier.State() == TopAbs_IN)
               {
                 if (myDstRef > Dstmin)
index dfda2e1bd5dae39f6343f5f2c7759d7785d37a3d..5076daea1a65627473fdafaeeeac850133d3ad57 100644 (file)
@@ -80,7 +80,7 @@ void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, const TopoDS_Face& F2)
   {
     // Exploration of points and classification
     BRepClass_FaceClassifier classifier;
-    const Standard_Real      Tol2 = BRep_Tool::Tolerance(F2);
+    const Standard_Real      Tol2d2 = BRep_Tool::Tolerance2d(F2, BRep_Tool::Tolerance(F2));
     Extrema_POnSurf          P1, P2;
 
     Standard_Integer i;
@@ -89,13 +89,14 @@ void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, const TopoDS_Face& F2)
       myExtSS.Points(i, P1, P2);
       P1.Parameter(U1, U2);
       const gp_Pnt2d Puv1(U1, U2);
-      classifier.Perform(F1, Puv1, Tol1);
+      const Standard_Real Tol2d1 = BRep_Tool::Tolerance2d(F1, Tol1);
+      classifier.Perform(F1, Puv1, Tol2d1);
       const TopAbs_State state1 = classifier.State();
       if (state1 == TopAbs_ON || state1 == TopAbs_IN)
       {
         P2.Parameter(U1, U2);
         const gp_Pnt2d Puv2(U1, U2);
-        classifier.Perform(F2, Puv2, Tol2);
+        classifier.Perform(F2, Puv2, Tol2d2);
         const TopAbs_State state2 = classifier.State();
         if (state2 == TopAbs_ON || state2 == TopAbs_IN)
         {
index 80fce2bfe2eb82551afc42ecd4e793fbaf64a38c..a72a2e5c7d75bf55bcaeba905624c2a395258b44 100644 (file)
@@ -79,12 +79,12 @@ void BRepExtrema_ExtPF::Perform(const TopoDS_Vertex& TheVertex, const TopoDS_Fac
   {
     BRepClass_FaceClassifier classifier;
     Standard_Real            U1, U2;
-    const Standard_Real      Tol = BRep_Tool::Tolerance(TheFace);
+    const Standard_Real      Tol2d = BRep_Tool::Tolerance2d(TheFace, BRep_Tool::Tolerance(TheFace));
     for (Standard_Integer i = 1; i <= myExtPS.NbExt(); i++)
     {
       myExtPS.Point(i).Parameter(U1, U2);
       const gp_Pnt2d Puv(U1, U2);
-      classifier.Perform(TheFace, Puv, Tol);
+      classifier.Perform(TheFace, Puv, Tol2d);
       const TopAbs_State state = classifier.State();
       if (state == TopAbs_ON || state == TopAbs_IN)
       {
diff --git a/tests/bugs/modalg_8/bug33394 b/tests/bugs/modalg_8/bug33394
new file mode 100644 (file)
index 0000000..0e77627
--- /dev/null
@@ -0,0 +1,14 @@
+puts "========================"
+puts "0033394: Modeling Algorithms - Wrong usage of BRepClass_FaceClassifier with 3d tolerance"
+puts "========================"
+puts ""
+
+pload MODELING
+restore [locate_data_file bug33394.brep] fb
+vertex vert 1016.3915670000133 17180 -5689.3758362036951
+distmini aa fb vert
+set tolerance [checkmaxtol aa]
+
+if { [dval aa_val] > ${tolerance} } {
+  puts "Error: The distance should be 0"
+}