]> OCCT Git - occt-copy.git/commitdiff
0028731: Restore Face Orientation tool runs very slow for specific CAD files
authorduv <duv@opencascade.com>
Mon, 26 Jun 2017 08:22:24 +0000 (11:22 +0300)
committerduv <duv@opencascade.com>
Mon, 26 Jun 2017 12:23:52 +0000 (15:23 +0300)
src/BRepMesh/BRepMesh_RestoreOrientationTool.cxx

index 3270da0d7f1f8684eb2489eecc4c896f31b7bc31..77ad33346f55ada44db47791a0d991305dd1f1e5 100644 (file)
@@ -60,6 +60,9 @@ const Standard_Real COHERENCY_WEIGHT = 50.0;
 // Indicates that ray does not hit any geometry.
 const Standard_Integer INVALID_HIT = -1;
 
+//! Maximum number of attempts for rejection sampling.
+const int MAX_SAMPLING_ATTEMPTS = 10;
+
 //! Samples value from array according to probabilities.
 Standard_Integer sampleValue (Standard_Real theKsi, const std::vector<Standard_Real>& theCDF)
 {
@@ -389,11 +392,16 @@ void BRepMesh_RestoreOrientationTool::computeVisibility (BVH_Triangulation<Stand
 
     // sample point in triangle uniformly
     Standard_Real aKsi, aPsi;
-    do
+    for (int i = 0; i < MAX_SAMPLING_ATTEMPTS; ++i)
     {
       aKsi = anRNG.NextReal();
       aPsi = anRNG.NextReal();
-    } while (aKsi + aPsi > 1.0);
+
+      if (aKsi + aPsi > 1.0)
+      {
+        break;
+      }
+    }
 
     const BVH_Vec3d& aPoint0 = thePatch->Vertices[aTriangle.x()];
     const BVH_Vec3d& aPoint1 = thePatch->Vertices[aTriangle.y()];
@@ -412,7 +420,7 @@ void BRepMesh_RestoreOrientationTool::computeVisibility (BVH_Triangulation<Stand
     BVH_Vec3d aDirection;
     Standard_Real aDot = 0.0;
 
-    do
+    for (int i = 0; i < MAX_SAMPLING_ATTEMPTS; ++i)
     {
       aKsi = anRNG.NextReal();
       aPsi = anRNG.NextReal();
@@ -425,7 +433,11 @@ void BRepMesh_RestoreOrientationTool::computeVisibility (BVH_Triangulation<Stand
 
       aDot = aDirection.Dot (aNormal);
 
-    } while (std::abs (aDot) < 0.2);
+      if (std::abs (aDot) < 0.2)
+      {
+        break;
+      }
+    }
 
     if (aDot < 0.0)
     {