-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterpolate_intersections.m
More file actions
327 lines (264 loc) · 7.74 KB
/
interpolate_intersections.m
File metadata and controls
327 lines (264 loc) · 7.74 KB
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
close all
% spline_surf_vec
%intersections
plot3(patch_bound_Xs,patch_bound_Ys,5*ones(us_n_basf-1,vs_n_basf-1),'LineWidth',4)
%plot3(patch_bound_X,patch_bound_Y,5*ones(u_n_basf-1,v_n_basf-1),'LineWidth',4)
hold on
plot3(patch_bound_Ys,patch_bound_Xs,5*ones(us_n_basf-1,vs_n_basf-1),'LineWidth',4)
%plot3(patch_bound_Y,patch_bound_X,5*ones(u_n_basf-1,v_n_basf-1),'LineWidth',4)
plotresultsvec(us_knots, vs_knots,P0s,P1s,P2s,P3s,Xs,zs,Errs)
plotresultsvec(u_knots, v_knots,P0,P1,P2,P3,X,z,Errs)
for i=1:n_points
plot3(point(i,5),point(i,6),point(i,7),'k.','MarkerSize',50);
end
% [uvu2v2(1:2)',u_knot(h),uvu2v2(3),ptl(1),ptl(2),ptl(3),k,l,m,o];
%pointx = point;
pointb = [point];
%%% sort intersections by patches (1st patch)
sp_i = (pointb(:,10)-1)*(us_n_intervs-1) + pointb(:,11);
sp_i2 = (pointb(:,8)-1)*(u_n_intervs-1) + pointb(:,9);
% [ssp_i idx] = sort(sp_i);
%
% m = length(sp_i); %m-out
%
%
%
% pointb = pointb(idx,:);
%
% %%% Compute intersectioned patches
% patch_int(1,2) = 1;
% patch_int(1,1) = ssp_i(1);
% %a = sp_i(1);
% different = 1;
% for i =2:n_points
% if ssp_i(i) == patch_int(different,1)%a
% patch_int(different,2) = patch_int(different,2) +1;
% continue
% else
% %a = sp_i(i);
% different = different +1;
% patch_int(different,1) = ssp_i(i);
% patch_int(different,2) = 1;
% end
% end
%
%
% different;
%return
%%% detect intersection point types
% -1 - interion
% 0 - global boundary
% 1 - patch boundary
coinf = zeros(n_points,2);
%out = zeros(different,1);
point_type = zeros(n_points,1); % 1D
for j=1:n_points
coinf(j,:) = boundary_point(pointb(j,3:4),pointb(j,10:11),us_knots,vs_knots);
%type of interrsection (u,v) % 2D
% if coinf(j,1) > -1 || coinf(j,2) > -1 % number of boundary points for patch
% out(j) = out(j) +1;
% end
% define intersection type
if coinf(j,1) == -1 && coinf(j,2) == -1 % internal
point_type(j) = -1;
elseif coinf(j,1) == 0 || coinf(j,2) == 0 % global boundary
point_type(j) = 0;
elseif coinf(j,1) == 1 && coinf(j,2) == 1 % patch internal boundary (patch edge)
point_type(j) = 11;
elseif coinf(j,1) == 1 || coinf(j,2) == 1 % patch internal boundary
point_type(j) = 1;
end
end
% number of outputs
% % Sort points in patch
% offset = 0;
% for j=1:different
%
%
% patch_points= offset:offset+patch_int(j,2);
%
% boundg = find(point_type(patch_points) == 0)
% boundi = find(point_type(patch_points) == 1)
% bound = [boundg , boundi];
%
% l = lenght(bound)
% if l >2
% disp('more then 2 boundary points')
% end
%
% dist = zeros(patch_int(j,2));
%
% for k = 1: offset+patch_int(j,2)
% for i = 1: offset+patch_int(j,2)
%
% dist(i) = norm(pointsb(patch_points(k),1:2)- pointsb(patch_points(i),1:2))
% i+offset
%
% end
%
% end
% offset = offset + patch_int(j,2);
% end
%
% Sort points in surface (create components)
n_components = 0;
% until 0 poits
offset = 1;
pointb = [pointb, coinf, point_type, sp_i];
matrixpoints = ones(n_points,1);
point_component = ones(n_points,1);
[a,b] = size(pointb);
splinepoint = pointb;
bound = find(pointb(offset:n_points,14) == 0); % find boundary point
while(isempty(bound) == 0) % tests if there exist not yet connected point on the boundary of the surface
n_components = n_components +1;
comp_bounds(n_components,1) = offset;
for i=offset:n_points-1 % while "end of the component - podminka"
patch = pointb(i,15);
id_point = find(pointb(i+1:n_points,15) == patch)+i;
n_patch_points = length(id_point);
if n_patch_points == 0 % "end of the component" - other
%???
break
elseif n_patch_points == 1 %two points on patch
pointb = swaplines(pointb,i+1,id_point );
offset = offset +1;
else % more then two points on patch
for l=1:n_patch_points
dist = 1/eps * ones(n_patch_points,1);
for k=l:n_patch_points
if id_point(k) ~= 0
dist(k) = norm(pointb(i+l-1,1:2) - pointb(id_point(k),1:2));
end
end
[~, b] = min(dist);
pointb = swaplines(pointb,i+l,id_point(b));
id_point(b) = 0;
end
offset = offset + n_patch_points;
break
end
id = get_neigbour(pointb(offset-1,:))
% connect new patch
% test last point (zero flag)
end
comp_bounds(n_components,2) = offset; %% offset + 1
bound = find(pointb(offset:n_points,14) == 0); % find next boundary point (if exist)
end
% %current patch ID
% % +2
% if isempty(id_out) == 1
% break
% %get_neigbour
% else
% splinepoint = swaplines(splinepoint,offset+2,offset+bound(1)); % indexy
% end
%
%
%
% splinepoint = swaplines(splinepoint,offset+1,offset+bound(1));
%
% start = offset+1;
% comp_bounds(n_components,1) = start;
%
% for j=offset+1:n_points-1
% dist = 1/eps * ones(n_points,1);
% for k=j+1:n_points
% dist(k) = norm(splinepoint(j,1:2) - splinepoint(k,1:2));
% end
% [a b] = min(dist);
% splinepoint = swaplines(splinepoint,b,j+1);
% offset = offset +1;
% if (splinepoint(j+1,14)==0)
% break
% end
% end
% comp_bounds(n_components,2) = offset;
%
% bound = find(pointb(offset+1:n_points,14) == 0)
% pause
% end
%%%% Remove duplicite points ()
% for i=start:offset
% % if splinepoint(i,14) == 1
% % a = 1;
% % end
% if splinepoint(i,14)*a == 1
% matrixpoints(i) = 0;
% a = 0;
% elseif splinepoint(i,14) == 1
% a =1;
% else
% a = 0;
% end
% end
% a = 0;
% for i=start:offset
% % if splinepoint(i,14) == 1
% % a = 1;
% % end
% if splinepoint(i,14)*a == 1
% matrixpoints(i) = 0;
% a = 0;
% elseif splinepoint(i,14) == 1
% a =1;
% else
% a = 0;
% end
% end
% Interpolate points
%
%
% pointb = pointb(1:m-out,:)
%
% mm = m - out;
%
% %return
%
mr = sum(matrixpoints);
XYZ = zeros(mr,3);
uv = zeros(mr,2);
uvs = zeros(mr,2);
deltas = zeros(mr,1);
j = 0;
for i=1:m
if matrixpoints(i)==1
j = j+1;
XYZ(j,:) =splinepoint(i,5:7);
uv = splinepoint(i,1:2);
uvs = splinepoint(i,3:4);
if j~=1
deltas(j) = norm(XYZ(j,:)-XYZ(j-1,:));
end
end
end
Deltas = zeros(mr,1);
for i=2:mr
Deltas(i)=sum(deltas(1:i));
end
pointspersegment=4;
nbasf = ceil(mr/pointspersegment);
t_knots = get_knot_vector(nbasf+2);
t = Deltas/Deltas(mr);
X = zeros(mr,nbasf+2);
for i=1:mr
[tf, ~] = splinebasevec(t_knots,t(i),0);
X(i,:) = tf;
end
sol = X\XYZ;
sol1 = X\uv;
sol2 = X\uvs;
X*sol - XYZ;
%X'*X\X'*XYZ
ns = 100;
td = linspace(0,1,ns);
for i=1:ns
PT(i,:)=splinebasevec(t_knots,td(i),0)'*sol;
end
plot3(PT(:,1),PT(:,2),PT(:,3),'r','LineWidth',3);
%
%
%
%
%
%