Python library for Solid Modelling - Cadmium

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

Python library for Solid Modelling - Cadmium

Jayesh Salvi
Hello all,

I would like to share a project with you that I've been working on for
past few weeks. It is inspired by OpenSCAD and tries to achieve same
goal, that's why I am announcing it on this mailing list.

Cadmium is a python library that allows you to write python code to
create primitive objects (Box, Cylinder, Sphere, etc.) and apply CSG
operations (Addition, Subtraction, Intersection) on them to create
advanced solid models. The primitives have support for affine
transformations too (translation, rotation).

The project is in early stages, but it is functional.

Checkout some screenshots at: http://jayesh3.github.com/cadmium/
Get the source and see some example scripts at:
https://github.com/jayesh3/cadmium

I know about the python libraries announced on this list, but Cadmium
is much different from them. It's a completely separate implementation
from OpenSCAD.

Some of Cadmium highlights are:
* The modelling scripts are written in Python, you don't have to learn
any new syntax.
* Most of Cadmium code is written in Python itself. Only <200 lines of
C/C++ code is used to load CGAL
* It has no GUI. Therefore it's light weight. It generates output in
STL format, which can be viewed in STL viewer of your choice. By
dropping GUI requirements, Cadmium sports minimal dependencies. (only
one - CGAL)

Please give it a try and let me know what you think.
Thanks,
--
Jayesh
Twitter: @jyro

Reply | Threaded
Open this post in threaded view
|

Re: Python library for Solid Modelling - Cadmium

Giles Bathgate-2
On 28 May 2011 09:34, Jayesh Salvi <[hidden email]> wrote:
> Hello all,
>
> I would like to share a project with you that I've been working on for
> past few weeks.

Cool,

Have you implemented a way of doing linear extrude? I am currently
having trouble getting RapCAD's linear extrude module to work
optimally.

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: Python library for Solid Modelling - Cadmium

Jayesh Salvi
--
Jayesh



On Sun, May 29, 2011 at 2:11 AM, Giles Bathgate
<[hidden email]> wrote:

> On 28 May 2011 09:34, Jayesh Salvi <[hidden email]> wrote:
>> Hello all,
>>
>> I would like to share a project with you that I've been working on for
>> past few weeks.
>
> Cool,
>
> Have you implemented a way of doing linear extrude? I am currently
> having trouble getting RapCAD's linear extrude module to work
> optimally.

Not yet. Currently I've managed to implement only the CSG operations
and affine transformations. I'll check how linear extrusion algorithm
works.

I assume you are talking about
http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion
Thanks for pointing it out, I didn't know about this OpenSCAD feature before.

>
> Regards
>
> Giles
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

Reply | Threaded
Open this post in threaded view
|

Re: Python library for Solid Modelling - Cadmium

Atrus
Hmm, when I try and use scons I get the following output...

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/cgal-wrapper/csgop.os -c -fPIC -I/usr/local/include src/cgal-wrapper/csgop.cpp
src/cgal-wrapper/csgop.cpp:6:32: fatal error: CGAL/Inverse_index.h: No such file or directory
compilation terminated.
scons: *** [src/cgal-wrapper/csgop.os] Error 1
scons: building terminated because of errors.

Openscad works fine, so I'm not exactly sure what the issue is?

Tim

On Sat, May 28, 2011 at 10:18 PM, Jayesh Salvi <[hidden email]> wrote:
--
Jayesh



On Sun, May 29, 2011 at 2:11 AM, Giles Bathgate
<[hidden email]> wrote:
> On 28 May 2011 09:34, Jayesh Salvi <[hidden email]> wrote:
>> Hello all,
>>
>> I would like to share a project with you that I've been working on for
>> past few weeks.
>
> Cool,
>
> Have you implemented a way of doing linear extrude? I am currently
> having trouble getting RapCAD's linear extrude module to work
> optimally.

Not yet. Currently I've managed to implement only the CSG operations
and affine transformations. I'll check how linear extrusion algorithm
works.

I assume you are talking about
http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion
Thanks for pointing it out, I didn't know about this OpenSCAD feature before.

>
> Regards
>
> Giles
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: Python library for Solid Modelling - Cadmium

Jayesh Salvi-2
The build script assumes that you have CGAL installed in /usr/local/,
that's why it expects to find the header file in
/usr/local/include/CGAL path. If you have CGAL installed elsewhere on
your system, you should edit the CPPPATH and LIBPATH variables in
SConstruct file.

If you don't know which CGAL you are using and assuming you are using
Linux, try "locate CGAL"

If you don't find anything after 'locate', you need to build and
install CGAL 3.8. Follow the instructions at the bottom of this page
https://github.com/jayesh3/cadmium to see how.
--
Jayesh
http://www.3dtin.com
Twitter: @3dtin
Facebook: http://www.facebook.com/3DTin




On Sun, May 29, 2011 at 9:30 AM, Atrus <[hidden email]> wrote:

> Hmm, when I try and use scons I get the following output...
>
> scons: Reading SConscript files ...
> scons: done reading SConscript files.
> scons: Building targets ...
> g++ -o src/cgal-wrapper/csgop.os -c -fPIC -I/usr/local/include
> src/cgal-wrapper/csgop.cpp
> src/cgal-wrapper/csgop.cpp:6:32: fatal error: CGAL/Inverse_index.h: No such
> file or directory
> compilation terminated.
> scons: *** [src/cgal-wrapper/csgop.os] Error 1
> scons: building terminated because of errors.
> Openscad works fine, so I'm not exactly sure what the issue is?
> Tim
> On Sat, May 28, 2011 at 10:18 PM, Jayesh Salvi <[hidden email]>
> wrote:
>>
>> --
>> Jayesh
>>
>>
>>
>> On Sun, May 29, 2011 at 2:11 AM, Giles Bathgate
>> <[hidden email]> wrote:
>> > On 28 May 2011 09:34, Jayesh Salvi <[hidden email]> wrote:
>> >> Hello all,
>> >>
>> >> I would like to share a project with you that I've been working on for
>> >> past few weeks.
>> >
>> > Cool,
>> >
>> > Have you implemented a way of doing linear extrude? I am currently
>> > having trouble getting RapCAD's linear extrude module to work
>> > optimally.
>>
>> Not yet. Currently I've managed to implement only the CSG operations
>> and affine transformations. I'll check how linear extrusion algorithm
>> works.
>>
>> I assume you are talking about
>> http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion
>> Thanks for pointing it out, I didn't know about this OpenSCAD feature
>> before.
>>
>> >
>> > Regards
>> >
>> > Giles
>> > _______________________________________________
>> > OpenSCAD mailing list
>> > [hidden email]
>> > http://rocklinux.net/mailman/listinfo/openscad
>> >
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Python library for Solid Modelling - Cadmium

Triffid Hunter
In reply to this post by Jayesh Salvi
On Sun, May 29, 2011 at 12:18 PM, Jayesh Salvi <[hidden email]> wrote:
> On Sun, May 29, 2011 at 2:11 AM, Giles Bathgate
> <[hidden email]> wrote:
>> Have you implemented a way of doing linear extrude? I am currently
>> having trouble getting RapCAD's linear extrude module to work
>> optimally.
> Not yet. Currently I've managed to implement only the CSG operations
> and affine transformations. I'll check how linear extrusion algorithm
> works.

Isn't linear extrude as simple as duplicating all the 2d object's
vertices along lines parallel to the normal and connecting edges as
appropriate to form faces?

Reply | Threaded
Open this post in threaded view
|

Re: Python library for Solid Modelling - Cadmium

Jayesh Salvi
On Mon, May 30, 2011 at 3:03 PM, Triffid Hunter
<[hidden email]> wrote:

> On Sun, May 29, 2011 at 12:18 PM, Jayesh Salvi <[hidden email]> wrote:
>> On Sun, May 29, 2011 at 2:11 AM, Giles Bathgate
>> <[hidden email]> wrote:
>>> Have you implemented a way of doing linear extrude? I am currently
>>> having trouble getting RapCAD's linear extrude module to work
>>> optimally.
>> Not yet. Currently I've managed to implement only the CSG operations
>> and affine transformations. I'll check how linear extrusion algorithm
>> works.
>
> Isn't linear extrude as simple as duplicating all the 2d object's
> vertices along lines parallel to the normal and connecting edges as
> appropriate to form faces?

That would be one way to implement it. But I think a more generic way
is to use Minkowski sum
http://www.cgal.org/Manual/3.5/doc_html/cgal_manual/Minkowski_sum_3/Chapter_main.html

> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

Reply | Threaded
Open this post in threaded view
|

Re: Python library for Solid Modelling - Cadmium

Giles Bathgate-2
On 30 May 2011 10:46, Jayesh Salvi <[hidden email]> wrote:
> On Mon, May 30, 2011 at 3:03 PM, Triffid Hunter
> <[hidden email]> wrote:
>> Isn't linear extrude as simple as duplicating all the 2d object's
>> vertices along lines parallel to the normal and connecting edges as
>> appropriate to form faces?
>
> That would be one way to implement it. But I think a more generic way
> is to use Minkowski sum
> http://www.cgal.org/Manual/3.5/doc_html/cgal_manual/Minkowski_sum_3/Chapter_main.html

Yep, I have done both approaches, and infact they both work.

So.. Minkowski sum only works when one of the polyhedra are "fully
dimentional" otherwise in debug mode it throws an assertion exception.
Curiously when the source is compiled with -DNDEBUG minkowski actually
works for shells with no volume, but alas the resulting nef polyhedra
don't work with other boolean set operations....also its un-acceptably
slow.

In the other approach, which triffid mentioned I extrude each facet by
copying it at distance h, and then adding the sides.
This works for simple 2D shapes in which the union is represented by a
single complex facet. However now consider 2 triangles that share one
edge but are NOT co-planar e.g:

polyhedron([[0,0,0],[0,10,0],[10,0,0],[10,10,2]],[[0,1,2],[1,3,2]]);

This is not technically 2D (which is why you have no hope of doing a
linear_extrude with this shape properly using openscad)

The problem is that currently in RapCAD I treat the two triangles as
two separate instances, I copy each instance by distance h, add the
sides to both triangles an union two resulting triangular prisms.

An optimal approach would be to copy both the triangles by distance h,
and add the sides of the perimeter of both triangles.

The difficult bit is finding the perimeter of the triangles (which
would just be the four outer edges)

Regards

Giles