Cleaned up python tutorials and added dependency checks to all tutorials

Former-commit-id: 246017f041
This commit is contained in:
Sebastian Koch
2016-06-07 16:28:06 +02:00
parent c94e83cf08
commit 594aad7067
30 changed files with 621 additions and 513 deletions
+24 -16
View File
@@ -1,9 +1,15 @@
# Add the igl library to the modules search path
import sys, os
sys.path.insert(0, os.getcwd() + "/../")
# Add the igl library to the modules search path
sys.path.insert(0, os.getcwd() + "/../")
import pyigl as igl
from shared import TUTORIAL_SHARED_PATH, check_dependencies
dependencies = ["viewer"]
check_dependencies(dependencies)
V = igl.eigen.MatrixXd()
F = igl.eigen.MatrixXi()
V_uv = igl.eigen.MatrixXd()
@@ -11,6 +17,7 @@ initial_guess = igl.eigen.MatrixXd()
show_uv = False
def key_down(viewer, key, modifier):
global show_uv, V_uv
if key == ord('1'):
@@ -20,43 +27,44 @@ def key_down(viewer, key, modifier):
elif key == ord('q'):
V_uv = initial_guess
if (show_uv):
viewer.data.set_mesh(V_uv,F)
viewer.core.align_camera_center(V_uv,F)
if show_uv:
viewer.data.set_mesh(V_uv, F)
viewer.core.align_camera_center(V_uv, F)
else:
viewer.data.set_mesh(V,F)
viewer.core.align_camera_center(V,F)
viewer.data.set_mesh(V, F)
viewer.core.align_camera_center(V, F)
viewer.data.compute_normals()
return False
# Load a mesh in OFF format
igl.readOFF("../../tutorial/shared/camelhead.off", V, F)
igl.readOFF(TUTORIAL_SHARED_PATH + "camelhead.off", V, F)
# Compute the initial solution for ARAP (harmonic parametrization)
bnd = igl.eigen.MatrixXi()
igl.boundary_loop(F,bnd)
igl.boundary_loop(F, bnd)
bnd_uv = igl.eigen.MatrixXd()
igl.map_vertices_to_circle(V,bnd,bnd_uv)
igl.map_vertices_to_circle(V, bnd, bnd_uv)
igl.harmonic(V,F,bnd,bnd_uv,1,initial_guess)
igl.harmonic(V, F, bnd, bnd_uv, 1, initial_guess)
# Add dynamic regularization to avoid to specify boundary conditions
arap_data = igl.ARAPData()
arap_data.with_dynamics = True
b = igl.eigen.MatrixXi.Zero(0,0);
bc = igl.eigen.MatrixXd.Zero(0,0);
b = igl.eigen.MatrixXi.Zero(0, 0)
bc = igl.eigen.MatrixXd.Zero(0, 0)
# Initialize ARAP
arap_data.max_iter = 100
# 2 means that we're going to *solve* in 2d
igl.arap_precomputation(V,F,2,b,arap_data)
igl.arap_precomputation(V, F, 2, b, arap_data)
# Solve arap using the harmonic map as initial guess
V_uv = igl.eigen.MatrixXd(initial_guess) # important, make a copy of it!
V_uv = igl.eigen.MatrixXd(initial_guess) # important, make a copy of it!
igl.arap_solve(bc,arap_data,V_uv)
igl.arap_solve(bc, arap_data, V_uv)
# Scale UV to make the texture more clear
V_uv *= 20