forked from inconvergent/differential-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·184 lines (127 loc) · 2.99 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from numpy import pi
from numpy import sqrt
from numpy import zeros
from numpy import cos
from numpy import sin
from numpy.random import random
from modules.timers import named_sub_timers
NMAX = 10e7
SIZE = 5000
ONE = 1./SIZE
RAD = 3*ONE
H = sqrt(3.)*RAD
NEARL = 2*RAD
FARL = RAD*20
OPT_STP = 1./SIZE*0.5
MID = 0.5
STEPS_ITT = 100
LINEWIDTH = 1*ONE
STP = 1./SIZE*0.5
ATTRACT_STP = STP*0.1
REJECT_STP = STP
TRIANGLE_STP = STP*0.01
ALPHA = 0
DIMINISH = 0.99
MINIMUM_LENGTH = H*0.8
MAXIMUM_LENGTH = H*2
SPLIT_LIMIT = H*2
FLIP_LIMIT = NEARL*0.5
BACK = [1,1,1,1]
FRONT = [0,0,0,0.3]
PROCS = 6
PREFIX = './res/exp_a'
TWOPI = pi*2.
np_coord = zeros((NMAX,6), 'float')
def show(render, dm):
global np_coord
render.clear_canvas()
num = dm.np_get_triangles_coordinates(np_coord)
render_random_triangle = render.random_triangle
rgba = FRONT
render.set_front(rgba)
for e,vv in enumerate(np_coord[:num,:]):
render_random_triangle(*vv,grains=80)
render.write_to_png('{:s}_{:05d}.png'.format(PREFIX,render.num_img))
def main():
from differentialMesh import DifferentialMesh
from render.render import Render
from time import time
from modules.helpers import print_stats
from numpy import array
# from modules.utils import get_exporter
# exporter = get_exporter(NMAX)
DM = DifferentialMesh(NMAX, 2*FARL, NEARL, FARL, PROCS)
DM.new_faces_in_ngon(MID, MID, H, 6, 0.0)
render = Render(SIZE, BACK, FRONT)
render.set_line_width(LINEWIDTH)
# st = named_sub_timers()
tsum = 0
for i in xrange(10000000):
t1 = time()
for _ in xrange(STEPS_ITT):
# st.start()
DM.optimize_position(
ATTRACT_STP,
REJECT_STP,
TRIANGLE_STP,
ALPHA,
DIMINISH,
-1
)
# st.t('opt')
henum = DM.get_henum()
# st.t('rnd')
surface_edges = array(
[DM.is_surface_edge(e)>0
for e in range(henum)],
'bool').nonzero()[0]
# st.t('surf')
rnd = random(size=len(surface_edges)*2)
the = (1.-2*rnd[::2])*pi
rad = rnd[1::2]*0.5*H
dx = cos(the)*rad
dy = sin(the)*rad
# st.t('rnd2')
DM.new_triangles_from_surface_edges(
surface_edges,
len(surface_edges),
H,
dx,
dy,
MINIMUM_LENGTH,
MAXIMUM_LENGTH,
1
)
# st.t('tri')
# st.start()
DM.optimize_edges(
SPLIT_LIMIT,
FLIP_LIMIT
)
# st.t('opte')
tsum += time() - t1
print_stats(i*STEPS_ITT, tsum, DM)
## export png
show(render, DM)
## export obj
# exporter(
# DM,
# {
# 'procs': PROCS,
# 'nearl': NEARL,
# 'farl': FARL,
# 'prefix': PREFIX,
# 'reject_stp': 0,
# 'attract_stp': 0,
# 'triangle_stp': 0,
# 'size': SIZE
# },
# i*STEPS_ITT
# )
tsum = 0
# st.p()
if __name__ == '__main__' :
main()