-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_and_render.py
352 lines (295 loc) · 11.8 KB
/
run_and_render.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import meshio
import numpy as np
import igl
import re
import subprocess
from utils import *
class fig1_fat(common_process):
base = 'fig1-fat/'
threads = [0, 1, 2, 4, 8, 16, 32]
input = f'input_data/39507.stl'
timer_regex = r"^.*total time (.*)s$"
@classmethod
def run_tw(cls):
t = 10
exe = apps['tetra']
output = f'{cls.outpath()}/{t}.tetra.msh'
params = [basepath + exe, '-i', cls.input, '-o', output] + \
f'-j {t} --max-its 25 --filter-with-input'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.tw.log', 'w') as fp:
subprocess.run(params, stdout=fp)
@classmethod
def run_remenv(cls):
t = 32
exe = apps['remesh']
output = f'{cls.outpath()}/{t}.remesh.obj'
params = [basepath + exe, cls.input, output] + \
f'-e 1e-3 -j {t} -r 0.01 -f 0'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
@classmethod
def run_qslim(cls):
t = 32
exe = apps['qslim']
output = f'{cls.outpath()}/{t}.qslim.obj'
params = [basepath + exe, cls.input, output] + \
f'-j {t} -t 5e-3'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.qslim.log', 'w') as fp:
subprocess.run(params, stdout=fp)
@classmethod
def run_secenv(cls):
t = 32
exe = apps['sec']
output = f'{cls.outpath()}/{t}.sec.obj'
params = [basepath + exe, cls.input, output] + \
f'-e 1e-2 -j {t} -t 1e-3'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.sec.log', 'w') as fp:
subprocess.run(params, stdout=fp)
@classmethod
def run_harmo(cls):
t = 32
inp = f'{cls.outpath()}/10.tetra.msh_final.msh'
output = f'{cls.outpath()}/{t}.harmo.msh'
params = [basepath + apps['harmo'], inp, output] + \
f'-j {t}'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.harmo.log', 'w') as fp:
subprocess.run(params, stdout=fp)
@classmethod
def run(cls):
cls.run_tw()
cls.run_harmo()
cls.run_remenv()
cls.run_qslim()
@classmethod
def log_info(c):
for key in ['tetra', 'sec', 'harmo', 'remesh']:
timer = parse_log(c.timer_regex, [
(t, f'{c.logpath()}/{t}.{key}.log') for t in c.threads])
np.savetxt(f"{c.base}/timer.{key}.csv",
np.asarray(timer), delimiter=",")
plot_scatter(f'{c.base}/scale.{key}.svg', np.asarray(timer))
@classmethod
def blender_process(c, t=32):
v, f = igl.read_triangle_mesh(c.input)
scale(v)
blfile = f'{c.base}/render.blend'
blend_surf_file(blfile, (use_scale(v), f), f'{c.base}/input.png', plot_edge=False)
for key in ['qslim' , 'remesh']:
v1, f1 = igl.read_triangle_mesh(f'{c.outpath()}/{t}.{key}.obj')
blend_surf_file(blendfile=f'{c.base}/render.blend', obj=(
use_scale(v1), f1), png=f'{c.base}/{key}.png', plot_edge=True)
slice_and_render(blfile,
mesh=f'{c.outpath()}/10.tetra.msh_final.msh',
slicer=[0.27, 1, 0.35, -6.6], pngpath=f'{c.base}/tetra.png')
slice_and_render(blfile,
mesh=f'{c.outpath()}/32.harmo.msh',
slicer=[0.27, 1, 0.35, -6.6], pngpath=f'{c.base}/harmo.png')
class fig3_sec(common_process):
threads = [0, 1, 2, 4, 8, 16, 32]
base = 'fig3-statue-sec/'
input = f'input_data/Sapphos_Head.stl'
timer_regex = r"^.*runtime (.*)$"
timer_unit = 1e-3
exe = apps['sec']
reference = 'reference_result/sec-statue-igl.obj'
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.obj'
params = [basepath + cls.exe, cls.input,
output] + f'-j {t}'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
class fig3_qslim(common_process):
threads = [0, 1, 2, 4, 8, 16, 32]
base = 'fig3-qslim/'
input = f'input_data/48013.stl'
timer_regex = r"^.*runtime (.*)$"
timer_unit = 1e-3
exe = apps['qslim']
reference = 'reference_result/qslim-golden-igl.obj'
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.obj'
params = [basepath + cls.exe, cls.input,
output] + f'-j {t}'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
class fig3_qslim_up(common_process):
threads = [0, 1, 2, 4, 8, 16, 32]
base = 'fig3-qslim-up/'
input = f'input_data/upsampled_golden.obj'
timer_regex = r"^.*runtime (.*)$"
timer_unit = 1e-3
exe = apps['qslim']
reference = 'reference_result/upsample_qslim.obj'
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.obj'
params = [basepath + cls.exe, cls.input,
output] + f'-j {t} -t 0.01'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
class fig4_rem(common_process):
threads = [0, 1, 2, 4, 8, 16, 32]
base = 'fig4-hellskull-UniRem/'
input = f'input_data/hellSkull_126k.stl'
timer_regex = r"^.*runtime (.*)$"
timer_unit = 1e-3
exe = apps['remesh']
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.obj'
params = [basepath + cls.exe, cls.input, output] + \
f'-j {t} -r 0.01 -f 0'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
class fig4_lucy_rem(common_process):
threads = [0, 1, 2, 4, 8, 16, 32]
base = 'fig4-lucy-UniRem/'
input = f'input_data/120628.stl'
timer_regex = r"^.*runtime (.*)$"
timer_unit = 1e-3
exe = apps['remesh']
reference = 'reference_result/OpenFlipper_lucy_9.obj'
@classmethod
def run(cls, threads=None):
if threads is None:
threads = cls.threads
for t in threads:
output = f'{cls.outpath()}/{t}.obj'
params = [basepath + cls.exe, cls.input, output] + \
f'-j {t} -r 0.01 -f 0'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
class fig5_harmo(common_process):
base = 'fig5-gauss-harm/'
threads = [0, 1, 2, 4, 8, 16, 32]
input = f'input_data/gaussian_points_1M.ply'
exe = apps['harmo']
timer_regex = r"^.*Time cost: (.*)$"
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.msh'
params = [basepath + cls.exe, cls.input, output] + \
f'--harmonize -j {t}'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
@classmethod
def blender_process(c, t=32):
outname = 'reference_result/reference-res.msh'
m = meshio.read(outname)
tetv, tett = m.points, m.cells[0].data
tetv = scale(tetv)
V, F, marker = slicetmesh(tetv, tett, [-1, 0, 0, 0.8])
blend_surf_file(blendfile=f'{c.base}/render.blend', obj=(V, F[marker == 0]), png=f'{c.base}/ref.png',
plot_edge=True)
outname = f'{c.outpath()}/{t}.msh'
m = meshio.read(outname)
tetv, tett = m.points, m.cells[0].data
tetv = scale(tetv)
V, F, marker = slicetmesh(tetv, tett, [-1, 0, 0, 0.8])
blend_surf_file(blendfile=f'{c.base}/render.blend', obj=(V, F[marker == 0]), png=f'{c.base}/out.png',
plot_edge=True)
class fig6_tw(common_process):
base = 'fig6-octocat-tw/'
threads = [0, 1, 2, 4, 8, 16, 32]
input = f'input_data/dragon.off'
exe = apps['tetra']
timer_regex = r"^.*total time (.*)s$"
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.msh'
params = [basepath + cls.exe, '-i', cls.input, '-o', output] + \
f'-j {t} --max-its 10'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
@classmethod
def blender_process(c, t=0):
v, _ = igl.read_triangle_mesh(c.input)
scale(v)
slice_and_render(blendfile=f'{c.base}/render.blend', mesh=f'{c.outpath()}/{t}.msh_final.msh',
slicer=[0, 0, -1, 0], pngpath=f'{c.base}/out.png')
class fig6_tw_sample(common_process):
base = 'fig6-tw-sample/'
threads = [0, 1, 2, 4, 8, 16, 32]
input = f'input_data/dragon.off'
exe = apps['tetra']
timer_regex = r"^.*total time (.*)s$"
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.msh'
params = [basepath + cls.exe, '-i', cls.input, '-o', output] + \
f'-j {t} --max-its 10 --sample-envelope'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
@classmethod
def blender_process(c, t=0):
v, f = igl.read_triangle_mesh(c.input)
scale(v)
blend_surf_file(blendfile=f'{c.base}/render.blend', obj=(scale(v), f), png=f'{c.base}/input.png', plot_edge=False)
slice_and_render(blendfile=f'{c.base}/render.blend', mesh='reference_result/dragon.msh',
slicer=[0, 0, -1, 0], pngpath=f'{c.base}/tetwild.png')
slice_and_render(blendfile=f'{c.base}/render.blend', mesh=f'{c.outpath()}/{t}.msh_final.msh',
slicer=[0, 0, -1, 0], pngpath=f'{c.base}/out.png')
class fig7_secenv(common_process):
threads = [0, 1, 2, 4, 8, 16, 32]
base = 'fig7-eins-secenv/'
input = f'input_data/einstein_big.stl'
timer_regex = r"^.*runtime (.*)$"
timer_unit = 1e-3
exe = apps['sec']
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.obj'
params = [basepath + cls.exe, cls.input, output] + \
f'-e 1e-3 -j {t} -t 1e-2'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
class fig8_rem_env(common_process):
threads = [0, 1, 2, 4, 8, 16, 32]
base = 'fig8-headported-UniRemEnv/'
input = f'input_data/head_-_ported_-_scaled.stl'
timer_regex = r"^.*runtime (.*)$"
timer_unit = 1e-3
exe = apps['remesh']
@classmethod
def run(cls):
for t in cls.threads[::-1]:
output = f'{cls.outpath()}/{t}.obj'
params = [basepath + cls.exe, cls.input, output] + \
f'-e 1e-3 -j {t} -r 0.01 -f 0'.split()
print(' '.join(params))
with open(f'{cls.logpath()}/{t}.log', 'w') as fp:
subprocess.run(params, stdout=fp)
if __name__ == '__main__':
# for f in [fig3_sec, fig3_qslim, fig4_lucy_rem, fig7_secenv, fig8_rem_env]:
# f.log_info();
#fig3_sec, fig3_ /qslim, fig3_sec, fig4_lucy_rem, fig6_tw, fig7_secenv, fig5_harmo,
fig1_fat.blender_process()
# fig6_tw_sample
# v,f = igl.read_triangle_mesh('fig1-fat/out/32.remesh.obj')
# igl.write_triangle_mesh('temp.ply', scale(v), f)
# render_input(fig3_qslim_up)
# fig3_qslim_up.blender_process()