Updated tutorial 404 to use features of newer pybind11 version,

Introduced typedefs
This commit is contained in:
Sebastian Koch
2016-07-12 17:15:40 +02:00
parent 0258e9fb60
commit a6b2fd045a
10 changed files with 66 additions and 34 deletions
+13 -7
View File
@@ -188,9 +188,15 @@ py::class_<igl::viewer::ViewerCore> viewercore_class(me, "ViewerCore");
})
.def_readwrite("lighting_factor",&igl::viewer::ViewerCore::lighting_factor)
.def_readwrite("model_zoom",&igl::viewer::ViewerCore::model_zoom)
.def_property("trackball_angle",
[](const igl::viewer::ViewerCore& core) {return Eigen::Quaterniond(core.trackball_angle.cast<double>());},
[](igl::viewer::ViewerCore& core, const Eigen::Quaterniond& q)
{
core.trackball_angle = Eigen::Quaternionf(q.cast<float>());
})
.def_property("model_translation",
[](const igl::viewer::ViewerCore& core) {return Eigen::MatrixXd(core.model_translation.cast<double>());},
[](igl::viewer::ViewerCore& core, const Eigen::MatrixXd& v)
@@ -316,13 +322,13 @@ py::class_<igl::viewer::ViewerCore> viewercore_class(me, "ViewerCore");
// UI Enumerations
py::class_<igl::viewer::Viewer> viewer_class(me, "Viewer");
#ifdef IGL_VIEWER_WITH_NANOGUI
py::object fh = (py::object) py::module::import("nanogui").attr("FormHelper");
py::class_<nanogui::FormHelper> form_helper_class(me, "FormHelper", fh);
// #ifdef IGL_VIEWER_WITH_NANOGUI
// py::object fh = (py::object) py::module::import("nanogui").attr("FormHelper");
// py::class_<nanogui::FormHelper> form_helper_class(me, "FormHelper", fh);
py::object screen = (py::object) py::module::import("nanogui").attr("Screen");
py::class_<nanogui::Screen> screen_class(me, "Screen", screen);
#endif
// py::object screen = (py::object) py::module::import("nanogui").attr("Screen");
// py::class_<nanogui::Screen> screen_class(me, "Screen", screen);
// #endif
py::enum_<igl::viewer::Viewer::MouseButton>(viewer_class, "MouseButton")
.value("Left", igl::viewer::Viewer::MouseButton::Left)
+12
View File
@@ -0,0 +1,12 @@
py::class_<RotationList>(m, "RotationList")
.def(py::init<>())
.def("pop_back", &RotationList::pop_back)
/* There are multiple versions of push_back(), etc. Select the right ones. */
.def("append", (void (RotationList::*)(const Eigen::Quaterniond &)) &RotationList::push_back)
.def("back", (Eigen::Quaterniond &(RotationList::*)()) &RotationList::back)
.def("__len__", [](const RotationList &v) { return v.size(); })
.def("__getitem__", [](const RotationList &v, int b) { return v.at(b); })
.def("__setitem__", [](RotationList &v, int b, Eigen::Quaterniond &c) { return v.at(b) = c; })
.def("__iter__", [](RotationList &v) {
return py::make_iterator(v.begin(), v.end());
}, py::keep_alive<0, 1>());
+5
View File
@@ -0,0 +1,5 @@
typedef std::vector<Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > RotationList;
PYBIND11_MAKE_OPAQUE(RotationList);
//typedef std::vector<Eigen::Vector3d> TranslationList;
//PYBIND11_MAKE_OPAQUE(TranslationList);
+5 -2
View File
@@ -68,7 +68,7 @@ py::class_<Type> bind_eigen_2(py::module &m, const char *name,
})
.def("__init__", [](Type &m, py::buffer b) {
py::buffer_info info = b.request();
if (info.format != py::format_descriptor<Scalar>::value())
if (info.format != py::format_descriptor<Scalar>::value)
throw std::runtime_error("Incompatible buffer format!");
if (info.ndim == 1) {
new (&m) Type(info.shape[0], 1);
@@ -319,7 +319,7 @@ py::class_<Type> bind_eigen_2(py::module &m, const char *name,
m.data(), /* Pointer to buffer */
sizeof(Scalar), /* Size of one scalar */
/* Python struct-style format descriptor */
py::format_descriptor<Scalar>::value(),
py::format_descriptor<Scalar>::value,
2, /* Number of dimensions */
{ (size_t) m.rows(), /* Buffer dimensions */
(size_t) m.cols() },
@@ -735,6 +735,9 @@ void python_export_vector(py::module &m) {
.def("conjugate",[](Eigen::Quaterniond& q) {
return q.conjugate();
})
.def("normalize",[](Eigen::Quaterniond& q) {
return q.normalize();
})
.def("slerp",[](Eigen::Quaterniond& q, double & t, Eigen::Quaterniond other) {
return q.slerp(t, other);
})