]> OCCT Git - occt-copy.git/commitdiff
# compute all grid points in a single pass to avoid cache rebuild on BSpline surfaces. CR30892_2
authoremv <emv@opencascade.com>
Fri, 18 Sep 2020 10:06:08 +0000 (13:06 +0300)
committeremv <emv@opencascade.com>
Fri, 18 Sep 2020 13:17:42 +0000 (16:17 +0300)
# use iterator for array initialization with default distance values.

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

index 5d764cbf1f306239d2180d4698b5e984202654ad..bfedbda6321eb388939c435fe597d0049af0ddef 100644 (file)
@@ -263,25 +263,16 @@ void Extrema_GenExtPS::Perform (const gp_Pnt& thePoint,
   if (myTarget == Extrema_ExtFlag_MIN)
     mySqDistance = RealLast();
   else if (myTarget == Extrema_ExtFlag_MAX)
-    mySqDistance = -1;
+    mySqDistance = -1.;
 
   // Fill Square distances with default values
-  for (int iU = 0; iU <= myNbUSamples + 1; ++iU)
+  Handle(Extrema_HArray2OfPOnSurfParams) anArrays[] = 
+    { myPoints, myFacePntParams, myUEdgePntParams, myVEdgePntParams };
+  for (Standard_Integer i = 0; i < 4; ++i)
   {
-    for (int iV = 0; iV <= myNbVSamples + 1; ++iV)
+    for (Extrema_Array2OfPOnSurfParams::Iterator it (anArrays[i]->Array2()); it.More(); it.Next())
     {
-      myPoints->ChangeValue (iU, iV).SetSqrDistance (-1.);
-
-      if (iU <= myNbUSamples && iV <= myNbVSamples)
-        myFacePntParams->ChangeValue (iU, iV).SetSqrDistance (-1.);
-
-      if (iU > 0 && iU <= myNbUSamples && iV > 0 && iV <= myNbVSamples)
-      {
-        if (iU < myNbUSamples)
-          myUEdgePntParams->ChangeValue (iU, iV).SetSqrDistance (-1.);
-        if (iV < myNbVSamples)
-          myVEdgePntParams->ChangeValue (iU, iV).SetSqrDistance (-1.);
-      }
+      it.ChangeValue().SetSqrDistance (-1.);
     }
   }
 
@@ -368,9 +359,13 @@ void Extrema_GenExtPS::BuildGrid()
   }
 
   myPoints = new Extrema_HArray2OfPOnSurfParams (0, myNbUSamples + 1, 0, myNbVSamples + 1);
+  myMidPoints = new Extrema_HArray2OfPOnSurf (1, myNbUSamples, 1, myNbVSamples);
+
   for (int iU = 1; iU <= myNbUSamples; iU++)
   {
     Standard_Real U = myUParams->Value (iU);
+    Standard_Integer aUCoeff = (iU < myNbUSamples) ? 1 : 0;
+    Standard_Real UMax = aUCoeff ? myUParams->Value (iU + aUCoeff) : U;
     for (int iV = 1; iV <= myNbVSamples; iV++)
     {
       Standard_Real V = myVParams->Value (iV);
@@ -379,6 +374,18 @@ void Extrema_GenExtPS::BuildGrid()
       aParam.SetElementType (Extrema_Node);
       aParam.SetIndices (iU, iV);
       myPoints->SetValue (iU, iV, aParam);
+
+      if (myTarget != Extrema_ExtFlag_MINMAX)
+      {
+        Standard_Integer aVCoeff = (iV < myNbVSamples) ? 1 : 0;
+        if (aUCoeff != 0 || aVCoeff != 0)
+        {
+          Standard_Real VMax = aVCoeff ? myVParams->Value (iV + aVCoeff) : V;
+          Standard_Real UMid = (U + UMax) * 0.5, VMid = (V + VMax) * 0.5;
+          gp_Pnt aPMid = myS->Value (UMid, VMid);
+          myMidPoints->SetValue (iU, iV, Extrema_POnSurf (UMid, VMid, aPMid));
+        }
+      }
     }
   }
 
@@ -468,17 +475,13 @@ void Extrema_GenExtPS::BuildTree()
             aGridBox.Add (myPoints->Value (iU + i * aUCoeff, iV + j * aVCoeff).Value());
         aGridBox.Enlarge (Precision::Confusion());
 
-        const Extrema_POnSurf& aPMin = myPoints->Value (iU, iV);
-        const Extrema_POnSurf& aPMax = myPoints->Value (iU + aUCoeff, iV + aVCoeff);
-
-        Standard_Real U1, V1, U2, V2;
-        aPMin.Parameter (U1, V1);
-        aPMax.Parameter (U2, V2);
-
         // Enlarge box to make sure the whole cell is covered
-        if (U1 != U2 || V1 != V2)
+        if (aUCoeff > 0 || aVCoeff > 0)
         {
-          gp_Pnt aPMid = myS->Value ((U1 + U2) * 0.5, (V1 + V2) * 0.5);
+          gp_Pnt aPMid = myMidPoints->Value (iU, iV).Value();
+
+          const Extrema_POnSurf& aPMin = myPoints->Value (iU, iV);
+          const Extrema_POnSurf& aPMax = myPoints->Value (iU + aUCoeff, iV + aVCoeff);
 
           gp_Vec aDir (aPMin.Value(), aPMax.Value());
           Standard_Real diag = aDir.SquareMagnitude();
index 46f264f2cfc94e4cf39c1f203a6b337a9503d589..1e0ac6e01c7f8c5f3dcc2617c67dc0601bcee204 100644 (file)
@@ -25,6 +25,7 @@
 #include <BVH_BoxSet.hxx>
 #include <BVH_IndexedBoxSet.hxx>
 #include <BVH_Traverse.hxx>
+#include <Extrema_HArray2OfPOnSurf.hxx>
 #include <Extrema_HArray2OfPOnSurfParams.hxx>
 #include <Extrema_FuncPSNorm.hxx>
 #include <Extrema_POnSurfParams.hxx>
@@ -395,6 +396,7 @@ protected: //! @name Fields
   // Intermediate data
 
   Handle(Extrema_HArray2OfPOnSurfParams) myPoints; //!< Grid points
+  Handle(Extrema_HArray2OfPOnSurf) myMidPoints;    //!< Points in the middle of the cell
   Handle(TColStd_HArray1OfReal) myUParams;         //!< Grid parameters in U parametric direction
   Handle(TColStd_HArray1OfReal) myVParams;         //!< Grid parameters in V parametric direction