Wrap PinholeBaseK to python and declare it as parent of PinholeCamera

release/4.3a0
Ellon Mendes 2015-11-23 20:36:01 +01:00
parent c878278687
commit 49d02c798f
3 changed files with 81 additions and 11 deletions

View File

@ -34,6 +34,7 @@ void exportRot2();
void exportRot3(); void exportRot3();
void exportPose2(); void exportPose2();
void exportPose3(); void exportPose3();
void exportPinholeBaseK();
void exportPinholeCamera(); void exportPinholeCamera();
void exportCal3_S2(); void exportCal3_S2();
@ -73,6 +74,7 @@ BOOST_PYTHON_MODULE(libgtsam_python){
exportRot3(); exportRot3();
exportPose2(); exportPose2();
exportPose3(); exportPose3();
exportPinholeBaseK();
exportPinholeCamera(); exportPinholeCamera();
exportCal3_S2(); exportCal3_S2();

View File

@ -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 PinholeCamera classes to python
* @author Ellon Paiva Mendes (LAAS-CNRS)
**/
#include <boost/python.hpp>
#define NO_IMPORT_ARRAY
#include <numpy_eigen/NumpyEigenConverter.hpp>
#include "gtsam/geometry/PinholeCamera.h"
#include "gtsam/geometry/Cal3_S2.h"
using namespace boost::python;
using namespace gtsam;
typedef PinholeBaseK<Cal3_S2> PinholeBaseKCal3_S2;
// Wrapper on PinholeBaseK<Cal3_S2> because it has pure virtual method calibration()
struct PinholeBaseKCal3_S2Callback : PinholeBaseKCal3_S2, wrapper<PinholeBaseKCal3_S2>
{
const Cal3_S2 & calibration () const {
return this->get_override("calibration")();
}
};
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(project_overloads, PinholeBaseKCal3_S2::project, 2, 4)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(range_overloads, PinholeBaseKCal3_S2::range, 1, 3)
// Function pointers to desambiguate project() calls
Point2 (PinholeBaseKCal3_S2::*project1) (const Point3 &pw) const = &PinholeBaseKCal3_S2::project;
Point2 (PinholeBaseKCal3_S2::*project2) (const Point3 &pw, OptionalJacobian< 2, 6 > Dpose, OptionalJacobian< 2, 3 > Dpoint, OptionalJacobian< 2, FixedDimension<Cal3_S2>::value > Dcal) const = &PinholeBaseKCal3_S2::project;
Point2 (PinholeBaseKCal3_S2::*project3) (const Unit3 &pw, OptionalJacobian< 2, 6 > Dpose, OptionalJacobian< 2, 2 > Dpoint, OptionalJacobian< 2, FixedDimension<Cal3_S2>::value > Dcal) const = &PinholeBaseKCal3_S2::project;
// function pointers to desambiguate range() calls
double (PinholeBaseKCal3_S2::*range1) (const Point3 &point, OptionalJacobian< 1, 6 > Dcamera, OptionalJacobian< 1, 3 > Dpoint) const = &PinholeBaseKCal3_S2::range;
double (PinholeBaseKCal3_S2::*range2) (const Pose3 &pose, OptionalJacobian< 1, 6 > Dcamera, OptionalJacobian< 1, 6 > Dpose) const = &PinholeBaseKCal3_S2::range;
double (PinholeBaseKCal3_S2::*range3) (const CalibratedCamera &camera, OptionalJacobian< 1, 6 > Dcamera, OptionalJacobian< 1, 6 > Dother) const = &PinholeBaseKCal3_S2::range;
void exportPinholeBaseK(){
class_<PinholeBaseKCal3_S2Callback, boost::noncopyable>("PinholeBaseKCal3_S2", no_init)
.def("calibration", pure_virtual(&PinholeBaseKCal3_S2::calibration), return_value_policy<copy_const_reference>())
.def("project", project1)
.def("project", project2, project_overloads())
.def("project", project3, project_overloads())
.def("backproject", &PinholeBaseKCal3_S2::backproject)
.def("backproject_point_at_infinity", &PinholeBaseKCal3_S2::backprojectPointAtInfinity)
.def("range", range1, range_overloads())
.def("range", range2, range_overloads())
.def("range", range3, range_overloads())
;
}

View File

@ -22,27 +22,29 @@
#include "gtsam/geometry/PinholeCamera.h" #include "gtsam/geometry/PinholeCamera.h"
#include "gtsam/geometry/Cal3_S2.h" #include "gtsam/geometry/Cal3_S2.h"
using namespace boost::python; using namespace boost::python;
using namespace gtsam; using namespace gtsam;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(print_overloads, PinholeCamera<Cal3_S2>::print, 0, 1) typedef PinholeBaseK<Cal3_S2> PinholeBaseKCal3_S2;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(equals_overloads, PinholeCamera<Cal3_S2>::equals, 1, 2) typedef PinholeCamera<Cal3_S2> PinholeCameraCal3_S2;
BOOST_PYTHON_FUNCTION_OVERLOADS(Lookat_overloads, PinholeCamera<Cal3_S2>::Lookat, 3, 4)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(print_overloads, PinholeCameraCal3_S2::print, 0, 1)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(equals_overloads, PinholeCameraCal3_S2::equals, 1, 2)
BOOST_PYTHON_FUNCTION_OVERLOADS(Lookat_overloads, PinholeCameraCal3_S2::Lookat, 3, 4)
void exportPinholeCamera(){ void exportPinholeCamera(){
class_<PinholeCamera<Cal3_S2> >("PinholeCameraCal3_S2") class_<PinholeCameraCal3_S2, bases<PinholeBaseKCal3_S2> >("PinholeCameraCal3_S2", init<>())
.def(init<>())
.def(init<const Pose3 &>()) .def(init<const Pose3 &>())
.def(init<const Pose3 &, const Cal3_S2 &>()) .def(init<const Pose3 &, const Cal3_S2 &>())
.def(init<const Vector &>()) .def(init<const Vector &>())
.def(init<const Vector &, const Vector &>()) .def(init<const Vector &, const Vector &>())
.def("print", &PinholeCamera<Cal3_S2>::print, print_overloads(args("s"))) .def("print", &PinholeCameraCal3_S2::print, print_overloads(args("s")))
.def("equals", &PinholeCamera<Cal3_S2>::equals, equals_overloads(args("q","tol"))) .def("equals", &PinholeCameraCal3_S2::equals, equals_overloads(args("q","tol")))
.def("pose", &PinholeCamera<Cal3_S2>::pose, return_value_policy<copy_const_reference>()) .def("pose", &PinholeCameraCal3_S2::pose, return_value_policy<copy_const_reference>())
.def("calibration", &PinholeCamera<Cal3_S2>::calibration, return_value_policy<copy_const_reference>()) // We don't need to define calibration() here because it's already defined as virtual in the base class PinholeBaseKCal3_S2
.def("Lookat", &PinholeCamera<Cal3_S2>::Lookat, Lookat_overloads()) // .def("calibration", &PinholeCameraCal3_S2::calibration, return_value_policy<copy_const_reference>())
.def("Lookat", &PinholeCameraCal3_S2::Lookat, Lookat_overloads())
.staticmethod("Lookat") .staticmethod("Lookat")
; ;