Python example of Polyhedron_incremental_builder_3 ?

46 views
Skip to first unread message

Patrick Surry

unread,
May 10, 2012, 1:09:16 PM5/10/12
to cgal-bindi...@googlegroups.com
I see the Modifier_base class is wrapped up (along with a Build_triangle() and Build_square() stub class which seems odd?) but is there an example of how I can use it from Python?  Perhaps something along the lines of the incremental builder example in the CGAL documentation:
examples/Polyhedron/polyhedron_prog_incr_builder.cpp

Thanks,
Patrick

Sebastien Loriot (GeometryFactory)

unread,
May 10, 2012, 1:57:28 PM5/10/12
to cgal-bindi...@googlegroups.com
On 05/10/2012 07:09 PM, Patrick Surry wrote:
> I see the Modifier_base class is wrapped up (along with a Build_triangle() and Build_square() stub class which seems odd?) but is there an example of how I can use it from Python? Perhaps something along the lines of the incremental builder example in the CGAL documentation:
>
> examples/Polyhedron/polyhedron_prog_incr_builder.cpp <../../../examples/Polyhedron/polyhedron_prog_incr_builder.cpp
>>
>
>
> Thanks,
> Patrick
>
Hello,

I just added an example,
see this commit:
http://code.google.com/p/cgal-bindings/source/detail?r=aa764bbf3679468ba127dc5dbc724afaeb48336d

FYI, a more complicated example is done in Java.

Sebastien.

Patrick Surry

unread,
May 10, 2012, 4:00:58 PM5/10/12
to cgal-bindi...@googlegroups.com
Thanks - I guess I'd like to be able to write the derived class in Python, i.e. instead of 

P = Polyhedron_3()
modifier=Polyhedron_3_Modifier_1()
P.delegate(modifier.get_modifier())
print P.size_of_vertices()

I just want to write a Python function to model the Modifier.operator(), e.g.:

def modifier(B):
        B.begin_surface( 3, 1, 6)
        B.add_vertex( Point_3( 0, 0, 0))
        B.add_vertex( Point_3( 1, 0, 0))
        B.add_vertex( Point_3( 0, 1, 0))
        B.begin_facet()
        B.add_vertex_to_facet( 0)
        B.add_vertex_to_facet( 1)
        B.add_vertex_to_facet( 2)
        B.end_facet()
        B.end_surface()
  
and then do something like:

P = Polyhedron_3()
P.delegate(Polyhedron_3_Modifier(modifier))
print P.size_of_vertices()

or even more Pythonically perhaps

def modifier(B):
        B.begin_surface( 3, 1, 6)
        B.add_vertices( [ Point_3( 0, 0, 0), Point_3( 1, 0, 0), Point_3( 0, 1, 0) ] )
        B.add_facet( [0, 1, 2 ] )
        B.end_surface()

P = Polyhedron_3()
P.modify(modifier)
print P.size_of_vertices()


but all that requires you to be able to pass a Python function or a Python class derived from a C++ back in to C++ - not sure if that is possible?  Maybe it needs to be modeled some other way.

Cheers,
Patrick

jelle feringa

unread,
May 10, 2012, 4:23:43 PM5/10/12
to cgal-bindi...@googlegroups.com
Patrick,

What about the "with" statement here?

with modifier(P) as B:
        B.begin_surface( 3, 1, 6)
        B.add_vertices( [ Point_3( 0, 0, 0), Point_3( 1, 0, 0), Point_3( 0, 1, 0) ] )
        B.add_facet( [0, 1, 2 ] )
        B.end_surface()

-jelle

Patrick Surry

unread,
May 10, 2012, 4:25:46 PM5/10/12
to cgal-bindi...@googlegroups.com
It looks like maybe you could do something like this with Swig directors?  http://www.swig.org/Doc2.0/Python.html#Python_directorshttp://www.swig.org/Doc2.0/Java.html#Java_directors

Have you played with that at all?  (Sorry for all these questions, I'm new to Swig, CGAL, etc)

Cheers,
Patrick

Sebastien Loriot (GeometryFactory)

unread,
May 12, 2012, 2:45:21 AM5/12/12
to cgal-bindi...@googlegroups.com
Hi,

see this page:
http://code.google.com/p/cgal-bindings/wiki/BindingsExamples#Polyhedron_3:_partial_interface_to__Polyhedron_incremental_build
and this commit:
http://code.google.com/p/cgal-bindings/source/detail?r=e77c16bd5a65603a5b609976e798ec9c4bed6a70

What is missing is the add_facet function taking a range of int. New
some work to adapt the iterator mechanism.

Sebastien.
> examples/Polyhedron/__polyhedron_prog_incr_builder.__cpp
> <../../../examples/Polyhedron/__polyhedron_prog_incr_builder.__cpp
>
>
>
>
> Thanks,
> Patrick
>
> Hello,
>
> I just added an example,
> see this commit:
> http://code.google.com/p/cgal-__bindings/source/detail?r=__aa764bbf3679468ba127dc5dbc724a__faeb48336d

Patrick Surry

unread,
May 12, 2012, 6:25:57 AM5/12/12
to cgal-bindi...@googlegroups.com
Cool, thanks, I will play with that.

Cheers,
Patrick
Reply all
Reply to author
Forward
0 new messages