Jelajahi Sumber

finished overlay tutorial

Former-commit-id: 1a5e91672ac10a4e7d486a524afebb6e3304047f
Daniele Panozzo 9 tahun lalu
induk
melakukan
4e3778918a
3 mengubah file dengan 75 tambahan dan 6 penghapusan
  1. 69 0
      python/105_Overlays.py
  2. 5 5
      python/iglhelpers.py
  3. 1 1
      python/py_igl_viewer.cpp

+ 69 - 0
python/105_Overlays.py

@@ -0,0 +1,69 @@
+import igl
+import numpy as np
+from iglhelpers import *
+
+V = igl.eigen.MatrixXd()
+F = igl.eigen.MatrixXi()
+
+# Load a mesh in OFF format
+igl.readOFF("../tutorial/shared/bunny.off", V, F)
+
+# Find the bounding box
+m = V.colwiseMinCoeff()
+M = V.colwiseMaxCoeff()
+
+# Corners of the bounding box
+V_box = p2e(np.matrix(
+[
+[m[0,0], m[0,1], m[0,2]],
+[M[0,0], m[0,1], m[0,2]],
+[M[0,0], M[0,1], m[0,2]],
+[m[0,0], M[0,1], m[0,2]],
+[m[0,0], m[0,1], M[0,2]],
+[M[0,0], m[0,1], M[0,2]],
+[M[0,0], M[0,1], M[0,2]],
+[m[0,0], M[0,1], M[0,2]]
+]
+))
+
+E_box = p2e(np.matrix(
+[
+[0, 1],
+[1, 2],
+[2, 3],
+[3, 0],
+[4, 5],
+[5, 6],
+[6, 7],
+[7, 4],
+[0, 4],
+[1, 5],
+[2, 6],
+[7 ,3]
+], dtype='int32'
+))
+
+# Plot the mesh
+viewer = igl.viewer.Viewer()
+viewer.data.set_mesh(V, F)
+
+# Plot the corners of the bounding box as points
+viewer.data.add_points(V_box,p2e(np.array([[1,0,0]], dtype='float64')))
+
+# Plot the edges of the bounding box
+
+for i in range(0,E_box.rows()):
+    viewer.data.add_edges(
+        V_box.row(E_box[i,0]),
+        V_box.row(E_box[i,1]),
+        p2e(np.array([[1,0,0]], dtype='float64')))
+
+# Plot labels with the coordinates of bounding box vertices
+l1 = 'x: ' + str(m[0,0]) + ' y: ' + str(m[0,1]) + ' z: ' + str(m[0,2])
+viewer.data.add_label(m.transpose(),l1)
+
+l2 = 'x: ' + str(M[0,0]) + ' y: ' + str(M[0,1]) + ' z: ' + str(M[0,2])
+viewer.data.add_label(M.transpose(),l2);
+
+# Launch the viewer
+viewer.launch();

+ 5 - 5
python/iglhelpers.py

@@ -4,11 +4,11 @@ import igl
 
 def p2e(m):
     if isinstance(m, np.ndarray):
-        if m.dtype.type == np.int64:
+        if m.dtype.type == np.int32:
             return igl.eigen.MatrixXi(m)
         elif m.dtype.type == np.float64:
             return igl.eigen.MatrixXd(m)
-        raise TypeError("p2e only support dtype float64 or int64")
+        raise TypeError("p2e only support dtype float64 or int32")
     if sparse.issparse(m):
         # convert in a dense matrix with triples
         coo = m.tocoo()
@@ -16,7 +16,7 @@ def p2e(m):
 
         triples_eigen_wrapper = igl.eigen.MatrixXd(triplets)
 
-        if m.dtype.type == np.int64:
+        if m.dtype.type == np.int32:
             t = igl.eigen.SparseMatrixi()
             t.fromcoo(triples_eigen_wrapper)
             return t
@@ -33,7 +33,7 @@ def e2p(m):
     if isinstance(m, igl.eigen.MatrixXd):
         return np.array(m, dtype='float64')
     elif isinstance(m, igl.eigen.MatrixXi):
-        return np.array(m, dtype='int64')
+        return np.array(m, dtype='int32')
     elif isinstance(m, igl.eigen.SparseMatrixd):
         coo = np.array(m.toCOO())
         I = coo[:, 0]
@@ -45,4 +45,4 @@ def e2p(m):
         I = coo[:, 0]
         J = coo[:, 1]
         V = coo[:, 2]
-        return sparse.coo_matrix((V,(I,J)), shape=(m.rows(),m.cols()), dtype='int64')
+        return sparse.coo_matrix((V,(I,J)), shape=(m.rows(),m.cols()), dtype='int32')

+ 1 - 1
python/py_igl_viewer.cpp

@@ -281,7 +281,7 @@ py::class_<igl::viewer::ViewerCore> viewercore_class(me, "ViewerCore");
         .value("Right", igl::viewer::Viewer::MouseButton::Right)
         .export_values();
 
-    viewercore_class
+    viewer_class
     .def(py::init<>())
     .def_readwrite("data", &igl::viewer::Viewer::data)
     .def_readwrite("core", &igl::viewer::Viewer::core)