-
Notifications
You must be signed in to change notification settings - Fork 326
/
meshwav_1_subdivision_curves.py
232 lines (208 loc) · 5.3 KB
/
meshwav_1_subdivision_curves.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
def exo1():
"""
Perform several step of subdivision. Display the different curves.
"""
Jmax = 3
f = f0
for j in 0: Jmax:
f = subdivide(f, h)
subplot(2, 2, j + 1)
hold on
myplot(f, 'k.-')
myplot(f0, 'r.--')
myaxis(0)
def exo2():
"""
Compute the scaling function $\phi$
associated to the subdivision.
"""
n = 6
f = zeros(n, 1); f(n/ 2 + 1) = 1
for i in 1: 5:
f = subdivide(f, h)
plot(linspace(-1/ 2, 1/ 2, length(f)), f); axis([-1/ 2 1/ 2 -.01 max(f)*1.03])
def exo3():
"""
Test with different configurations of control points.
"""
f0 = [0 + 0i; 1 + 0i; 1 + 1i; 0 + 1i]
f = f0
for j in 0: Jmax:
f = subdivide(f, h)
subplot(2, 2, j + 1)
hold on
myplot(f, 'k.-')
myplot(f0, 'r.--')
myaxis(.03)
def exo4():
"""
Test the corner-cutting for $w=3$.
"""
h = hcc(3)
f = f0
for j in 0: Jmax:
f = subdivide(f, h)
subplot(2, 2, j + 1)
hold on
myplot(f, 'k.-')
myplot(f0, 'r.--')
myaxis(.03)
def exo5():
"""
Test the corner-cutting for vaious values of $w$.
"""
wlist = [1 2 3 6]
subd = lambda f, w: f
for i in 1: 5:
subd = lambda f, w: subdivide(subd(f, w), hcc(w))
lgd = {}
F = []
for i in 1: length(wlist):
w = wlist(i)
F(: , end + 1) = subd(f0, w)
lgd{i} = ['w = ' num2str(w*16)]
hold on
plot(F([1: end 1], : ), 'LineWidth', 2)
myplot(f0, 'r.--')
legend(lgd)
myaxis(.03)
def exo6():
"""
Perform the interpolating subdivision
for $w=1/16$.
"""
w = 1/ 16
h = h4pt(w)
f = f0
for j in 0: Jmax:
f = subdivide(f, h)
subplot(2, 2, j + 1)
hold on
myplot(f, 'k.-')
myplot(f0, 'r.--')
myaxis(.13)
hold off
def exo7():
"""
Test the influence of $w$.
"""
wlist = [.5 1 1.5 2]/ 16
subd = lambda f, w: f
for i in 1: 5:
subd = lambda f, w: subdivide(subd(f, w), h4pt(w))
lgd = {}
F = []
for i in 1: length(wlist):
w = wlist(i)
F(: , end + 1) = subd(f0, w)
lgd{i} = ['w = ' num2str(w*16) '/ 16']
hold on
plot(F([1: end 1], : ), 'LineWidth', 2)
myplot(f0, 'r.--')
legend(lgd)
axis tight; axis off; axis equal
def exo8():
"""
Compare the result of the quadratic B-spline, cubic B-spline,
and 4-points interpolating.
"""
hh = []
hh{end + 1} = [1 3 3 1]/ 4
hh{end + 1} = [1 4 6 4 1]/ 8
hh{end + 1} = [-1, 0, 9, 1, 9, 0, -1]/ 16
hh{end}((end + 1)/ 2) = 1
lgd = {'Quadratic', 'Cubic', 'Interpolating'}
col = {'r' 'g' 'b'}
clf; hold on
for k in 1: length(hh):
h = hh{k}
f = f0
for j in 0: 7:
f = subdivide(f, h)
myplot(f, col{k})
myplot(f0, 'k.--')
axis tight; axis off
legend(lgd)
def exo9():
"""
Display the scaling function associated to these Deslauriers-Dubuc filters.
"""
n = 8
for k in 1: 4:
h = hdd(k)
f = zeros(n, 1); f(n/ 2 + 1) = 1
for i in 1: 5:
f = subdivide(f, h)
subplot(4, 1, k)
plot(linspace(-n/ 2, n/ 2, length(f)), f)
axis([-n/ 2 n/ 2 -.15 1.03])
def exo10():
"""
Perform an approximation $f$ of the curve using a uniform sampling with $N_0=20$
points.
"""
p = 28
t0 = (0: 1/ n: 1-1/ n)'
t = (0: 1/ p: 1-1/ p)'
f0 = interp1(t0, F, t)
f = f0
Jmax = ceil(log2(n/ p))
for j in 0: Jmax:
f = subdivide(f, h)
clf; hold on
myplot(F, 'k')
myplot(f0, 'k.')
myplot(f, 'r')
myaxis(0)
def exo11():
"""
Display the decay of the Hausdorff approximation error as the number $N_0$ of
sampling points increases.
"""
q = 15
plist = round(linspace(8, 80, q))
d = []
for k in 1: length(plist):
p = plist(k)
% sample
t0 = (0: 1/ n: 1-1/ n)'
t = (0: 1/ p: 1-1/ p)'
f0 = interp1(t0, F, t)
% interpolate
f = f0
Jmax = ceil(log2(n/ p))
for j in 0: Jmax:
f = subdivide(f, h)
% record distance
d(end + 1) = hausdorff(F, f)
plot(plist, d, 'LineWidth', 2)
xlabel('N_0'); ylabel('d')
axis tight
def exo12():
"""
Perform curve subdivision in 3D space.
ontrol mesh.
"""
f0 = rand(12, 3)
Jmax = 4; ms = 20; lw = 1.5
f = f0
for j in 0: Jmax:
f = cat(2, upsampling(f(: , 1)), upsampling(f(: , 2)), upsampling(f(: , 3)))
f = cat(2, cconv(f(: , 1), h), cconv(f(: , 2), h), cconv(f(: , 3), h))
subplot(1, 2, 1)
hold on
hh = plot3([f(: , 1); f(1, 1)], [f(: , 2); f(1, 2)], [f(: , 3); f(1, 3)], 'k-')
set(hh, 'MarkerSize', ms)
set(hh, 'LineWidth', lw)
hh = plot3([f0(: , 1); f0(1, 1)], [f0(: , 2); f0(1, 2)], [f0(: , 3); f0(1, 3)], 'r.--')
set(hh, 'LineWidth', lw)
axis('tight'); box('on'); view(3); % axis('off')
subplot(1, 2, 2)
hold on
hh = plot3([f(: , 1); f(1, 1)], [f(: , 2); f(1, 2)], [f(: , 3); f(1, 3)], 'k-')
set(hh, 'MarkerSize', ms)
set(hh, 'LineWidth', lw)
hh = plot3([f0(: , 1); f0(1, 1)], [f0(: , 2); f0(1, 2)], [f0(: , 3); f0(1, 3)], 'r.--')
set(hh, 'LineWidth', lw)
axis('tight'); box('on')
view(70, 25)