Discussion:
[OpenSCAD] Lattice structure
MichaelAtOz
2017-03-23 05:50:26 UTC
Permalink
Hello guys ,
I am writing this message to inquire about the possibility of producing
lattice structures within openscad platform please see the attached image
files ... if anyone has tried them before , would be of great help
with many thanks
Saumyam
<Loading Image...>
A simple lattice structure would be straight forward and a good model to
learn OpenSCAD with.



-----
Admin - PM me if you need anything, or if I've done something stupid...

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!
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21002.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
MichaelAtOz
2017-03-23 05:51:47 UTC
Permalink
p.s. Your post is still flagged as "This post has NOT been accepted by the
mailing list yet", so nobody gets it unless they look.
You need to subscribe to the mailing list
<http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1> ,
and CLICK THE LINK in the registration email.



-----
Admin - PM me if you need anything, or if I've done something stupid...

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!
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21003.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Parkinbot
2017-03-23 11:09:28 UTC
Permalink
OpenSCAD has the problem that rendering can get extremly slow whenever
Boolean operations over a large number of objects come into play. And this
is the front door for producing lattice structures - define a large object
and difference a union of a large number of smaller objects from it.

However, while this is a known major drawback of OpenSCAD, there is a
(somehow clumsy) work-around, which I use frequently to bypass this problem.
I never found out, why the discussion about this was so rudely cut by the
moderator, but you can read it up here:
http://forum.openscad.org/rendering-for-paper-assembly-manual-tp20108p20126.html

I call the approach /lazy union/, because it bypasses intersection checks
for non intersecting elements by definition (note that it can't be used for
intersecting objects). To apply it, you have to generate the objects by code
and stuff them all into a single polyhedron call. I gave some example code
for it.
But it depends on your programming skills, whether you will be able to use
it.





--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21004.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Ronaldo
2017-03-24 01:45:09 UTC
Permalink
If all your latices are extrusions as the left image latice seems to be, you
n = 15;
h = 11;
sx = 120;
sy = 100;
th = 1;
module latice(sx,sy,h,th,n)
linear_extrude(height=h)
difference(){
square([sx,sy]);
m = ceil(n*sy/sx); echo(m);
for(i=[0:n], j=[0:2*m])
translate([(i+(j%2)/2)*sx/n, j*sx/n/2])
rotate(45)
square(sx/n/sqrt(2)-th,center=true);
}
latice(sx,sy,h,th,n);
//translate([0,0,h]) cube([sx,sy,th]);
//translate([0,0,h+th]) latice(sx,sy,h,th,n);
The render of latice() alone is very fast. But, uncommenting the following
two lines, the render time starts to bother.




--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21009.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
s.dwivedi
2017-03-24 06:45:51 UTC
Permalink
this seems to work absolutely fine however I am not able to grasp the
programming bit, could you be more elaborate

from what I have understood , you define a certain latice in 2d followed by
extrusion command , can you explain afterwards ?

also can we do same with a circular mesh structure
<Loading Image...>






--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21010.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
MichaelAtOz
2017-03-24 08:39:41 UTC
Permalink
I don't suppose this is part of your class work?



-----
Admin - PM me if you need anything, or if I've done something stupid...

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!
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21011.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Parkinbot
2017-03-24 12:07:16 UTC
Permalink
That is exactly the point. Anything beyond linear_extruding a 2d object, is
exactly where the problem starts. Try to render (F6) the following small
piece - about 6 minutes on my machine. Then just multiply any dimension sx,
sy, or sz by just 2 and watch how render time grows.
<Loading Image...>
$fn = 20;
n = 2; // joints per 10mm
sx = 20;
sy = 30;
sz = 10;
th = 1;
lattice();
module lattice()
{
for(x=[0:10/n:sx], y=[0:10/n:sy], z=[0:10/n:sz] )
translate([sx/2-x,sy/2-y,sz/2-z])
sphere(th);
for(x=[0:10/n:sx], z=[0:10/n:sz] ) // y bars
translate([sx/2-x,0,sz/2-z])
rotate([90, 0])
cylinder(r=th/2, h=sy, center = true);
for(y=[0:10/n:sy], z=[0:10/n:sz] ) // y bars
translate([0, sy/2-y,sz/2-z])
rotate([0, 90])
cylinder(r=th/2, h=sx, center = true);
for(x=[0:10/n:sx], y=[0:10/n:sy] ) // z bars
translate([sx/2-x, sy/2-y])
cylinder(r=th/2, h=sz, center = true);
}
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21013.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
jon
2017-03-24 12:15:55 UTC
Permalink
I am not sure what "That is exactly the point" means, Parkinbot. I
reviewed the thread, and was still unclear. A number of points were
made in the thread. Exactly what is it that your example, below,
demonstrates, please.

Jon
Post by Parkinbot
That is exactly the point. Anything beyond linear_extruding a 2d object, is
exactly where the problem starts. Try to render (F6) the following small
piece - about 6 minutes on my machine. Then just multiply any dimension sx,
sy, or sz by just 2 and watch how render time grows.
<http://forum.openscad.org/file/n21013/lattice.png>
$fn = 20;
n = 2; // joints per 10mm
sx = 20;
sy = 30;
sz = 10;
th = 1;
lattice();
module lattice()
{
for(x=[0:10/n:sx], y=[0:10/n:sy], z=[0:10/n:sz] )
translate([sx/2-x,sy/2-y,sz/2-z])
sphere(th);
for(x=[0:10/n:sx], z=[0:10/n:sz] ) // y bars
translate([sx/2-x,0,sz/2-z])
rotate([90, 0])
cylinder(r=th/2, h=sy, center = true);
for(y=[0:10/n:sy], z=[0:10/n:sz] ) // y bars
translate([0, sy/2-y,sz/2-z])
rotate([0, 90])
cylinder(r=th/2, h=sx, center = true);
for(x=[0:10/n:sx], y=[0:10/n:sy] ) // z bars
translate([sx/2-x, sy/2-y])
cylinder(r=th/2, h=sz, center = true);
}
doug moen
2017-03-24 14:40:23 UTC
Permalink
Parkinbot is pointing out that the "obvious" way of constructing a 3-D
lattice in OpenSCAD (unioning together the lattice elements) is likely to
be unacceptably slow, so you need to resort to other techniques.
Linear_extrude of a 2-D lattice works, as long as your lattice can be
described that way, and so far, s.dwivedi's examples are all
linear-extrudeable. The more general approach is to use polyhedron, but
that's more difficult. Once you have a big lattice, you have to be careful
not to union it with other shapes, or the performance problem reappears.
This issue (complex lattices vs boolean operations) is a limitation in the
design of OpenSCAD.
Post by jon
I am not sure what "That is exactly the point" means, Parkinbot. I
reviewed the thread, and was still unclear. A number of points were made
in the thread. Exactly what is it that your example, below, demonstrates,
please.
Jon
Post by Parkinbot
That is exactly the point. Anything beyond linear_extruding a 2d object, is
exactly where the problem starts. Try to render (F6) the following small
piece - about 6 minutes on my machine. Then just multiply any dimension sx,
sy, or sz by just 2 and watch how render time grows.
<http://forum.openscad.org/file/n21013/lattice.png>
$fn = 20;
n = 2; // joints per 10mm
sx = 20;
sy = 30;
sz = 10;
th = 1;
lattice();
module lattice()
{
for(x=[0:10/n:sx], y=[0:10/n:sy], z=[0:10/n:sz] )
translate([sx/2-x,sy/2-y,sz/2-z])
sphere(th);
for(x=[0:10/n:sx], z=[0:10/n:sz] ) // y bars
translate([sx/2-x,0,sz/2-z])
rotate([90, 0])
cylinder(r=th/2, h=sy, center = true);
for(y=[0:10/n:sy], z=[0:10/n:sz] ) // y bars
translate([0, sy/2-y,sz/2-z])
rotate([0, 90])
cylinder(r=th/2, h=sx, center = true);
for(x=[0:10/n:sx], y=[0:10/n:sy] ) // z bars
translate([sx/2-x, sy/2-y])
cylinder(r=th/2, h=sz, center = true);
}
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Parkinbot
2017-03-25 23:11:11 UTC
Permalink
Sorry, I somehow replied to the wrong post. My answer was addressed at the 2D
approach of Ronaldo. But Dough perfectly explained my arguments. Thanks.
Post by jon
I am not sure what "That is exactly the point" means, Parkinbot. I
reviewed the thread, and was still unclear. A number of points were
made in the thread. Exactly what is it that your example, below,
demonstrates, please.
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21038.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Carsten Arnholm
2017-03-24 19:40:46 UTC
Permalink
Post by Parkinbot
That is exactly the point. Anything beyond linear_extruding a 2d object, is
exactly where the problem starts. Try to render (F6) the following small
piece - about 6 minutes on my machine. Then just multiply any dimension sx,
sy, or sz by just 2 and watch how render time grows.
<http://forum.openscad.org/file/n21013/lattice.png>
I tried your code on my new Linux machine using 2015.03-1 and found it
(F6) completed in 2 minutes and 48 seconds. I also translated your
OpenSCAD code into AngelScript and ran it through my Carve based boolean
engine on the same computer. It completed in 23 seconds, with a result
that looks similar to openSCAD.

Elsewhere, doug moen mentions that "This issue (complex lattices vs
boolean operations) is a limitation in the design of OpenSCAD."

One could argue that it is probably not so much a limitation in the
design of OpenSCAD but perhaps more a question of the characteristics of
the boolean engines (CGAL vs. Carve).

One thing I found was that creating subgroups (spheres+ybars, xbars,
zbars) was helpful in speeding things up in my code. I am guessing it is
because of bounding box checks.

As mentioned before, I am going to release my carve based engine on
github when I get around to it (need to learn git as well).

Carsten Arnholm
doug moen
2017-03-24 23:54:16 UTC
Permalink
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second. Suppose you
wanted a 100x100x100 grid, instead of 2x4x6? With linear scaling, that
would be more than 7 days of rendering, but union scales non-linearly in
OpenSCAD, and probably in Carv as well.
Post by Carsten Arnholm
Post by Parkinbot
That is exactly the point. Anything beyond linear_extruding a 2d object, is
exactly where the problem starts. Try to render (F6) the following small
piece - about 6 minutes on my machine. Then just multiply any dimension sx,
sy, or sz by just 2 and watch how render time grows.
<http://forum.openscad.org/file/n21013/lattice.png>
I tried your code on my new Linux machine using 2015.03-1 and found it
(F6) completed in 2 minutes and 48 seconds. I also translated your OpenSCAD
code into AngelScript and ran it through my Carve based boolean engine on
the same computer. It completed in 23 seconds, with a result that looks
similar to openSCAD.
Elsewhere, doug moen mentions that "This issue (complex lattices vs
boolean operations) is a limitation in the design of OpenSCAD."
One could argue that it is probably not so much a limitation in the design
of OpenSCAD but perhaps more a question of the characteristics of the
boolean engines (CGAL vs. Carve).
One thing I found was that creating subgroups (spheres+ybars, xbars,
zbars) was helpful in speeding things up in my code. I am guessing it is
because of bounding box checks.
As mentioned before, I am going to release my carve based engine on github
when I get around to it (need to learn git as well).
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
MichaelAtOz
2017-03-25 02:31:46 UTC
Permalink
It's all in the facets

<Loading Image...>



-----
Admin - PM me if you need anything, or if I've done something stupid...

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!
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21021.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
a***@arnholm.org
2017-03-25 11:14:48 UTC
Permalink
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one
major factor, but it isn't the only answer.

My little example showed it is possible to improve ~an order of
magnitude just by using another boolean engine. There are also other
paths to pursue, such as multi-threaded processing, which I will try at
some stage. The numbers I gave were just snapshots of current working
implementations for comparison, both single threaded.

Another thing I tried was observing memory use. I factored the
dimensions up by 2 and watched memory use. For this relatively small
model, OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems
hard to justify. That alone is a major performance issue. My Carve-based
engine was never higher than 400MB ram for the same problem, so you are
looking at an order of magnitude difference there.

Carsten Arnholm
nop head
2017-03-25 12:25:43 UTC
Permalink
So is there anything that would prevent CGAL being replaced by Carve? Does
it miss some features?

I don't think it would be too hard to speed up CGAL by many orders of
magnitude that may be naive. It obviously does make any attempt to skip the
facets that need no modification in a union, which is often all of them.
Post by a***@arnholm.org
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one major
factor, but it isn't the only answer.
My little example showed it is possible to improve ~an order of magnitude
just by using another boolean engine. There are also other paths to pursue,
such as multi-threaded processing, which I will try at some stage. The
numbers I gave were just snapshots of current working implementations for
comparison, both single threaded.
Another thing I tried was observing memory use. I factored the dimensions
up by 2 and watched memory use. For this relatively small model,
OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems hard to
justify. That alone is a major performance issue. My Carve-based engine was
never higher than 400MB ram for the same problem, so you are looking at an
order of magnitude difference there.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
nop head
2017-03-25 12:26:55 UTC
Permalink
Sorry typed the opposite of what I meant.


I don't think it would be too hard to speed up CGAL by many orders of
magnitude, but that may be naive. It obviously doesn't make any attempt to
skip the facets that need no modification in a union, which is often all of
them.
Post by nop head
So is there anything that would prevent CGAL being replaced by Carve? Does
it miss some features?
I don't think it would be too hard to speed up CGAL by many orders of
magnitude that may be naive. It obviously does make any attempt to skip the
facets that need no modification in a union, which is often all of them.
Post by a***@arnholm.org
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one major
factor, but it isn't the only answer.
My little example showed it is possible to improve ~an order of magnitude
just by using another boolean engine. There are also other paths to pursue,
such as multi-threaded processing, which I will try at some stage. The
numbers I gave were just snapshots of current working implementations for
comparison, both single threaded.
Another thing I tried was observing memory use. I factored the dimensions
up by 2 and watched memory use. For this relatively small model,
OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems hard to
justify. That alone is a major performance issue. My Carve-based engine was
never higher than 400MB ram for the same problem, so you are looking at an
order of magnitude difference there.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
noil
2017-03-26 12:03:05 UTC
Permalink
I don't think, that is the main problem.
Even for the amount of faces CGAL does render it often takes way longer,
than it should.
Is it possible, that it renders on the CPU?
Post by nop head
Sorry typed the opposite of what I meant.
I don't think it would be too hard to speed up CGAL by many orders of
magnitude, but that may be naive. It obviously doesn't make any attempt to
skip the facets that need no modification in a union, which is often all of
them.
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21039.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
nop head
2017-03-26 12:46:36 UTC
Permalink
No I don't think CGAL does any actual rendering of pixels. It just
calculates the geometry using the CPU. After that OpenSCAD can render the
results to screen very quickly using OpenCG and your graphics card. When
you pan around with the mouse after F6 it is faster than after F5.
Post by noil
I don't think, that is the main problem.
Even for the amount of faces CGAL does render it often takes way longer,
than it should.
Is it possible, that it renders on the CPU?
Post by nop head
Sorry typed the opposite of what I meant.
I don't think it would be too hard to speed up CGAL by many orders of
magnitude, but that may be naive. It obviously doesn't make any attempt
to
Post by nop head
skip the facets that need no modification in a union, which is often all of
them.
--
View this message in context: http://forum.openscad.org/Lattice-structure-
tp21001p21039.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
nop head
2017-03-26 12:47:19 UTC
Permalink
Sorry OpenCG should be OpenGL.
Post by nop head
No I don't think CGAL does any actual rendering of pixels. It just
calculates the geometry using the CPU. After that OpenSCAD can render the
results to screen very quickly using OpenCG and your graphics card. When
you pan around with the mouse after F6 it is faster than after F5.
Post by noil
I don't think, that is the main problem.
Even for the amount of faces CGAL does render it often takes way longer,
than it should.
Is it possible, that it renders on the CPU?
Post by nop head
Sorry typed the opposite of what I meant.
I don't think it would be too hard to speed up CGAL by many orders of
magnitude, but that may be naive. It obviously doesn't make any attempt
to
Post by nop head
skip the facets that need no modification in a union, which is often all of
them.
--
View this message in context: http://forum.openscad.org/Latt
ice-structure-tp21001p21039.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
noil
2017-03-29 15:44:28 UTC
Permalink
I did not think about pixels, but caluculating the geometry is exactly
something, that should take place on the GPU.
Post by nop head
Sorry OpenCG should be OpenGL.
On 26 March 2017 at 13:46, nop head &lt;
Post by nop head
No I don't think CGAL does any actual rendering of pixels. It just
calculates the geometry using the CPU. After that OpenSCAD can render the
results to screen very quickly using OpenCG and your graphics card. When
you pan around with the mouse after F6 it is faster than after F5.
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21055.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
nop head
2017-03-29 15:57:46 UTC
Permalink
Really, I thought they were dedicated to transforming and rending geometry,
not doing CSG operations like union, intersection and difference.
Post by noil
I did not think about pixels, but caluculating the geometry is exactly
something, that should take place on the GPU.
Post by nop head
Sorry OpenCG should be OpenGL.
On 26 March 2017 at 13:46, nop head &lt;
Post by nop head
No I don't think CGAL does any actual rendering of pixels. It just
calculates the geometry using the CPU. After that OpenSCAD can render
the
Post by nop head
Post by nop head
results to screen very quickly using OpenCG and your graphics card.
When
Post by nop head
Post by nop head
you pan around with the mouse after F6 it is faster than after F5.
--
View this message in context: http://forum.openscad.org/Lattice-structure-
tp21001p21055.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
doug moen
2017-03-29 19:45:27 UTC
Permalink
GPUs can be used for general purpose parallel computing in cases where the
same code is simultaneously executed on many different pieces of data.
There are some restrictions: no recursive functions, no function pointers,
no dynamic memory allocation. Often there is no double precision floating
point arithmetic, only 32 bit.

You can definitely use a GPU to directly render an F-Rep CSG tree onto a
display, without first rendering to polygons. I've got that much working in
my new geometry engine. I think it should be possible to use a GPU to
convert F-Rep into STL, but I'm not at that stage of my project yet.

An interesting question for OpenSCAD is whether you can implement boolean
operations on meshes using a GPU. Ie, a drop in replacement for CGAL or
Carve that runs on the GPU.

I dunno if this has been done. It seems like a challenging problem. A quick
google search doesn't find exactly this, but there is some related tech.

*Approximate* boolean operations on meshes. Page 13 compares performance to
CGAL:
https://pdfs.semanticscholar.org/6bcd/0369f5fe36dc7c807891a241c1c33f9a0e94.pdf

Fast, robust, accurate, multithreaded booleans. No mention of GPU, though.
http://dl.acm.org/citation.cfm?id=2442403

These projects sound more like better alternatives to OpenCSG:
http://www.cc.gatech.edu/~jarek/papers/Blister.pdf
https://people.eecs.berkeley.edu/~sequin/CS285/PAPERS/Zhao_Boolean-on-Solids.pdf

This uses a GPU to compute intersections of NURBS surfaces.
http://www.nvidia.com/content/gtc-2010/pdfs/2171_gtc2010.pdf
Post by nop head
Really, I thought they were dedicated to transforming and rending
geometry, not doing CSG operations like union, intersection and difference.
Post by noil
I did not think about pixels, but caluculating the geometry is exactly
something, that should take place on the GPU.
Post by nop head
Sorry OpenCG should be OpenGL.
On 26 March 2017 at 13:46, nop head &lt;
Post by nop head
No I don't think CGAL does any actual rendering of pixels. It just
calculates the geometry using the CPU. After that OpenSCAD can render
the
Post by nop head
Post by nop head
results to screen very quickly using OpenCG and your graphics card.
When
Post by nop head
Post by nop head
you pan around with the mouse after F6 it is faster than after F5.
--
View this message in context: http://forum.openscad.org/Latt
ice-structure-tp21001p21055.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
nop head
2017-03-29 20:21:05 UTC
Permalink
What we need is a hardware infinite precision rationals unit. That is if
rational representation is the only way to get exact geometry.

When you have circles, cylinders and spheres or any rotation not by
multiples of 90 then most of the vertices become irrational numbers, so it
is no surprise CGAL uses an enormous amount of time and memory trying to
represent them as rationals. Is it possible to do CSG with floats and get
correct results?

It would be interesting to try the sphere and cylinder lattice with
vertices snapped to a fairly course grid to see if it vastly increases
speed and reduces CGAL memory usage. I.e. so that the irrational numbers
become three digit fractions instead of a full floating point mantissa
worth of digits as a numerator.
Post by doug moen
GPUs can be used for general purpose parallel computing in cases where the
same code is simultaneously executed on many different pieces of data.
There are some restrictions: no recursive functions, no function pointers,
no dynamic memory allocation. Often there is no double precision floating
point arithmetic, only 32 bit.
You can definitely use a GPU to directly render an F-Rep CSG tree onto a
display, without first rendering to polygons. I've got that much working in
my new geometry engine. I think it should be possible to use a GPU to
convert F-Rep into STL, but I'm not at that stage of my project yet.
An interesting question for OpenSCAD is whether you can implement boolean
operations on meshes using a GPU. Ie, a drop in replacement for CGAL or
Carve that runs on the GPU.
I dunno if this has been done. It seems like a challenging problem. A
quick google search doesn't find exactly this, but there is some related
tech.
*Approximate* boolean operations on meshes. Page 13 compares performance
https://pdfs.semanticscholar.org/6bcd/0369f5fe36dc7c807891a241c1c33f
9a0e94.pdf
Fast, robust, accurate, multithreaded booleans. No mention of GPU, though.
http://dl.acm.org/citation.cfm?id=2442403
http://www.cc.gatech.edu/~jarek/papers/Blister.pdf
https://people.eecs.berkeley.edu/~sequin/CS285/PAPERS/Zhao_
Boolean-on-Solids.pdf
This uses a GPU to compute intersections of NURBS surfaces.
http://www.nvidia.com/content/gtc-2010/pdfs/2171_gtc2010.pdf
Post by nop head
Really, I thought they were dedicated to transforming and rending
geometry, not doing CSG operations like union, intersection and difference.
Post by noil
I did not think about pixels, but caluculating the geometry is exactly
something, that should take place on the GPU.
Post by nop head
Sorry OpenCG should be OpenGL.
On 26 March 2017 at 13:46, nop head &lt;
Post by nop head
No I don't think CGAL does any actual rendering of pixels. It just
calculates the geometry using the CPU. After that OpenSCAD can render
the
Post by nop head
Post by nop head
results to screen very quickly using OpenCG and your graphics card.
When
Post by nop head
Post by nop head
you pan around with the mouse after F6 it is faster than after F5.
--
View this message in context: http://forum.openscad.org/Latt
ice-structure-tp21001p21055.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
wolf
2017-03-30 22:35:16 UTC
Permalink
What we need is a hardware infinite precision rationals unit.
unquote
If it were that simple . . . How to build even one component of such a
machine, memory capable of storing a single number, at infinite precision,
in a finitely sized space containing a finite amount of matter, as small as
Special Relativity demands our universe is, with lower spatial resolution
limited by the Heisenberg uncertainty principle, I shall leave to Nophead to
explain to all of us.
As far as I know, lies are most effectively told by not mentioning certain
facts - as Nophead did by not mentioning that our universe contains only a
finite amount of matter from which memory may be constructed. Had he
considered it, I don't think he would have lied to himself, as he so clearly
did.
If you want to do CSG operations (unions, . . .) on a computer, you have to
program a routine that handles the intersection of parallel planes, planes
that in Euclidean Geometry do not intersect at all. That isn't so difficult,
but what about planes that are just shy of being parallel? Mathematically,
the procedures needed to calculate the intersection involve a division, by
zero for truly parallel planes, by near zero, for nearly parallel planes. To
solve that, you need to understand Cardinal Numbers, and in particular how
to expand the concept of Cardinal numbers to sets of finite size. As far as
I know, CGAL uses just that understanding to sail around the problems. And
that means it uses rational numbers, or, if you allow me some inaccuracy, it
does not do divisions at all. (In a binary number system, divisions by any
number other than powers of two leads to infinite series of digits, and thus
imprecise results.) And these mathematics tricks, otherwise known as
arbitrary precision arithmetic, take lots of computing time, according to
one source 1000 times as long as without them.
If this number is correct, then parallel computing is not an answer to slow
rendering times either, as you may be able to increase speed say 10fold, but
not 1000fold unless you invest a lot of money in a large GPU farm,
containing hundreds of GPU. Who would be able to afford that?
So here you have another lie: parallel processing will speed up rendering.
Indeed it does, but by how much its proponents never say, or it would not so
ardently be promoted.


. . .That is if rational representation is the only way to get exact
geometry.
. . .
Is it possible to do CSG with floats and get correct results?
. . .
unquote
The answer here is a flat no. It is not possible to get "exact geometry" if
you restrict yourself to floats. And again I must invoke the hated word
"lie" to explain what can be done.
First of all, the so-called "exact answer" is an approximation of reality,
as it implies infinite precision. And infinite precision is not attainable
by any instrumentation in the light of the Heisenberg uncertainty principle.
What Peter Hachenberger, one of the authors of CGAL, has shown in his
doctoral thesis is that CGAL is more robust towards mis-use than the
competition. What I cannot answer here is whether this statement holds for
all possible competitors, or only for those he, and I, have considered. The
lie here is to consider "exact answer" as a bijective mapping of the
computer model onto something that can be produced by a "perfect" printer.
My own work in identifying the causes of "degenerate triangles" has given me
hope that something like an "exact approximation" is possible, as it has led
me to understand the design errors that underpin CGAL, or, better said, the
design flaws arising out of joining CGAL into OpenSCAD. If my current
thinking pans out, I expect to obtain a ten thousandfold speed increase in
rendering objects. The price for this effort is steep, however: It demands
that current OpenSCAD developers are moved from coders (people who can
string together libraries) into programmers (people who consider and
implement the constraints and assumptions underlying those libraries).
I will conclude my remarks with a short quote from issue1258.stl, an
OpenSCAD generated .stl file:
facet normal -1 -4.4983e-08 -4.4983e-08
outer loop
vertex -0.249999 -29.6066 22.3934
vertex -0.25 -20 32
vertex -0.249999 -20 12.7868
endloop
This short excerpt says it quite clearly: whoever coded the .stl generator
had no clue about data accuracy, about what is realistic to report, and what
denotes sheer stupidity and ignorance. Otherwise, it would have read
facet normal -1 0 0
outer loop
vertex -0.25 -29.6066 22.3934
vertex -0.25 -20 32
vertex -0.25 -20 12.7868
endloop
Why? The coder decided to report 6 decimal places. This is quite
appropriate, if not excessive, for an item that is produced with final
dimensions to maybe two and, at best, within four decimal places. But then
he/she should have realized that, firstly, the largest dimension ends at
four places behind the decimal point. Thus, reporting other dimensions to
more places behind the decimal point is a form of bullshitting, of lulling
the user into false trust. There is simply no real difference between
-0.249999 and -0.25. But coding for the first output is less work, in
particular less mental work, than coding for the second output.
As far as lattices go, they can be constructed in OpenSCAD quickly and
rendered within seconds, if you do not involve CGAL at all in generating the
output .stl file, i.e. if you let polyhedron() do all the work. Both points
and faces can be generated with for loops without a problem, but doing so is
not a task for a newbie.
wolf



--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21060.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
MichaelAtOz
2017-03-30 22:52:24 UTC
Permalink
Post by wolf
If it were that simple . . . How to build even one component of such a
machine, memory capable of storing a single number, at infinite precision,
in a finitely sized space containing a finite amount of matter, as small
as Special Relativity demands our universe is
Why limit oneself to just this universe?



-----
Admin - PM me if you need anything, or if I've done something stupid...

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!
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21061.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

a***@arnholm.org
2017-03-25 13:07:16 UTC
Permalink
Post by nop head
So is there anything that would prevent CGAL being replaced by Carve?
Does it miss some features?
Well, esoteric features (IMHO) like Minkowski is not there, so if you
consider it essential it will need an independent implementation. It is
a 3d boolean engine, you still need e.g. Clipper for 2d.

Carsten Arnholm
nop head
2017-03-25 13:37:59 UTC
Permalink
If it has hull and convex decomposition we can make Minkowski.
Post by a***@arnholm.org
Post by nop head
So is there anything that would prevent CGAL being replaced by Carve?
Does it miss some features?
Well, esoteric features (IMHO) like Minkowski is not there, so if you
consider it essential it will need an independent implementation. It is a
3d boolean engine, you still need e.g. Clipper for 2d.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
doug moen
2017-03-25 17:35:32 UTC
Permalink
OpenSCAD is an awesome tool, but I don't think its design is the best for
doing George Hart style fractals, lattices, etc.

Consider Parkinbot's lattice, a union of spheres and cylinders. OpenSCAD
converts these spheres and cylinders into mesh approximations as early as
possible, and then uses a very expensive mesh-based union operator
(currently from CGAL) to perform the union. The performance and memory
consumption degrades non-linearly as $fn gets higher. That will still be
true if OpenSCAD switches to Carve.

A better approach, I think, it to represent spheres and cylinders exactly,
using a very cheap representation (origin, radius, height), and delay the
construction of the mesh until the final stage of rendering, using high
level information from the CSG tree to pick rendering strategies.

OpenSCAD is also single threaded. I think the best performance will result
from doing the rendering on the GPU, because then you can take advantage of
massive parallelism.

I'm interested in exploring these ideas within an open source project.
Post by a***@arnholm.org
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one major
factor, but it isn't the only answer.
My little example showed it is possible to improve ~an order of magnitude
just by using another boolean engine. There are also other paths to pursue,
such as multi-threaded processing, which I will try at some stage. The
numbers I gave were just snapshots of current working implementations for
comparison, both single threaded.
Another thing I tried was observing memory use. I factored the dimensions
up by 2 and watched memory use. For this relatively small model,
OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems hard to
justify. That alone is a major performance issue. My Carve-based engine was
never higher than 400MB ram for the same problem, so you are looking at an
order of magnitude difference there.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
David Coneff
2017-03-25 20:00:21 UTC
Permalink
Doug,

What you're referring to is B-REP (boundary representation), and OpenSCAD
would need to be rebuilt from the ground up to do that unfortunately.
ImplicitCAD, Antimony <http://www.mattkeeter.com/projects/antimony/3/>, and
BRL-CAD are examples of open-source software that does that. I looked into
using them instead, but ran into roadblocks pretty immediately -
ImplicitCAD is built mainly for linux, and none of the dev's have windows
machines to test a windows build on, I tried installing it and couldn't get
it done; Antimony is built for linux and OS-X and has an experimental
windows build (haven't tried it yet); BRL-CAD is probably a great piece of
software for an experienced developer but has a very steep learning curve
since it is meant for managing very large, multi-purpose designs (e.g.,
having a full operational schematic of the parts for a tank, and being able
to both create a nice 3D rendering of it as well as CAD files of each
individual part for giving a manufacturer a dimensional specification for
an order).

Antimony <http://www.mattkeeter.com/projects/antimony/3/> has the most
forward thinking GUI interface that naturally keeps track of the branching
of successive operations on an object (intersections, subtractions, locking
the relation of the dimension of a second part based on a first part,
etc.). If I had a linux OS installed or could get one to dual boot just for
using that piece of software, I would. I believe OpenSCAD's popularity
within the 3D printing community comes from the accessibility of the
documentation, ease of install without errors on every platform, and the
quick-render ability to iterate your design before doing a full render.
ImplicitCAD showed similar promise in being easy to use, but was never
developed to the level that it had the quick render / GUI apparatus to
check your design with each change you make - you'd have to run a render
from the command line and then open the generated image file which is a
rather clunky process, but since it naturally runs multi-threaded from the
ground up with implicit surfaces (B-REP), the render time is much faster
(seconds vs. minutes to hours in OpenSCAD) for relatively simple stuff like
these meshes.

If there were some developers willing to really put in the time, that type
of render engine could probably be integrated into OpenSCAD, but it would
take a lot of effort and you can't complain too much when someone gives you
software for free! I think OpenSCAD's primary usefulness is for either
generating extremely simple models, or modifying existing ones that are
imported. One example is a wire-mesh klein bottle I found on thingiverse
<http://www.thingiverse.com/thing:525567> - it doesn't have an open hole
where the pipe intersects the side of the bottle, so I imported it into
OpenSCAD and did a boolean operation to cut a hole, and added a ring to
create a clean support structure for the intersection of the pipe and the
bottle. The result turned out perfect when I printed it.

While I'd like to do more complicated things with OpenSCAD, it is not
well-suited to do the more organic designs like voronoi meshes. I made a
basic wire-frame library, but since OpenSCAD doesn't like to deal with
for() loops of greater than 10,000 iterations without some great pain,
you're really better off generating mesh point sets using an external
scripting library like SolidPython if you're insistent on using OpenSCAD
for the render itself. I've done a few experiments with SolidPython, and it
is pretty good at generating the polyehdron facet sets that OpenSCAD
understands, and OpenSCAD definitely renders them much faster since it
doesn't have to do any of the successive boolean operations itself.
Post by doug moen
OpenSCAD is an awesome tool, but I don't think its design is the best for
doing George Hart style fractals, lattices, etc.
Consider Parkinbot's lattice, a union of spheres and cylinders. OpenSCAD
converts these spheres and cylinders into mesh approximations as early as
possible, and then uses a very expensive mesh-based union operator
(currently from CGAL) to perform the union. The performance and memory
consumption degrades non-linearly as $fn gets higher. That will still be
true if OpenSCAD switches to Carve.
A better approach, I think, it to represent spheres and cylinders exactly,
using a very cheap representation (origin, radius, height), and delay the
construction of the mesh until the final stage of rendering, using high
level information from the CSG tree to pick rendering strategies.
OpenSCAD is also single threaded. I think the best performance will result
from doing the rendering on the GPU, because then you can take advantage of
massive parallelism.
I'm interested in exploring these ideas within an open source project.
Post by a***@arnholm.org
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one major
factor, but it isn't the only answer.
My little example showed it is possible to improve ~an order of magnitude
just by using another boolean engine. There are also other paths to pursue,
such as multi-threaded processing, which I will try at some stage. The
numbers I gave were just snapshots of current working implementations for
comparison, both single threaded.
Another thing I tried was observing memory use. I factored the dimensions
up by 2 and watched memory use. For this relatively small model,
OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems hard to
justify. That alone is a major performance issue. My Carve-based engine was
never higher than 400MB ram for the same problem, so you are looking at an
order of magnitude difference there.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
David Coneff
2017-03-25 20:21:18 UTC
Permalink
As an aside, Making this sort of lattice structure would be hugely more
efficient in OpenSCAD if the cylinders were replaced with rectangular
cubes. Cubes have such a simple vertex structure that they are handled by
both CGAL and OpenGL with ease. If you're trying to make a lattice of a
certain size and just want to make a mock-up before doing a full render, it
would make more sense to start with code that can replace the geometric
primitive with a simpler one first, and do the final render for STL export
(if you're 3D printing it) with the cylinders later. Ultimately though, the
slowness is a product of how OpenSCAD operates at a pretty base level and
F-REP/ B-REP is the only way to make it faster and truly multi-threaded.
Post by David Coneff
Doug,
What you're referring to is B-REP (boundary representation), and OpenSCAD
would need to be rebuilt from the ground up to do that unfortunately.
ImplicitCAD, Antimony <http://www.mattkeeter.com/projects/antimony/3/>,
and BRL-CAD are examples of open-source software that does that. I looked
into using them instead, but ran into roadblocks pretty immediately -
ImplicitCAD is built mainly for linux, and none of the dev's have windows
machines to test a windows build on, I tried installing it and couldn't get
it done; Antimony is built for linux and OS-X and has an experimental
windows build (haven't tried it yet); BRL-CAD is probably a great piece of
software for an experienced developer but has a very steep learning curve
since it is meant for managing very large, multi-purpose designs (e.g.,
having a full operational schematic of the parts for a tank, and being able
to both create a nice 3D rendering of it as well as CAD files of each
individual part for giving a manufacturer a dimensional specification for
an order).
Antimony <http://www.mattkeeter.com/projects/antimony/3/> has the most
forward thinking GUI interface that naturally keeps track of the branching
of successive operations on an object (intersections, subtractions, locking
the relation of the dimension of a second part based on a first part,
etc.). If I had a linux OS installed or could get one to dual boot just for
using that piece of software, I would. I believe OpenSCAD's popularity
within the 3D printing community comes from the accessibility of the
documentation, ease of install without errors on every platform, and the
quick-render ability to iterate your design before doing a full render.
ImplicitCAD showed similar promise in being easy to use, but was never
developed to the level that it had the quick render / GUI apparatus to
check your design with each change you make - you'd have to run a render
from the command line and then open the generated image file which is a
rather clunky process, but since it naturally runs multi-threaded from the
ground up with implicit surfaces (B-REP), the render time is much faster
(seconds vs. minutes to hours in OpenSCAD) for relatively simple stuff like
these meshes.
If there were some developers willing to really put in the time, that type
of render engine could probably be integrated into OpenSCAD, but it would
take a lot of effort and you can't complain too much when someone gives you
software for free! I think OpenSCAD's primary usefulness is for either
generating extremely simple models, or modifying existing ones that are
imported. One example is a wire-mesh klein bottle I found on thingiverse
<http://www.thingiverse.com/thing:525567> - it doesn't have an open hole
where the pipe intersects the side of the bottle, so I imported it into
OpenSCAD and did a boolean operation to cut a hole, and added a ring to
create a clean support structure for the intersection of the pipe and the
bottle. The result turned out perfect when I printed it.
While I'd like to do more complicated things with OpenSCAD, it is not
well-suited to do the more organic designs like voronoi meshes. I made a
basic wire-frame library, but since OpenSCAD doesn't like to deal with
for() loops of greater than 10,000 iterations without some great pain,
you're really better off generating mesh point sets using an external
scripting library like SolidPython if you're insistent on using OpenSCAD
for the render itself. I've done a few experiments with SolidPython, and it
is pretty good at generating the polyehdron facet sets that OpenSCAD
understands, and OpenSCAD definitely renders them much faster since it
doesn't have to do any of the successive boolean operations itself.
Post by doug moen
OpenSCAD is an awesome tool, but I don't think its design is the best for
doing George Hart style fractals, lattices, etc.
Consider Parkinbot's lattice, a union of spheres and cylinders. OpenSCAD
converts these spheres and cylinders into mesh approximations as early as
possible, and then uses a very expensive mesh-based union operator
(currently from CGAL) to perform the union. The performance and memory
consumption degrades non-linearly as $fn gets higher. That will still be
true if OpenSCAD switches to Carve.
A better approach, I think, it to represent spheres and cylinders
exactly, using a very cheap representation (origin, radius, height), and
delay the construction of the mesh until the final stage of rendering,
using high level information from the CSG tree to pick rendering strategies.
OpenSCAD is also single threaded. I think the best performance will
result from doing the rendering on the GPU, because then you can take
advantage of massive parallelism.
I'm interested in exploring these ideas within an open source project.
Post by a***@arnholm.org
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one major
factor, but it isn't the only answer.
My little example showed it is possible to improve ~an order of
magnitude just by using another boolean engine. There are also other paths
to pursue, such as multi-threaded processing, which I will try at some
stage. The numbers I gave were just snapshots of current working
implementations for comparison, both single threaded.
Another thing I tried was observing memory use. I factored the
dimensions up by 2 and watched memory use. For this relatively small model,
OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems hard to
justify. That alone is a major performance issue. My Carve-based engine was
never higher than 400MB ram for the same problem, so you are looking at an
order of magnitude difference there.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
doug moen
2017-03-25 21:09:58 UTC
Permalink
Hi David.

B-Rep means boundary representation: a shape is represented by its
boundary. OpenSCAD's mesh/polyhedron representation is a kind of B-Rep.
NURBS are another kind of boundary representation. CSG means that you
represent a shape as a tree of primitive shapes and operations on those
shapes (like boolean operations and affine transformations). OpenSCAD
evaluates a program to construct a CSG, which is then converted to a mesh
(B-Rep) using CGAL et al.

I've looked at BRL-CAD, but I encountered the same learning curve problem,
and haven't tried to use it. It seems to use CSG and two kinds of B-Rep
(NURBS and meshes) to represent shapes. I don't see any support for F-Rep.

F-Rep is functional representation. There is no explicit representation of
a shape's boundary. Instead, there is a distance function that maps every
point [x,y,z] in 3-space onto a signed distance value, which indicates the
distance of the point from the boundary of the object, and the sign
indicates whether the point is inside or outside of the object. Antimony
and ImplicitCAD use F-Rep. Although they can export STL files, they can't
directly manipulate B-Rep representations the same way OpenSCAD can.

I've read the source code for ImplicitCAD and Antimony, and I'm currently
trying to build an F-Rep geometry kernel that runs on a GPU, to see if it
will have the performance characteristics I want. F-Rep has very cheap
boolean operations, and avoids the cost of performing boolean operations on
polyhedral approximations of curved surfaces. Also, F-Rep is easy to
parallelize on a GPU. So right now it looks like a good way to achieve my
goals. Eventually, though, I'd like to extend this to an F-Rep/B-Rep hybrid
system, to make it more general purpose.

It would be difficult to integrate my work back into OpenSCAD. One problem
is that my approach represents shapes as functions, and requires a
functional language with first class function values (ie, closures), and
it's very difficult to retrofit this feature into OpenSCAD without breaking
backward compatibility. Another problem is due to the fact that I don't
convert curved surfaces into polygons before applying boolean operations
and other transformations. They remain as mathematically exact curved
surfaces. In OpenSCAD, users rely on the fact that circle, sphere and
cylinder return polygons and polyhedra, not curved shapes. Eg,
circle(r,$fn=6) is a regular hexagon. My system has circle and
regular_polygon as separate primitives. So that would be another backward
compatibility problem.
Post by David Coneff
Doug,
What you're referring to is B-REP (boundary representation), and OpenSCAD
would need to be rebuilt from the ground up to do that unfortunately.
ImplicitCAD, Antimony <http://www.mattkeeter.com/projects/antimony/3/>,
and BRL-CAD are examples of open-source software that does that. I looked
into using them instead, but ran into roadblocks pretty immediately -
ImplicitCAD is built mainly for linux, and none of the dev's have windows
machines to test a windows build on, I tried installing it and couldn't get
it done; Antimony is built for linux and OS-X and has an experimental
windows build (haven't tried it yet); BRL-CAD is probably a great piece of
software for an experienced developer but has a very steep learning curve
since it is meant for managing very large, multi-purpose designs (e.g.,
having a full operational schematic of the parts for a tank, and being able
to both create a nice 3D rendering of it as well as CAD files of each
individual part for giving a manufacturer a dimensional specification for
an order).
Antimony <http://www.mattkeeter.com/projects/antimony/3/> has the most
forward thinking GUI interface that naturally keeps track of the branching
of successive operations on an object (intersections, subtractions, locking
the relation of the dimension of a second part based on a first part,
etc.). If I had a linux OS installed or could get one to dual boot just for
using that piece of software, I would. I believe OpenSCAD's popularity
within the 3D printing community comes from the accessibility of the
documentation, ease of install without errors on every platform, and the
quick-render ability to iterate your design before doing a full render.
ImplicitCAD showed similar promise in being easy to use, but was never
developed to the level that it had the quick render / GUI apparatus to
check your design with each change you make - you'd have to run a render
from the command line and then open the generated image file which is a
rather clunky process, but since it naturally runs multi-threaded from the
ground up with implicit surfaces (B-REP), the render time is much faster
(seconds vs. minutes to hours in OpenSCAD) for relatively simple stuff like
these meshes.
If there were some developers willing to really put in the time, that type
of render engine could probably be integrated into OpenSCAD, but it would
take a lot of effort and you can't complain too much when someone gives you
software for free! I think OpenSCAD's primary usefulness is for either
generating extremely simple models, or modifying existing ones that are
imported. One example is a wire-mesh klein bottle I found on thingiverse
<http://www.thingiverse.com/thing:525567> - it doesn't have an open hole
where the pipe intersects the side of the bottle, so I imported it into
OpenSCAD and did a boolean operation to cut a hole, and added a ring to
create a clean support structure for the intersection of the pipe and the
bottle. The result turned out perfect when I printed it.
While I'd like to do more complicated things with OpenSCAD, it is not
well-suited to do the more organic designs like voronoi meshes. I made a
basic wire-frame library, but since OpenSCAD doesn't like to deal with
for() loops of greater than 10,000 iterations without some great pain,
you're really better off generating mesh point sets using an external
scripting library like SolidPython if you're insistent on using OpenSCAD
for the render itself. I've done a few experiments with SolidPython, and it
is pretty good at generating the polyehdron facet sets that OpenSCAD
understands, and OpenSCAD definitely renders them much faster since it
doesn't have to do any of the successive boolean operations itself.
Post by doug moen
OpenSCAD is an awesome tool, but I don't think its design is the best for
doing George Hart style fractals, lattices, etc.
Consider Parkinbot's lattice, a union of spheres and cylinders. OpenSCAD
converts these spheres and cylinders into mesh approximations as early as
possible, and then uses a very expensive mesh-based union operator
(currently from CGAL) to perform the union. The performance and memory
consumption degrades non-linearly as $fn gets higher. That will still be
true if OpenSCAD switches to Carve.
A better approach, I think, it to represent spheres and cylinders
exactly, using a very cheap representation (origin, radius, height), and
delay the construction of the mesh until the final stage of rendering,
using high level information from the CSG tree to pick rendering strategies.
OpenSCAD is also single threaded. I think the best performance will
result from doing the rendering on the GPU, because then you can take
advantage of massive parallelism.
I'm interested in exploring these ideas within an open source project.
Post by a***@arnholm.org
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one major
factor, but it isn't the only answer.
My little example showed it is possible to improve ~an order of
magnitude just by using another boolean engine. There are also other paths
to pursue, such as multi-threaded processing, which I will try at some
stage. The numbers I gave were just snapshots of current working
implementations for comparison, both single threaded.
Another thing I tried was observing memory use. I factored the
dimensions up by 2 and watched memory use. For this relatively small model,
OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems hard to
justify. That alone is a major performance issue. My Carve-based engine was
never higher than 400MB ram for the same problem, so you are looking at an
order of magnitude difference there.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
David Coneff
2017-03-25 21:50:05 UTC
Permalink
You're right, I mixed up some of the details between F-REP and B-REP. F-REP
definitely seems like the way to go, I'm not certain but I think Blender is
a hybrid F-REP/B-REP system - even simple things like cubes with filleted
corners that would slow down OpenSCAD's engine enormously for manipulation
in the GUI run very smoothly in Blender. It even has a terminal for running
python scripts! Only thing is, it also has an extremely steep learning
curve due to its very multi-purpose nature (animation, model production,
etc.) despite the much slicker interface and active development community
compared to BRL-CAD. I'm probably still going to invest some time in
learning that software as well since it is the fastest path to more organic
designs and creating computationally generated designs with python scripts,
but for the moment I can get more done in a day with OpenSCAD than Blender
since I spend so much time just fighting the GUI and various quirks of
Blender. Any advanced tool is bound to have those problems with a learning
curve though.

If OpenSCAD is to have F-REP as a hybrid system, there will inevitably be
some breaks in the backward compatibility, and IMO that's not something to
be avoided. The use of circle($fn=6) to get a hexagon is at best a hacky
use of the available tool for what the program was at its inception in
order to get the job done. It is better to proceed with being able to use
exact representations and provide alternative functions for regular
polyhedra. OpenSCAD's simplicity of scripting + an easy preview + free to
download is what makes it important to the majority of designers I think.
If development moved in the direction of utilizing the GPU core that nearly
everyone has these days, the performance would be amazing. I have a pretty
decent gaming rig that can handle the excesses of OpenSCAD's RAM usage, but
the single-threaded nature of it really holds it back. If I were a more
knowledgeable programmer I'd volunteer to get into the guts of it, but I
only have a rudimentary understanding of how to use git so far and am still
learning quite a bit. Ultimately though I need to spend time on creating 3D
designs, not the programs that create them, since that's where income is
likely to come from for me and I have a few ideas I'm only a couple steps
from being able to create using OpenSCAD as it is.
Post by doug moen
Hi David.
B-Rep means boundary representation: a shape is represented by its
boundary. OpenSCAD's mesh/polyhedron representation is a kind of B-Rep.
NURBS are another kind of boundary representation. CSG means that you
represent a shape as a tree of primitive shapes and operations on those
shapes (like boolean operations and affine transformations). OpenSCAD
evaluates a program to construct a CSG, which is then converted to a mesh
(B-Rep) using CGAL et al.
I've looked at BRL-CAD, but I encountered the same learning curve problem,
and haven't tried to use it. It seems to use CSG and two kinds of B-Rep
(NURBS and meshes) to represent shapes. I don't see any support for F-Rep.
F-Rep is functional representation. There is no explicit representation of
a shape's boundary. Instead, there is a distance function that maps every
point [x,y,z] in 3-space onto a signed distance value, which indicates the
distance of the point from the boundary of the object, and the sign
indicates whether the point is inside or outside of the object. Antimony
and ImplicitCAD use F-Rep. Although they can export STL files, they can't
directly manipulate B-Rep representations the same way OpenSCAD can.
I've read the source code for ImplicitCAD and Antimony, and I'm currently
trying to build an F-Rep geometry kernel that runs on a GPU, to see if it
will have the performance characteristics I want. F-Rep has very cheap
boolean operations, and avoids the cost of performing boolean operations on
polyhedral approximations of curved surfaces. Also, F-Rep is easy to
parallelize on a GPU. So right now it looks like a good way to achieve my
goals. Eventually, though, I'd like to extend this to an F-Rep/B-Rep hybrid
system, to make it more general purpose.
It would be difficult to integrate my work back into OpenSCAD. One problem
is that my approach represents shapes as functions, and requires a
functional language with first class function values (ie, closures), and
it's very difficult to retrofit this feature into OpenSCAD without breaking
backward compatibility. Another problem is due to the fact that I don't
convert curved surfaces into polygons before applying boolean operations
and other transformations. They remain as mathematically exact curved
surfaces. In OpenSCAD, users rely on the fact that circle, sphere and
cylinder return polygons and polyhedra, not curved shapes. Eg,
circle(r,$fn=6) is a regular hexagon. My system has circle and
regular_polygon as separate primitives. So that would be another backward
compatibility problem.
Post by David Coneff
Doug,
What you're referring to is B-REP (boundary representation), and OpenSCAD
would need to be rebuilt from the ground up to do that unfortunately.
ImplicitCAD, Antimony <http://www.mattkeeter.com/projects/antimony/3/>,
and BRL-CAD are examples of open-source software that does that. I looked
into using them instead, but ran into roadblocks pretty immediately -
ImplicitCAD is built mainly for linux, and none of the dev's have windows
machines to test a windows build on, I tried installing it and couldn't get
it done; Antimony is built for linux and OS-X and has an experimental
windows build (haven't tried it yet); BRL-CAD is probably a great piece of
software for an experienced developer but has a very steep learning curve
since it is meant for managing very large, multi-purpose designs (e.g.,
having a full operational schematic of the parts for a tank, and being able
to both create a nice 3D rendering of it as well as CAD files of each
individual part for giving a manufacturer a dimensional specification for
an order).
Antimony <http://www.mattkeeter.com/projects/antimony/3/> has the most
forward thinking GUI interface that naturally keeps track of the branching
of successive operations on an object (intersections, subtractions, locking
the relation of the dimension of a second part based on a first part,
etc.). If I had a linux OS installed or could get one to dual boot just for
using that piece of software, I would. I believe OpenSCAD's popularity
within the 3D printing community comes from the accessibility of the
documentation, ease of install without errors on every platform, and the
quick-render ability to iterate your design before doing a full render.
ImplicitCAD showed similar promise in being easy to use, but was never
developed to the level that it had the quick render / GUI apparatus to
check your design with each change you make - you'd have to run a render
from the command line and then open the generated image file which is a
rather clunky process, but since it naturally runs multi-threaded from the
ground up with implicit surfaces (B-REP), the render time is much faster
(seconds vs. minutes to hours in OpenSCAD) for relatively simple stuff like
these meshes.
If there were some developers willing to really put in the time, that
type of render engine could probably be integrated into OpenSCAD, but it
would take a lot of effort and you can't complain too much when someone
gives you software for free! I think OpenSCAD's primary usefulness is for
either generating extremely simple models, or modifying existing ones that
are imported. One example is a wire-mesh klein bottle I found on
thingiverse <http://www.thingiverse.com/thing:525567> - it doesn't have
an open hole where the pipe intersects the side of the bottle, so I
imported it into OpenSCAD and did a boolean operation to cut a hole, and
added a ring to create a clean support structure for the intersection of
the pipe and the bottle. The result turned out perfect when I printed it.
While I'd like to do more complicated things with OpenSCAD, it is not
well-suited to do the more organic designs like voronoi meshes. I made a
basic wire-frame library, but since OpenSCAD doesn't like to deal with
for() loops of greater than 10,000 iterations without some great pain,
you're really better off generating mesh point sets using an external
scripting library like SolidPython if you're insistent on using OpenSCAD
for the render itself. I've done a few experiments with SolidPython, and it
is pretty good at generating the polyehdron facet sets that OpenSCAD
understands, and OpenSCAD definitely renders them much faster since it
doesn't have to do any of the successive boolean operations itself.
Post by doug moen
OpenSCAD is an awesome tool, but I don't think its design is the best
for doing George Hart style fractals, lattices, etc.
Consider Parkinbot's lattice, a union of spheres and cylinders. OpenSCAD
converts these spheres and cylinders into mesh approximations as early as
possible, and then uses a very expensive mesh-based union operator
(currently from CGAL) to perform the union. The performance and memory
consumption degrades non-linearly as $fn gets higher. That will still be
true if OpenSCAD switches to Carve.
A better approach, I think, it to represent spheres and cylinders
exactly, using a very cheap representation (origin, radius, height), and
delay the construction of the mesh until the final stage of rendering,
using high level information from the CSG tree to pick rendering strategies.
OpenSCAD is also single threaded. I think the best performance will
result from doing the rendering on the GPU, because then you can take
advantage of massive parallelism.
I'm interested in exploring these ideas within an open source project.
Post by a***@arnholm.org
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one major
factor, but it isn't the only answer.
My little example showed it is possible to improve ~an order of
magnitude just by using another boolean engine. There are also other paths
to pursue, such as multi-threaded processing, which I will try at some
stage. The numbers I gave were just snapshots of current working
implementations for comparison, both single threaded.
Another thing I tried was observing memory use. I factored the
dimensions up by 2 and watched memory use. For this relatively small model,
OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems hard to
justify. That alone is a major performance issue. My Carve-based engine was
never higher than 400MB ram for the same problem, so you are looking at an
order of magnitude difference there.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
doug moen
2017-03-25 22:50:34 UTC
Permalink
I didn't get too far into Blender, because of the learning curve. Blender
supports Bezier curves and NURBS (aka B-Rep), either of which could be used
to represent cubes with rounded corners. However, you are correct, Blender
also supports F-Rep. At least, it has metaballs, which are F-Rep objects,
but I don't know how deep the F-Rep support goes.
Post by David Coneff
You're right, I mixed up some of the details between F-REP and B-REP.
F-REP definitely seems like the way to go, I'm not certain but I think
Blender is a hybrid F-REP/B-REP system - even simple things like cubes with
filleted corners that would slow down OpenSCAD's engine enormously for
manipulation in the GUI run very smoothly in Blender. It even has a
terminal for running python scripts! Only thing is, it also has an
extremely steep learning curve due to its very multi-purpose nature
(animation, model production, etc.) despite the much slicker interface and
active development community compared to BRL-CAD. I'm probably still going
to invest some time in learning that software as well since it is the
fastest path to more organic designs and creating computationally generated
designs with python scripts, but for the moment I can get more done in a
day with OpenSCAD than Blender since I spend so much time just fighting the
GUI and various quirks of Blender. Any advanced tool is bound to have those
problems with a learning curve though.
If OpenSCAD is to have F-REP as a hybrid system, there will inevitably be
some breaks in the backward compatibility, and IMO that's not something to
be avoided. The use of circle($fn=6) to get a hexagon is at best a hacky
use of the available tool for what the program was at its inception in
order to get the job done. It is better to proceed with being able to use
exact representations and provide alternative functions for regular
polyhedra. OpenSCAD's simplicity of scripting + an easy preview + free to
download is what makes it important to the majority of designers I think.
If development moved in the direction of utilizing the GPU core that nearly
everyone has these days, the performance would be amazing. I have a pretty
decent gaming rig that can handle the excesses of OpenSCAD's RAM usage, but
the single-threaded nature of it really holds it back. If I were a more
knowledgeable programmer I'd volunteer to get into the guts of it, but I
only have a rudimentary understanding of how to use git so far and am still
learning quite a bit. Ultimately though I need to spend time on creating 3D
designs, not the programs that create them, since that's where income is
likely to come from for me and I have a few ideas I'm only a couple steps
from being able to create using OpenSCAD as it is.
Post by doug moen
Hi David.
B-Rep means boundary representation: a shape is represented by its
boundary. OpenSCAD's mesh/polyhedron representation is a kind of B-Rep.
NURBS are another kind of boundary representation. CSG means that you
represent a shape as a tree of primitive shapes and operations on those
shapes (like boolean operations and affine transformations). OpenSCAD
evaluates a program to construct a CSG, which is then converted to a mesh
(B-Rep) using CGAL et al.
I've looked at BRL-CAD, but I encountered the same learning curve
problem, and haven't tried to use it. It seems to use CSG and two kinds of
B-Rep (NURBS and meshes) to represent shapes. I don't see any support for
F-Rep.
F-Rep is functional representation. There is no explicit representation
of a shape's boundary. Instead, there is a distance function that maps
every point [x,y,z] in 3-space onto a signed distance value, which
indicates the distance of the point from the boundary of the object, and
the sign indicates whether the point is inside or outside of the object.
Antimony and ImplicitCAD use F-Rep. Although they can export STL files,
they can't directly manipulate B-Rep representations the same way OpenSCAD
can.
I've read the source code for ImplicitCAD and Antimony, and I'm currently
trying to build an F-Rep geometry kernel that runs on a GPU, to see if it
will have the performance characteristics I want. F-Rep has very cheap
boolean operations, and avoids the cost of performing boolean operations on
polyhedral approximations of curved surfaces. Also, F-Rep is easy to
parallelize on a GPU. So right now it looks like a good way to achieve my
goals. Eventually, though, I'd like to extend this to an F-Rep/B-Rep hybrid
system, to make it more general purpose.
It would be difficult to integrate my work back into OpenSCAD. One
problem is that my approach represents shapes as functions, and requires a
functional language with first class function values (ie, closures), and
it's very difficult to retrofit this feature into OpenSCAD without breaking
backward compatibility. Another problem is due to the fact that I don't
convert curved surfaces into polygons before applying boolean operations
and other transformations. They remain as mathematically exact curved
surfaces. In OpenSCAD, users rely on the fact that circle, sphere and
cylinder return polygons and polyhedra, not curved shapes. Eg,
circle(r,$fn=6) is a regular hexagon. My system has circle and
regular_polygon as separate primitives. So that would be another backward
compatibility problem.
Post by David Coneff
Doug,
What you're referring to is B-REP (boundary representation), and
OpenSCAD would need to be rebuilt from the ground up to do that
unfortunately. ImplicitCAD, Antimony
<http://www.mattkeeter.com/projects/antimony/3/>, and BRL-CAD are
examples of open-source software that does that. I looked into using them
instead, but ran into roadblocks pretty immediately - ImplicitCAD is built
mainly for linux, and none of the dev's have windows machines to test a
windows build on, I tried installing it and couldn't get it done; Antimony
is built for linux and OS-X and has an experimental windows build (haven't
tried it yet); BRL-CAD is probably a great piece of software for an
experienced developer but has a very steep learning curve since it is meant
for managing very large, multi-purpose designs (e.g., having a full
operational schematic of the parts for a tank, and being able to both
create a nice 3D rendering of it as well as CAD files of each individual
part for giving a manufacturer a dimensional specification for an order).
Antimony <http://www.mattkeeter.com/projects/antimony/3/> has the most
forward thinking GUI interface that naturally keeps track of the branching
of successive operations on an object (intersections, subtractions, locking
the relation of the dimension of a second part based on a first part,
etc.). If I had a linux OS installed or could get one to dual boot just for
using that piece of software, I would. I believe OpenSCAD's popularity
within the 3D printing community comes from the accessibility of the
documentation, ease of install without errors on every platform, and the
quick-render ability to iterate your design before doing a full render.
ImplicitCAD showed similar promise in being easy to use, but was never
developed to the level that it had the quick render / GUI apparatus to
check your design with each change you make - you'd have to run a render
from the command line and then open the generated image file which is a
rather clunky process, but since it naturally runs multi-threaded from the
ground up with implicit surfaces (B-REP), the render time is much faster
(seconds vs. minutes to hours in OpenSCAD) for relatively simple stuff like
these meshes.
If there were some developers willing to really put in the time, that
type of render engine could probably be integrated into OpenSCAD, but it
would take a lot of effort and you can't complain too much when someone
gives you software for free! I think OpenSCAD's primary usefulness is for
either generating extremely simple models, or modifying existing ones that
are imported. One example is a wire-mesh klein bottle I found on
thingiverse <http://www.thingiverse.com/thing:525567> - it doesn't have
an open hole where the pipe intersects the side of the bottle, so I
imported it into OpenSCAD and did a boolean operation to cut a hole, and
added a ring to create a clean support structure for the intersection of
the pipe and the bottle. The result turned out perfect when I printed it.
While I'd like to do more complicated things with OpenSCAD, it is not
well-suited to do the more organic designs like voronoi meshes. I made a
basic wire-frame library, but since OpenSCAD doesn't like to deal with
for() loops of greater than 10,000 iterations without some great pain,
you're really better off generating mesh point sets using an external
scripting library like SolidPython if you're insistent on using OpenSCAD
for the render itself. I've done a few experiments with SolidPython, and it
is pretty good at generating the polyehdron facet sets that OpenSCAD
understands, and OpenSCAD definitely renders them much faster since it
doesn't have to do any of the successive boolean operations itself.
Post by doug moen
OpenSCAD is an awesome tool, but I don't think its design is the best
for doing George Hart style fractals, lattices, etc.
Consider Parkinbot's lattice, a union of spheres and cylinders.
OpenSCAD converts these spheres and cylinders into mesh approximations as
early as possible, and then uses a very expensive mesh-based union operator
(currently from CGAL) to perform the union. The performance and memory
consumption degrades non-linearly as $fn gets higher. That will still be
true if OpenSCAD switches to Carve.
A better approach, I think, it to represent spheres and cylinders
exactly, using a very cheap representation (origin, radius, height), and
delay the construction of the mesh until the final stage of rendering,
using high level information from the CSG tree to pick rendering strategies.
OpenSCAD is also single threaded. I think the best performance will
result from doing the rendering on the GPU, because then you can take
advantage of massive parallelism.
I'm interested in exploring these ideas within an open source project.
Post by a***@arnholm.org
Post by doug moen
Well, I think that even 23 seconds is a long time for such a trivial
construction. It really ought to be a fraction of a second.
Of course one wants everything at no cost, but that is not going to
happen. It is better to evaluate what the main factors are and what
realistically can be achieved. The number of facets is obviously one major
factor, but it isn't the only answer.
My little example showed it is possible to improve ~an order of
magnitude just by using another boolean engine. There are also other paths
to pursue, such as multi-threaded processing, which I will try at some
stage. The numbers I gave were just snapshots of current working
implementations for comparison, both single threaded.
Another thing I tried was observing memory use. I factored the
dimensions up by 2 and watched memory use. For this relatively small model,
OpenSCAD/CGAL required more than 6GB of ram (64bit), which seems hard to
justify. That alone is a major performance issue. My Carve-based engine was
never higher than 400MB ram for the same problem, so you are looking at an
order of magnitude difference there.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Ronaldo Persiano
2017-03-25 22:55:37 UTC
Permalink
I agree that F-rep is a good way to go. I have implemented a F-rep
evaluation system a few months ago written in OpenSCAD language and have
found how easy is to define not only the boolean operators as other
geometric operators like twist and even solid sweep. But I have faced its
drawbacks too. The main one is the absolute necessity of a feature
detection algorithm (I have not implemented none) which is not easy. Even
Hyperfun which has a worldwide development team has no feature detection
yet. Without feature detection all solid edges seems roughly blended even
if you refine the evaluation grid a lot.

Another issue is the apparent lack of a robust convex hull and minkowsky
algorithms for F-rep. And there is another issue I found trying to model
the intersection of a sphere and a paraboloid: the primitive function
scale. If a primitive function f() is multiplied by a constant the
corresponding solid is not changed as its is the set of points p such
f(p)>=0. But when the primitive is intercepted with another one (the min of
two functions) the relative scale of the two functions matters and the
intersection polygonalization may show very noticeable artifacts. I
observed this issue in my system and were able to reproduce it in Hyperfun.

Anyway, despite those issues I am a big enthusiast of F-rep.
Post by doug moen
Hi David.
B-Rep means boundary representation: a shape is represented by its
boundary. OpenSCAD's mesh/polyhedron representation is a kind of B-Rep.
NURBS are another kind of boundary representation. CSG means that you
represent a shape as a tree of primitive shapes and operations on those
shapes (like boolean operations and affine transformations). OpenSCAD
evaluates a program to construct a CSG, which is then converted to a mesh
(B-Rep) using CGAL et al.
I've looked at BRL-CAD, but I encountered the same learning curve problem,
and haven't tried to use it. It seems to use CSG and two kinds of B-Rep
(NURBS and meshes) to represent shapes. I don't see any support for F-Rep.
F-Rep is functional representation. There is no explicit representation of
a shape's boundary. Instead, there is a distance function that maps every
point [x,y,z] in 3-space onto a signed distance value, which indicates the
distance of the point from the boundary of the object, and the sign
indicates whether the point is inside or outside of the object. Antimony
and ImplicitCAD use F-Rep. Although they can export STL files, they can't
directly manipulate B-Rep representations the same way OpenSCAD can.
I've read the source code for ImplicitCAD and Antimony, and I'm currently
trying to build an F-Rep geometry kernel that runs on a GPU, to see if it
will have the performance characteristics I want. F-Rep has very cheap
boolean operations, and avoids the cost of performing boolean operations on
polyhedral approximations of curved surfaces. Also, F-Rep is easy to
parallelize on a GPU. So right now it looks like a good way to achieve my
goals. Eventually, though, I'd like to extend this to an F-Rep/B-Rep hybrid
system, to make it more general purpose.
It would be difficult to integrate my work back into OpenSCAD. One problem
is that my approach represents shapes as functions, and requires a
functional language with first class function values (ie, closures), and
it's very difficult to retrofit this feature into OpenSCAD without breaking
backward compatibility. Another problem is due to the fact that I don't
convert curved surfaces into polygons before applying boolean operations
and other transformations. They remain as mathematically exact curved
surfaces. In OpenSCAD, users rely on the fact that circle, sphere and
cylinder return polygons and polyhedra, not curved shapes. Eg,
circle(r,$fn=6) is a regular hexagon. My system has circle and
regular_polygon as separate primitives. So that would be another backward
compatibility problem.
doug moen
2017-03-26 14:37:07 UTC
Permalink
Hi Ronaldo.

"F-rep ... the absolute necessity of a feature detection algorithm"

If you use marching cubes to convert F-Rep to STL, then the results look
terrible if you have corners and edges. But this is a solved problem, there
are modern high quality conversion algorithms. For example, the following,
and also Dual Contouring.
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.
73.3235&rep=rep1&type=pdf

The ImpliSolid open source project claims to implement the above algorithm.
I haven't tried their code yet.
https://github.com/sohale/implisolid/

"Another issue is the apparent lack of a robust convex hull and minkowsky
algorithms for F-rep."

Have you found any non-robust convex hull algorithms? If so, please share.
My only idea so far is to convert the shapes to polyhedra first, as part of
a hybrid system.

I haven't tackled Minkowski sum yet. The only paper I found so far is this:
http://www.hyperfun.org/Mink.pdf
Do you know of any other algorithms, even if they aren't robust?

"And there is another issue I found trying to model the intersection of a
sphere and a paraboloid: the primitive function scale. If a primitive
function f() is multiplied by a constant the corresponding solid is not
changed as its is the set of points p such f(p)>=0. But when the primitive
is intercepted with another one (the min of two functions) the relative
scale of the two functions matters and the intersection polygonalization
may show very noticeable artifacts. I observed this issue in my system and
were able to reproduce it in Hyperfun."

I haven't run into this specific problem, as I haven't implemented
polygonalization yet.

Multiplying a distance function by a constant, without doing anything else,
will definitely screw up the distance field without changing the shape, as
you have noted, and that causes a problem for some shape operators. But
that's not how you scale a shape. To scale a distance function f by a
scalar constant c, you use
fscaled(p) = c * f(p/c)
which doesn't mess up the distance field of the result. So maybe I don't
understand exactly what you are doing.

The more general problem is this. For any given shape, there are an
infinite number of distance functions that represent it (all functions
whose zeros lie at the shape's boundary). The "best" distance function is
usually the one that gives the exact Euclidean distance to the closest
boundary, but often we deal with others that only approximate this. Some
shape operations are sensitive to the structure of the distance function,
and need it to satisfy certain properties (eg, it should be Euclidean for
points outside the boundary, for example). My system will provide a
protocol whereby shape operations can specify requirements on the distance
field structure to their shape arguments. That will allow me to implement a
larger set of shape operations that are more robust or have a higher range
of applicability. (I don't know of any other F-Rep systems that work this
way.)
Post by Ronaldo Persiano
I agree that F-rep is a good way to go. I have implemented a F-rep
evaluation system a few months ago written in OpenSCAD language and have
found how easy is to define not only the boolean operators as other
geometric operators like twist and even solid sweep. But I have faced its
drawbacks too. The main one is the absolute necessity of a feature
detection algorithm (I have not implemented none) which is not easy. Even
Hyperfun which has a worldwide development team has no feature detection
yet. Without feature detection all solid edges seems roughly blended even
if you refine the evaluation grid a lot.
Another issue is the apparent lack of a robust convex hull and minkowsky
algorithms for F-rep. And there is another issue I found trying to model
the intersection of a sphere and a paraboloid: the primitive function
scale. If a primitive function f() is multiplied by a constant the
corresponding solid is not changed as its is the set of points p such
f(p)>=0. But when the primitive is intercepted with another one (the min of
two functions) the relative scale of the two functions matters and the
intersection polygonalization may show very noticeable artifacts. I
observed this issue in my system and were able to reproduce it in Hyperfun.
Anyway, despite those issues I am a big enthusiast of F-rep.
Post by doug moen
Hi David.
B-Rep means boundary representation: a shape is represented by its
boundary. OpenSCAD's mesh/polyhedron representation is a kind of B-Rep.
NURBS are another kind of boundary representation. CSG means that you
represent a shape as a tree of primitive shapes and operations on those
shapes (like boolean operations and affine transformations). OpenSCAD
evaluates a program to construct a CSG, which is then converted to a mesh
(B-Rep) using CGAL et al.
I've looked at BRL-CAD, but I encountered the same learning curve
problem, and haven't tried to use it. It seems to use CSG and two kinds of
B-Rep (NURBS and meshes) to represent shapes. I don't see any support for
F-Rep.
F-Rep is functional representation. There is no explicit representation
of a shape's boundary. Instead, there is a distance function that maps
every point [x,y,z] in 3-space onto a signed distance value, which
indicates the distance of the point from the boundary of the object, and
the sign indicates whether the point is inside or outside of the object.
Antimony and ImplicitCAD use F-Rep. Although they can export STL files,
they can't directly manipulate B-Rep representations the same way OpenSCAD
can.
I've read the source code for ImplicitCAD and Antimony, and I'm currently
trying to build an F-Rep geometry kernel that runs on a GPU, to see if it
will have the performance characteristics I want. F-Rep has very cheap
boolean operations, and avoids the cost of performing boolean operations on
polyhedral approximations of curved surfaces. Also, F-Rep is easy to
parallelize on a GPU. So right now it looks like a good way to achieve my
goals. Eventually, though, I'd like to extend this to an F-Rep/B-Rep hybrid
system, to make it more general purpose.
It would be difficult to integrate my work back into OpenSCAD. One
problem is that my approach represents shapes as functions, and requires a
functional language with first class function values (ie, closures), and
it's very difficult to retrofit this feature into OpenSCAD without breaking
backward compatibility. Another problem is due to the fact that I don't
convert curved surfaces into polygons before applying boolean operations
and other transformations. They remain as mathematically exact curved
surfaces. In OpenSCAD, users rely on the fact that circle, sphere and
cylinder return polygons and polyhedra, not curved shapes. Eg,
circle(r,$fn=6) is a regular hexagon. My system has circle and
regular_polygon as separate primitives. So that would be another backward
compatibility problem.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Ronaldo Persiano
2017-03-26 15:22:42 UTC
Permalink
dough,

I am afraid to go into details on this matter within this thread. We may
either open a new one or discuss it privately. So I will address some few
points here.

No, I don't know any even non robust algorithm to compute convex hull of
implicitly-defined models. I have been contacted privately by a forum
member who told me he is working on that.

About minkowski: I have not fully read the Pasko paper; however, they say
in the conclusions that: "Implementation of Minkowski sums for 3D objects
will require parallel or distributed processing; we are planning to use
networked workstations with PVM system. Because the numerical procedure is
quite time consuming, the procedural definition is not directly applicable
in a modern practical modeling system." That was enough for me.

The issue I have observed relates to the choice of the "distance function".
It is not a model scale. We may discuss it elsewhere.
Post by doug moen
Hi Ronaldo.
"F-rep ... the absolute necessity of a feature detection algorithm"
If you use marching cubes to convert F-Rep to STL, then the results look
terrible if you have corners and edges. But this is a solved problem, there
are modern high quality conversion algorithms. For example, the following,
and also Dual Contouring.
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.73.
3235&rep=rep1&type=pdf
The ImpliSolid open source project claims to implement the above
algorithm. I haven't tried their code yet.
https://github.com/sohale/implisolid/
"Another issue is the apparent lack of a robust convex hull and minkowsky
algorithms for F-rep."
Have you found any non-robust convex hull algorithms? If so, please share.
My only idea so far is to convert the shapes to polyhedra first, as part of
a hybrid system.
http://www.hyperfun.org/Mink.pdf
Do you know of any other algorithms, even if they aren't robust?
"And there is another issue I found trying to model the intersection of a
sphere and a paraboloid: the primitive function scale. If a primitive
function f() is multiplied by a constant the corresponding solid is not
changed as its is the set of points p such f(p)>=0. But when the primitive
is intercepted with another one (the min of two functions) the relative
scale of the two functions matters and the intersection polygonalization
may show very noticeable artifacts. I observed this issue in my system and
were able to reproduce it in Hyperfun."
I haven't run into this specific problem, as I haven't implemented
polygonalization yet.
Multiplying a distance function by a constant, without doing anything
else, will definitely screw up the distance field without changing the
shape, as you have noted, and that causes a problem for some shape
operators. But that's not how you scale a shape. To scale a distance
function f by a scalar constant c, you use
fscaled(p) = c * f(p/c)
which doesn't mess up the distance field of the result. So maybe I don't
understand exactly what you are doing.
The more general problem is this. For any given shape, there are an
infinite number of distance functions that represent it (all functions
whose zeros lie at the shape's boundary). The "best" distance function is
usually the one that gives the exact Euclidean distance to the closest
boundary, but often we deal with others that only approximate this. Some
shape operations are sensitive to the structure of the distance function,
and need it to satisfy certain properties (eg, it should be Euclidean for
points outside the boundary, for example). My system will provide a
protocol whereby shape operations can specify requirements on the distance
field structure to their shape arguments. That will allow me to implement a
larger set of shape operations that are more robust or have a higher range
of applicability. (I don't know of any other F-Rep systems that work this
way.)
Post by Ronaldo Persiano
I agree that F-rep is a good way to go. I have implemented a F-rep
evaluation system a few months ago written in OpenSCAD language and have
found how easy is to define not only the boolean operators as other
geometric operators like twist and even solid sweep. But I have faced its
drawbacks too. The main one is the absolute necessity of a feature
detection algorithm (I have not implemented none) which is not easy. Even
Hyperfun which has a worldwide development team has no feature detection
yet. Without feature detection all solid edges seems roughly blended even
if you refine the evaluation grid a lot.
Another issue is the apparent lack of a robust convex hull and minkowsky
algorithms for F-rep. And there is another issue I found trying to model
the intersection of a sphere and a paraboloid: the primitive function
scale. If a primitive function f() is multiplied by a constant the
corresponding solid is not changed as its is the set of points p such
f(p)>=0. But when the primitive is intercepted with another one (the min of
two functions) the relative scale of the two functions matters and the
intersection polygonalization may show very noticeable artifacts. I
observed this issue in my system and were able to reproduce it in Hyperfun.
Anyway, despite those issues I am a big enthusiast of F-rep.
Post by doug moen
Hi David.
B-Rep means boundary representation: a shape is represented by its
boundary. OpenSCAD's mesh/polyhedron representation is a kind of B-Rep.
NURBS are another kind of boundary representation. CSG means that you
represent a shape as a tree of primitive shapes and operations on those
shapes (like boolean operations and affine transformations). OpenSCAD
evaluates a program to construct a CSG, which is then converted to a mesh
(B-Rep) using CGAL et al.
I've looked at BRL-CAD, but I encountered the same learning curve
problem, and haven't tried to use it. It seems to use CSG and two kinds of
B-Rep (NURBS and meshes) to represent shapes. I don't see any support for
F-Rep.
F-Rep is functional representation. There is no explicit representation
of a shape's boundary. Instead, there is a distance function that maps
every point [x,y,z] in 3-space onto a signed distance value, which
indicates the distance of the point from the boundary of the object, and
the sign indicates whether the point is inside or outside of the object.
Antimony and ImplicitCAD use F-Rep. Although they can export STL files,
they can't directly manipulate B-Rep representations the same way OpenSCAD
can.
I've read the source code for ImplicitCAD and Antimony, and I'm
currently trying to build an F-Rep geometry kernel that runs on a GPU, to
see if it will have the performance characteristics I want. F-Rep has very
cheap boolean operations, and avoids the cost of performing boolean
operations on polyhedral approximations of curved surfaces. Also, F-Rep is
easy to parallelize on a GPU. So right now it looks like a good way to
achieve my goals. Eventually, though, I'd like to extend this to an
F-Rep/B-Rep hybrid system, to make it more general purpose.
It would be difficult to integrate my work back into OpenSCAD. One
problem is that my approach represents shapes as functions, and requires a
functional language with first class function values (ie, closures), and
it's very difficult to retrofit this feature into OpenSCAD without breaking
backward compatibility. Another problem is due to the fact that I don't
convert curved surfaces into polygons before applying boolean operations
and other transformations. They remain as mathematically exact curved
surfaces. In OpenSCAD, users rely on the fact that circle, sphere and
cylinder return polygons and polyhedra, not curved shapes. Eg,
circle(r,$fn=6) is a regular hexagon. My system has circle and
regular_polygon as separate primitives. So that would be another backward
compatibility problem.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Ronaldo
2017-03-25 21:27:40 UTC
Permalink
Post by doug moen
A better approach, I think, it to represent spheres and cylinders exactly,
using a very cheap representation (origin, radius, height), and delay the
construction of the mesh until the final stage of rendering, using high
level information from the CSG tree to pick rendering strategies.
OpenSCAD is also single threaded. I think the best performance will result
from doing the rendering on the GPU, because then you can take advantage of
massive parallelism.
Although there are many independent ways OpenSCAD could follow to accelerate
the render, the simpler one that could give us immediate gain is to use
bounding boxes (and/or even better octrees). An array of just 6x6 disjoint
spheres takes almost 140 sec to render in my machine, about 75% of the
running time is needed when they overlap.
Post by doug moen
r = 10;
//s = 25; // disjoint
s = 15; // overlap
n = 6;
for(i=[0:n-1], j=[0:n-1]) translate([s*i,s*j,0]) sphere(r);
--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21034.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
s.dwivedi
2017-03-24 10:42:42 UTC
Permalink
this is the design I intend to develop as a scaffold system



--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21012.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Ronaldo
2017-03-24 22:27:50 UTC
Permalink
Post by s.dwivedi
this seems to work absolutely fine however I am not able to grasp the
programming bit, could you be more elaborate
from what I have understood , you define a certain latice in 2d followed
by extrusion command , can you explain afterwards ?
also can we do same with a circular mesh structure
In my last code, the for is responsible to generate the array of squares
corresponding to the holes of the latice. Subtracting this array from a
rectangle with the latice dimensions give us a 2D section of the latice. The
linear_extrude makes it emerge to the 3D world.

To have a latice with a shape that is no longer a rectange, it is just a
question of changing the square([sx,sy]) by another 2D polygon like a circle
for instance. You may try using

translate([sx,sy]/2) scale([sx,sy]/2) circle(1,$fn=16);

instead of square([sx,sy]) . This will give you a planar latice anyway.

If your latice has to be deformed, let's say, to a spherical shape, this
code is not useful anymore because there is no way to apply non-linear
transforms to an OpenSCAD object. In this last case, the only way I know is
to define the latice (or its holes, to be precise) as a lazzy union of
(deformed) polyhedra, as Parkinbot and doug moen pointed out.



--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21019.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
s.dwivedi
2017-03-25 04:01:25 UTC
Permalink
this explains it very clearly , the code seems to work fine.While extruding
it followed by rendering the final object it takes a few minutes.Open SCAD
does offer a good environment to perform a range of operations.

Prior to the start of my work while doing initial research I came across an
article that describes possibility of generating so called 'Selective space
structures' , that enables to generate these reticulated mesh arrays , I
believe it involves complex algorithm designs but nonetheless OpenScad works
fine


http://www.georgehart.com/rp/10-3.html
<http://www.georgehart.com/rp/10-3.html>






--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21022.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Ronaldo
2017-03-25 16:32:54 UTC
Permalink
Post by s.dwivedi
Prior to the start of my work while doing initial research I came across
an article that describes possibility of generating so called 'Selective
space structures' , that enables to generate these reticulated mesh arrays
, I believe it involves complex algorithm designs but nonetheless OpenScad
works fine
http://www.georgehart.com/rp/10-3.html
<http://www.georgehart.com/rp/10-3.html>
What a beautiful lattice! At least that one can be roughly modeled with
OpenSCAD.

<Loading Image...>
Post by s.dwivedi
// lattice data in the form [ vertex list, path list ]
lat = [ [ [0,0,4], [0,1,3], [1,1,2], [1,0,1], [0,0,0],
[4,4,4], [3,3,4], [3,2,3], [4,1,3], [4,0,4],
[0,4,0], [1,4,1], [2,3,1], [3,3,0], [4,4,0],
[2,2,2] ]/4,
[ [0,1,2,3,4], [5,6,7,8,9], [10,11,12,13,14],
[2,15,7], [15,12]] ];
WellsLattice(lat,20,3,3,3,1);
module WellsLattice(p,size,nx,ny,nz,th)
for(i=[0:nx-1])
for(j=[0:ny-1])
for(k=[0:nz-1])
color([1,0,0,2*(k/nz+j/ny+i/nx)/9+1/3]) // unnecessary
translate([i,j,k]*size)
latticeVoxel(p,size,th);
module latticeVoxel(p,size,th) {
for(pi=p[1]){
line = size*[for(nj=pi) p[0][nj]];
polyline(line,th=th);
}
}
module polyline(p,th)
for(i=[0:len(p)-2]){
hull() {
translate(p[i]) sphere(th*1.5);
translate((p[i+1]+p[i])/2) sphere(th/2);
}
hull() {
translate(p[i+1]) sphere(th*1.5);
translate((p[i+1]+p[i])/2) sphere(th/2);
}
}
The preview of a 4x4x4 lattice is very fast. The render took 2 min (3x3x3),
3.5 min (4x4x3) and 5.5 min (4x4x4) in my rather old machine.

Geroge Hart's images are far more smooth than mine. His technique is to make
a polyhedron model with triangulated faces (like mine) and apply a
subdivision method (such as Loop's one) to the surface. That would be
feasible to be done in OSCAD if we had a 2D manifold triangulation data
structure and a way to retrieve vertex data from a model. With these two
resources, organic model would be possible in OSCAD.




--
View this message in context: http://forum.openscad.org/Lattice-structure-tp21001p21029.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Loading...