reusing unions objects?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

reusing unions objects?

Antonin
This post has NOT been accepted by the mailing list yet.
Is there a way in Openscad to reuse an object that is made from the union of many smaller objects without recalculating it every time?

For exemple, I'm creating a object with a for loop that has n steps. But the shape repeats itself every n/10 steps, with only a translation difference. Is there a way to reuse the shape of the union of the n/10 steps, by doing 10 translations instead of redoing the whole calculation n times?

The goal of this is to save calculation time.
ajs
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

ajs
Hello there, I have a similar OpenSCAD design, the way I handled it (just yesterday!) was to export the "unit piece" to STL then I made a new model that imported and translated the STL unit from within a loop.  It worked for me but I really do not know if it shortened overall rendering time.  My unit piece took about an hour to render, I put 20 of them together, I hit render and went to bed.  They were done about 7 hours later....
tp3
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

tp3
On 03/13/2016 05:04 PM, Antonin wrote:
> Is there a way in Openscad to reuse an object that is made from the
> union of many smaller objects without recalculating it every time?
>
While the application is running, the cache should take care of
this. Having a persistent cache that would be able to work across
application starts is on the to-do list.

As additional helper, it's possible to add render() calls in the
model. This might slow down the first preview but allow OpenSCAD
to cache that part of the model as render() basically forces the
actual mesh to be calculated at this point.

That said, OpenSCAD currently struggles with a huge amount of
small objects as the underlying calculation engine is very slow
for unions. In some cases it might help to find a different way
to generate the model geometry (e.g. using 2D + extrusion, or
directly generating more complex polyhedrons). But that's very
model specific, so it's not possible to give anything like:
"Do this change and that will fix all performance issues".


On 03/13/2016 05:16 PM, ajs wrote:
> was to export the "unit piece" to STL then I made a new model
> that imported and translated the STL unit from within a loop.
>
In some cases that can speed up the whole model generation,
depending on where the performance hit comes from. In most
cases it will not help much as it's often the top level
unions that have the most vertices and therefor also need
the most time.

Using STL as external cache also create a huge risk of issues
as the export sometimes creates STL files that cause problems
when importing those again.

ciao,
  Torsten.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

cacb
On 13. mars 2016 20:15, Torsten Paul wrote:
> That said, OpenSCAD currently struggles with a huge amount of
> small objects as the underlying calculation engine is very slow
> for unions. In some cases it might help to find a different way
> to generate the model geometry (e.g. using 2D + extrusion, or
> directly generating more complex polyhedrons).

I have experimented generating polyhedrons using carve and saving them
in OpenSCAD format (using .csg files). Theoretically, one could then do
in OpenSCAD:

module my_thing()
{
    include <my_thing.csg>
}

my_thing();

This works just fine for display F5/F6/F12, but I am having no luck
doing any further boolean operations in OpenSCAD with my_thing(), even
though I know for sure the polyhedron contained is water tight.

i.e. the following typically fails:

difference()
{
    my_thing();
    cylinder(h=150,r=15,center=true);
}

This is different from doing the same difference in carve, which works.
I guess this problem reflects differences in requirements to polyhedrons
in OpenSCAD and carve.

If the above had worked in OpenSCAD, you would already have a
"persistent cache". I guess if you could export an OpenSCAD generated
polyhedrons (result of booleans) to a .csg or .scad file it might still
work.

Carsten Arnholm

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

jpmendes
In reply to this post by Antonin
In your case pre-rendering the basic shape should solve your problem.
In some cases for speed reasons you may have to save some rendered modules as .stl's and then import them to continue the work. If the saved stl's are well formed you may still execute boolean operarations with them, however sometimes is not possible.

jpmendes
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

MichaelAtOz
Administrator
In reply to this post by Antonin
In case your question was more basic, there are modules.

So you can do:

module ten_steps() {
  for ... //  your code that does the n/10 steps
}

for(i=[0:10:100])
  translate(whatever)
    ten_steps();

In theory the first run of ten_steps() will create the cached object, so it should not need to be regenerated.
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

cacb
On 14. mars 2016 03:28, MichaelAtOz wrote:
> for(i=[0:10:100])
>    translate(whatever)
>      ten_steps();
>
> In theory the first run of ten_steps() will create the cached object, so it
> should not need to be regenerated.

This comes at a considerable cost, does it not? The cache needs to be
somewhere. When I look at the memory use in an OpenSCAD run it tends to
just increase and rarely (never?) decrease. If the model is large
enough, the memory requirements can cause crashes. In such cases it
would be better to have an option to disable caching.

Carsten Arnholm


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

nophead
I think that is just the way C programs work. As the heap expands it page faults and the OS allocates more virtual memory. When you free some object's memory it just gets added to a lists of free chunks for reuse by the heap manager. It doesn't shrink the virtual address space as it would leave a gap in it. If it doesn't get used then the OS might page it out, freeing up physical memory, but the virtual space only ever increase.

On 14 March 2016 at 17:48, Carsten Arnholm <[hidden email]> wrote:
On 14. mars 2016 03:28, MichaelAtOz wrote:
for(i=[0:10:100])
   translate(whatever)
     ten_steps();

In theory the first run of ten_steps() will create the cached object, so it
should not need to be regenerated.

This comes at a considerable cost, does it not? The cache needs to be somewhere. When I look at the memory use in an OpenSCAD run it tends to just increase and rarely (never?) decrease. If the model is large enough, the memory requirements can cause crashes. In such cases it would be better to have an option to disable caching.

Carsten Arnholm


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

cacb
On 14. mars 2016 19:10, nop head wrote:
> I think that is just the way C programs work. As the heap expands it page
> faults and the OS allocates more virtual memory. When you free some
> object's memory it just gets added to a lists of free chunks for reuse by
> the heap manager. It doesn't shrink the virtual address space as it would
> leave a gap in it. If it doesn't get used then the OS might page it out,
> freeing up physical memory, but the virtual space only ever increase.

No, this is not generally true. I've written many programs that release
memory along the way, and it shows up as reduced memory footprint in the
operating system. It depends on how programs are written.

However, regardless of how an application returns memory to the OS (or
not), the fact that OpenSCAD keeps consuming more and more memory, means
there is something not quite right, because it really should not be
required.

For the "many holes" example posted by Maël Naccache 03. march, the
memory requirement in OpenSCAD generally just grows in one direction
(up) to more than 900MB (Win7 2015.03-2). For the same example, in my
experimental implementation using carve, the memory use rises and falls
many times between 50-150 MB only, the final results are similar in
resolution. I don't know what OpenSCAD does here, but the memory use is
clearly not optimal. If this has to do with caching I cannot say, but I
would check it.

Carsten Arnholm




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

Alan Cox
In reply to this post by nophead
On Mon, 14 Mar 2016 18:10:42 +0000
nop head <[hidden email]> wrote:

> I think that is just the way C programs work. As the heap expands it page
> faults and the OS allocates more virtual memory. When you free some
> object's memory it just gets added to a lists of free chunks for reuse by
> the heap manager. It doesn't shrink the virtual address space as it would
> leave a gap in it. If it doesn't get used then the OS might page it out,
> freeing up physical memory, but the virtual space only ever increase.

In the Linux case at least that is configurable. It doesn't normally
matter however as any unreturned memory will be idle and so just dumped
out to swap when other processes need RAM.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reusing unions objects?

MichaelAtOz
Administrator
In reply to this post by cacb
cacb wrote
When I look at the memory use in an OpenSCAD run it tends to
just increase and rarely (never?) decrease. If the model is large
enough, the memory requirements can cause crashes. In such cases it
would be better to have an option to disable caching.
Design/Flush_caches
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!