-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvisualize_in_polyscope.py
More file actions
93 lines (76 loc) · 4.36 KB
/
visualize_in_polyscope.py
File metadata and controls
93 lines (76 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import polyscope as ps
import mouette as M
import numpy as np
import argparse
import os
import cmath
BLACK = (0,0,0)
RED = (1,0,0)
GREEN = (0,1,0)
BLUE = (0,0,1)
ORANGE = (1., 112/255, 67/255)
GRAY = (0.7, 0.7, 0.7)
GRAY2 = (0.2, 0.2, 0.2)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("folder", type=str, \
help="path to the output folder generated by the main script.")
args = parser.parse_args()
ps.init()
ps.set_ground_plane_mode("none")
paths = dict([
(name, os.path.join(args.folder, file)) for (name,file) in
[
("work_mesh", "work_mesh.geogram_ascii"),
("seams", "seams.obj"),
("feat", "features.obj"),
("singu", "singularities.geogram_ascii")
]
])
if os.path.exists(paths["work_mesh"]):
work_mesh = M.mesh.load(paths["work_mesh"])
work_mesh_ps = ps.register_surface_mesh("work_mesh",
np.array(work_mesh.vertices), work_mesh.faces, color=GRAY, enabled=True)
### Export uv-coordinates
uv_coords = work_mesh.face_corners.get_attribute("uv_coords").as_array(len(work_mesh.face_corners))
work_mesh_ps.add_parameterization_quantity(
"parametrization", uv_coords,defined_on="corners",
checker_size=0.05, enabled=True, grid_colors=(GRAY,GRAY2)
)
### Export scale factors
scale_U = work_mesh.vertices.get_attribute("scale_U").as_array(len(work_mesh.vertices))
scale_V = work_mesh.vertices.get_attribute("scale_V").as_array(len(work_mesh.vertices))
work_mesh_ps.add_scalar_quantity("scale_u", scale_U)
work_mesh_ps.add_scalar_quantity("scale_v", scale_V)
### Export frame field
bases_X = work_mesh.faces.get_attribute("basesX").as_array(len(work_mesh.faces))
bases_Y = work_mesh.faces.get_attribute("basesY").as_array(len(work_mesh.faces))
for frame_attr_name in ["frames_init", "frames_final"]:
frames = work_mesh.faces.get_attribute(frame_attr_name)
frames0 = np.array([cmath.rect(1., cmath.phase(complex(frames[F][0], frames[F][1]))/4) for F in work_mesh.id_faces])
frames0 = np.stack([np.real(frames0), np.imag(frames0)], axis=-1)
work_mesh_ps.add_tangent_vector_quantity(frame_attr_name, frames0, bases_X, bases_Y, n_sym=4, defined_on="faces", color=BLACK, length=0.015, radius=0.001)
brushing = work_mesh.faces.get_attribute("brushing")
framesX = np.array([cmath.rect(1., (cmath.phase(complex(frames[F][0], frames[F][1])) + 2*np.pi*brushing[F])/4) for F in work_mesh.id_faces])
framesX = np.stack([np.real(framesX), np.imag(framesX)], axis=-1)
framesY = np.array([cmath.rect(1., (cmath.phase(complex(frames[F][0], frames[F][1])) + 2*np.pi*((brushing[F]+1)%4))/4) for F in work_mesh.id_faces])
framesY = np.stack([np.real(framesY), np.imag(framesY)], axis=-1)
# work_mesh_ps.add_tangent_vector_quantity("baseX", framesX, bases_X, bases_Y, defined_on="faces", color=GREEN, length=0.015, radius=0.015)
# work_mesh_ps.add_tangent_vector_quantity("baseY", framesY, bases_X, bases_Y, defined_on="faces", color=ORANGE, length=0.015, radius=0.015)
else:
raise Exception("No work mesh was found at this folder. Make sure you have enabled the --full-output option when running the main script.")
if os.path.exists(paths["seams"]):
seams = M.mesh.load(paths["seams"])
if isinstance(seams, M.mesh.PolyLine):
ps.register_curve_network("seams", np.asarray(seams.vertices), np.asarray(seams.edges), color=BLACK, enabled=True, radius=0.001)
if os.path.exists(paths["feat"]):
feat = M.mesh.load(paths["feat"])
if isinstance(seams, M.mesh.PolyLine):
ps.register_curve_network("features", np.asarray(feat.vertices), np.asarray(feat.edges), color=BLACK, enabled=True, radius=0.0015)
if os.path.exists(paths["singu"]):
singus = M.mesh.load(paths["singu"])
singus_ps = ps.register_point_cloud("singularities", np.asarray(singus.vertices), radius=0.005)
index = singus.vertices.get_attribute("index").as_array(len(singus.vertices))
singus_ps.add_scalar_quantity("index", index, enabled=True, vminmax=(-1,1), cmap="coolwarm")
singus_ps.enabled = False
ps.show()