Hello,<br><br>I am trying to use boost.python in order to bind a library called CGAL (and also to test if it's diffcult to bind such a library ;-). <a href="http://www.cgal.org/">http://www.cgal.org/</a><br>This library provide a class CGAL::Delaunay_Triangulation_2 which represent a Delaunay triangulation in two dimensions.
<br><br>I want to build a delaunay triangultion using the "push_back" method (which add a Point to the mesh).<br>Then, I want to iter over the vertexes, the faces and the edges of the mesh using a Python iterator which use the following methods :
<br> - Finite_vertices_iterator t.finite_vertices_begin () <br> - Finite_vertices_iterator t.finite_vertices_end () <br><br><br>I added the following line in my C++ boost code :<br>
<br><span style="font-weight: bold;"> class_<Delaunay>("Delaunay")</span><br style="font-weight: bold;"><span style="font-weight: bold;"> //...</span><br style="font-weight: bold;"><span style="font-weight: bold;">
.def("finite_vertices", range(&Delaunay::finite_vertices_begin, &Delaunay::finite_vertices_end))</span><br style="font-weight: bold;"><br><br>And the following code in my unit tests : <br><br><span style="font-weight: bold;">
class TestSequenceFunctions(unittest.TestCase):</span><br style="font-weight: bold;"><span style="font-weight: bold;"> def init_delaunay(self):</span><br style="font-weight: bold;"><span style="font-weight: bold;"> d =
pygale.Delaunay()</span><br style="font-weight: bold;"><span style="font-weight: bold;"> for x, y in self.seq:</span><br style="font-weight: bold;"><span style="font-weight: bold;"> d.push_back(pygale.Point
(x, y))</span><br style="font-weight: bold;"><span style="font-weight: bold;"> return d</span><br style="font-weight: bold;"><br style="font-weight: bold;"><span style="font-weight: bold;"> def test_delaunay_2(self):
</span><br style="font-weight: bold;"><span style="font-weight: bold;"> d = self.init_delaunay()</span><br style="font-weight: bold;"><span style="font-weight: bold;"> it = d.finite_vertices()</span><br style="font-weight: bold;">
<br><br>But when I call the method "finite_vertices", I get the following error : <br><br><span style="font-weight: bold;">Traceback (most recent call last):</span><br style="font-weight: bold;"><span style="font-weight: bold;">
File "testPygale.py", line 40, in test_delaunay_2</span><br style="font-weight: bold;"><span style="font-weight: bold;"> it = d.finite_vertices()</span><br style="font-weight: bold;"><span style="font-weight: bold;">
ArgumentError: Python argument types in</span><br style="font-weight: bold;"><span style="font-weight: bold;"> Delaunay.finite_vertices(Delaunay)</span><br style="font-weight: bold;"><span style="font-weight: bold;">
did not match C++ signature:</span><br style="font-weight: bold;"><span style="font-weight: bold;"> finite_vertices(boost::python::back_reference<CGAL::Triangulation_2<CGAL::Cartesian<double>, CGAL::Tds2<CGAL::Tvb<CGAL::Cartesian<double>, CGAL::Tdsvb<void> >, CGAL::Tdsfb<void> > >&>)
</span><br style="font-weight: bold;"> <br><br>If you can help me to solve this error, please... <br><br>Thanks in advance.<br><br><br>Cyril BAZIN<br><br><br>Annexes: <br>The classes to bind<br>The C++ code for boost<br>The python unittests
<br>The execution trace <br><br><br>--------------------------------------------------------- The classes to bind ---------------------------------------------<br>#include <CGAL/Cartesian.h><br>#include <CGAL/squared_distance_2.h>
<br>#include <CGAL/Delaunay_triangulation_2.h><br>#include <CGAL/Triangulation_2.h><br>#include <CGAL/Triangulation_face_base_2.h><br>#include <CGAL/Triangulation_euclidean_traits_2.h><br><br><br>#include <CGAL/Delaunay_triangulation_2.h>
<br><br>#include <iostream><br>#include <sstream><br><br>typedef CGAL::Cartesian<double> Gt;<br>typedef Gt::FT F_T;<br>typedef Gt::RT R_T;<br>typedef Gt::Point_2 Point;
<br>typedef Gt::Segment_2 Segment;<br>typedef Gt::Line_2 Line;<br>typedef Gt::Triangle_2 Triangle;<br>///typedef Gt::Bbox_2 Bbox;<br>typedef CGAL::Delaunay_triangulation_2<Gt> Delaunay;
<br>typedef Delaunay::Finite_vertices_iterator Finite_vertices_iterator;<br>typedef Delaunay::Vertex_handle Vertex_handle;<br>typedef Delaunay::Vertex Vertex;<br><br>-----------------------------------------------------------------------------------------------------------------------------
<br><br><br>---------------------------------------------------------- C++ code for boost --------------------------------------------<br>#include <boost/python.hpp><br>#include "pygale2.cpp"<br>using namespace boost::python;
<br><br>BOOST_PYTHON_MODULE(pygale2)<br>{<br> //......<br><br> class_<Vertex>("Vertex")<br> ;<br><br> class_<Vertex_handle>("Vertex_handle")<br> ;<br><br> class_<Finite_vertices_iterator>("Finite_vertices_iterator")
<br> ;<br><br> class_<Delaunay>("Delaunay")<br> .def(init<>())<br> .def("number_of_vertices", &Delaunay::number_of_vertices )<br> .def("number_of_faces", &Delaunay::number_of_faces )
<br> .def("push_back", &Delaunay::push_back )<br> .def("finite_vertices", range(&Delaunay::finite_vertices_begin, &Delaunay::finite_vertices_end))<br> ;<br> //.....<br>}<br>
------------------------------------------------------------------------------------------------------------------------------------<br><br><br>----------------------------------------------------The python unit tests ----------------------------------------------------
<br>import pygale2 as pygale<br>import unittest<br><br>class TestSequenceFunctions(unittest.TestCase):<br><br> def setUp(self):<br> self.seq = [(5, 8), (9, 6), (5, 2), (12, 9), (0, 0), (2, 7)]<br><br> #...<br>
<br> def init_delaunay(self):<br> d = pygale.Delaunay()<br> for x, y in self.seq:<br> d.push_back(pygale.Point(x, y))<br> return d<br><br> def test_delaunay(self):<br> d = self.init_delaunay
()<br> self.assertEqual(d.number_of_vertices(), len(self.seq))<br><br> def test_delaunay_2(self):<br> d = self.init_delaunay()<br> it = d.finite_vertices()<br><br><br>if __name__ == '__main__':<br>
suite = unittest.makeSuite(TestSequenceFunctions)<br> unittest.TextTestRunner(verbosity=2).run(suite)<br> #unittest.main()<br>-----------------------------------------------------------------------------------------------------------------------------------------
<br><br>------------------------------------------- The execution trace --------------------------------------------------------------<br>$make all test<br>g++ -I/export/home/cbazin/python/Python-2.4/ -I/usr/include/python2.4 -I/usr/local/include/boost-1_33_1/boost/ -I/usr/local/include
pygale2.boost.cpp -c -o pygale2.o<br>g++ pygale2.o -L/usr/local/lib/ -lboost_python -L/usr/lib/CGAL/ -lCGAL -o pygale2.so --shared<br>python testPygale.py<br>test_delaunay (__main__.TestSequenceFunctions) ... ok<br>test_delaunay_2 (__main__.TestSequenceFunctions) ... ERROR
<br>test_points (__main__.TestSequenceFunctions) ... ok<br>test_segments (__main__.TestSequenceFunctions) ... ok<br><br>======================================================================<br>ERROR: test_delaunay_2 (__main__.TestSequenceFunctions)
<br>----------------------------------------------------------------------<br>Traceback (most recent call last):<br> File "testPygale.py", line 40, in test_delaunay_2<br> it = d.finite_vertices()<br>ArgumentError: Python argument types in
<br> Delaunay.finite_vertices(Delaunay)<br>did not match C++ signature:<br> finite_vertices(boost::python::back_reference<CGAL::Triangulation_2<CGAL::Cartesian<double>, CGAL::Tds2<CGAL::Tvb<CGAL::Cartesian<double>, CGAL::Tdsvb<void> >, CGAL::Tdsfb<void> > >&>)
<br><br>----------------------------------------------------------------------<br>Ran 4 tests in 0.003s<br><br>FAILED (errors=1)<br>----------------------------------------------------------------------------------------------------------------------------------------
<br><br>