Browse Source

added 501

Former-commit-id: 821d857f0b899aaae642cab001c761af02a3570d
Daniele Panozzo 9 years ago
parent
commit
03e3692bd4

+ 49 - 0
python/501_HarmonicParam.py

@@ -0,0 +1,49 @@
+import igl
+
+V = igl.eigen.MatrixXd()
+F = igl.eigen.MatrixXi()
+V_uv = igl.eigen.MatrixXd()
+
+def key_down(viewer, key, modifier):
+    if key == ord('1'):
+        # Plot the 3D mesh
+        viewer.data.set_mesh(V,F)
+        viewer.core.align_camera_center(V,F)
+    elif key == ord('2'):
+        # Plot the mesh in 2D using the UV coordinates as vertex coordinates
+        viewer.data.set_mesh(V_uv,F)
+        viewer.core.align_camera_center(V_uv,F)
+    viewer.data.compute_normals()
+    return False
+
+# Load a mesh in OFF format
+igl.readOFF("../tutorial/shared/camelhead.off", V, F)
+
+# Find the open boundary
+bnd = igl.eigen.MatrixXi()
+igl.boundary_loop(F,bnd)
+
+# Map the boundary to a circle, preserving edge proportions
+bnd_uv = igl.eigen.MatrixXd()
+igl.map_vertices_to_circle(V,bnd,bnd_uv)
+
+# Harmonic parametrization for the internal vertices
+igl.harmonic(V,F,bnd,bnd_uv,1,V_uv)
+
+# Scale UV to make the texture more clear
+V_uv *= 5;
+
+# Plot the mesh
+viewer = igl.viewer.Viewer()
+viewer.data.set_mesh(V, F)
+viewer.data.set_uv(V_uv)
+viewer.callback_key_down = key_down
+
+# Disable wireframe
+viewer.core.show_lines = False
+
+# Draw checkerboard texture
+viewer.core.show_texture = True
+
+# Launch the viewer
+viewer.launch()

+ 5 - 0
python/py_igl.cpp

@@ -36,6 +36,8 @@
 #include <igl/harmonic.h>
 #include <igl/arap.h>
 #include <igl/ARAPEnergyType.h>
+#include <igl/boundary_loop.h>
+#include <igl/map_vertices_to_circle.h>
 
 void python_export_igl(py::module &m)
 {
@@ -73,4 +75,7 @@ void python_export_igl(py::module &m)
 #include "py_igl/py_harmonic.cpp"
 #include "py_igl/py_ARAPEnergyType.cpp"
 #include "py_igl/py_arap.cpp"
+#include "py_igl/py_boundary_loop.cpp"
+#include "py_igl/py_map_vertices_to_circle.cpp"
+
 }

+ 31 - 0
python/py_igl/py_boundary_loop.cpp

@@ -0,0 +1,31 @@
+m.def("boundary_loop", []
+(
+  const Eigen::MatrixXi& F,
+  std::vector<std::vector<int> >& L
+)
+{
+  return igl::boundary_loop(F,L);
+}, __doc_igl_boundary_loop,
+py::arg("F"), py::arg("L"));
+
+m.def("boundary_loop", []
+(
+  const Eigen::MatrixXi& F,
+  std::vector<int>& L
+)
+{
+  return igl::boundary_loop(F,L);
+}, __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"));

+ 11 - 0
python/py_igl/py_map_vertices_to_circle.cpp

@@ -0,0 +1,11 @@
+m.def("map_vertices_to_circle", []
+(
+  const Eigen::MatrixXd& V,
+  const Eigen::MatrixXi& bnd,
+  Eigen::MatrixXd& UV
+)
+{
+  assert_is_VectorX("bnd",bnd);
+  return igl::map_vertices_to_circle(V,bnd,UV);
+}, __doc_igl_map_vertices_to_circle,
+py::arg("V"), py::arg("bnd"), py::arg("UV"));

+ 2 - 2
python/py_vector.cpp

@@ -221,8 +221,8 @@ py::class_<Type> bind_eigen_2(py::module &m, const char *name,
         .def_cast(py::self += py::self)
         .def_cast(py::self -= py::self)
         .def_cast(py::self *= py::self)
-        // .def_cast(py::self *= Scalar())
-        // .def_cast(py::self /= Scalar())
+        .def_cast(py::self *= Scalar())
+        .def_cast(py::self /= Scalar())
 
         /* Comparison operators */
         .def(py::self == py::self)