]> OCCT Git - occt.git/commitdiff
A fix by mzernova for OCCT bugs 33664 and 33755 (Salome issues 42465 and 42518
authorjfa <jfa@opencascade.com>
Thu, 1 Aug 2024 10:50:57 +0000 (11:50 +0100)
committerjfa <jfa@opencascade.com>
Fri, 21 Feb 2025 11:43:49 +0000 (11:43 +0000)
src/StdSelect/StdSelect_BRepSelectionTool.cxx

index 0e4492055105d4a642c6220c21ae6921d6520f71..4a2960bf28a87447c6e2c400086b67ee9def94df 100644 (file)
 
 #define BVH_PRIMITIVE_LIMIT 800000
 
-namespace
-{
-//=======================================================================
-// function : getCylinderCircles
-// purpose  : Extracts up to two circular edges from a hollow cylinder face
-//=======================================================================
-std::array<gp_Circ, 2> getCylinderCircles(const TopoDS_Face& theHollowCylinder,
-                                          Standard_Size&     theNumCircles)
-{
-  std::array<gp_Circ, 2> aCircles; // Array to store up to two circles
-  theNumCircles             = 0;   // Initialize the number of circles found
-  Standard_Integer aLinesNb = 0;   // Counter for the number of edges processed
-
-  for (TopExp_Explorer anEdgeExp(theHollowCylinder, TopAbs_EDGE); anEdgeExp.More();
-       anEdgeExp.Next())
-  {
-    const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
-    BRepAdaptor_Curve  anAdaptor(anEdge);
-    aLinesNb++;
-
-    if (anAdaptor.GetType() == GeomAbs_Circle && BRep_Tool::IsClosed(anEdge))
-    {
-      theNumCircles++;
-      aCircles[theNumCircles - 1] = anAdaptor.Circle();
-    }
-    else if (anAdaptor.GetType() != GeomAbs_Line || aLinesNb > 4)
-    {
-      theNumCircles = 0;
-      return std::array<gp_Circ, 2>();
-    }
-    if (theNumCircles == 2)
-    {
-      break;
-    }
-  }
-
-  return aCircles;
-}
-} // namespace
+// The following flag can be used to enable optimization of cone/cylinder selection
+// Unfortunately, this optimization is not stable and may lead to incorrect selection
+// in some cases. It is disabled by default.
+//#define OPTIMIZE_CONE_CYLINDER_SELECTION
 
 //==================================================
 // function: PreBuildBVH
@@ -642,6 +607,48 @@ void StdSelect_BRepSelectionTool::GetEdgeSensitive(const TopoDS_Shape&
   }
 }
 
+#ifdef OPTIMIZE_CONE_CYLINDER_SELECTION
+namespace
+{
+//=======================================================================
+// function : getCylinderCircles
+// purpose  : Extracts up to two circular edges from a hollow cylinder face
+//=======================================================================
+std::array<gp_Circ, 2> getCylinderCircles(const TopoDS_Face& theHollowCylinder,
+                                          Standard_Size&     theNumCircles)
+{
+  std::array<gp_Circ, 2> aCircles; // Array to store up to two circles
+  theNumCircles             = 0;   // Initialize the number of circles found
+  Standard_Integer aLinesNb = 0;   // Counter for the number of edges processed
+
+  for (TopExp_Explorer anEdgeExp(theHollowCylinder, TopAbs_EDGE); anEdgeExp.More();
+       anEdgeExp.Next())
+  {
+    const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
+    BRepAdaptor_Curve  anAdaptor(anEdge);
+    aLinesNb++;
+
+    if (anAdaptor.GetType() == GeomAbs_Circle && BRep_Tool::IsClosed(anEdge))
+    {
+      theNumCircles++;
+      aCircles[theNumCircles - 1] = anAdaptor.Circle();
+    }
+    else if (anAdaptor.GetType() != GeomAbs_Line || aLinesNb > 4)
+    {
+      theNumCircles = 0;
+      return std::array<gp_Circ, 2>();
+    }
+    if (theNumCircles == 2)
+    {
+      break;
+    }
+  }
+
+  return aCircles;
+}
+} // namespace
+#endif /*OPTIMIZE_CONE_CYLINDER_SELECTION*/
+
 //=================================================================================================
 
 Standard_Boolean StdSelect_BRepSelectionTool::GetSensitiveForFace(
@@ -688,6 +695,7 @@ Standard_Boolean StdSelect_BRepSelectionTool::GetSensitiveForFace(
         return Standard_True;
       }
     }
+#ifdef OPTIMIZE_CONE_CYLINDER_SELECTION
     else if (Handle(Geom_ConicalSurface) aGeomCone = Handle(Geom_ConicalSurface)::DownCast(aSurf))
     {
       Standard_Size                aNumCircles;
@@ -748,6 +756,7 @@ Standard_Boolean StdSelect_BRepSelectionTool::GetSensitiveForFace(
         return Standard_True;
       }
     }
+#endif /*OPTIMIZE_CONE_CYLINDER_SELECTION*/
     else if (Handle(Geom_Plane) aGeomPlane = Handle(Geom_Plane)::DownCast(aSurf))
     {
       TopTools_IndexedMapOfShape aSubfacesMap;