From: abv Date: Fri, 24 Feb 2017 14:33:11 +0000 (+0300) Subject: Added tests for performance of bspline curve evaluation X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=41c79a7727afb5238a5f7259d50efe49e74ab9c9;p=occt-copy.git Added tests for performance of bspline curve evaluation --- diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index 5be38190b9..28c3eaceb2 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -57,6 +57,12 @@ #include +#include +#include +#include +#include +#include + //======================================================================= //function : SurfaceGenOCC26675_1 //purpose : Generates a surface for intersect (in corresponding @@ -2140,6 +2146,78 @@ static Standard_Integer OCC27875(Draw_Interpretor& theDI, return 0; } +// calculate specified number of points on a curve +template +void evalCurve (const AdCurve& theCurve, int theNbP, bool isRandom, double theUMin, double theUMax) +{ + std::srand(1); + double aStep = (theUMax - theUMin) / (! isRandom && theNbP > 0 ? theNbP : 1); + for (int i = 0; i < theNbP; i++) + { + double aU = theUMin + aStep * (isRandom ? std::rand() / (double)RAND_MAX : (double)i); + theCurve.Value (aU); +// Standard_ASSERT_VOID(theCurve.Value (aU).SquareDistance (theCurve.BSpline()->Value(aU)) < 1e-20, +// "Different points at the same parameter"); + } +} + +static Standard_Integer probspline (Draw_Interpretor& theDI, + Standard_Integer theNArg, + const char ** theArgVal) +{ + if (theNArg < 2) + { + std::cout << "Measures time of evaluating points on bspline" << std::endl; + std::cout << "Use: \n" << theArgVal[0] << " bspline nbpoints [-r{andom}] [ustart uend]" << std::endl; + return 1; + } + + Handle(Geom2d_BSplineCurve) aCurve2d = DrawTrSurf::GetBSplineCurve2d (theArgVal[1]); + Handle(Geom_BSplineCurve) aCurve = DrawTrSurf::GetBSplineCurve (theArgVal[1]); + if (aCurve2d.IsNull() && aCurve.IsNull()) + { + std::cout << "Error: " << theArgVal[1] << " is neither 2d nor 3d bspline" << std::endl; + return 1; + } + + Standard_Integer aNbP = Draw::Atoi (theArgVal[2]); + Standard_Boolean isRandom = Standard_False; + Standard_Integer nbArg = 3; + if (theNArg > 3 && theArgVal[nbArg][0] == '-' && theArgVal[nbArg][1] == 'r') + { + isRandom = Standard_True; + nbArg++; + } + Standard_Real aUMin = (! aCurve2d.IsNull() ? aCurve2d->FirstParameter() : aCurve->FirstParameter()); + Standard_Real aUMax = (! aCurve2d.IsNull() ? aCurve2d->LastParameter() : aCurve->LastParameter()); + if (nbArg + 1 < theNArg) + { + aUMin = Draw::Atof (theArgVal[nbArg++]); + aUMax = Draw::Atof (theArgVal[nbArg++]); + } + + std::cout << "Evaluating " << aNbP << (isRandom ? " random" : "sequential") << " points on " + << (! aCurve2d.IsNull() ? "2d" : "3d") << " bspline curve " << theArgVal[1] + << " in range [" << aUMin << ", " << aUMax << "]" << std::endl; + OSD_Timer aTimer; + aTimer.Start(); + if (! aCurve2d.IsNull()) + { + Geom2dAdaptor_Curve aC (aCurve2d); + evalCurve (aC, aNbP, isRandom, aUMin, aUMax); + } + else if (! aCurve.IsNull()) + { + GeomAdaptor_Curve aC (aCurve); + evalCurve (aC, aNbP, isRandom, aUMin, aUMax); + } + Standard_Real aSec, aCPU; + Standard_Integer aMin, aHour; + aTimer.Show (aSec, aMin, aHour, aCPU); + theDI << "Elapsed " << (aSec + 60. * aMin + 3600. * aHour) << " sec, CPU = " << aCPU << " sec"; + + return 0; +} #include #include @@ -2274,5 +2352,7 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) { theCommands.Add("OCC27875", "OCC27875 curve", __FILE__, OCC27875, group); theCommands.Add("OCC28389", "OCC28389", __FILE__, OCC28389, group); + theCommands.Add("probspline", "probspline curve nbpoints [-random] [umin umax]", __FILE__, probspline, group); + return; } diff --git a/tests/perf/bspline/curve_c1 b/tests/perf/bspline/curve_c1 new file mode 100644 index 0000000000..c813a72af1 --- /dev/null +++ b/tests/perf/bspline/curve_c1 @@ -0,0 +1,20 @@ +puts "Evaluation of complex curve, random, in range" + +pload QAcommands +bsplinecurve c 3 37 \ +0 4 1 1 2 1 3 1 5 1 6 1 7 1 8 1 9 1 10 1 \ +11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 \ +21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 \ +31 1 32 1 33 1 34 1 35 1 36 1 37 4 \ +0 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 \ +0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 \ +0 2 0 1 0 2 1 1 1 2 1 1 1 2 0 1 \ +0 3 0 1 0 3 1 1 1 3 1 1 1 3 0 1 \ +0 4 0 1 0 4 1 1 1 4 1 1 1 4 0 1 \ +0 5 0 1 0 5 1 1 1 5 1 1 1 5 0 1 \ +0 6 0 1 0 6 1 1 1 6 1 1 1 6 0 1 \ +0 7 0 1 0 7 1 1 1 7 1 1 1 7 0 1 \ +0 8 0 1 0 8 1 1 1 8 1 1 1 8 0 1 \ +0 9 0 1 0 9 1 1 1 9 1 1 1 9 0 1 + +probspline c 10000000 -r diff --git a/tests/perf/bspline/curve_c2 b/tests/perf/bspline/curve_c2 new file mode 100644 index 0000000000..8efbd06e50 --- /dev/null +++ b/tests/perf/bspline/curve_c2 @@ -0,0 +1,20 @@ +puts "Evaluation of complex curve, sequential, in range" + +pload QAcommands +bsplinecurve c 3 37 \ +0 4 1 1 2 1 3 1 5 1 6 1 7 1 8 1 9 1 10 1 \ +11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 \ +21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 \ +31 1 32 1 33 1 34 1 35 1 36 1 37 4 \ +0 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 \ +0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 \ +0 2 0 1 0 2 1 1 1 2 1 1 1 2 0 1 \ +0 3 0 1 0 3 1 1 1 3 1 1 1 3 0 1 \ +0 4 0 1 0 4 1 1 1 4 1 1 1 4 0 1 \ +0 5 0 1 0 5 1 1 1 5 1 1 1 5 0 1 \ +0 6 0 1 0 6 1 1 1 6 1 1 1 6 0 1 \ +0 7 0 1 0 7 1 1 1 7 1 1 1 7 0 1 \ +0 8 0 1 0 8 1 1 1 8 1 1 1 8 0 1 \ +0 9 0 1 0 9 1 1 1 9 1 1 1 9 0 1 + +probspline c 10000000 diff --git a/tests/perf/bspline/curve_c3 b/tests/perf/bspline/curve_c3 new file mode 100644 index 0000000000..be253fa214 --- /dev/null +++ b/tests/perf/bspline/curve_c3 @@ -0,0 +1,20 @@ +puts "Evaluation of complex curve, random, out of range" + +pload QAcommands +bsplinecurve c 3 37 \ +0 4 1 1 2 1 3 1 5 1 6 1 7 1 8 1 9 1 10 1 \ +11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 \ +21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 \ +31 1 32 1 33 1 34 1 35 1 36 1 37 4 \ +0 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 \ +0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 \ +0 2 0 1 0 2 1 1 1 2 1 1 1 2 0 1 \ +0 3 0 1 0 3 1 1 1 3 1 1 1 3 0 1 \ +0 4 0 1 0 4 1 1 1 4 1 1 1 4 0 1 \ +0 5 0 1 0 5 1 1 1 5 1 1 1 5 0 1 \ +0 6 0 1 0 6 1 1 1 6 1 1 1 6 0 1 \ +0 7 0 1 0 7 1 1 1 7 1 1 1 7 0 1 \ +0 8 0 1 0 8 1 1 1 8 1 1 1 8 0 1 \ +0 9 0 1 0 9 1 1 1 9 1 1 1 9 0 1 + +probspline c 10000000 -r -100. 0. diff --git a/tests/perf/bspline/curve_c4 b/tests/perf/bspline/curve_c4 new file mode 100644 index 0000000000..cc1e5e60a4 --- /dev/null +++ b/tests/perf/bspline/curve_c4 @@ -0,0 +1,20 @@ +puts "Evaluation of complex curve, random, narrow range" + +pload QAcommands +bsplinecurve c 3 37 \ +0 4 1 1 2 1 3 1 5 1 6 1 7 1 8 1 9 1 10 1 \ +11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 \ +21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 \ +31 1 32 1 33 1 34 1 35 1 36 1 37 4 \ +0 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 \ +0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 \ +0 2 0 1 0 2 1 1 1 2 1 1 1 2 0 1 \ +0 3 0 1 0 3 1 1 1 3 1 1 1 3 0 1 \ +0 4 0 1 0 4 1 1 1 4 1 1 1 4 0 1 \ +0 5 0 1 0 5 1 1 1 5 1 1 1 5 0 1 \ +0 6 0 1 0 6 1 1 1 6 1 1 1 6 0 1 \ +0 7 0 1 0 7 1 1 1 7 1 1 1 7 0 1 \ +0 8 0 1 0 8 1 1 1 8 1 1 1 8 0 1 \ +0 9 0 1 0 9 1 1 1 9 1 1 1 9 0 1 + +probspline c 10000000 -r 10. 11. diff --git a/tests/perf/bspline/curve_s1 b/tests/perf/bspline/curve_s1 new file mode 100644 index 0000000000..ccbbe0e99d --- /dev/null +++ b/tests/perf/bspline/curve_s1 @@ -0,0 +1,5 @@ +puts "Evaluation of simple curve, random, in range" + +pload QAcommands +bsplinecurve c 3 2 0 4 1 4 0 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 +probspline c 100000000 -r diff --git a/tests/perf/bspline/curve_s2 b/tests/perf/bspline/curve_s2 new file mode 100644 index 0000000000..65df9cd443 --- /dev/null +++ b/tests/perf/bspline/curve_s2 @@ -0,0 +1,5 @@ +puts "Evaluation of simple curve, sequential, in range" + +pload QAcommands +bsplinecurve c 3 2 0 4 1 4 0 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 +probspline c 10000000 diff --git a/tests/perf/bspline/curve_s3 b/tests/perf/bspline/curve_s3 new file mode 100644 index 0000000000..c0d5980a3e --- /dev/null +++ b/tests/perf/bspline/curve_s3 @@ -0,0 +1,5 @@ +puts "Evaluation of simple curve, random, out of range" + +pload QAcommands +bsplinecurve c 3 2 0 4 1 4 0 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 +probspline c 10000000 -r -100. 100.