]> OCCT Git - occt-copy.git/commitdiff
# Decrease the box of the sample to make BVH tree more effective.
authoremv <emv@opencascade.com>
Fri, 13 Sep 2019 10:55:52 +0000 (13:55 +0300)
committeremv <emv@opencascade.com>
Mon, 18 May 2020 20:27:26 +0000 (23:27 +0300)
# When looking for MINMAX solutions search first for Min solutions first and then for Max.

src/Extrema/Extrema_GenExtPS.cxx
src/Extrema/Extrema_GenExtPS.hxx

index b8d2e80ffd1257af9376125eb8a2c200e7623be7..23e381bf97a76c0b5f01895dbd40697cc62e255f 100644 (file)
@@ -330,7 +330,11 @@ void Extrema_GenExtPS::Perform (const gp_Pnt& thePoint)
     const Standard_Integer aNbCells = myGridBoxSet->Size();
     for (Standard_Integer i = 0; i < aNbCells; ++i)
     {
-      Accept (i, 0.0);
+      FindSolution (i, 0.0, Extrema_ExtFlag_MIN);
+    }
+    for (Standard_Integer i = 0; i < aNbCells; ++i)
+    {
+      FindSolution (i, 0.0, Extrema_ExtFlag_MAX);
     }
 
     // Copy solutions
@@ -432,10 +436,8 @@ void Extrema_GenExtPS::BuildTree()
         for (int j = 0; j < 2; ++j)
           aBox.Add (myPoints->Value (iU + i * aUCoeff, iV + j * aVCoeff).Value());
 
-      //aBox.Add (myS->Value ((U1 + U2) * 0.5, V1));
-      //aBox.Add (myS->Value ((U1 + U2) * 0.5, V2));
-      //aBox.Add (myS->Value (U1, (V1 + V2) * 0.5));
-      //aBox.Add (myS->Value (U2, (V1 + V2) * 0.5));
+      aBox.Enlarge (Precision::Confusion());
+
       const Extrema_POnSurf& aPMin = myPoints->Value (iU, iV);
       const Extrema_POnSurf& aPMax = myPoints->Value (iU + aUCoeff, iV + aVCoeff);
 
@@ -443,14 +445,18 @@ void Extrema_GenExtPS::BuildTree()
       aPMin.Parameter (U1, V1);
       aPMax.Parameter (U2, V2);
 
-      gp_Pnt aPMid = myS->Value ((U1 + U2) * 0.5, (V1 + V2) * 0.5);
-      aBox.Add (aPMid);
-
       // Enlarge box to make sure the whole cell is covered
-      aBox.Enlarge (Sqrt (aBox.SquareExtent()));
+      if (U1 != U2 || V1 != V2)
+      {
+        gp_Pnt aPMid = myS->Value ((U1 + U2) * 0.5, (V1 + V2) * 0.5);
+        aBox.Add (aPMid);
 
-      //aBox.Enlarge (Precision::Confusion() + 
-      //              gp_Lin (aPMin.Value(), gp_Vec (aPMin.Value(), aPMax.Value())).Distance (aPMid));
+        gp_Vec aDir(aPMin.Value(), aPMax.Value());
+        if (aDir.SquareMagnitude() > gp::Resolution())
+        {
+          aBox.Enlarge (gp_Lin (aPMin.Value(), aDir).Distance (aPMid));
+        }
+      }
 
       myGridBoxSet->UpdateBox (iCell, Bnd_Tools::Bnd2BVH (aBox));
     }
@@ -599,7 +605,18 @@ Standard_Boolean Extrema_GenExtPS::IsMetricBetter (const Standard_Real& theLeft,
 //purpose  : 
 //=======================================================================
 Standard_Boolean Extrema_GenExtPS::Accept (const Standard_Integer theIndex,
-                                           const Standard_Real&)
+                                           const Standard_Real& theMetric)
+{
+  return FindSolution (theIndex, theMetric, myTarget);
+}
+
+//=======================================================================
+//function : Accept
+//purpose  : 
+//=======================================================================
+Standard_Boolean Extrema_GenExtPS::FindSolution (const Standard_Integer theIndex,
+                                                 const Standard_Real&,
+                                                 const Extrema_ExtFlag theTarget)
 {
   const GridCell& aCell = myGridBoxSet->Element (theIndex);
 
@@ -618,7 +635,7 @@ Standard_Boolean Extrema_GenExtPS::Accept (const Standard_Integer theIndex,
   fillSqDist (aParam11, aPoint);
 
   if (nU != myNbUSamples && nV != myNbVSamples &&
-     (myTarget == Extrema_ExtFlag_MIN || myTarget == Extrema_ExtFlag_MINMAX))
+     (theTarget == Extrema_ExtFlag_MIN || theTarget == Extrema_ExtFlag_MINMAX))
   {
     // Find minimum
 
@@ -714,7 +731,7 @@ Standard_Boolean Extrema_GenExtPS::Accept (const Standard_Integer theIndex,
     }
   }
 
-  if (myTarget == Extrema_ExtFlag_MAX || myTarget == Extrema_ExtFlag_MINMAX)
+  if (theTarget == Extrema_ExtFlag_MAX || theTarget == Extrema_ExtFlag_MINMAX)
   {
     // Find maximum
     Extrema_POnSurfParams &aParam1 = myPoints->ChangeValue (nU - 1, nV - 1);
index 84ff1ec5f0116df81a53182b455f7ba0e5562b98..f47c45d5a89276dc6c5ed6c992848f35e5f45130 100644 (file)
@@ -290,6 +290,11 @@ private: //! @name Private methods performing the job
                            const gp_Pnt& thePoint,
                            const Standard_Real theDiffTol);
 
+  //! Looks for the Min or Max Solution (depending on the given target).
+  Standard_EXPORT Standard_Boolean FindSolution (const Standard_Integer theIndex,
+                                                 const Standard_Real& theMetric,
+                                                 const Extrema_ExtFlag theTarget);
+
   //! structure to keep the results
   struct ExtPSResult
   {