@@ -65,7 +65,7 @@ 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);
|
||||
viewer.data.add_label(M.transpose(),l2)
|
||||
|
||||
# Launch the viewer
|
||||
viewer.launch();
|
||||
viewer.launch()
|
||||
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
# Add the igl library to the modules search path
|
||||
import sys, os
|
||||
|
||||
sys.path.insert(0, os.getcwd() + "/../")
|
||||
|
||||
import pyigl as igl
|
||||
import random
|
||||
from math import cos, sin, pi
|
||||
|
||||
TUTORIAL_SHARED_PATH = "../../tutorial/shared/"
|
||||
|
||||
viewer = igl.viewer.Viewer()
|
||||
|
||||
# Quad mesh generated from conjugate field
|
||||
VQC = igl.eigen.MatrixXd()
|
||||
FQC = igl.eigen.MatrixXi()
|
||||
FQCtri = igl.eigen.MatrixXi()
|
||||
PQC0 = igl.eigen.MatrixXd()
|
||||
PQC1 = igl.eigen.MatrixXd()
|
||||
PQC2 = igl.eigen.MatrixXd()
|
||||
PQC3 = igl.eigen.MatrixXd()
|
||||
|
||||
# Planarized quad mesh
|
||||
VQCplan = igl.eigen.MatrixXd()
|
||||
FQCtriplan = igl.eigen.MatrixXi()
|
||||
PQC0plan = igl.eigen.MatrixXd()
|
||||
PQC1plan = igl.eigen.MatrixXd()
|
||||
PQC2plan = igl.eigen.MatrixXd()
|
||||
PQC3plan = igl.eigen.MatrixXd()
|
||||
|
||||
|
||||
def key_down(viewer, key, modifier):
|
||||
if key == ord('1'):
|
||||
# Draw the triangulated quad mesh
|
||||
viewer.data.set_mesh(VQC, FQCtri)
|
||||
|
||||
# Assign a color to each quad that corresponds to its planarity
|
||||
planarity = igl.eigen.MatrixXd()
|
||||
igl.quad_planarity(VQC, FQC, planarity)
|
||||
Ct = igl.eigen.MatrixXd()
|
||||
igl.jet(planarity, 0, 0.01, Ct)
|
||||
C = igl.eigen.MatrixXd(FQCtri.rows(), 3)
|
||||
C.setTopRows(Ct.rows(), Ct)
|
||||
C.setBottomRows(Ct.rows(), Ct)
|
||||
viewer.data.set_colors(C)
|
||||
|
||||
# Plot a line for each edge of the quad mesh
|
||||
viewer.data.add_edges(PQC0, PQC1, igl.eigen.MatrixXd([[0, 0, 0]]))
|
||||
viewer.data.add_edges(PQC1, PQC2, igl.eigen.MatrixXd([[0, 0, 0]]))
|
||||
viewer.data.add_edges(PQC2, PQC3, igl.eigen.MatrixXd([[0, 0, 0]]))
|
||||
viewer.data.add_edges(PQC3, PQC0, igl.eigen.MatrixXd([[0, 0, 0]]))
|
||||
|
||||
elif key == ord('2'):
|
||||
# Draw the planar quad mesh
|
||||
viewer.data.set_mesh(VQCplan, FQCtri)
|
||||
|
||||
# Assign a color to each quad that corresponds to its planarity
|
||||
planarity = igl.eigen.MatrixXd()
|
||||
igl.quad_planarity(VQCplan, FQC, planarity)
|
||||
Ct = igl.eigen.MatrixXd()
|
||||
igl.jet(planarity, 0, 0.01, Ct)
|
||||
C = igl.eigen.MatrixXd(FQCtri.rows(), 3)
|
||||
C.setTopRows(Ct.rows(), Ct)
|
||||
C.setBottomRows(Ct.rows(), Ct)
|
||||
viewer.data.set_colors(C)
|
||||
|
||||
# Plot a line for each edge of the quad mesh
|
||||
viewer.data.add_edges(PQC0plan, PQC1plan, igl.eigen.MatrixXd([[0, 0, 0]]))
|
||||
viewer.data.add_edges(PQC1plan, PQC2plan, igl.eigen.MatrixXd([[0, 0, 0]]))
|
||||
viewer.data.add_edges(PQC2plan, PQC3plan, igl.eigen.MatrixXd([[0, 0, 0]]))
|
||||
viewer.data.add_edges(PQC3plan, PQC0plan, igl.eigen.MatrixXd([[0, 0, 0]]))
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# Load a quad mesh generated by a conjugate field
|
||||
igl.readOFF(TUTORIAL_SHARED_PATH + "inspired_mesh_quads_Conjugate.off", VQC, FQC)
|
||||
|
||||
# Convert it to a triangle mesh
|
||||
FQCtri.resize(2 * FQC.rows(), 3)
|
||||
|
||||
FQCtriUpper = igl.eigen.MatrixXi(FQC.rows(), 3)
|
||||
FQCtriLower = igl.eigen.MatrixXi(FQC.rows(), 3)
|
||||
|
||||
FQCtriUpper.setCol(0, FQC.col(0))
|
||||
FQCtriUpper.setCol(1, FQC.col(1))
|
||||
FQCtriUpper.setCol(2, FQC.col(2))
|
||||
FQCtriLower.setCol(0, FQC.col(2))
|
||||
FQCtriLower.setCol(1, FQC.col(3))
|
||||
FQCtriLower.setCol(2, FQC.col(0))
|
||||
|
||||
FQCtri.setTopRows(FQCtriUpper.rows(), FQCtriUpper)
|
||||
FQCtri.setBottomRows(FQCtriLower.rows(), FQCtriLower)
|
||||
|
||||
igl.slice(VQC, FQC.col(0), 1, PQC0)
|
||||
igl.slice(VQC, FQC.col(1), 1, PQC1)
|
||||
igl.slice(VQC, FQC.col(2), 1, PQC2)
|
||||
igl.slice(VQC, FQC.col(3), 1, PQC3)
|
||||
|
||||
# Planarize it
|
||||
igl.planarize_quad_mesh(VQC, FQC, 100, 0.005, VQCplan)
|
||||
|
||||
# Convert the planarized mesh to triangles
|
||||
igl.slice(VQCplan, FQC.col(0), 1, PQC0plan)
|
||||
igl.slice(VQCplan, FQC.col(1), 1, PQC1plan)
|
||||
igl.slice(VQCplan, FQC.col(2), 1, PQC2plan)
|
||||
igl.slice(VQCplan, FQC.col(3), 1, PQC3plan)
|
||||
|
||||
# Launch the viewer
|
||||
key_down(viewer, ord('2'), 0)
|
||||
viewer.core.invert_normals = True
|
||||
viewer.core.show_lines = False
|
||||
viewer.callback_key_down = key_down
|
||||
viewer.launch()
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
# Add the igl library to the modules search path
|
||||
import sys, os
|
||||
sys.path.insert(0, os.getcwd() + "/../")
|
||||
|
||||
import pyigl as igl
|
||||
|
||||
# Input polygon
|
||||
V = igl.eigen.MatrixXd([[-1, -1], [1, -1], [1, 1], [-1, 1], [-2, -2], [2, -2], [2, 2], [-2, 2]])
|
||||
E = igl.eigen.MatrixXi([[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6,7], [7,4]])
|
||||
H = igl.eigen.MatrixXd([[0, 0]])
|
||||
|
||||
# Triangulated Interior
|
||||
V2 = igl.eigen.MatrixXd()
|
||||
F2 = igl.eigen.MatrixXi()
|
||||
|
||||
igl.triangle_triangulate(V, E, H, "a0.005q", V2, F2)
|
||||
|
||||
# Plot the mesh
|
||||
viewer = igl.viewer.Viewer()
|
||||
viewer.data.set_mesh(V2, F2)
|
||||
viewer.launch()
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
# Add the igl library to the modules search path
|
||||
import sys, os
|
||||
sys.path.insert(0, os.getcwd() + "/../")
|
||||
|
||||
import pyigl as igl
|
||||
|
||||
TUTORIAL_SHARED_PATH = "../../tutorial/shared/"
|
||||
|
||||
|
||||
# Input polygon
|
||||
V = igl.eigen.MatrixXd()
|
||||
F = igl.eigen.MatrixXi()
|
||||
B = igl.eigen.MatrixXd()
|
||||
|
||||
# Tetrahedralized interior
|
||||
TV = igl.eigen.MatrixXd()
|
||||
TT = igl.eigen.MatrixXi()
|
||||
TF = igl.eigen.MatrixXi()
|
||||
|
||||
viewer = igl.viewer.Viewer()
|
||||
|
||||
|
||||
def key_down(viewer, key, modifier):
|
||||
if key >= ord('1') and key <= ord('9'):
|
||||
t = float((key - ord('1')) + 1) / 9.0
|
||||
v = igl.eigen.MatrixXd()
|
||||
v = B.col(2) - B.col(2).minCoeff()
|
||||
v /= v.col(0).maxCoeff()
|
||||
|
||||
s = []
|
||||
for i in range(v.size()):
|
||||
if v[i, 0] < t:
|
||||
s.append(i)
|
||||
|
||||
V_temp = igl.eigen.MatrixXd(len(s) * 4, 3)
|
||||
F_temp = igl.eigen.MatrixXi(len(s) * 4, 3)
|
||||
|
||||
for i in range(len(s)):
|
||||
V_temp.setRow(i * 4 + 0, TV.row(TT[s[i], 0]))
|
||||
V_temp.setRow(i * 4 + 1, TV.row(TT[s[i], 1]))
|
||||
V_temp.setRow(i * 4 + 2, TV.row(TT[s[i], 2]))
|
||||
V_temp.setRow(i * 4 + 3, TV.row(TT[s[i], 3]))
|
||||
|
||||
F_temp.setRow(i * 4 + 0, igl.eigen.MatrixXi([[(i*4)+0, (i*4)+1, (i*4)+3]]))
|
||||
F_temp.setRow(i * 4 + 1, igl.eigen.MatrixXi([[(i*4)+0, (i*4)+2, (i*4)+1]]))
|
||||
F_temp.setRow(i * 4 + 2, igl.eigen.MatrixXi([[(i*4)+3, (i*4)+2, (i*4)+0]]))
|
||||
F_temp.setRow(i * 4 + 3, igl.eigen.MatrixXi([[(i*4)+1, (i*4)+2, (i*4)+3]]))
|
||||
|
||||
viewer.data.clear()
|
||||
viewer.data.set_mesh(V_temp, F_temp)
|
||||
viewer.data.set_face_based(True)
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# Load a surface mesh
|
||||
igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V, F)
|
||||
|
||||
# Tetrahedralize the interior
|
||||
igl.copyleft_tetgen_tetrahedralize(V, F, "pq1.414Y", TV, TT, TF)
|
||||
|
||||
# Compute barycenters
|
||||
igl.barycenter(TV, TT, B)
|
||||
|
||||
# Plot the generated mesh
|
||||
key_down(viewer, ord('5'), 0)
|
||||
viewer.callback_key_down = key_down
|
||||
viewer.launch()
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
# Add the igl library to the modules search path
|
||||
import sys, os
|
||||
|
||||
import math
|
||||
|
||||
sys.path.insert(0, os.getcwd() + "/../")
|
||||
|
||||
import pyigl as igl
|
||||
|
||||
TUTORIAL_SHARED_PATH = "../../tutorial/shared/"
|
||||
|
||||
|
||||
# Mesh + AO values + Normals
|
||||
V = igl.eigen.MatrixXd()
|
||||
F = igl.eigen.MatrixXi()
|
||||
AO = igl.eigen.MatrixXd()
|
||||
N = igl.eigen.MatrixXd()
|
||||
|
||||
|
||||
viewer = igl.viewer.Viewer()
|
||||
|
||||
|
||||
def key_down(viewer, key, modifier):
|
||||
|
||||
color = igl.eigen.MatrixXd([[0.9, 0.85, 0.9]])
|
||||
|
||||
if key == ord('1'):
|
||||
# Show the mesh without the ambient occlusion factor
|
||||
viewer.data.set_colors(color)
|
||||
elif key == ord('2'):
|
||||
# Show the mesh with the ambient occlusion factor
|
||||
C = color.replicate(V.rows(), 1)
|
||||
for i in range(C.rows()):
|
||||
C.setRow(i, C.row(i) * AO[i, 0])
|
||||
viewer.data.set_colors(C)
|
||||
elif key == ord('.'):
|
||||
viewer.core.lighting_factor += 0.1
|
||||
elif key == ord(','):
|
||||
viewer.core.lighting_factor -= 0.1
|
||||
else:
|
||||
return False
|
||||
|
||||
viewer.core.lighting_factor = min(max(viewer.core.lighting_factor, 0.0), 1.0)
|
||||
return True
|
||||
|
||||
|
||||
print("Press 1 to turn off Ambient Occlusion\nPress 2 to turn on Ambient Occlusion\nPress . to turn up lighting\nPress , to turn down lighting")
|
||||
|
||||
# Load a surface mesh
|
||||
igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V, F)
|
||||
|
||||
# Calculate vertex normals
|
||||
igl.per_vertex_normals(V, F, N)
|
||||
|
||||
# Compute ambient occlusion factor using embree
|
||||
igl.embree_ambient_occlusion(V, F, V, N, 500, AO)
|
||||
AO = 1.0 - AO
|
||||
|
||||
# Plot the generated mesh
|
||||
viewer.data.set_mesh(V, F)
|
||||
key_down(viewer, ord('2'), 0)
|
||||
viewer.callback_key_down = key_down
|
||||
viewer.core.show_lines = False
|
||||
viewer.core.lighting_factor = 0.0
|
||||
viewer.launch()
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
# Add the igl library to the modules search path
|
||||
import sys, os
|
||||
sys.path.insert(0, os.getcwd() + "/../")
|
||||
|
||||
import pyigl as igl
|
||||
|
||||
TUTORIAL_SHARED_PATH = "../../tutorial/shared/"
|
||||
|
||||
|
||||
# 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()
|
||||
|
||||
# Cast a ray in the view direction starting from the mouse position
|
||||
fid = igl.eigen.MatrixXi([-1])
|
||||
coord = igl.eigen.MatrixXd([viewer.current_mouse_x, viewer.core.viewport[3] - viewer.current_mouse_y])
|
||||
hit = igl.unproject_onto_mesh(coord, viewer.core.view * viewer.core.model,
|
||||
viewer.core.proj, viewer.core.viewport, V, F, fid, bc)
|
||||
if hit:
|
||||
C.setRow(fid[0, 0], igl.eigen.MatrixXd([[1, 0, 0]]))
|
||||
viewer.data.set_colors(C)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
print("Usage: [LeftMouseClick] to select a face")
|
||||
|
||||
# Load a mesh in OFF format
|
||||
igl.readOFF(TUTORIAL_SHARED_PATH + "fertility.off", V, F)
|
||||
|
||||
# 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()
|
||||
@@ -2,6 +2,7 @@ from __future__ import print_function
|
||||
|
||||
# Add the igl library to the modules search path
|
||||
import sys, os
|
||||
|
||||
sys.path.insert(0, os.getcwd() + "/../")
|
||||
|
||||
import pyigl as igl
|
||||
@@ -82,7 +83,7 @@ def update_visualization(viewer):
|
||||
igl.parula(S_vis, False, C_vis)
|
||||
|
||||
if overlay:
|
||||
append_mesh(C_vis, F_vis, V_vis, V, F, igl.eigen.MatrixXd([0.8, 0.8, 0.8]))
|
||||
append_mesh(C_vis, F_vis, V_vis, V, F, igl.eigen.MatrixXd([[0.8, 0.8, 0.8]]))
|
||||
|
||||
viewer.data.clear()
|
||||
viewer.data.set_mesh(V_vis, F_vis)
|
||||
@@ -110,7 +111,7 @@ print("Press [space] to toggle showing surface.")
|
||||
print("Press '.'/',' to push back/pull forward slicing plane.")
|
||||
|
||||
# Load mesh: (V,T) tet-mesh of convex hull, F contains original surface triangles
|
||||
igl.readMESH(TUTORIAL_SHARED_PATH + "bunny.mesh", V, T, F);
|
||||
igl.readMESH(TUTORIAL_SHARED_PATH + "bunny.mesh", V, T, F)
|
||||
|
||||
# Call to point_mesh_squared_distance to determine bounds
|
||||
sqrD = igl.eigen.MatrixXd()
|
||||
|
||||
Reference in New Issue
Block a user