forked from inconvergent/leaf-cuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·169 lines (121 loc) · 3.39 KB
/
main.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
#!/usr/bin/python
# 30- coding: utf-8 -*-
from __future__ import print_function
from __future__ import division
def get_wrap(l, colors, node_rad, render_steps=10, export_steps=10):
from time import time
from time import strftime
from numpy.linalg import norm
from numpy import sqrt
from dddUtils.ioOBJ import export_2d as export
t0 = time()
from fn import Fn
fn = Fn(prefix='./res/')
step = l.step()
kill_rad = l.kill_rad
one = l.one
def wrap(render):
final = False
vs_xy = []
try:
vs_xy = step.next()
except StopIteration:
final = True
if (l.itt % render_steps == 0) or final:
vnum = l.vnum
edges = l.edges[:l.enum,:]
width = l.width_calc(scale=3*node_rad, min_width=node_rad*0.7, po=0.2)
vxy = l.vxy[:vnum,:]
zsize = len(l.zone_node)
print(strftime("%Y-%m-%d %H:%M:%S"), 'itt', l.itt,
'snum', l.snum, 'vnum', vnum, 'zone', zsize, 'time', time()-t0)
render.clear_canvas()
# # nearby
# render.set_front(colors['cyan'])
# for v,s in vs_xy:
# render.line(v[0], v[1], s[0], s[1])
# veins
# render.set_front(colors['vein'])
# for i,(x,y) in enumerate(vxy):
# r = node_rad
# # r = (((max_gen-gen[i])/max_gen)**1.1)*node_rad
# render.circle(x, y, r, fill=True)
# edges
render.set_front(colors['vein'])
for ee in edges:
xy = vxy[ee, :]
# r = node_rad
r = width[ee[1]]
render.circles(xy[0,0], xy[0,1], xy[1,0], xy[1,1], r, nmin=3)
## sources
# render.set_front(colors['red'])
# for x,y in l.sxy:
# render.circle(x, y, one, fill=True)
# for x,y in l.sxy[l.smask]:
# render.circle(x, y, kill_rad, fill=False)
if (l.itt % export_steps == 0) or final:
name = fn.name()
render.write_to_png(name+'.png')
# export('leaf', name+'.2obj', vxy)
if final:
return False
# raw_input('')
return True
return wrap
def main():
from modules.leaf import LeafClosed as Leaf
from render.render import Animate
from numpy.random import random
from numpy import array
colors = {
'back': [1,1,1,1],
'front': [0,0,0,0.3],
'vein': [0,0,0,0.9],
'edge': [0,0,0,0.6],
'cyan': [0,0.6,0.6,0.3],
'red': [0.7,0.0,0.0,0.8],
'blue': [0.0,0.0,0.7,0.8],
'light': [0,0,0,0.2],
}
threads = 256
render_steps = 10
export_steps = 10
size = 512*2
one = 1.0/size
node_rad = 1*one
area_rad = 15*node_rad
stp = node_rad*2
kill_rad = 2*stp
sources_dst = 2*kill_rad
init_num_sources = 3
# init_num_sources = 4
# init_veins = 0.2+0.6*random((init_num_sources,2))
init_veins = array([[0.5, 0.5]])
init_num_sources = 100000
# from dddUtils.random import darts
# init_sources = darts(init_num_sources, 0.5, 0.5, 0.45, sources_rad)
from dddUtils.random import darts_rect
init_sources = darts_rect(init_num_sources, 0.5, 0.5, 0.95, 0.95, sources_dst)
L = Leaf(
size,
stp,
init_sources,
init_veins,
area_rad,
kill_rad,
threads = threads
)
print('nz', L.nz)
print('dens', L.sv_leap)
wrap = get_wrap(
L,
colors,
node_rad=node_rad,
export_steps=export_steps,
render_steps=render_steps
)
render = Animate(size, colors['back'], colors['front'], wrap)
render.set_line_width(L.one*2)
render.start()
if __name__ == '__main__':
main()