[OpenSCAD] Do empty nodes take time in the implicit union ? -or- Slow rendering of recursive models.

Ivo ivo.knutsel at gmail.com
Fri Apr 17 15:45:16 EDT 2015


I'm doing lots-of-non-unionable things again and have noticed that recursive
definitions render slower than non recursive definitions. The preview is
just as fast.

Here is my problem, workaround, and problem with the workaround :
Non-unioning renders are slow in OpenSCAD due to the implicit top level
union. The "-lazyunion" flag is not available to me on Windows. Rendering
performance seems to be O(n^2). 

My workaround is to number each object in the openscad design and make the
design so that i can selectively render objects form a range of objects. I
use this design in a script where i render a range of numbered objects and
merge the generated .stl files. As the objects do not interact, merging
stl's is simple. Performance seems to be around O(n).

I'm now doing designs that can most comfortably be described recursively,
the position of object n+1 depends on object n, even though object n is
disabled from rendering itself. What i'm seeing now is that in a chain of 20
objects, rendering only the first 10 is much faster than rendering the last
10, 45 seconds vs 128 seconds. The generated files are almost the same size,
and have the same number of objects.

Recursive #1 -#10 V 11880 F 3960   46 sec
Recursive #11-#20 V 11880 F 3960  134 sec
Recursive #20     V  1198 F  396   22 sec
Recursive #0      V  1188 F  396    1 sec

Iterative #1 -#10 V 11880 F 3960    8 sec
Iterative #11-#20 V 11880 F 3960   11 sec
Iterative #20     V  1188 F  396    1 sec
Iterative #0      V  1188 F  396    1 sec

========== code ==========

NUDGE = 1;

$fs=0.1;

module thing(number,firstnumber,lastnumber) {
  rotate([90,0,0]) {
  if ((number >= firstnumber) && (number <= lastnumber))
  {
    difference() {
      union() {
        cylinder(h=10,r1=6,r2=6,center=true);
        rotate([0,90,0]) translate([0,0,25.5])
cylinder(h=40,r1=3,r2=3,center=true);
      }
      cylinder(h = 10 + (2 * NUDGE),r1=4,r2=4,center=true);
    }
  }
  rotate([180,90,90]) translate([-20,0,0]) children();
}
}


module thing_r(count,number,firstnumber,lastnumber) {
  if (count >= 0) {
    thing(number,firstnumber,lastnumber) {
      thing_r(count-1,number+1,firstnumber,lastnumber) 
      {
      }
    }
  }
}

// first = 11;
// last  = 20;

module iterativethings(first,last)
{
  for(i= [0:10]) {
    translate([i*25,-i*25,0]) {
      translate([25,0,0]) 
      rotate([0,0,-90]) 
      thing(i*2+1,first,last){};
      thing(i*2,first,last){};
    }
  }
}

module nestedthings(first,last)
{
  thing(0,first,last) {
    thing(1,first,last) {
      thing(2,first,last) {
        thing(3,first,last) {
          thing(4,first,last) {
            thing(5,first,last) {
              thing(6,first,last) {
                thing(7,first,last) {
                  thing(8,first,last) {
                    thing(9,first,last) {
                      thing(10,first,last) {
    thing(11,first,last) {
      thing(12,first,last) {
        thing(13,first,last) {
          thing(14,first,last) {
            thing(15,first,last) {
              thing(16,first,last) {
                thing(17,first,last) {
                  thing(18,first,last) {
                    thing(19,first,last) {
                      thing(20,first,last) {
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

module recursivethings(first,last)
{
  thing_r(20,0,first,last) {}
}

first = 1;
last = 20;
// iterativethings();
// nestedthings();
echo("Rendering objects ",first," to ",last);
iterativethings(first,last);
// nestedthings(first,last);
// recursivethings(first,last);



  





--
View this message in context: http://forum.openscad.org/Do-empty-nodes-take-time-in-the-implicit-union-or-Slow-rendering-of-recursive-models-tp12408.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list