Browse Source

added 302 sort

Former-commit-id: e2e452f5564f6b6196ac23aa3f2a67c72f1010b9
Daniele Panozzo 9 years ago
parent
commit
fbb66fc3d8

+ 34 - 0
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()

+ 4 - 0
python/py_igl.cpp

@@ -23,6 +23,8 @@
 #include <igl/floor.h>
 #include <igl/slice.h>
 #include <igl/slice_into.h>
+#include <igl/sortrows.h>
+#include <igl/colon.h>
 
 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"
 
 }

+ 74 - 0
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<double,Eigen::Dynamic,1> temp;
+  igl::colon<double>(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<double,Eigen::Dynamic,1> temp;
+  igl::colon<double>(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<double>(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<int,Eigen::Dynamic,1> temp;
+  igl::colon<int>(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<int,Eigen::Dynamic,1> temp;
+  igl::colon<int>(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<int>(low,high));
+}, __doc_igl_colon,
+py::arg("low"), py::arg("high"));

+ 55 - 0
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<int>& X,
+  const Eigen::MatrixXi& R,
+  const Eigen::MatrixXi& C,
+  Eigen::SparseMatrix<int>& 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"));

+ 23 - 0
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"));

+ 3 - 0
python/py_vector.cpp

@@ -86,6 +86,9 @@ py::class_<Type> 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<double>());})
+        .def("castint", [](const Type &m) {return Eigen::MatrixXi(m.template cast<int>());})
+
         /* Component-wise operations */
         .def("cwiseAbs", &Type::cwiseAbs)
         .def("cwiseAbs2", &Type::cwiseAbs2)