[OpenSCAD] STL without render?

Ronaldo rcmpersiano at gmail.com
Thu Jun 2 21:58:36 EDT 2016


I did some very basic speed tests and even so the results were very
surprising.

A sphere with 250000 facets ($fn=500) takes virtually no time to render
(less than 1sec). But if you render the union of a few disjoint spheres the
time grows very fast:

>                total #        total         total #
>                facets         time        of spheres ($fn=20)
> 		   362          0s              1 
> 		  3100        31s            10
> 		 31000      550s           100

The union of 10 coincident spheres (r=10, $fn=20) spent 800s!, that is much
more than 10 similar disjoint spheres.

What was a lot surprising for me was the time only one refined cylinder
spent to render.

> 		# facets           time
> 		 50000               7s
> 		100000             29s
> 		200000           129s
> 		250000           212s

To confirm that using polyhedron is faster, I wrote the following code that
is able to generate a set (union) of disjoint "spheres"  using only one call
of polyhedron:

> n = 20; // $fn
> m = n/2;
> N = 2000; // number of spheres
> radius = 10;
> 
> unitary_circle = [ for(i=[0:n]) [ cos(360*i/n), sin(360*i/n), 0 ] ];
> // sphere 
> sphere_vertices  = radius*[ for( j=[-m/2:m/2], p=unitary_circle ) 
>                             cos(180*j/m) * p + [0, 0, sin(180*j/m)] ];
> nvert = len(sphere_vertices);
> 
> // triangulated faces of the sphere
> faces = concat(
>             [ for(i=[0:n-1]) 
>                     [ 0, n+i+1, n+i+2 ] ] ,
>             [ for(j=[1:m-1], i=[0:n-1]) 
>                     [ (n+1)*j+i+1, (n+1)*j+i, (n+1)*(j+1)+i ] ] ,
>             [ for(j=[1:m-1], i=[0:n-1]) 
>                     [ (n+1)*j+i+1, (n+1)*(j+1)+i, (n+1)*(j+1)+i+1 ] ] ,
>             [ for(i=[0:n-1]) 
>                     [ (n+1)*(m-1)+i, (n+1)*(m+1)-1, (n+1)*(m-1)+i+1] ] ) ; 
> 
> // vertices of the union of N spheres
> unispheres = [ for(k=[1:N], p=sphere_vertices) p+[25*k,0,0] ];
> 
> // facets of the union of N spheres
> unifaces  = [ for(k=[1:N], f=faces) [for(i=f) i+nvert*(k-1) ] ];
> 
> polyhedron( points = unispheres, faces = unifaces);
> sphere(10); // a regular sphere

As expected, the set of spheres generated by this code renders a lot faster
than the regular union of OpenSCAD spheres. And the time seems to grow
linearly:

> timing of a set of sphere in one polyhedron
>                # facets       time        # spheres
>                  40000            2s         100
> 		400000          22s        1000 

A neuron with just 1600 disjoint $fn=20 spheres will require a lot of time
to render. I don't believe that doing hulls between spheres and the
cylinders would result in a significant gain because those parts need to be
unioned and that is the bottleneck. To get a significant reduction in the
render time you will need to code the generation of vertices and facets to
be sent to polyhedron as the code above do. Doing that for a whole neuron is
a huge task.

The lesson here is: to do CSG operations with B-rep (the internal
representation CGAL uses) works only for small number of primitives. To deal
with a great number of primitives OpenSCAD needs to look for alternative
internal representations.




--
View this message in context: http://forum.openscad.org/STL-without-render-tp17503p17543.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list