-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
executable file
·96 lines (68 loc) · 2.06 KB
/
run.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
#!/usr/bin/python3
import os
simulate = True
render = True
generate = True
reverse = True
input = 'map.sr'
folder = 'output'
output = 'result'
avi = 'result_3'
steps = '1500'
dt = '0.03'
exp_iter = '100'
rho = '1000'
max_iter = '1000'
tol = '1e-7'
theme = 'Paper'
width = '3840'
height = '3840'
#width = 1920
#height = 1080
resize_width = 1080
resize_height = 1080
############
if simulate:
os.system("rm ./{}/*".format(folder))
print("simulating ...")
output_path = os.path.join(folder, output)
os.system("time ./main {} {} {} {} {} {} {} {}".format(input, output_path, steps, dt, rho, exp_iter, max_iter, tol))
###############
if render:
print("rendering ...")
mapsr = [ os.path.join(folder, x) for x in os.listdir(folder) if x.endswith('.sr')]
mapsr = sorted(mapsr)
for idx, sr in enumerate(mapsr):
print('Rendering {} frame'.format(idx))
os.system('./renderer/main -i {} -o {} --width {} --height {} -t {} -m'.format(sr, sr.replace('.sr', '.png'), width, height, theme))
###########
if generate:
print("generating animation...")
import cv2
pngs = [ os.path.join(folder, x) for x in os.listdir(folder) if x.endswith('.png')]
pngs = sorted(pngs)
video = None
for idx, p in enumerate(pngs):
print('Generating {}'.format(p))
f = cv2.imread(p)
f = cv2.resize(f, (resize_width, resize_height))
if video == None:
h, w, l = f.shape
video = cv2.VideoWriter('{}.avi'.format(avi), cv2.VideoWriter_fourcc(*'XVID'), 30, (w, h))
if idx == 0:
for i in range(40):
video.write(f)
video.write(f)
if reverse:
print('reverse!')
pngs = sorted(pngs, reverse=True)
for idx, p in enumerate(pngs):
print('reversing {}'.format(p))
f = cv2.imread(p)
f = cv2.resize(f, (resize_width, resize_height))
if idx == 0:
for i in range(3):
video.write(f)
video.write(f)
video.release()
print("done")