A Nurbs Optimization (Getting A Point On A Bezier Curve)

So over the course of doing research to understand nurbs basis functions and tangents I realized that pre-computing the basis functions for the curve could save some time.


Initially I tried it just comparing a simple python api function to the MFnNurbsSurface.getPointAtParam method. In that test my function was noticeably slower than the built-in api command, but it was close enough that I figured doing it in C++ would close the gap.


So I wrote up a simple test MPxNode to compare these two methods of computing a point on a curve (just for the specific case of a single-segment cubic nurbs curve).


if (useCache_val)

{

for (unsigned k = 0; k < 100000; k++)

{

res_point = points[0] * pow(1.0 - param_val, 3);

res_point += points[1] * (3*param_val * pow(1.0 - param_val, 2));

res_point += points[2] * (3 * pow(param_val,2) * (1.0 - param_val));

res_point += points[3] * pow(param_val,3);

}

}

else

{

for (unsigned k = 0; k < 100000; k++)

mFnCurve.getPointAtParam(param_val, res_point);

}



and my tests showed that "hard coding" the basis function calculation is almost twice as fast as getPointAtParam. Some of that speed improvement will get eaten up once I make the necessary changes to make this work on nurbs curves with multiple spans, but it's a promising result and could help me loosen the getPointAtParam bottleneck the translateUVN deformer has right now. It may even be an important step towards computing it on the GPU :).

Featured Posts
Recent Posts
Archive