Browse Source

added 304
fixed bug in py_jet


Former-commit-id: 7db5843947125e0d14769ad2d34bae3367b70b46

Daniele Panozzo 9 years ago
parent
commit
026cea6924

+ 2 - 7
python/301_Slice.py

@@ -6,18 +6,13 @@ F = igl.eigen.MatrixXi()
 
 igl.readOFF("../tutorial/shared/decimated-knight.off",V,F)
 
-temp  = igl.eigen.MatrixXd()
-
 # 100 random indicies into rows of F
-temp.setRandom(100,1)
-
 I = igl.eigen.MatrixXi()
-igl.floor((0.5*(temp+1.)*F.rows()),I);
+igl.floor((0.5*(igl.eigen.MatrixXd.Random(100,1)+1.)*F.rows()),I);
 
 # 50 random indicies into rows of I
-temp.setRandom(50,1)
 J = igl.eigen.MatrixXi()
-igl.floor((0.5*(temp+1.)*I.rows()),J)
+igl.floor((0.5*(igl.eigen.MatrixXd.Random(50,1)+1.)*I.rows()),J)
 
 # K = I(J);
 K = igl.eigen.MatrixXi()

+ 96 - 0
python/304_LinearEqualityConstraints.py

@@ -0,0 +1,96 @@
+import igl
+
+V = igl.eigen.MatrixXd()
+F = igl.eigen.MatrixXi()
+
+igl.readOFF("../tutorial/shared/cheburashka.off",V,F)
+
+# Two fixed points
+# Left hand, left foot
+b = igl.eigen.MatrixXi([[4331],[5957]])
+bc = igl.eigen.MatrixXd([[1],[-1]])
+
+# Construct Laplacian and mass matrix
+L = igl.eigen.SparseMatrixd()
+M = igl.eigen.SparseMatrixd()
+Minv = igl.eigen.SparseMatrixd()
+Q = igl.eigen.SparseMatrixd()
+
+igl.cotmatrix(V,F,L)
+igl.massmatrix(V,F,igl.MASSMATRIX_TYPE_VORONOI,M)
+igl.invert_diag(M,Minv)
+
+# Bi-Laplacian
+Q = L * (Minv * L);
+
+# Zero linear term
+B = igl.eigen.MatrixXd.Zero(V.rows(),1);
+
+Z       = igl.eigen.MatrixXd()
+Z_const = igl.eigen.MatrixXd()
+
+# Alternative, short hand
+mqwf = igl.min_quad_with_fixed_data()
+
+# Empty constraints
+Beq = igl.eigen.MatrixXd()
+Aeq = igl.eigen.SparseMatrixd()
+
+igl.min_quad_with_fixed_precompute(Q,b,Aeq,True,mqwf)
+igl.min_quad_with_fixed_solve(mqwf,B,bc,Beq,Z)
+
+# Constraint forcing difference of two points to be 0
+Aeq = igl.eigen.SparseMatrixd(1,V.rows())
+
+# Right hand, right foot
+Aeq.insert(0,6074,1)
+Aeq.insert(0,6523,-1)
+Aeq.makeCompressed()
+
+Beq = igl.eigen.MatrixXd([[0]])
+igl.min_quad_with_fixed_precompute(Q,b,Aeq,True,mqwf)
+igl.min_quad_with_fixed_solve(mqwf,B,bc,Beq,Z_const)
+
+# Pseudo-color based on solution
+global C
+C = igl.eigen.MatrixXd()
+
+global C_const
+C_const = igl.eigen.MatrixXd()
+
+global toggle
+toggle = True
+
+# Use same color axes
+min_z = min(Z.minCoeff(),Z_const.minCoeff())
+max_z = max(Z.maxCoeff(),Z_const.maxCoeff())
+
+igl.jet(      Z,min_z,max_z,C);
+igl.jet(Z_const,min_z,max_z,C_const);
+
+# Plot the mesh with pseudocolors
+viewer = igl.viewer.Viewer()
+viewer.data.set_mesh(V, F)
+viewer.core.show_lines = False
+viewer.data.set_colors(C)
+
+def key_down(viewer,key,mode):
+    if key == ord(' '):
+        global toggle
+        global C
+        global C_const
+
+        if toggle:
+            viewer.data.set_colors(C)
+        else:
+            viewer.data.set_colors(C_const)
+
+        toggle = not toggle;
+        return True
+
+    return False
+
+viewer.callback_key_down = key_down
+
+print("Press [space] to toggle between unconstrained and constrained.")
+viewer.launch()

+ 3 - 0
python/iglhelpers.py

@@ -46,3 +46,6 @@ def e2p(m):
         J = coo[:, 1]
         V = coo[:, 2]
         return sparse.coo_matrix((V,(I,J)), shape=(m.rows(),m.cols()), dtype='int32')
+
+def printMatrixSizes(x,xn):
+    print(xn + " (" + str(x.rows()) + "," + str(x.cols()) + ")")

+ 2 - 1
python/py_igl/py_jet.cpp

@@ -12,12 +12,13 @@ py::arg("Z"), py::arg("normalize"), py::arg("C"));
 
 m.def("jet", []
 (
-  const Eigen::VectorXd& Z,
+  const Eigen::MatrixXd& Z,
   const double min_Z,
   const double max_Z,
   Eigen::MatrixXd& C
 )
 {
+  assert_is_VectorX("Z",Z);
   return igl::jet(Z,min_Z,max_Z,C);
 }, __doc_igl_jet,
 py::arg("Z"), py::arg("min_Z"), py::arg("max_Z"), py::arg("C"));

+ 14 - 0
python/py_vector.cpp

@@ -109,6 +109,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("minCoeff", [](const Type &m) {return m.minCoeff();} )
+        .def("maxCoeff", [](const Type &m) {return m.maxCoeff();} )
+
         .def("castdouble", [](const Type &m) {return Eigen::MatrixXd(m.template cast<double>());})
         .def("castint", [](const Type &m) {return Eigen::MatrixXi(m.template cast<int>());})
 
@@ -243,6 +246,7 @@ py::class_<Type> bind_eigen_2(py::module &m, const char *name,
 
         /* Static initializers */
         .def_static("Zero", [](size_t n, size_t m) { return Type(Type::Zero(n, m)); })
+        .def_static("Random", [](size_t n, size_t m) { return Type(Type::Random(n, m)); })
         .def_static("Ones", [](size_t n, size_t m) { return Type(Type::Ones(n, m)); })
         .def_static("Constant", [](size_t n, size_t m, Scalar value) { return Type(Type::Constant(n, m, value)); })
         .def_static("Identity", [](size_t n, size_t m) { return Type(Type::Identity(n, m)); })
@@ -446,6 +450,16 @@ py::class_<Type> bind_eigen_sparse_2(py::module &m, const char *name,
           m.setFromTriplets(tripletList.begin(), tripletList.end());
         }, py::arg("t"), py::arg("rows") = -1, py::arg("cols") = -1)
 
+        .def("insert",[](Type& m, const int row, const int col, const Scalar value)
+        {
+          return m.insert(row,col) = value;
+        }, py::arg("row"), py::arg("col"), py::arg("value"))
+
+        .def("makeCompressed",[](Type& m)
+        {
+          return m.makeCompressed();
+        })
+
         ;
     return matrix;
 }