Fix inheritance problem on python wrapping of noise models

release/4.3a0
Ellon Mendes 2015-11-18 17:28:44 +01:00
parent 72d73c6721
commit 6684f69d0a
1 changed files with 9 additions and 7 deletions

View File

@ -24,17 +24,17 @@
#include <boost/python.hpp>
#include <numpy_eigen/NumpyEigenConverter.hpp>
#include <gtsam/linear/NoiseModel.h>
using namespace boost::python;
using namespace gtsam;
using namespace gtsam::noiseModel;
// Wrap around pure virtual class Base
// Wrap around pure virtual class Base.
// 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 BaseWrap : Base, wrapper<Base>
struct BaseCallback : Base, wrapper<Base>
{
void print (const std::string & name="") const {
this->get_override("print")();
@ -67,18 +67,20 @@ struct BaseWrap : Base, wrapper<Base>
this->get_override("WhitenSystem")();
}
// TODO(Ellon) Wrap non-pure virtual methods here. See: http://www.boost.org/doc/libs/1_59_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.virtual_functions_with_default_implementations
// TODO(Ellon): Wrap non-pure virtual methods should go here.
// See: http://www.boost.org/doc/libs/1_59_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.virtual_functions_with_default_implementations
};
BOOST_PYTHON_MODULE(libnoiseModel_python)
{
class_<BaseWrap,boost::noncopyable>("Base")
class_<BaseCallback,boost::noncopyable>("Base")
.def("print", pure_virtual(&Base::print))
;
class_<Gaussian, boost::shared_ptr<Gaussian>, bases<BaseWrap> >("Gaussian", no_init)
// NOTE: We should use "Base" in "bases<...>", and not "BaseCallback" (it was not clear at the begining)
class_<Gaussian, boost::shared_ptr<Gaussian>, bases<Base> >("Gaussian", no_init)
.def("SqrtInformation",&Gaussian::SqrtInformation)
.staticmethod("SqrtInformation")
.def("Information",&Gaussian::Information)