1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-24 13:50:49 +03:00

Added tests for performance of bspline curve evaluation

This commit is contained in:
abv
2017-02-24 17:33:11 +03:00
parent be887d7884
commit 41c79a7727
8 changed files with 175 additions and 0 deletions

View File

@@ -57,6 +57,12 @@
#include <HLRAppli_ReflectLines.hxx>
#include <OSD_Timer.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <GeomAdaptor_Curve.hxx>
//=======================================================================
//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 <class AdCurve>
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 <TDF_Tool.hxx>
#include <XCAFDoc_View.hxx>
@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -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.