RhinoOffsetCurveOnSrf speeding

Hello everyone!

I’m using RhinoOffsetCurveOnSrf in for loop in which I need to find offsets of one curve for different distances. I’ve noticed that this function spends approximately same time for every offset. Since my vector of distance is about 20 distances and I coll this loop several times (about 500 times) in my algorithm the algorithm is very slow. I was wandering is it possible to calculate offset curves for all my distances at ones?

This is the loop that I’m asking to be reduced

for (int i=0; i<dist.size(); i++)
//call RhinoOffsetCurveOnSrf for every dist
//and collect resulting curves

I guess you could parallelize the calls to offset curve on surface. This will speed up if you have multi-core processor(s). For example, in C++ you can use OpenMP; in C# Task Parallel Library.

Another way you could possibly do this is to use not 20 but maybe 5 distances, and interpolate the curve control points in between. The “in between” curves, however, may not be exactly on the surface, especially if the surface is not very smooth.

Yep, using a parallel for loop would be my suggestion too. That seems like a quick fix to at least help improve the speed.

Hello again

Thanks for the suggestions, I tried to use OpenMP but since I haven’t use parallel computing I’m not sure if I use it wright because computing time is still the same. Here is how I use it:

pragma omp parallel shared (2) private ( i )

pragma omp parallel for

for (int i = 0;  i < forCount;  i++)
    //code for offset

And about the second suggestion to interpolate curve control points in between I don’t know how to find those control points since I have ON_Curve object.

Thanks for the advice!

You need to initialize your OpenMP code first. I’m not an expert at all but something along the lines of the code below should be called at the start of your command code.

// get the number of processors
int nProcs = omp_get_num_procs();
// set the number of OpenMP threads equal to number of processors
// use this to test number of threads 
nProcs = omp_get_num_threads(); 

You need to enable Open MP in your C++ project settings in order for the parallel for pragmas to work