Add inheritance to from NonlinearFactor to BetweenFactor.

Nonlinear factor is pure virtual, so we need to declare a wrapper, even
if we don't export anything from it.

Also, we don't make explicit all the chain of inheritance from BetweenFactor,
since it looks like exporting inheritance directly from NonlinearFactor allows
adding it to NonlinearFactorGraph.
release/4.3a0
Ellon Mendes 2015-11-19 10:09:15 +01:00
parent 828b230e17
commit 72a800f70f
1 changed files with 22 additions and 1 deletions

View File

@ -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<NonlinearFactor>
{
double error (const Values & values) const {
return this->get_override("error")(values);
}
size_t dim () const {
return this->get_override("dim")();
}
boost::shared_ptr<GaussianFactor> 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<VALUE> >("BetweenFactor"#VALUE) \
class_< BetweenFactor<VALUE>, bases<NonlinearFactor>, boost::shared_ptr< BetweenFactor<VALUE> > >("BetweenFactor"#VALUE) \
.def(init<Key,Key,VALUE,noiseModel::Base::shared_ptr>()) \
.def("measured", &BetweenFactor<VALUE>::measured, return_internal_reference<>()) \
;
@ -43,6 +61,9 @@ using namespace gtsam;
BOOST_PYTHON_MODULE(libslam_python)
{
class_<NonlinearFactorCallback,boost::noncopyable>("NonlinearFactor")
;
BETWEENFACTOR(Point3)
BETWEENFACTOR(Rot3)