]> OCCT Git - occt.git/commitdiff
0032225: Modeling Data - Wrong result of extrema curve-surface
authorifv <ifv@opencascade.com>
Thu, 18 Mar 2021 14:07:37 +0000 (17:07 +0300)
committerbugmaster <bugmaster@opencascade.com>
Sat, 27 Mar 2021 10:46:04 +0000 (13:46 +0300)
Extrema_GenExtCS.cxx: subdivision on intervals for periodic c curves is added

Extrema_FuncExtCS.hxx: access to fields mySqDist, myPoint1, myPoint2 is added

bug32225: new test case is added

src/Extrema/Extrema_FuncExtCS.hxx
src/Extrema/Extrema_GenExtCS.cxx
tests/lowalgos/extcs/bug32225 [new file with mode: 0644]
tests/vselect/bugs/bug544 [deleted file]

index 70aa2b2cfbb6016e4c8ec03214195686ed270430..a97462df138ed0f98568c5934bff3f2938b68987 100644 (file)
@@ -82,6 +82,22 @@ public:
   //! Return the Nth extremum on S.
   Standard_EXPORT const Extrema_POnSurf& PointOnSurface (const Standard_Integer N) const;
 
+  //! Change Sequence of SquareDistance
+  TColStd_SequenceOfReal& SquareDistances()
+  {
+    return mySqDist;
+  }
+  //! Change Sequence of PointOnCurv
+  Extrema_SequenceOfPOnCurv& PointsOnCurve()
+  {
+    return myPoint1;
+  }
+  //! Change Sequence of PointOnSurf
+  Extrema_SequenceOfPOnSurf& PointsOnSurf()
+  {
+    return myPoint2;
+  }
+
 private:
 
   const Adaptor3d_Curve* myC;
index 0642f5dccca36a7da38856f9031773b263c9832c..bf88033beed1d70e2cef22aa42bc6cf1421f6e26 100644 (file)
@@ -304,33 +304,83 @@ void Extrema_GenExtCS::Perform (const Adaptor3d_Curve& C,
   Tol(2) = mytol2;
   Tol(3) = mytol2;
   //
-  TUVinf(1) = mytmin;
-  TUVinf(2) = trimumin;
-  TUVinf(3) = trimvmin;
-  //
-  TUVsup(1) = mytsup;
-  TUVsup(2) = trimusup;
-  TUVsup(3) = trimvsup;
-  //
   // Number of particles used in PSO algorithm (particle swarm optimization).
   const Standard_Integer aNbParticles = 48;
-  //
-  if (aNbVar == 3)
+
+  Standard_Integer aNbIntC = 1;
+  if (C.IsClosed() || C.IsPeriodic())
   {
-    GlobMinGenCS(C, aNbParticles, TUVinf, TUVsup, TUV);
+    Standard_Real aPeriod = C.Period();
+    if (C.LastParameter() - C.FirstParameter() > 2. * aPeriod / 3.)
+    {
+      aNbIntC = 2;
+    }
   }
-  else if (aNbVar == 2)
+
+  Standard_Integer anInt;
+  Standard_Real dT = (mytsup - mytmin) / aNbIntC;
+  for (anInt = 1; anInt <= aNbIntC; anInt++)
   {
-    GlobMinConicS(C, aNbParticles, TUVinf, TUVsup, TUV);
+    TUVinf(1) = mytmin + (anInt - 1) * dT;
+    TUVinf(2) = trimumin;
+    TUVinf(3) = trimvmin;
+    //
+    TUVsup(1) = TUVinf(1) + dT; // mytsup;
+    TUVsup(2) = trimusup;
+    TUVsup(3) = trimvsup;
+    //
+    if (aNbVar == 3)
+    {
+      GlobMinGenCS(C, aNbParticles, TUVinf, TUVsup, TUV);
+    }
+    else if (aNbVar == 2)
+    {
+      GlobMinConicS(C, aNbParticles, TUVinf, TUVsup, TUV);
+    }
+    else
+    {
+      GlobMinCQuadric(C, aNbParticles, TUVinf, TUVsup, TUV);
+    }
+
+    // Find min approximation
+    math_FunctionSetRoot anA(myF, Tol);
+    anA.Perform(myF, TUV, TUVinf, TUVsup);
   }
-  else
+  if (aNbIntC > 1 && myF.NbExt() > 1)
   {
-    GlobMinCQuadric(C, aNbParticles, TUVinf, TUVsup, TUV);
+    //Try to remove "false" extrema caused by dividing curve interval
+    TColStd_SequenceOfReal& aSqDists = myF.SquareDistances();
+    Extrema_SequenceOfPOnCurv& aPntsOnCrv = myF.PointsOnCurve();
+    Extrema_SequenceOfPOnSurf& aPntsOnSurf = myF.PointsOnSurf();
+    TColStd_SequenceOfReal aSqDists1(aSqDists);
+    Extrema_SequenceOfPOnCurv aPntsOnCrv1(aPntsOnCrv);
+    Extrema_SequenceOfPOnSurf aPntsOnSurf1(aPntsOnSurf);
+
+    Standard_Real aMinDist = aSqDists(1);
+    Standard_Integer i;
+    for (i = 2; i <= aSqDists.Length(); ++i)
+    {
+      Standard_Real aDist = aSqDists(i);
+      if (aDist < aMinDist)
+      {
+        aMinDist = aDist;
+      }
+    }
+    aSqDists.Clear();
+    aPntsOnCrv.Clear();
+    aPntsOnSurf.Clear();
+    Standard_Real aTol = Precision::SquareConfusion();
+    for (i = 1; i <= aSqDists1.Length(); ++i)
+    {
+      Standard_Real aDist = aSqDists1(i);
+      if (Abs(aDist - aMinDist) <= aTol)
+      {
+        aSqDists.Append(aDist);
+        aPntsOnCrv.Append(aPntsOnCrv1(i));
+        aPntsOnSurf.Append(aPntsOnSurf1(i));
+      }
+    }
   }
-
-  // Find min approximation
-  math_FunctionSetRoot anA(myF, Tol);
-  anA.Perform(myF, TUV, TUVinf, TUVsup);
   myDone = Standard_True;
 
 }
diff --git a/tests/lowalgos/extcs/bug32225 b/tests/lowalgos/extcs/bug32225
new file mode 100644 (file)
index 0000000..35362be
--- /dev/null
@@ -0,0 +1,28 @@
+puts "========"
+puts "OCC32225: Modeling Data - Wrong result of extrema curve-surface"
+puts "========"
+puts ""
+
+restore [locate_data_file bug32225_curve.draw] c
+restore [locate_data_file bug32225_surf.draw] s
+
+extrema c s
+
+if {[isdraw ext_1]} {
+  set ext_dist [lindex [length ext_1] end]
+  checkreal "Ext_1 min distance" $ext_dist 0. 1.e-10 1.e-10
+} else {
+  puts "Error: invalid result"
+}
+
+if {[isdraw ext_2]} {
+  set ext_dist [lindex [length ext_2] end]
+  checkreal "Ext_2 min distance" $ext_dist 0. 1.e-10 1.e-10
+} else {
+  puts "Error: invalid result"
+}
+smallview
+donly c ext_1 ext_2  
+fit
+disp s
+checkview -screenshot -2d -path ${imagedir}/${test_image}.png
\ No newline at end of file
diff --git a/tests/vselect/bugs/bug544 b/tests/vselect/bugs/bug544
deleted file mode 100644 (file)
index 9591792..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-puts "========"
-puts "OCC544: Problems with the results of MakePipeShell"
-puts "========"
-puts ""
-
-pload MODELING VISUALIZATION QAcommands
-
-vinit View1
-vsetdispmode 1
-OCC544
-vdisplay result
-vsetmaterial result PLASTIC
-vsetcolor result MATRABLUE
-vsettransparency result 0.5
-vsetdispmode 1
-vfit
-vviewparams -scale 2.05374 -proj 0.135192 -0.978297 -0.157031 -up -0.399854 -0.198875 0.894743 -at 415.781529476262 349.647084890243 417.026634136105
-
-vmoveto 300 70
-checkcolor 220 110 0.04 0.04 0.5
-
-vdump $imagedir/${casename}.png