diff --git a/python/302_Sort.py b/python/302_Sort.py new file mode 100644 index 000000000..26379be30 --- /dev/null +++ b/python/302_Sort.py @@ -0,0 +1,34 @@ +import igl + +V = igl.eigen.MatrixXd() +F = igl.eigen.MatrixXi() + +igl.readOFF("../tutorial/shared/decimated-knight.off",V,F) + +# Sort barycenters lexicographically +BC = igl.eigen.MatrixXd() +sorted_BC = igl.eigen.MatrixXd() + +igl.barycenter(V,F,BC); + +I = igl.eigen.MatrixXi() +J = igl.eigen.MatrixXi() + +# sorted_BC = BC(I,:) +igl.sortrows(BC,True,sorted_BC,I) + +# Get sorted "place" from sorted indices +J.resize(I.rows(),1) +# J(I) = 1:numel(I) + +igl.slice_into(igl.coloni(0,I.size())-1,I,J) + +# Pseudo-color based on sorted place +C = igl.eigen.MatrixXd() +igl.jet(J.castdouble(),True,C) + +# Plot the mesh with pseudocolors +viewer = igl.viewer.Viewer() +viewer.data.set_mesh(V, F) +viewer.data.set_colors(C) +viewer.launch() diff --git a/python/py_igl.cpp b/python/py_igl.cpp index e055d9520..c16775bd5 100644 --- a/python/py_igl.cpp +++ b/python/py_igl.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include void python_export_igl(py::module &m) { @@ -47,5 +49,7 @@ void python_export_igl(py::module &m) #include "py_igl/py_floor.cpp" #include "py_igl/py_slice.cpp" #include "py_igl/py_slice_into.cpp" +#include "py_igl/py_sortrows.cpp" +#include "py_igl/py_colon.cpp" } diff --git a/python/py_igl/py_colon.cpp b/python/py_igl/py_colon.cpp new file mode 100644 index 000000000..409727b9d --- /dev/null +++ b/python/py_igl/py_colon.cpp @@ -0,0 +1,74 @@ +m.def("colon", [] +( + const double low, + const double step, + const double high, + Eigen::MatrixXd& I +) +{ + Eigen::Matrix temp; + igl::colon(low,step,high,temp); + I = temp; +}, __doc_igl_colon, +py::arg("low"), py::arg("step"), py::arg("high"), py::arg("I")); + +m.def("colon", [] +( + const double low, + const double high, + Eigen::MatrixXd& I +) +{ + Eigen::Matrix temp; + igl::colon(low,high,temp); + I = temp; +}, __doc_igl_colon, +py::arg("low"), py::arg("high"), py::arg("I")); + +m.def("colon", [] +( + const double& low, + const double& high +) +{ + return Eigen::MatrixXd(igl::colon(low,high)); +}, __doc_igl_colon, +py::arg("low"), py::arg("high")); + + +m.def("coloni", [] +( + const int low, + const int step, + const int high, + Eigen::MatrixXi& I +) +{ + Eigen::Matrix temp; + igl::colon(low,step,high,temp); + I = temp; +}, __doc_igl_colon, +py::arg("low"), py::arg("step"), py::arg("high"), py::arg("I")); + +m.def("coloni", [] +( + const int low, + const int high, + Eigen::MatrixXi& I +) +{ + Eigen::Matrix temp; + igl::colon(low,high,temp); + I = temp; +}, __doc_igl_colon, +py::arg("low"), py::arg("high"), py::arg("I")); + +m.def("coloni", [] +( + const int& low, + const int& high +) +{ + return Eigen::MatrixXi(igl::colon(low,high)); +}, __doc_igl_colon, +py::arg("low"), py::arg("high")); diff --git a/python/py_igl/py_slice_into.cpp b/python/py_igl/py_slice_into.cpp index 06a7640e0..08a7118c9 100644 --- a/python/py_igl/py_slice_into.cpp +++ b/python/py_igl/py_slice_into.cpp @@ -50,3 +50,58 @@ m.def("slice_into", [] return igl::slice_into(X,R,Y); }, __doc_igl_slice_into, py::arg("X"), py::arg("R"), py::arg("Y")); + +// int + +m.def("slice_into", [] +( + const Eigen::SparseMatrix& X, + const Eigen::MatrixXi& R, + const Eigen::MatrixXi& C, + Eigen::SparseMatrix& Y +) +{ + assert_is_VectorX("R",R); + assert_is_VectorX("C",C); + return igl::slice_into(X,R,C,Y); +}, __doc_igl_slice_into, +py::arg("X"), py::arg("R"), py::arg("C"), py::arg("Y")); + +m.def("slice_into", [] +( + const Eigen::MatrixXi& X, + const Eigen::MatrixXi& R, + const Eigen::MatrixXi& C, + Eigen::MatrixXi& Y +) +{ + assert_is_VectorX("R",R); + assert_is_VectorX("C",C); + return igl::slice_into(X,R,C,Y); +}, __doc_igl_slice_into, +py::arg("X"), py::arg("R"), py::arg("C"), py::arg("Y")); + +m.def("slice_into", [] +( + const Eigen::MatrixXi& X, + const Eigen::MatrixXi& R, + const int& dim, + Eigen::MatrixXi& Y +) +{ + assert_is_VectorX("R",R); + return igl::slice_into(X,R,dim,Y); +}, __doc_igl_slice_into, +py::arg("X"), py::arg("R"), py::arg("dim"), py::arg("Y")); + +m.def("slice_into", [] +( + const Eigen::MatrixXi& X, + const Eigen::MatrixXi& R, + Eigen::MatrixXi& Y +) +{ + assert_is_VectorX("R",R); + return igl::slice_into(X,R,Y); +}, __doc_igl_slice_into, +py::arg("X"), py::arg("R"), py::arg("Y")); diff --git a/python/py_igl/py_sortrows.cpp b/python/py_igl/py_sortrows.cpp new file mode 100644 index 000000000..b35d03968 --- /dev/null +++ b/python/py_igl/py_sortrows.cpp @@ -0,0 +1,23 @@ +m.def("sortrows", [] +( + const Eigen::MatrixXd& X, + const bool ascending, + Eigen::MatrixXd& Y, + Eigen::MatrixXi& I +) +{ + return igl::sortrows(X,ascending,Y,I); +}, __doc_igl_sortrows, +py::arg("X"), py::arg("ascending"), py::arg("Y"), py::arg("I")); + +m.def("sortrows", [] +( + const Eigen::MatrixXi& X, + const bool ascending, + Eigen::MatrixXi& Y, + Eigen::MatrixXi& I +) +{ + return igl::sortrows(X,ascending,Y,I); +}, __doc_igl_sortrows, +py::arg("X"), py::arg("ascending"), py::arg("Y"), py::arg("I")); diff --git a/python/py_vector.cpp b/python/py_vector.cpp index 48ee0637c..6c3e7639b 100644 --- a/python/py_vector.cpp +++ b/python/py_vector.cpp @@ -86,6 +86,9 @@ py::class_ bind_eigen_2(py::module &m, const char *name, .def("norm", [](const Type &m) {return m.norm();}) .def("squaredNorm", [](const Type &m) {return m.squaredNorm();}) + .def("castdouble", [](const Type &m) {return Eigen::MatrixXd(m.template cast());}) + .def("castint", [](const Type &m) {return Eigen::MatrixXi(m.template cast());}) + /* Component-wise operations */ .def("cwiseAbs", &Type::cwiseAbs) .def("cwiseAbs2", &Type::cwiseAbs2)