Browse Source

Moved and refactored picking tutorial 607->708

Former-commit-id: 76c80d3c0bae3e17df63af668ce007080a27e7d6
Sebastian Koch 9 years ago
parent
commit
64c62a6050
1 changed files with 21 additions and 18 deletions
  1. 21 18
      python/tutorial/708_Picking.py

+ 21 - 18
python/tutorial/607_Picking.py → python/tutorial/708_Picking.py

@@ -5,19 +5,12 @@ sys.path.insert(0, os.getcwd() + "/../")
 import pyigl as igl
 
 
-from shared import TUTORIAL_SHARED_PATH, check_dependencies
+from shared import TUTORIAL_SHARED_PATH, check_dependencies, print_usage
 
 dependencies = ["viewer"]
 check_dependencies(dependencies)
 
 
-# Mesh with per-face color
-V = igl.eigen.MatrixXd()
-F = igl.eigen.MatrixXi()
-C = igl.eigen.MatrixXd()
-
-viewer = igl.viewer.Viewer()
-
 def mouse_down(viewer, a, b):
     bc = igl.eigen.MatrixXd()
 
@@ -27,6 +20,7 @@ def mouse_down(viewer, a, b):
     hit = igl.unproject_onto_mesh(coord, viewer.core.view * viewer.core.model,
       viewer.core.proj, viewer.core.viewport, V, F, fid, bc)
     if hit:
+        # paint hit red
         C.setRow(fid[0, 0], igl.eigen.MatrixXd([[1, 0, 0]]))
         viewer.data.set_colors(C)
         return True
@@ -34,16 +28,25 @@ def mouse_down(viewer, a, b):
     return False
 
 
-print("Usage: [LeftMouseClick] to select a face")
+if __name__ == "__main__":
+    keys = {"click": "Pick face on shape"}
+    print_usage(keys)
+
+    # Mesh with per-face color
+    V = igl.eigen.MatrixXd()
+    F = igl.eigen.MatrixXi()
+    C = igl.eigen.MatrixXd()
 
-# Load a mesh in OFF format
-igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V, F)
+    # Load a mesh in OFF format
+    igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V, F)
 
-# Initialize white
-C.setConstant(F.rows(), 3, 1.0)
+    # Initialize white
+    C.setConstant(F.rows(), 3, 1.0)
 
-viewer.data.set_mesh(V, F)
-viewer.data.set_colors(C)
-viewer.core.show_lines = False
-viewer.callback_mouse_down = mouse_down
-viewer.launch()
+    # Show mesh
+    viewer = igl.viewer.Viewer()
+    viewer.data.set_mesh(V, F)
+    viewer.data.set_colors(C)
+    viewer.core.show_lines = False
+    viewer.callback_mouse_down = mouse_down
+    viewer.launch()