|
@@ -1,9 +1,15 @@
|
|
|
-# Add the igl library to the modules search path
|
|
|
import sys, os
|
|
|
-sys.path.insert(0, os.getcwd() + "/../")
|
|
|
+from math import pi
|
|
|
|
|
|
+# Add the igl library to the modules search path
|
|
|
+sys.path.insert(0, os.getcwd() + "/../")
|
|
|
import pyigl as igl
|
|
|
-from math import pi
|
|
|
+
|
|
|
+from shared import TUTORIAL_SHARED_PATH, check_dependencies
|
|
|
+
|
|
|
+dependencies = ["comiso", "viewer"]
|
|
|
+check_dependencies(dependencies)
|
|
|
+
|
|
|
|
|
|
V = igl.eigen.MatrixXd()
|
|
|
F = igl.eigen.MatrixXi()
|
|
@@ -13,7 +19,7 @@ B = igl.eigen.MatrixXd()
|
|
|
|
|
|
# Scale for visualizing the fields
|
|
|
global_scale = 1
|
|
|
-extend_arrows = False;
|
|
|
+extend_arrows = False
|
|
|
|
|
|
# Cross field
|
|
|
X1 = igl.eigen.MatrixXd()
|
|
@@ -54,25 +60,27 @@ texture_R = igl.eigen.MatrixXuc()
|
|
|
texture_G = igl.eigen.MatrixXuc()
|
|
|
texture_B = igl.eigen.MatrixXuc()
|
|
|
|
|
|
+
|
|
|
# Create a texture that hides the integer translation in the parametrization
|
|
|
def line_texture():
|
|
|
size = 128
|
|
|
- size2 = int(size/2)
|
|
|
+ size2 = int(size / 2)
|
|
|
lineWidth = 3
|
|
|
texture_R.setConstant(size, size, 255)
|
|
|
|
|
|
- for i in range(0,size):
|
|
|
- for j in range(size2-lineWidth,size2+lineWidth+1):
|
|
|
- texture_R[i,j] = 0
|
|
|
+ for i in range(0, size):
|
|
|
+ for j in range(size2 - lineWidth, size2 + lineWidth + 1):
|
|
|
+ texture_R[i, j] = 0
|
|
|
|
|
|
- for i in range(size2-lineWidth,size2+lineWidth+1):
|
|
|
- for j in range(0,size):
|
|
|
- texture_R[i,j] = 0
|
|
|
+ for i in range(size2 - lineWidth, size2 + lineWidth + 1):
|
|
|
+ for j in range(0, size):
|
|
|
+ texture_R[i, j] = 0
|
|
|
|
|
|
texture_G = texture_R.copy()
|
|
|
texture_B = texture_R.copy()
|
|
|
return (texture_R, texture_G, texture_B)
|
|
|
|
|
|
+
|
|
|
def key_down(viewer, key, modifier):
|
|
|
global extend_arrows, texture_R, texture_G, texture_B
|
|
|
|
|
@@ -80,7 +88,7 @@ def key_down(viewer, key, modifier):
|
|
|
extend_arrows = not extend_arrows
|
|
|
|
|
|
if key < ord('1') or key > ord('8'):
|
|
|
- return False;
|
|
|
+ return False
|
|
|
|
|
|
viewer.data.clear()
|
|
|
viewer.core.show_lines = False
|
|
@@ -89,20 +97,26 @@ def key_down(viewer, key, modifier):
|
|
|
if key == ord('1'):
|
|
|
# Cross field
|
|
|
viewer.data.set_mesh(V, F)
|
|
|
- viewer.data.add_edges(B - global_scale*X1 if extend_arrows else B, B + global_scale*X1 , igl.eigen.MatrixXd([[1,0,0]]))
|
|
|
- viewer.data.add_edges(B - global_scale*X2 if extend_arrows else B, B + global_scale*X2 , igl.eigen.MatrixXd([[0,0,1]]))
|
|
|
+ viewer.data.add_edges(B - global_scale * X1 if extend_arrows else B, B + global_scale * X1,
|
|
|
+ igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
+ viewer.data.add_edges(B - global_scale * X2 if extend_arrows else B, B + global_scale * X2,
|
|
|
+ igl.eigen.MatrixXd([[0, 0, 1]]))
|
|
|
|
|
|
if key == ord('2'):
|
|
|
# Bisector field
|
|
|
viewer.data.set_mesh(V, F)
|
|
|
- viewer.data.add_edges(B - global_scale*BIS1 if extend_arrows else B, B + global_scale*BIS1 , igl.eigen.MatrixXd([[1,0,0]]))
|
|
|
- viewer.data.add_edges(B - global_scale*BIS2 if extend_arrows else B, B + global_scale*BIS2 , igl.eigen.MatrixXd([[0,0,1]]))
|
|
|
+ viewer.data.add_edges(B - global_scale * BIS1 if extend_arrows else B, B + global_scale * BIS1,
|
|
|
+ igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
+ viewer.data.add_edges(B - global_scale * BIS2 if extend_arrows else B, B + global_scale * BIS2,
|
|
|
+ igl.eigen.MatrixXd([[0, 0, 1]]))
|
|
|
|
|
|
if key == ord('3'):
|
|
|
# Bisector field combed
|
|
|
viewer.data.set_mesh(V, F)
|
|
|
- viewer.data.add_edges(B - global_scale*BIS1_combed if extend_arrows else B, B + global_scale*BIS1_combed , igl.eigen.MatrixXd([[1,0,0]]))
|
|
|
- viewer.data.add_edges(B - global_scale*BIS2_combed if extend_arrows else B, B + global_scale*BIS2_combed , igl.eigen.MatrixXd([[0,0,1]]))
|
|
|
+ viewer.data.add_edges(B - global_scale * BIS1_combed if extend_arrows else B, B + global_scale * BIS1_combed,
|
|
|
+ igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
+ viewer.data.add_edges(B - global_scale * BIS2_combed if extend_arrows else B, B + global_scale * BIS2_combed,
|
|
|
+ igl.eigen.MatrixXd([[0, 0, 1]]))
|
|
|
|
|
|
if key == ord('4'):
|
|
|
# Singularities and cuts
|
|
@@ -110,53 +124,55 @@ def key_down(viewer, key, modifier):
|
|
|
|
|
|
# Plot cuts
|
|
|
l_count = Seams.sum()
|
|
|
- P1 = igl.eigen.MatrixXd(l_count,3)
|
|
|
- P2 = igl.eigen.MatrixXd(l_count,3)
|
|
|
+ P1 = igl.eigen.MatrixXd(l_count, 3)
|
|
|
+ P2 = igl.eigen.MatrixXd(l_count, 3)
|
|
|
|
|
|
- for i in range(0,Seams.rows()):
|
|
|
- for j in range(0,Seams.cols()):
|
|
|
- if Seams[i,j] != 0:
|
|
|
- P1.setRow(l_count-1, V.row(F[i,j]))
|
|
|
- P2.setRow(l_count-1, V.row(F[i,(j+1)%3]))
|
|
|
- l_count = l_count - 1
|
|
|
+ for i in range(0, Seams.rows()):
|
|
|
+ for j in range(0, Seams.cols()):
|
|
|
+ if Seams[i, j] != 0:
|
|
|
+ P1.setRow(l_count - 1, V.row(F[i, j]))
|
|
|
+ P2.setRow(l_count - 1, V.row(F[i, (j + 1) % 3]))
|
|
|
+ l_count -= 1
|
|
|
|
|
|
viewer.data.add_edges(P1, P2, igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
|
|
|
# Plot the singularities as colored dots (red for negative, blue for positive)
|
|
|
- for i in range(0,singularityIndex.size()):
|
|
|
- if singularityIndex[i] < 2 and singularityIndex[i] > 0:
|
|
|
- viewer.data.add_points(V.row(i),igl.eigen.MatrixXd([[1,0,0]]))
|
|
|
+ for i in range(0, singularityIndex.size()):
|
|
|
+ if 2 > singularityIndex[i] > 0:
|
|
|
+ viewer.data.add_points(V.row(i), igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
elif singularityIndex[i] > 2:
|
|
|
- viewer.data.add_points(V.row(i),igl.eigen.MatrixXd([[1,0,0]]))
|
|
|
+ viewer.data.add_points(V.row(i), igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
|
|
|
if key == ord('5'):
|
|
|
# Singularities and cuts, original field
|
|
|
# Singularities and cuts
|
|
|
viewer.data.set_mesh(V, F)
|
|
|
- viewer.data.add_edges(B - global_scale*X1_combed if extend_arrows else B, B + global_scale*X1_combed ,igl.eigen.MatrixXd([[1,0,0]]))
|
|
|
- viewer.data.add_edges(B - global_scale*X2_combed if extend_arrows else B, B + global_scale*X2_combed ,igl.eigen.MatrixXd([[0,0,1]]))
|
|
|
+ viewer.data.add_edges(B - global_scale * X1_combed if extend_arrows else B, B + global_scale * X1_combed,
|
|
|
+ igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
+ viewer.data.add_edges(B - global_scale * X2_combed if extend_arrows else B, B + global_scale * X2_combed,
|
|
|
+ igl.eigen.MatrixXd([[0, 0, 1]]))
|
|
|
|
|
|
# Plot cuts
|
|
|
l_count = Seams.sum()
|
|
|
|
|
|
- P1 = igl.eigen.MatrixXd(l_count,3)
|
|
|
- P2 = igl.eigen.MatrixXd(l_count,3)
|
|
|
+ P1 = igl.eigen.MatrixXd(l_count, 3)
|
|
|
+ P2 = igl.eigen.MatrixXd(l_count, 3)
|
|
|
|
|
|
for i in range(0, Seams.rows()):
|
|
|
for j in range(0, Seams.cols()):
|
|
|
- if Seams[i,j] != 0:
|
|
|
- P1.setRow(l_count-1,V.row(F[i,j]))
|
|
|
- P2.setRow(l_count-1,V.row(F[i,(j+1)%3]))
|
|
|
- l_count = l_count - 1
|
|
|
+ if Seams[i, j] != 0:
|
|
|
+ P1.setRow(l_count - 1, V.row(F[i, j]))
|
|
|
+ P2.setRow(l_count - 1, V.row(F[i, (j + 1) % 3]))
|
|
|
+ l_count -= 1
|
|
|
|
|
|
viewer.data.add_edges(P1, P2, igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
|
|
|
# Plot the singularities as colored dots (red for negative, blue for positive)
|
|
|
- for i in range(0,singularityIndex.size()):
|
|
|
- if singularityIndex[i] < 2 and singularityIndex[i] > 0:
|
|
|
- viewer.data.add_points(V.row(i),igl.eigen.MatrixXd([[1,0,0]]))
|
|
|
+ for i in range(0, singularityIndex.size()):
|
|
|
+ if 2 > singularityIndex[i] > 0:
|
|
|
+ viewer.data.add_points(V.row(i), igl.eigen.MatrixXd([[1, 0, 0]]))
|
|
|
elif singularityIndex[i] > 2:
|
|
|
- viewer.data.add_points(V.row(i),igl.eigen.MatrixXd([[0,1,0]]))
|
|
|
+ viewer.data.add_points(V.row(i), igl.eigen.MatrixXd([[0, 1, 0]]))
|
|
|
|
|
|
if key == ord('6'):
|
|
|
# Global parametrization UV
|
|
@@ -167,49 +183,50 @@ def key_down(viewer, key, modifier):
|
|
|
if key == ord('7'):
|
|
|
# Global parametrization in 3D
|
|
|
viewer.data.set_mesh(V, F)
|
|
|
- viewer.data.set_uv(UV,FUV)
|
|
|
+ viewer.data.set_uv(UV, FUV)
|
|
|
viewer.core.show_texture = True
|
|
|
|
|
|
if key == ord('8'):
|
|
|
# Global parametrization in 3D with seams
|
|
|
viewer.data.set_mesh(V, F)
|
|
|
- viewer.data.set_uv(UV_seams,FUV_seams)
|
|
|
+ viewer.data.set_uv(UV_seams, FUV_seams)
|
|
|
viewer.core.show_texture = True
|
|
|
|
|
|
- viewer.data.set_colors(igl.eigen.MatrixXd([[1,1,1]]))
|
|
|
+ viewer.data.set_colors(igl.eigen.MatrixXd([[1, 1, 1]]))
|
|
|
|
|
|
viewer.data.set_texture(texture_R, texture_B, texture_G)
|
|
|
|
|
|
- viewer.core.align_camera_center(viewer.data.V,viewer.data.F)
|
|
|
+ viewer.core.align_camera_center(viewer.data.V, viewer.data.F)
|
|
|
|
|
|
return False
|
|
|
|
|
|
+
|
|
|
# Load a mesh in OFF format
|
|
|
-igl.readOFF("../../tutorial/shared/3holes.off", V, F)
|
|
|
+igl.readOFF(TUTORIAL_SHARED_PATH + "3holes.off", V, F)
|
|
|
|
|
|
# Compute face barycenters
|
|
|
igl.barycenter(V, F, B)
|
|
|
|
|
|
# Compute scale for visualizing fields
|
|
|
-global_scale = .5*igl.avg_edge_length(V, F)
|
|
|
+global_scale = .5 * igl.avg_edge_length(V, F)
|
|
|
|
|
|
# Contrain one face
|
|
|
-b = igl.eigen.MatrixXi([[0]])
|
|
|
-bc = igl.eigen.MatrixXd([[1,0,0]])
|
|
|
+b = igl.eigen.MatrixXi([[0]])
|
|
|
+bc = igl.eigen.MatrixXd([[1, 0, 0]])
|
|
|
|
|
|
# Create a smooth 4-RoSy field
|
|
|
S = igl.eigen.MatrixXd()
|
|
|
|
|
|
-igl.comiso.nrosy(V,F,b,bc,igl.eigen.MatrixXi(),igl.eigen.MatrixXd(),igl.eigen.MatrixXd(),4,0.5,X1,S)
|
|
|
+igl.comiso.nrosy(V, F, b, bc, igl.eigen.MatrixXi(), igl.eigen.MatrixXd(), igl.eigen.MatrixXd(), 4, 0.5, X1, S)
|
|
|
|
|
|
# Find the the orthogonal vector
|
|
|
B1 = igl.eigen.MatrixXd()
|
|
|
B2 = igl.eigen.MatrixXd()
|
|
|
B3 = igl.eigen.MatrixXd()
|
|
|
|
|
|
-igl.local_basis(V,F,B1,B2,B3)
|
|
|
+igl.local_basis(V, F, B1, B2, B3)
|
|
|
|
|
|
-X2 = igl.rotate_vectors(X1, igl.eigen.MatrixXd.Constant(1,1,pi/2), B1, B2)
|
|
|
+X2 = igl.rotate_vectors(X1, igl.eigen.MatrixXd.Constant(1, 1, pi / 2), B1, B2)
|
|
|
|
|
|
gradient_size = 50
|
|
|
iterations = 0
|
|
@@ -226,7 +243,7 @@ igl.comb_cross_field(V, F, BIS1, BIS2, BIS1_combed, BIS2_combed)
|
|
|
igl.cross_field_missmatch(V, F, BIS1_combed, BIS2_combed, True, MMatch)
|
|
|
|
|
|
# Find the singularities
|
|
|
-igl.find_cross_field_singularities(V, F, MMatch, isSingularity, singularityIndex);
|
|
|
+igl.find_cross_field_singularities(V, F, MMatch, isSingularity, singularityIndex)
|
|
|
|
|
|
# Cut the mesh, duplicating all vertices on the seams
|
|
|
igl.cut_mesh_from_singularities(V, F, MMatch, Seams)
|
|
@@ -235,39 +252,12 @@ igl.cut_mesh_from_singularities(V, F, MMatch, Seams)
|
|
|
igl.comb_frame_field(V, F, X1, X2, BIS1_combed, BIS2_combed, X1_combed, X2_combed)
|
|
|
|
|
|
# Global parametrization
|
|
|
-igl.comiso.miq(V,
|
|
|
- F,
|
|
|
- X1_combed,
|
|
|
- X2_combed,
|
|
|
- MMatch,
|
|
|
- isSingularity,
|
|
|
- Seams,
|
|
|
- UV,
|
|
|
- FUV,
|
|
|
- gradient_size,
|
|
|
- stiffness,
|
|
|
- direct_round,
|
|
|
- iterations,
|
|
|
- 5,
|
|
|
- True,
|
|
|
- True);
|
|
|
+igl.comiso.miq(V, F, X1_combed, X2_combed, MMatch, isSingularity, Seams, UV, FUV, gradient_size, stiffness,
|
|
|
+ direct_round, iterations, 5, True, True)
|
|
|
|
|
|
# Global parametrization (with seams, only for demonstration)
|
|
|
-igl.comiso.miq(V,
|
|
|
- F,
|
|
|
- X1_combed,
|
|
|
- X2_combed,
|
|
|
- MMatch,
|
|
|
- isSingularity,
|
|
|
- Seams,
|
|
|
- UV_seams,
|
|
|
- FUV_seams,
|
|
|
- gradient_size,
|
|
|
- stiffness,
|
|
|
- direct_round,
|
|
|
- iterations,
|
|
|
- 5,
|
|
|
- False);
|
|
|
+igl.comiso.miq(V, F, X1_combed, X2_combed, MMatch, isSingularity, Seams, UV_seams, FUV_seams, gradient_size,
|
|
|
+ stiffness, direct_round, iterations, 5, False)
|
|
|
|
|
|
# Plot the mesh
|
|
|
viewer = igl.viewer.Viewer()
|
|
@@ -276,7 +266,7 @@ viewer = igl.viewer.Viewer()
|
|
|
(texture_R, texture_G, texture_B) = line_texture()
|
|
|
|
|
|
# Plot the original mesh with a texture parametrization
|
|
|
-key_down(viewer,ord('7'),0)
|
|
|
+key_down(viewer, ord('7'), 0)
|
|
|
|
|
|
# Launch the viewer
|
|
|
viewer.callback_key_down = key_down
|