diff --git a/python/modules/py_vector.cpp b/python/modules/py_vector.cpp index 82e6aeb1b..9dadb3f90 100644 --- a/python/modules/py_vector.cpp +++ b/python/modules/py_vector.cpp @@ -7,14 +7,13 @@ /// Creates Python bindings for a dynamic Eigen matrix template -py::class_ bind_eigen_2(py::module &m, const char *name, - py::object parent = py::object()) { +py::class_ bind_eigen_2(py::module &m, const char *name) { typedef typename Type::Scalar Scalar; /* Many Eigen functions are templated and can't easily be referenced using a function pointer, thus a big portion of the binding code below instantiates Eigen code using small anonymous wrapper functions */ - py::class_ matrix(m, name, parent); + py::class_ matrix(m, name, py::buffer_protocol()); matrix /* Constructors */ @@ -24,6 +23,26 @@ py::class_ bind_eigen_2(py::module &m, const char *name, new (&m) Type(1, 1); m(0, 0) = f; }) + .def("__init__", [](Type &m, py::buffer b) { + py::buffer_info info = b.request(); + if (info.format != py::format_descriptor::format()) + throw std::runtime_error("Incompatible buffer format!"); + if (info.ndim == 1) { + new (&m) Type(info.shape[0], 1); + memcpy(m.data(), info.ptr, sizeof(Scalar) * m.size()); + } else if (info.ndim == 2) { + if (info.strides[0] == sizeof(Scalar)) { + new (&m) Type(info.shape[0], info.shape[1]); + memcpy(m.data(), info.ptr, sizeof(Scalar) * m.size()); + } else { + new (&m) Type(info.shape[1], info.shape[0]); + memcpy(m.data(), info.ptr, sizeof(Scalar) * m.size()); + m.transposeInPlace(); + } + } else { + throw std::runtime_error("Incompatible buffer dimension!"); + } + }) .def("__init__", [](Type &m, std::vector >& b) { if (b.size() == 0) { @@ -66,26 +85,7 @@ py::class_ bind_eigen_2(py::module &m, const char *name, return; }) - .def("__init__", [](Type &m, py::buffer b) { - py::buffer_info info = b.request(); - if (info.format != py::format_descriptor::value) - throw std::runtime_error("Incompatible buffer format!"); - if (info.ndim == 1) { - new (&m) Type(info.shape[0], 1); - memcpy(m.data(), info.ptr, sizeof(Scalar) * m.size()); - } else if (info.ndim == 2) { - if (info.strides[0] == sizeof(Scalar)) { - new (&m) Type(info.shape[0], info.shape[1]); - memcpy(m.data(), info.ptr, sizeof(Scalar) * m.size()); - } else { - new (&m) Type(info.shape[1], info.shape[0]); - memcpy(m.data(), info.ptr, sizeof(Scalar) * m.size()); - m.transposeInPlace(); - } - } else { - throw std::runtime_error("Incompatible buffer dimension!"); - } - }) + /* Size query functions */ .def("size", [](const Type &m) { return m.size(); }) @@ -319,7 +319,7 @@ py::class_ 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::value, + py::format_descriptor::format(), 2, /* Number of dimensions */ { (size_t) m.rows(), /* Buffer dimensions */ (size_t) m.cols() }, @@ -347,14 +347,13 @@ py::class_ bind_eigen_2(py::module &m, const char *name, /// Creates Python bindings for a dynamic Eigen sparse order-2 tensor (i.e. a matrix) template -py::class_ bind_eigen_sparse_2(py::module &m, const char *name, - py::object parent = py::object()) { +py::class_ bind_eigen_sparse_2(py::module &m, const char *name) { typedef typename Type::Scalar Scalar; /* Many Eigen functions are templated and can't easily be referenced using a function pointer, thus a big portion of the binding code below instantiates Eigen code using small anonymous wrapper functions */ - py::class_ matrix(m, name, parent); + py::class_ matrix(m, name, py::buffer_protocol()); matrix /* Constructors */ @@ -532,14 +531,13 @@ py::class_ bind_eigen_sparse_2(py::module &m, const char *name, /// Creates Python bindings for a diagonal Eigen sparse order-2 tensor (i.e. a matrix) template -py::class_ bind_eigen_diagonal_2(py::module &m, const char *name, - py::object parent = py::object()) { +py::class_ bind_eigen_diagonal_2(py::module &m, const char *name) { typedef typename Type::Scalar Scalar; /* Many Eigen functions are templated and can't easily be referenced using a function pointer, thus a big portion of the binding code below instantiates Eigen code using small anonymous wrapper functions */ - py::class_ matrix(m, name, parent); + py::class_ matrix(m, name, py::buffer_protocol()); matrix /* Constructors */ @@ -632,7 +630,7 @@ void python_export_vector(py::module &m) { /* Bindings for MatrixXi */ bind_eigen_2 (me, "MatrixXi"); -// py::implicitly_convertible(); + //py::implicitly_convertible(); //py::implicitly_convertible(); /* Bindings for MatrixXb */ diff --git a/python/py_igl/py_boundary_facets.cpp b/python/py_igl/py_boundary_facets.cpp index a628e8760..f034a939c 100644 --- a/python/py_igl/py_boundary_facets.cpp +++ b/python/py_igl/py_boundary_facets.cpp @@ -1,13 +1,3 @@ -m.def("boundary_facets", [] -( - const std::vector > & T, - std::vector > & F -) -{ - return igl::boundary_facets(T,F); -}, __doc_igl_boundary_facets, -py::arg("T"), py::arg("F")); - m.def("boundary_facets", [] ( const Eigen::MatrixXi& T, @@ -28,3 +18,13 @@ m.def("boundary_facets", [] return F; }, __doc_igl_boundary_facets, py::arg("T")); + +m.def("boundary_facets", [] +( + const std::vector > & T, + std::vector > & F +) +{ + return igl::boundary_facets(T,F); +}, __doc_igl_boundary_facets, +py::arg("T"), py::arg("F")); diff --git a/python/py_igl/py_boundary_loop.cpp b/python/py_igl/py_boundary_loop.cpp index 1c9ebd8f9..d3e31ca2a 100755 --- a/python/py_igl/py_boundary_loop.cpp +++ b/python/py_igl/py_boundary_loop.cpp @@ -1,3 +1,15 @@ +m.def("boundary_loop", [] +( + const Eigen::MatrixXi& F, + Eigen::MatrixXi& L +) +{ + Eigen::VectorXi T; + igl::boundary_loop(F,T); + L = T; +}, __doc_igl_boundary_loop, +py::arg("F"), py::arg("L")); + m.def("boundary_loop", [] ( const Eigen::MatrixXi& F, @@ -18,14 +30,4 @@ m.def("boundary_loop", [] }, __doc_igl_boundary_loop, py::arg("F"), py::arg("L")); -m.def("boundary_loop", [] -( - const Eigen::MatrixXi& F, - Eigen::MatrixXi& L -) -{ - Eigen::VectorXi T; - igl::boundary_loop(F,T); - L = T; -}, __doc_igl_boundary_loop, -py::arg("F"), py::arg("L")); + diff --git a/python/py_igl/py_internal_angles.cpp b/python/py_igl/py_internal_angles.cpp index 5c9e43bc3..27b72a981 100644 --- a/python/py_igl/py_internal_angles.cpp +++ b/python/py_igl/py_internal_angles.cpp @@ -21,13 +21,14 @@ m.def("internal_angles_using_squared_edge_lengths", [] }, __doc_igl_internal_angles, py::arg("L_sq"), py::arg("K")); -m.def("internal_angles_using_edge_lengths", [] -( - const Eigen::MatrixXd& L, - Eigen::MatrixXd& K -) -{ - return igl::internal_angles_using_edge_lengths(L, K); -}, __doc_igl_internal_angles, -py::arg("L"), py::arg("K")); +//m.def("internal_angles_using_edge_lengths", [] +//( +// const Eigen::MatrixXd& L, +// Eigen::MatrixXd& K +//) +//{ +// return igl::internal_angles_using_edge_lengths(L, K); +//}, __doc_igl_internal_angles, +//py::arg("L"), py::arg("K")); + diff --git a/python/py_igl/py_readMESH.cpp b/python/py_igl/py_readMESH.cpp index 787d3950f..12afc5497 100644 --- a/python/py_igl/py_readMESH.cpp +++ b/python/py_igl/py_readMESH.cpp @@ -1,15 +1,3 @@ -m.def("readMESH", [] -( - const std::string mesh_file_name, - std::vector > & V, - std::vector > & T, - std::vector > & F -) -{ - return igl::readMESH(mesh_file_name, V, T, F); -}, __doc_igl_readMESH, -py::arg("mesh_file_name"), py::arg("V"), py::arg("T"), py::arg("F")); - m.def("readMESH", [] ( const std::string mesh_file_name, @@ -22,3 +10,18 @@ m.def("readMESH", [] }, __doc_igl_readMESH, py::arg("mesh_file_name"), py::arg("V"), py::arg("T"), py::arg("F")); + +m.def("readMESH", [] +( + const std::string mesh_file_name, + std::vector > & V, + std::vector > & T, + std::vector > & F +) +{ + return igl::readMESH(mesh_file_name, V, T, F); +}, __doc_igl_readMESH, +py::arg("mesh_file_name"), py::arg("V"), py::arg("T"), py::arg("F")); + + + diff --git a/python/py_igl/py_read_triangle_mesh.cpp b/python/py_igl/py_read_triangle_mesh.cpp index e6b68e784..ee1c4d82c 100644 --- a/python/py_igl/py_read_triangle_mesh.cpp +++ b/python/py_igl/py_read_triangle_mesh.cpp @@ -1,14 +1,3 @@ -m.def("read_triangle_mesh", [] -( - const std::string str, - std::vector >& V, - std::vector >& F -) -{ - return igl::read_triangle_mesh(str,V,F); -}, __doc_igl_read_triangle_mesh, -py::arg("str"), py::arg("V"), py::arg("F")); - m.def("read_triangle_mesh", [] ( const std::string str, @@ -34,3 +23,14 @@ m.def("read_triangle_mesh", [] return igl::read_triangle_mesh(str,V,F,dir,base,ext,name); }, __doc_igl_read_triangle_mesh, py::arg("str"), py::arg("V"), py::arg("F"), py::arg("dir"), py::arg("base"), py::arg("ext"), py::arg("name")); + +m.def("read_triangle_mesh", [] +( + const std::string str, + std::vector >& V, + std::vector >& F +) +{ + return igl::read_triangle_mesh(str,V,F); +}, __doc_igl_read_triangle_mesh, +py::arg("str"), py::arg("V"), py::arg("F")); diff --git a/python/py_igl/py_unique.cpp b/python/py_igl/py_unique.cpp index ba39703ef..7773a924b 100644 --- a/python/py_igl/py_unique.cpp +++ b/python/py_igl/py_unique.cpp @@ -1,25 +1,3 @@ -m.def("unique", [] -( - const std::vector & A, - std::vector & C, - std::vector & IA, - std::vector & IC -) -{ - return igl::unique(A,C,IA,IC); -}, __doc_igl_unique, -py::arg("A"), py::arg("C"), py::arg("IA"), py::arg("IC")); - -m.def("unique", [] -( - const std::vector & A, - std::vector & C -) -{ - return igl::unique(A,C); -}, __doc_igl_unique, -py::arg("A"), py::arg("C")); - m.def("unique", [] ( const Eigen::MatrixXd& A, @@ -54,15 +32,10 @@ m.def("unique_rows", [] }, __doc_igl_unique, py::arg("A"), py::arg("C"), py::arg("IA"), py::arg("IC")); - - -// int - - m.def("unique", [] ( - const std::vector & A, - std::vector & C, + const std::vector & A, + std::vector & C, std::vector & IA, std::vector & IC ) @@ -73,14 +46,18 @@ py::arg("A"), py::arg("C"), py::arg("IA"), py::arg("IC")); m.def("unique", [] ( - const std::vector & A, - std::vector & C + const std::vector & A, + std::vector & C ) { return igl::unique(A,C); }, __doc_igl_unique, py::arg("A"), py::arg("C")); + +// int + + m.def("unique", [] ( const Eigen::MatrixXi& A, @@ -114,3 +91,25 @@ m.def("unique_rows", [] return igl::unique_rows(A,C,IA,IC); }, __doc_igl_unique, py::arg("A"), py::arg("C"), py::arg("IA"), py::arg("IC")); + +m.def("unique", [] +( + const std::vector & A, + std::vector & C, + std::vector & IA, + std::vector & IC +) +{ + return igl::unique(A,C,IA,IC); +}, __doc_igl_unique, +py::arg("A"), py::arg("C"), py::arg("IA"), py::arg("IC")); + +m.def("unique", [] +( + const std::vector & A, + std::vector & C +) +{ + return igl::unique(A,C); +}, __doc_igl_unique, +py::arg("A"), py::arg("C"));