[C++-sig] ArgumentError...

Cyril Bazin cyril.bazin at info.unicaen.fr
Mon Jun 19 17:35:39 CEST 2006


Hello,

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 ;-).
http://www.cgal.org/
This library provide a class CGAL::Delaunay_Triangulation_2 which represent
a Delaunay triangulation in two dimensions.

I want to build a delaunay triangultion using the "push_back" method (which
add a Point to the mesh).
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 :
 - Finite_vertices_iterator    t.finite_vertices_begin ()
 - Finite_vertices_iterator    t.finite_vertices_end ()


I added the following line in my C++ boost code :

   class_<Delaunay>("Delaunay")
       //...
       .def("finite_vertices", range(&Delaunay::finite_vertices_begin,
&Delaunay::finite_vertices_end))


And the following code in my unit tests :

class TestSequenceFunctions(unittest.TestCase):
   def init_delaunay(self):
        d = pygale.Delaunay()
        for x, y in self.seq:
            d.push_back(pygale.Point(x, y))
        return d

    def test_delaunay_2(self):
        d = self.init_delaunay()
        it = d.finite_vertices()


But when I call the method "finite_vertices", I get the following error :

Traceback (most recent call last):
   File "testPygale.py", line 40, in test_delaunay_2
     it = d.finite_vertices()
ArgumentError: Python argument types in
     Delaunay.finite_vertices(Delaunay)
did not match C++ signature:

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> > >&>)


If you can help me to solve this error, please...

Thanks in advance.


Cyril BAZIN


Annexes:
The classes to bind
The C++ code for boost
The python unittests
The execution trace


--------------------------------------------------------- The classes to
bind ---------------------------------------------
#include <CGAL/Cartesian.h>
#include <CGAL/squared_distance_2.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_2.h>
#include <CGAL/Triangulation_face_base_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>


#include <CGAL/Delaunay_triangulation_2.h>

#include <iostream>
#include <sstream>

typedef CGAL::Cartesian<double>    Gt;
typedef Gt::FT                     F_T;
typedef Gt::RT                     R_T;
typedef Gt::Point_2                Point;
typedef Gt::Segment_2              Segment;
typedef Gt::Line_2                 Line;
typedef Gt::Triangle_2             Triangle;
///typedef Gt::Bbox_2                 Bbox;
typedef CGAL::Delaunay_triangulation_2<Gt>      Delaunay;
typedef Delaunay::Finite_vertices_iterator   Finite_vertices_iterator;
typedef Delaunay::Vertex_handle              Vertex_handle;
typedef Delaunay::Vertex                     Vertex;

-----------------------------------------------------------------------------------------------------------------------------


---------------------------------------------------------- C++ code for
boost --------------------------------------------
#include <boost/python.hpp>
#include "pygale2.cpp"
using namespace boost::python;

BOOST_PYTHON_MODULE(pygale2)
{
   //......

   class_<Vertex>("Vertex")
    ;

   class_<Vertex_handle>("Vertex_handle")
    ;

   class_<Finite_vertices_iterator>("Finite_vertices_iterator")
    ;

   class_<Delaunay>("Delaunay")
        .def(init<>())
        .def("number_of_vertices", &Delaunay::number_of_vertices )
        .def("number_of_faces", &Delaunay::number_of_faces )
        .def("push_back", &Delaunay::push_back )
        .def("finite_vertices", range(&Delaunay::finite_vertices_begin,
&Delaunay::finite_vertices_end))
    ;
   //.....
}
------------------------------------------------------------------------------------------------------------------------------------


----------------------------------------------------The python unit tests
----------------------------------------------------
import pygale2 as pygale
import unittest

class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.seq = [(5, 8), (9, 6), (5, 2), (12, 9), (0, 0), (2, 7)]

    #...

    def init_delaunay(self):
        d = pygale.Delaunay()
        for x, y in self.seq:
            d.push_back(pygale.Point(x, y))
        return d

    def test_delaunay(self):
        d = self.init_delaunay()
        self.assertEqual(d.number_of_vertices(), len(self.seq))

    def test_delaunay_2(self):
        d = self.init_delaunay()
        it = d.finite_vertices()


if __name__ == '__main__':
    suite = unittest.makeSuite(TestSequenceFunctions)
    unittest.TextTestRunner(verbosity=2).run(suite)
    #unittest.main()
-----------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------- The execution trace
--------------------------------------------------------------
$make all test
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
g++ pygale2.o -L/usr/local/lib/ -lboost_python -L/usr/lib/CGAL/ -lCGAL -o
pygale2.so --shared
python testPygale.py
test_delaunay (__main__.TestSequenceFunctions) ... ok
test_delaunay_2 (__main__.TestSequenceFunctions) ... ERROR
test_points (__main__.TestSequenceFunctions) ... ok
test_segments (__main__.TestSequenceFunctions) ... ok

======================================================================
ERROR: test_delaunay_2 (__main__.TestSequenceFunctions)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "testPygale.py", line 40, in test_delaunay_2
    it = d.finite_vertices()
ArgumentError: Python argument types in
    Delaunay.finite_vertices(Delaunay)
did not match C++ signature:
    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> > >&>)

----------------------------------------------------------------------
Ran 4 tests in 0.003s

FAILED (errors=1)
----------------------------------------------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060619/a67253a9/attachment.htm>


More information about the Cplusplus-sig mailing list