-
Notifications
You must be signed in to change notification settings - Fork 36
/
export.py
165 lines (142 loc) · 4.7 KB
/
export.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""
Exports all views to a html page.
"""
import os
import meshlib
import numpy as np
from animation import make_animation
from config import ConfigFile
from correspondence import get_correspondence
from transformation import Transformation
import render.plotly_html
if __name__ == "__main__":
import render.plot_result as plt_res
import render.plot as plt
name = "horsecamel"
cfg = ConfigFile.load(ConfigFile.Paths.highpoly.horse_camel)
# name = "catdog"
# cfg = ConfigFile.load(ConfigFile.Paths.lowpoly.catdog)
# name = "catlion"
# cfg = ConfigFile.load(ConfigFile.Paths.highpoly.cat_lion)
# name = "catvoxel"
# cfg = ConfigFile.load(ConfigFile.Paths.lowpoly.catvoxel)
corr_markers = cfg.markers # List of vertex-tuples (source, target)
identity = False
if identity:
corr_markers = np.ascontiguousarray(
np.array((corr_markers[:, 0], corr_markers[:, 0]), dtype=np.int).T
)
#########################################################
# Load meshes
original_source = meshlib.Mesh.load(cfg.source.reference)
original_pose = meshlib.Mesh.load(cfg.source.poses[0])
original_target = meshlib.Mesh.load(cfg.target.reference)
if identity:
original_target = meshlib.Mesh.load(cfg.source.reference)
#########################################################
# Load correspondence from cache if possible
mapping = get_correspondence(
original_source, original_target, corr_markers, plot=False
)
transf = Transformation(original_source, original_target, mapping)
result = transf(original_pose)
path = f"result/{name}"
os.makedirs(path, exist_ok=True)
plt.MeshPlots.plot_correspondence(
original_source, original_target, mapping
).finalize().write_html(
os.path.join(path, "correspondence.html"), include_plotlyjs="cdn"
)
plt_res.plot(original_source, original_target).write_html(
os.path.join(path, "reference.html"), include_plotlyjs="cdn"
)
plt_res.plot(original_pose, result).write_html(
os.path.join(path, "result.html"), include_plotlyjs="cdn"
)
poses_meshes = list(cfg.source.load_poses())
make_animation(transf, poses_meshes).write_html(
os.path.join(path, "animation.html"), include_plotlyjs="cdn"
)
poses = []
for n, pose in enumerate(poses_meshes):
filename = f"pose.{n}.html"
poses.append(filename)
plt_res.plot(pose, transf(pose)).write_html(
os.path.join(path, filename), include_plotlyjs="cdn"
)
files = [
"reference.html",
"correspondence.html",
"result.html",
"animation.html",
*poses,
]
html = f"""<html>
<head>
<title>{name}</title>"""
html += """
<style>
html, body {
height: 100%;
margin: 0;
}
#iframe_page {
width:100%;height:100%;
display: inline-block;
padding:0; margin:0;
}
/* DivTable.com */
.divTable{
display: table;
width: 100%; height:100%;
}
.divTableRow {
display: table-row;
}
.divTableHeading {
background-color: #EEE;
display: table-header-group;
}
.divTableCell, .divTableHead {
border: 1px solid #999999;
display: table-cell;
padding: 3px 10px;
}
.divTableHeading {
background-color: #EEE;
display: table-header-group;
font-weight: bold;
}
.divTableFoot {
background-color: #EEE;
display: table-footer-group;
font-weight: bold;
}
.divTableBody {
display: table-row-group;
}
</style>
</head>
<body>
<div class="divTable">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell" style="vertical-align: top; max-width: 40px;">
<div>
<ul>
"""
for file in files:
html += f'<li><a href="{file}" target="page">{file}</a></li>'
html += f"""
</ul>
</div>
</div>
<div class="divTableCell" style="position:relative;padding:0; margin:0;"><iframe src="{files[0]}" name="page" id="iframe_page"></iframe></div>
</div>
</div>
</div>
</body>
</html>
"""
with open(os.path.join(path, "index.html"), "wt") as f:
f.writelines(html)