diff --git a/python/handwritten/slam_python.cpp b/python/handwritten/slam_python.cpp index f2c56cae4..67aaf50c6 100644 --- a/python/handwritten/slam_python.cpp +++ b/python/handwritten/slam_python.cpp @@ -32,10 +32,28 @@ using namespace gtsam; // Prototypes used to perform overloading // See: http://www.boost.org/doc/libs/1_59_0/libs/python/doc/tutorial/doc/html/python/functions.html +// *NONE* + +// Wrap around pure virtual class NonlinearFactor. +// All pure virtual methods should be wrapped. Non-pure may be wrapped if we want to mimic the +// overloading through inheritance in Python. +// See: http://www.boost.org/doc/libs/1_59_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions +struct NonlinearFactorCallback : NonlinearFactor, wrapper +{ + double error (const Values & values) const { + return this->get_override("error")(values); + } + size_t dim () const { + return this->get_override("dim")(); + } + boost::shared_ptr linearize(const Values & values) const { + return this->get_override("linearize")(values); + } +}; // Macro used to define a BetweenFactor given the type. #define BETWEENFACTOR(VALUE) \ - class_< BetweenFactor >("BetweenFactor"#VALUE) \ + class_< BetweenFactor, bases, boost::shared_ptr< BetweenFactor > >("BetweenFactor"#VALUE) \ .def(init()) \ .def("measured", &BetweenFactor::measured, return_internal_reference<>()) \ ; @@ -43,6 +61,9 @@ using namespace gtsam; BOOST_PYTHON_MODULE(libslam_python) { + class_("NonlinearFactor") + ; + BETWEENFACTOR(Point3) BETWEENFACTOR(Rot3)