Wrap symbol to python
parent
982d81e1c9
commit
818db17392
|
|
@ -36,6 +36,9 @@ void exportPose2();
|
|||
void exportPose3();
|
||||
void exportPinholeCamera();
|
||||
|
||||
// Inference
|
||||
void exportSymbol();
|
||||
|
||||
// Linear
|
||||
void exportNoiseModels();
|
||||
|
||||
|
|
@ -70,6 +73,8 @@ BOOST_PYTHON_MODULE(libgtsam_python){
|
|||
exportPose3();
|
||||
exportPinholeCamera();
|
||||
|
||||
exportSymbol();
|
||||
|
||||
exportNoiseModels();
|
||||
|
||||
exportValues();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||
* Atlanta, Georgia 30332-0415
|
||||
* All Rights Reserved
|
||||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||
|
||||
* See LICENSE for the license information
|
||||
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief wraps Symbol class to python
|
||||
* @author Ellon Paiva Mendes (LAAS-CNRS)
|
||||
**/
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#define NO_IMPORT_ARRAY
|
||||
#include <numpy_eigen/NumpyEigenConverter.hpp>
|
||||
|
||||
#include "gtsam/inference/Symbol.h"
|
||||
|
||||
using namespace boost::python;
|
||||
using namespace gtsam;
|
||||
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(print_overloads, Symbol::print, 0, 1)
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(equals_overloads, Symbol::equals, 1, 2)
|
||||
|
||||
// Helper function to allow building a symbol from a python string and a index.
|
||||
static boost::shared_ptr<Symbol> makeSymbol(const std::string &str, size_t j)
|
||||
{
|
||||
if(str.size() > 1)
|
||||
throw std::runtime_error("string argument must have one character only");
|
||||
|
||||
return boost::make_shared<Symbol>(str.at(0),j);
|
||||
}
|
||||
|
||||
// Helper function to print the symbol as "char-and-index" in python
|
||||
std::string selfToString(const Symbol & self)
|
||||
{
|
||||
return (std::string)self;
|
||||
}
|
||||
|
||||
void exportSymbol(){
|
||||
|
||||
class_<Symbol, boost::shared_ptr<Symbol> >("Symbol")
|
||||
.def(init<>())
|
||||
.def(init<const Symbol &>())
|
||||
.def("__init__", make_constructor(makeSymbol))
|
||||
.def(init<Key>())
|
||||
.def("print", &Symbol::print, print_overloads(args("s")))
|
||||
.def("equals", &Symbol::equals, equals_overloads(args("q","tol")))
|
||||
.def("key", &Symbol::key)
|
||||
.def("chr", &Symbol::chr)
|
||||
.def("index", &Symbol::index)
|
||||
.def(self < self)
|
||||
.def(self == self)
|
||||
.def(self == other<Key>())
|
||||
.def(self != self)
|
||||
.def(self != other<Key>())
|
||||
.def("__repr__", &selfToString)
|
||||
;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue