19 |
|
static EDGE *Edges=NULL; |
20 |
|
static int Ecnt=0; |
21 |
|
|
22 |
– |
#define remove_tri_compress remove_tri |
23 |
– |
remove_tri(qtptr,fptr,tptr) |
24 |
– |
QUADTREE *qtptr; |
25 |
– |
int *fptr; |
26 |
– |
int *tptr; |
27 |
– |
{ |
28 |
– |
int n; |
29 |
– |
|
30 |
– |
if(QT_IS_EMPTY(*qtptr)) |
31 |
– |
return; |
32 |
– |
if(QT_LEAF_IS_FLAG(*qtptr)) |
33 |
– |
return; |
34 |
– |
|
35 |
– |
n = QT_SET_CNT(qtqueryset(*qtptr))-1; |
36 |
– |
*qtptr = qtdelelem(*qtptr,*tptr); |
37 |
– |
if(n == 0) |
38 |
– |
(*fptr) |= QT_COMPRESS; |
39 |
– |
if(!QT_FLAG_FILL_TRI(*fptr)) |
40 |
– |
(*fptr)++; |
41 |
– |
} |
42 |
– |
|
43 |
– |
|
44 |
– |
smLocator_remove_tri(sm,t_id,v0_id,v1_id,v2_id) |
45 |
– |
SM *sm; |
46 |
– |
int t_id; |
47 |
– |
int v0_id,v1_id,v2_id; |
48 |
– |
{ |
49 |
– |
STREE *st; |
50 |
– |
FVECT v0,v1,v2; |
51 |
– |
|
52 |
– |
st = SM_LOCATOR(sm); |
53 |
– |
|
54 |
– |
VSUB(v0,SM_NTH_WV(sm,v0_id),SM_VIEW_CENTER(sm)); |
55 |
– |
VSUB(v1,SM_NTH_WV(sm,v1_id),SM_VIEW_CENTER(sm)); |
56 |
– |
VSUB(v2,SM_NTH_WV(sm,v2_id),SM_VIEW_CENTER(sm)); |
57 |
– |
|
58 |
– |
qtClearAllFlags(); |
59 |
– |
|
60 |
– |
stApply_to_tri(st,v0,v1,v2,remove_tri,remove_tri_compress,&t_id); |
61 |
– |
|
62 |
– |
} |
63 |
– |
|
22 |
|
smFree_tri(sm,id) |
23 |
|
SM *sm; |
24 |
|
int id; |
25 |
|
{ |
26 |
< |
TRI *tri; |
26 |
> |
TRI *tri,*t; |
27 |
|
|
28 |
|
tri = SM_NTH_TRI(sm,id); |
29 |
|
/* Add to the free_list */ |
30 |
+ |
smClear_tri_flags(sm,id); |
31 |
|
T_NEXT_FREE(tri) = SM_FREE_TRIS(sm); |
32 |
|
SM_FREE_TRIS(sm) = id; |
33 |
|
T_VALID_FLAG(tri) = -1; |
47 |
|
to id because the vertices can no longer |
48 |
|
point to tri id as being the first triangle pointer |
49 |
|
*/ |
50 |
< |
if(!SM_IS_NTH_T_BASE(sm,t_id)) |
51 |
< |
{ |
52 |
< |
SM_SAMPLE_TRIS(sm)--; |
53 |
< |
if(SM_IS_NTH_T_NEW(sm,t_id)) |
95 |
< |
smNew_tri_cnt--; |
96 |
< |
} |
50 |
> |
SM_SAMPLE_TRIS(sm)--; |
51 |
> |
if(SM_IS_NTH_T_NEW(sm,t_id)) |
52 |
> |
smNew_tri_cnt--; |
53 |
> |
|
54 |
|
smClear_tri_flags(sm,t_id); |
55 |
|
|
56 |
|
smFree_tri(sm,t_id); |
67 |
|
if(Ecnt >= Max_edges) |
68 |
|
{ |
69 |
|
if(Max_edges > 10000) |
70 |
< |
error(CONSISTENCY,"Too many edges in vertex loop\n"); |
70 |
> |
{ |
71 |
> |
eputs("Too many edges in vertex loop\n"); |
72 |
> |
return(-1); |
73 |
> |
} |
74 |
|
Max_edges += 100; |
75 |
|
if(!(Edges = (EDGE *)realloc(Edges,(Max_edges+1)*sizeof(EDGE)))) |
76 |
|
goto memerr; |
81 |
|
error(SYSTEM,"eNew_edge(): Unable to allocate memory"); |
82 |
|
} |
83 |
|
|
84 |
+ |
/* Return list of edges defining polygon formed by boundary of triangles |
85 |
+ |
adjacent to id. Return set of triangles adjacent to id to delete in delptr |
86 |
+ |
*/ |
87 |
|
LIST |
88 |
< |
*smVertex_star_polygon(sm,id,delptr) |
88 |
> |
*smVertexPolygon(sm,id,del_ptr) |
89 |
|
SM *sm; |
90 |
|
int id; |
91 |
< |
QUADTREE *delptr; |
91 |
> |
LIST **del_ptr; |
92 |
|
{ |
93 |
|
TRI *tri,*t_next; |
94 |
|
LIST *elist,*end; |
95 |
< |
int t_id,v_next,t_next_id; |
133 |
< |
int e; |
134 |
< |
OBJECT del_set[2]; |
95 |
> |
int e,t_id,v_next,t_next_id,b_id,v_id; |
96 |
|
|
97 |
+ |
eClear_edges(); |
98 |
|
elist = end = NULL; |
99 |
+ |
|
100 |
|
/* Get the first triangle adjacent to vertex id */ |
101 |
|
t_id = SM_NTH_VERT(sm,id); |
102 |
|
tri = SM_NTH_TRI(sm,t_id); |
103 |
|
|
104 |
< |
if((e = eNew_edge()) == INVALID) |
142 |
< |
return(NULL); |
104 |
> |
e = eNew_edge(); |
105 |
|
|
106 |
< |
v_next = (T_WHICH_V(tri,id)+1)%3; |
107 |
< |
SET_E_NTH_VERT(e,0,T_NTH_V(tri,v_next)); |
106 |
> |
/* Get the next vertex on the polygon boundary */ |
107 |
> |
v_id = T_WHICH_V(tri,id); |
108 |
> |
b_id = (v_id + 1)%3; |
109 |
> |
/* Create an edge */ |
110 |
> |
SET_E_NTH_VERT(e,0,T_NTH_V(tri,b_id)); |
111 |
|
SET_E_NTH_TRI(e,0,INVALID); |
112 |
< |
SET_E_NTH_TRI(e,1,T_NTH_NBR(tri,v_next)); |
113 |
< |
v_next = (T_WHICH_V(tri,id)+2)%3; |
114 |
< |
SET_E_NTH_VERT(e,1,T_NTH_V(tri,v_next)); |
112 |
> |
SET_E_NTH_TRI(e,1,T_NTH_NBR(tri,v_id)); |
113 |
> |
v_next = T_NTH_V(tri,(b_id+1)%3); |
114 |
> |
SET_E_NTH_VERT(e,1,v_next); |
115 |
|
elist = add_data_to_circular_list(elist,&end,e); |
151 |
– |
|
116 |
|
t_next_id = t_id; |
117 |
|
t_next = tri; |
118 |
|
|
119 |
< |
del_set[0] =1; del_set[1] = t_id; |
120 |
< |
*delptr = qtnewleaf(del_set); |
119 |
> |
*del_ptr = push_data(*del_ptr,t_id); |
120 |
> |
/* Create a set to hold all of the triangles for deletion later */ |
121 |
|
|
122 |
< |
while((t_next_id = T_NTH_NBR(t_next,v_next)) != t_id) |
123 |
< |
{ |
124 |
< |
if((e = eNew_edge()) == INVALID) |
122 |
> |
while((t_next_id = T_NTH_NBR(t_next,b_id)) != t_id) |
123 |
> |
{ |
124 |
> |
e = eNew_edge(); |
125 |
> |
if(e== INVALID) |
126 |
|
return(NULL); |
162 |
– |
|
127 |
|
t_next = SM_NTH_TRI(sm,t_next_id); |
128 |
< |
v_next = (T_WHICH_V(t_next,id)+1)%3; |
165 |
< |
|
166 |
< |
SET_E_NTH_VERT(e,0,T_NTH_V(t_next,v_next)); |
128 |
> |
SET_E_NTH_VERT(e,0,v_next); |
129 |
|
SET_E_NTH_TRI(e,0,INVALID); |
130 |
< |
SET_E_NTH_TRI(e,1,T_NTH_NBR(t_next,v_next)); |
131 |
< |
v_next = (T_WHICH_V(t_next,id)+2)%3; |
132 |
< |
SET_E_NTH_VERT(e,1,T_NTH_V(t_next,v_next)); |
130 |
> |
v_id = T_WHICH_V(t_next,id); |
131 |
> |
b_id = (v_id + 1)%3; |
132 |
> |
SET_E_NTH_TRI(e,1,T_NTH_NBR(t_next,v_id)); |
133 |
> |
v_next = T_NTH_V(t_next,(b_id+1)%3); |
134 |
> |
SET_E_NTH_VERT(e,1,v_next); |
135 |
|
elist = add_data_to_circular_list(elist,&end,e); |
136 |
< |
|
173 |
< |
|
174 |
< |
if(qtinset(*delptr,t_next_id)) |
175 |
< |
{ |
176 |
< |
#ifdef DEBUG |
177 |
< |
eputs("smVertex_star_polygon(): id already in set\n"); |
178 |
< |
#endif |
179 |
< |
free_list(elist); |
180 |
< |
return(NULL); |
181 |
< |
} |
182 |
< |
else |
183 |
< |
qtaddelem(*delptr,t_next_id); |
136 |
> |
*del_ptr = push_data(*del_ptr,t_next_id); |
137 |
|
} |
138 |
|
return(elist); |
139 |
|
} |
140 |
|
|
141 |
+ |
|
142 |
|
int |
143 |
< |
smEdge_intersect_polygon(sm,v0,v1,l) |
143 |
> |
smTriangulate_add_tri(sm,id0,id1,id2,e0,e1,e2ptr) |
144 |
|
SM *sm; |
145 |
< |
FVECT v0,v1; |
192 |
< |
LIST *l; |
145 |
> |
int id0,id1,id2,e0,e1,*e2ptr; |
146 |
|
{ |
147 |
< |
FVECT e0,e1; |
148 |
< |
int e,id_e0,id_e1; |
196 |
< |
LIST *el,*eptr; |
197 |
< |
|
198 |
< |
/* Test the edges in l against v0v1 to see if v0v1 intersects |
199 |
< |
any other edges |
200 |
< |
*/ |
201 |
< |
|
202 |
< |
el = l; |
147 |
> |
int t_id; |
148 |
> |
int e2; |
149 |
|
|
150 |
< |
while(el) |
151 |
< |
{ |
152 |
< |
e = (int)LIST_DATA(el); |
207 |
< |
id_e0 = E_NTH_VERT(e,0); |
208 |
< |
id_e1 = E_NTH_VERT(e,1); |
209 |
< |
|
210 |
< |
VSUB(e0,SM_NTH_WV(sm,id_e0),SM_VIEW_CENTER(sm)); |
211 |
< |
VSUB(e1,SM_NTH_WV(sm,id_e1),SM_VIEW_CENTER(sm)); |
212 |
< |
if(sedge_intersect(v0,v1,e0,e1)) |
213 |
< |
return(TRUE); |
214 |
< |
|
215 |
< |
el = LIST_NEXT(el); |
216 |
< |
if(el == l) |
217 |
< |
break; |
218 |
< |
} |
219 |
< |
return(FALSE); |
220 |
< |
} |
221 |
< |
|
222 |
< |
int |
223 |
< |
smFind_next_convex_vertex(sm,id0,id1,v0,v1,l) |
224 |
< |
SM *sm; |
225 |
< |
int id0,id1; |
226 |
< |
FVECT v0,v1; |
227 |
< |
LIST *l; |
228 |
< |
{ |
229 |
< |
int e,id; |
230 |
< |
LIST *el; |
231 |
< |
FVECT v; |
232 |
< |
|
233 |
< |
/* starting with the end of edge at head of l, search sequentially for |
234 |
< |
vertex v such that v0v1v is a convex angle, and the edge v1v does |
235 |
< |
not intersect any other edges |
236 |
< |
*/ |
237 |
< |
id = INVALID; |
238 |
< |
el = l; |
239 |
< |
while(id != id0) |
240 |
< |
{ |
241 |
< |
e = (int)LIST_DATA(el); |
242 |
< |
id = E_NTH_VERT(e,1); |
243 |
< |
|
244 |
< |
smDir(sm,v,id); |
245 |
< |
|
246 |
< |
if(convex_angle(v0,v1,v) && !smEdge_intersect_polygon(sm,v1,v,l)) |
247 |
< |
return(id); |
248 |
< |
|
249 |
< |
el = LIST_NEXT(el); |
250 |
< |
if(el == l) |
251 |
< |
break; |
252 |
< |
} |
253 |
< |
return(INVALID); |
254 |
< |
} |
255 |
< |
|
256 |
< |
int |
257 |
< |
split_edge_list(id0,id_new,l,lnew) |
258 |
< |
int id0,id_new; |
259 |
< |
LIST **l,**lnew; |
260 |
< |
{ |
261 |
< |
LIST *list,*lptr,*end; |
262 |
< |
int e,e1,e2,new_e; |
263 |
< |
|
264 |
< |
e2 = INVALID; |
265 |
< |
list = lptr = *l; |
266 |
< |
|
267 |
< |
if((new_e = eNew_edge())==INVALID) |
268 |
< |
{ |
269 |
< |
#ifdef DEBUG |
270 |
< |
eputs("split_edge_list():Too many edges\n"); |
150 |
> |
#ifdef DEBUG |
151 |
> |
if(id0 == INVALID || id1==INVALID || id2==INVALID) |
152 |
> |
error(CONSISTENCY,"bad id- smTriangulate_add_tri()\n"); |
153 |
|
#endif |
154 |
< |
return(FALSE); |
155 |
< |
} |
156 |
< |
SET_E_NTH_VERT(new_e,0,id0); |
157 |
< |
SET_E_NTH_VERT(new_e,1,id_new); |
158 |
< |
SET_E_NTH_TRI(new_e,0,INVALID); |
159 |
< |
SET_E_NTH_TRI(new_e,1,INVALID); |
160 |
< |
|
161 |
< |
while(e2 != id_new) |
162 |
< |
{ |
163 |
< |
lptr = LIST_NEXT(lptr); |
164 |
< |
e = (int)LIST_DATA(lptr); |
165 |
< |
e2 = E_NTH_VERT(e,1); |
166 |
< |
if(lptr == list) |
285 |
< |
{ |
286 |
< |
#ifdef DEBUG |
287 |
< |
eputs("split_edge_list():cant find vertex\n"); |
288 |
< |
#endif |
289 |
< |
*lnew = NULL; |
290 |
< |
return(FALSE); |
291 |
< |
} |
154 |
> |
t_id = smAdd_tri(sm,id0,id1,id2); |
155 |
> |
if(*e2ptr == 0) |
156 |
> |
{ |
157 |
> |
e2 = eNew_edge(); |
158 |
> |
SET_E_NTH_VERT(e2,0,id2); |
159 |
> |
SET_E_NTH_VERT(e2,1,id0); |
160 |
> |
} |
161 |
> |
else |
162 |
> |
e2 = *e2ptr; |
163 |
> |
/* set appropriate tri for each edge*/ |
164 |
> |
SET_E_NTH_TRI(e0,0,t_id); |
165 |
> |
SET_E_NTH_TRI(e1,0,t_id); |
166 |
> |
SET_E_NTH_TRI(e2,0,t_id); |
167 |
|
|
168 |
< |
} |
169 |
< |
end = lptr; |
295 |
< |
lptr = LIST_NEXT(lptr); |
296 |
< |
list = add_data_to_circular_list(list,&end,-new_e); |
297 |
< |
*lnew = list; |
298 |
< |
|
299 |
< |
/* now follow other cycle */ |
300 |
< |
|
301 |
< |
list = lptr; |
302 |
< |
e2 = INVALID; |
303 |
< |
while(e2 != id0) |
304 |
< |
{ |
305 |
< |
lptr = LIST_NEXT(lptr); |
306 |
< |
e = (int)LIST_DATA(lptr); |
307 |
< |
e2 = E_NTH_VERT(e,1); |
308 |
< |
if(lptr == list) |
309 |
< |
{ |
310 |
< |
#ifdef DEBUG |
311 |
< |
eputs("split_edge_list():cant find intial vertex\n"); |
312 |
< |
#endif |
313 |
< |
*l = NULL; |
314 |
< |
return(FALSE); |
315 |
< |
} |
316 |
< |
|
317 |
< |
} |
318 |
< |
end = lptr; |
319 |
< |
list = add_data_to_circular_list(list,&end,new_e); |
320 |
< |
*l = list; |
321 |
< |
return(TRUE); |
168 |
> |
*e2ptr = e2; |
169 |
> |
return(t_id); |
170 |
|
} |
171 |
|
|
324 |
– |
|
172 |
|
int |
173 |
< |
smTriangulate_convex(sm,plist,add_ptr) |
173 |
> |
smTriangulateConvex(sm,plist,add_ptr) |
174 |
|
SM *sm; |
175 |
|
LIST *plist,**add_ptr; |
176 |
|
{ |
177 |
|
int t_id,e_id0,e_id1,e_id2; |
178 |
|
int v_id0,v_id1,v_id2; |
179 |
|
LIST *lptr; |
333 |
– |
int cnt; |
180 |
|
|
181 |
|
lptr = plist; |
182 |
|
e_id0 = (int)LIST_DATA(lptr); |
187 |
|
e_id1 = (int)LIST_DATA(lptr); |
188 |
|
v_id1 = E_NTH_VERT(e_id1,0); |
189 |
|
v_id2 = E_NTH_VERT(e_id1,1); |
344 |
– |
/* form a triangle for each triple of with v0 as base of star */ |
345 |
– |
t_id = smAdd_tri(sm,v_id0,v_id1,v_id2); |
346 |
– |
*add_ptr = push_data(*add_ptr,t_id); |
347 |
– |
|
348 |
– |
/* add which pointer?*/ |
349 |
– |
|
190 |
|
lptr = LIST_NEXT(lptr); |
191 |
|
|
192 |
< |
if(LIST_NEXT(lptr) != plist) |
193 |
< |
{ |
354 |
< |
e_id2 = eNew_edge(); |
355 |
< |
SET_E_NTH_VERT(e_id2,0,v_id2); |
356 |
< |
SET_E_NTH_VERT(e_id2,1,v_id0); |
357 |
< |
} |
192 |
> |
if(LIST_NEXT(lptr) != plist) |
193 |
> |
e_id2 = 0; |
194 |
|
else |
195 |
|
e_id2 = (int)LIST_DATA(lptr); |
196 |
< |
|
197 |
< |
/* set appropriate tri for each edge*/ |
362 |
< |
SET_E_NTH_TRI(e_id0,0,t_id); |
363 |
< |
SET_E_NTH_TRI(e_id1,0,t_id); |
364 |
< |
SET_E_NTH_TRI(e_id2,0,t_id); |
365 |
< |
|
196 |
> |
t_id = smTriangulate_add_tri(sm,v_id0,v_id1,v_id2,e_id0,e_id1,&e_id2); |
197 |
> |
*add_ptr = push_data(*add_ptr,t_id); |
198 |
|
e_id0 = -e_id2; |
199 |
|
} |
200 |
|
free_list(plist); |
201 |
|
return(TRUE); |
202 |
|
} |
203 |
< |
int |
204 |
< |
smTriangulate_elist(sm,plist,add_ptr) |
205 |
< |
SM *sm; |
374 |
< |
LIST *plist,**add_ptr; |
375 |
< |
{ |
376 |
< |
LIST *l,*el1; |
377 |
< |
FVECT v0,v1,v2; |
378 |
< |
int id0,id1,id2,e,id_next; |
379 |
< |
char flipped; |
380 |
< |
int done; |
381 |
< |
|
382 |
< |
l = plist; |
383 |
< |
|
384 |
< |
while(l) |
385 |
< |
{ |
386 |
< |
/* get v0,v1,v2 */ |
387 |
< |
e = (int)LIST_DATA(l); |
388 |
< |
id0 = E_NTH_VERT(e,0); |
389 |
< |
id1 = E_NTH_VERT(e,1); |
390 |
< |
l = LIST_NEXT(l); |
391 |
< |
e = (int)LIST_DATA(l); |
392 |
< |
id2 = E_NTH_VERT(e,1); |
393 |
< |
|
394 |
< |
smDir(sm,v0,id0); |
395 |
< |
smDir(sm,v1,id1); |
396 |
< |
smDir(sm,v2,id2); |
397 |
< |
/* determine if convex (left turn), or concave(right turn) angle */ |
398 |
< |
if(convex_angle(v0,v1,v2)) |
399 |
< |
{ |
400 |
< |
if(l == plist) |
401 |
< |
break; |
402 |
< |
else |
403 |
< |
continue; |
404 |
< |
} |
405 |
< |
/* if concave: add edge and recurse on two sub polygons */ |
406 |
< |
id_next = smFind_next_convex_vertex(sm,id0,id1,v0,v1,LIST_NEXT(l)); |
407 |
< |
if(id_next == INVALID) |
408 |
< |
{ |
409 |
< |
#ifdef DEBUG |
410 |
< |
eputs("smTriangulate_elist():Unable to find convex vertex\n"); |
203 |
> |
#ifdef TEST_DRIVER |
204 |
> |
FVECT Norm[500],B_V[500]; |
205 |
> |
int Ncnt,Bcnt,Del=0; |
206 |
|
#endif |
412 |
– |
return(FALSE); |
413 |
– |
} |
414 |
– |
/* add edge */ |
415 |
– |
el1 = NULL; |
416 |
– |
/* Split edge list l into two lists: one from id1-id_next-id1, |
417 |
– |
and the next from id2-id_next-id2 |
418 |
– |
*/ |
419 |
– |
split_edge_list(id1,id_next,&l,&el1); |
420 |
– |
/* Recurse and triangulate the two edge lists */ |
421 |
– |
done = smTriangulate_elist(sm,l,add_ptr); |
422 |
– |
if(done) |
423 |
– |
done = smTriangulate_elist(sm,el1,add_ptr); |
424 |
– |
return(done); |
425 |
– |
} |
426 |
– |
done = smTriangulate_convex(sm,plist,add_ptr); |
427 |
– |
return(done); |
428 |
– |
} |
207 |
|
|
430 |
– |
int |
431 |
– |
smTriangulate_add_tri(sm,id0,id1,id2,e0,e1,e2ptr) |
432 |
– |
SM *sm; |
433 |
– |
int id0,id1,id2,e0,e1,*e2ptr; |
434 |
– |
{ |
435 |
– |
int t_id; |
436 |
– |
int e2; |
208 |
|
|
209 |
< |
t_id = smAdd_tri(sm,id0,id1,id2); |
210 |
< |
if(*e2ptr == 0) |
211 |
< |
{ |
212 |
< |
e2 = eNew_edge(); |
213 |
< |
SET_E_NTH_VERT(e2,0,id2); |
443 |
< |
SET_E_NTH_VERT(e2,1,id0); |
444 |
< |
} |
445 |
< |
else |
446 |
< |
e2 = *e2ptr; |
447 |
< |
/* set appropriate tri for each edge*/ |
448 |
< |
SET_E_NTH_TRI(e0,0,t_id); |
449 |
< |
SET_E_NTH_TRI(e1,0,t_id); |
450 |
< |
SET_E_NTH_TRI(e2,0,t_id); |
209 |
> |
/* Triangulate the polygon defined by plist, and generating vertex p_id. |
210 |
> |
Return list of added triangles in list add_ptr. Returns TRUE if |
211 |
> |
successful, FALSE otherwise. This is NOT a general triangulation routine, |
212 |
> |
assumes polygon star relative to id |
213 |
> |
*/ |
214 |
|
|
452 |
– |
*e2ptr = e2; |
453 |
– |
return(t_id); |
454 |
– |
} |
215 |
|
int |
216 |
< |
smTriangulate_elist_new(sm,id,plist,add_ptr) |
216 |
> |
smTriangulate(sm,id,plist,add_ptr) |
217 |
|
SM *sm; |
218 |
|
int id; |
219 |
|
LIST *plist,**add_ptr; |
220 |
|
{ |
221 |
|
LIST *l,*prev,*t; |
222 |
|
FVECT v0,v1,v2,n,p; |
223 |
< |
int is_tri,loop,t_id,id0,id1,id2,e2,eprev,enext; |
223 |
> |
int is_tri,is_convex,cut,t_id,id0,id1,id2,e2,e1,enew; |
224 |
|
double dp; |
225 |
+ |
static int debug=0; |
226 |
|
|
227 |
< |
smDir(sm,p,id); |
228 |
< |
enext=0; |
229 |
< |
is_tri= loop = FALSE; |
227 |
> |
VSUB(p,SM_NTH_WV(sm,id),SM_VIEW_CENTER(sm)); |
228 |
> |
enew = 0; |
229 |
> |
is_convex = TRUE; |
230 |
> |
cut = is_tri= FALSE; |
231 |
|
l = prev = plist; |
232 |
< |
/* get v0,v1,v2 */ |
233 |
< |
eprev = (int)LIST_DATA(l); |
234 |
< |
id0 = E_NTH_VERT(eprev,0); |
235 |
< |
id1 = E_NTH_VERT(eprev,1); |
236 |
< |
smDir(sm,v0,id0); |
237 |
< |
smDir(sm,v1,id1); |
232 |
> |
|
233 |
> |
/* get v0,v1 */ |
234 |
> |
e1 = (int)LIST_DATA(l); |
235 |
> |
id0 = E_NTH_VERT(e1,0); |
236 |
> |
id1 = E_NTH_VERT(e1,1); |
237 |
> |
VSUB(v0,SM_NTH_WV(sm,id0),SM_VIEW_CENTER(sm)); |
238 |
> |
VSUB(v1,SM_NTH_WV(sm,id1),SM_VIEW_CENTER(sm)); |
239 |
> |
#ifdef TEST_DRIVER |
240 |
> |
Del = TRUE; |
241 |
> |
VCOPY(B_V[0],v0); |
242 |
> |
VCOPY(B_V[1],v1); |
243 |
> |
Bcnt = 2; |
244 |
> |
Ncnt = 0; |
245 |
> |
#endif |
246 |
|
while(l) |
247 |
|
{ |
248 |
|
l = LIST_NEXT(l); |
249 |
+ |
/* Get v2 */ |
250 |
|
e2 = (int)LIST_DATA(l); |
251 |
|
id2 = E_NTH_VERT(e2,1); |
252 |
< |
/* Check if have a triangle */ |
252 |
> |
VSUB(v2,SM_NTH_WV(sm,id2),SM_VIEW_CENTER(sm)); |
253 |
> |
#ifdef TEST_DRIVER |
254 |
> |
VCOPY(B_V[Bcnt++],v2); |
255 |
> |
#endif |
256 |
|
if(LIST_NEXT(LIST_NEXT(l)) == prev) |
257 |
< |
{ |
258 |
< |
is_tri = TRUE; |
259 |
< |
break; |
257 |
> |
{/* Check if have a triangle */ |
258 |
> |
is_tri = TRUE; |
259 |
> |
break; |
260 |
|
} |
261 |
< |
if(LIST_NEXT(l) == plist) |
261 |
> |
|
262 |
> |
/* determine if v0-v1-v2 is convex:defined clockwise on the sphere- |
263 |
> |
so switch orientation |
264 |
> |
*/ |
265 |
> |
if(convex_angle(v2,v1,v0)) |
266 |
|
{ |
267 |
< |
if(!loop) |
268 |
< |
loop = 1; |
269 |
< |
else |
270 |
< |
loop++; |
271 |
< |
if(loop > 3) |
272 |
< |
break; |
267 |
> |
/* test if safe to cut off v0-v1-v2 by testing if p lies outside of |
268 |
> |
triangle v0-v1-v2: if so, because plist is the star polygon around p, |
269 |
> |
the new edge v2-v0 cannot intersect any existing edges |
270 |
> |
*/ |
271 |
> |
VCROSS(n,v0,v2); |
272 |
> |
dp = DOT(n,p); |
273 |
> |
if(dp <= 0.0) |
274 |
> |
{ |
275 |
> |
/* remove edges e1,e2 and add triangle id0,id1,id2 */ |
276 |
> |
enew = 0; |
277 |
> |
t_id = smTriangulate_add_tri(sm,id0,id1,id2,e1,e2,&enew); |
278 |
> |
cut = TRUE; |
279 |
> |
*add_ptr = push_data(*add_ptr,t_id); |
280 |
> |
/* Insert edge enew into the list, reuse prev list element */ |
281 |
> |
LIST_NEXT(prev) = LIST_NEXT(l); |
282 |
> |
LIST_DATA(prev) = e1 = -enew; |
283 |
> |
/* If removing head of list- reset plist pointer */ |
284 |
> |
if(l== plist) |
285 |
> |
plist = prev; |
286 |
> |
/* free list element for e2 */ |
287 |
> |
LIST_NEXT(l)=NULL; |
288 |
> |
free_list(l); |
289 |
> |
l = prev; |
290 |
> |
VCOPY(v1,v2); |
291 |
> |
id1 = id2; |
292 |
> |
continue; |
293 |
> |
} |
294 |
|
} |
295 |
< |
smDir(sm,v2,id2); |
296 |
< |
/* determine if convex (left turn), or concave(right turn) angle */ |
297 |
< |
if(!convex_angle(v0,v1,v2)) |
499 |
< |
{ |
500 |
< |
VCOPY(v0,v1); |
501 |
< |
VCOPY(v1,v2); |
502 |
< |
id0 = id1; |
503 |
< |
id1 = id2; |
504 |
< |
prev = l; |
505 |
< |
eprev = e2; |
506 |
< |
continue; |
507 |
< |
} |
508 |
< |
VCROSS(n,v0,v2); |
509 |
< |
dp = DOT(n,p); |
510 |
< |
if(loop <=1 && (!ZERO(dp) && dp < 0.0)) |
511 |
< |
{ |
512 |
< |
VCOPY(v0,v1); |
513 |
< |
VCOPY(v1,v2); |
514 |
< |
id0 = id1; |
515 |
< |
id1 = id2; |
516 |
< |
eprev = e2; |
517 |
< |
prev = l; |
518 |
< |
continue; |
519 |
< |
} |
520 |
< |
loop = FALSE; |
521 |
< |
|
522 |
< |
enext = 0; |
523 |
< |
t_id = smTriangulate_add_tri(sm,id0,id1,id2,eprev,e2,&enext); |
524 |
< |
*add_ptr = push_data(*add_ptr,t_id); |
525 |
< |
|
526 |
< |
LIST_NEXT(prev) = LIST_NEXT(l); |
527 |
< |
LIST_DATA(prev) = eprev = -enext; |
528 |
< |
LIST_NEXT(l)=NULL; |
529 |
< |
if(l== plist) |
530 |
< |
plist = prev; |
531 |
< |
free_list(l); |
532 |
< |
l = prev; |
295 |
> |
else |
296 |
> |
is_convex = FALSE; |
297 |
> |
VCOPY(v0,v1); |
298 |
|
VCOPY(v1,v2); |
299 |
+ |
id0 = id1; |
300 |
|
id1 = id2; |
301 |
+ |
e1 = e2; |
302 |
+ |
/* check if gone around circular list without adding any |
303 |
+ |
triangles: prevent infinite loop */ |
304 |
+ |
if(l == plist) |
305 |
+ |
{ |
306 |
+ |
if(LIST_NEXT(LIST_NEXT(l)) == prev) |
307 |
+ |
{/* Check if have a triangle */ |
308 |
+ |
is_tri = TRUE; |
309 |
+ |
break; |
310 |
+ |
} |
311 |
+ |
|
312 |
+ |
if(is_convex) |
313 |
+ |
break; |
314 |
+ |
if(!cut) |
315 |
+ |
{ |
316 |
+ |
#ifdef DEBUG |
317 |
+ |
eputs("smTriangulate():Unable to triangulate\n"); |
318 |
+ |
#endif |
319 |
+ |
free_list(l); |
320 |
+ |
while(*add_ptr) |
321 |
+ |
{ |
322 |
+ |
t_id = pop_list(add_ptr); |
323 |
+ |
smDelete_tri(sm,t_id); |
324 |
+ |
} |
325 |
+ |
return(FALSE); |
326 |
+ |
} |
327 |
+ |
|
328 |
+ |
cut = FALSE; |
329 |
+ |
is_convex = TRUE; |
330 |
+ |
} |
331 |
+ |
prev = l; |
332 |
|
} |
333 |
|
if(is_tri) |
334 |
|
{ |
335 |
|
l = LIST_NEXT(l); |
336 |
< |
enext = (int)LIST_DATA(l); |
337 |
< |
t_id = smTriangulate_add_tri(sm,id0,id1,id2,eprev,e2,&enext); |
336 |
> |
enew = (int)LIST_DATA(l); |
337 |
> |
t_id = smTriangulate_add_tri(sm,id0,id1,id2,e1,e2,&enew); |
338 |
|
*add_ptr = push_data(*add_ptr,t_id); |
339 |
|
free_list(l); |
340 |
< |
} |
340 |
> |
} |
341 |
|
else |
342 |
< |
{ |
546 |
< |
#ifdef DEBUG |
547 |
< |
eputs("smTriangulate_elist()Unable to triangulate\n"); |
548 |
< |
#endif |
342 |
> |
if(!smTriangulateConvex(sm,l,add_ptr)) |
343 |
|
return(FALSE); |
550 |
– |
} |
551 |
– |
return(TRUE); |
552 |
– |
} |
344 |
|
|
345 |
< |
int |
346 |
< |
smTriangulate(sm,p_id,plist,add_ptr) |
556 |
< |
SM *sm; |
557 |
< |
int p_id; |
558 |
< |
LIST *plist,**add_ptr; |
559 |
< |
{ |
560 |
< |
int e,id_t0,id_t1,e0,e1; |
561 |
< |
int test; |
562 |
< |
|
563 |
< |
test = smTriangulate_elist_new(sm,p_id,plist,add_ptr); |
564 |
< |
#if 0 |
565 |
< |
test = smTriangulate_elist(sm,plist,add_ptr); |
566 |
< |
#endif |
567 |
< |
|
568 |
< |
if(!test) |
569 |
< |
return(test); |
570 |
< |
|
571 |
< |
FOR_ALL_EDGES(e) |
345 |
> |
/* Set triangle adjacencies based on edge adjacencies */ |
346 |
> |
FOR_ALL_EDGES(enew) |
347 |
|
{ |
348 |
< |
id_t0 = E_NTH_TRI(e,0); |
349 |
< |
id_t1 = E_NTH_TRI(e,1); |
575 |
< |
if((id_t0==INVALID) || (id_t1==INVALID)) |
576 |
< |
{ |
577 |
< |
#ifdef DEBUG |
578 |
< |
eputs("smTriangulate(): Unassigned edge neighbor\n"); |
579 |
< |
#endif |
580 |
< |
continue; |
581 |
< |
} |
348 |
> |
id0 = E_NTH_TRI(enew,0); |
349 |
> |
id1 = E_NTH_TRI(enew,1); |
350 |
|
|
351 |
< |
e0 = T_WHICH_V(SM_NTH_TRI(sm,id_t0),E_NTH_VERT(e,0)); |
352 |
< |
T_NTH_NBR(SM_NTH_TRI(sm,id_t0),e0) = id_t1; |
353 |
< |
|
354 |
< |
e1 = T_WHICH_V(SM_NTH_TRI(sm,id_t1),E_NTH_VERT(e,1)); |
355 |
< |
T_NTH_NBR(SM_NTH_TRI(sm,id_t1),e1) = id_t0; |
351 |
> |
e1 = (T_WHICH_V(SM_NTH_TRI(sm,id0),E_NTH_VERT(enew,0))+2)%3; |
352 |
> |
T_NTH_NBR(SM_NTH_TRI(sm,id0),e1) = id1; |
353 |
> |
|
354 |
> |
e2 = (T_WHICH_V(SM_NTH_TRI(sm,id1),E_NTH_VERT(enew,1))+2)%3; |
355 |
> |
T_NTH_NBR(SM_NTH_TRI(sm,id1),e2) = id0; |
356 |
|
} |
357 |
< |
return(test); |
357 |
> |
return(TRUE); |
358 |
|
} |
359 |
|
|
360 |
|
eIn_tri(e,t) |
369 |
|
return(T_NTH_V(t,0)==E_NTH_VERT(e,1)||T_NTH_V(t,2)==E_NTH_VERT(e,1)); |
370 |
|
else if(T_NTH_V(t,2)==E_NTH_VERT(e,0)) |
371 |
|
return(T_NTH_V(t,0)==E_NTH_VERT(e,1)||T_NTH_V(t,1)==E_NTH_VERT(e,1)); |
372 |
+ |
|
373 |
|
return(FALSE); |
374 |
|
} |
375 |
|
|
376 |
< |
smFix_edges(sm,add_list,delptr) |
376 |
> |
/* Test the new set of triangles for Delaunay condition. 'Edges' contains |
377 |
> |
all of the new edges added. The CCW triangle assoc with each edge is |
378 |
> |
tested against the opposite vertex of the CW triangle. If the vertex |
379 |
> |
lies inside the circle defined by the CCW triangle- the edge is swapped |
380 |
> |
for the opposite diagonal |
381 |
> |
*/ |
382 |
> |
smFixEdges(sm,add_list) |
383 |
|
SM *sm; |
384 |
|
LIST *add_list; |
610 |
– |
QUADTREE *delptr; |
611 |
– |
|
385 |
|
{ |
386 |
|
int e,t0_id,t1_id,e_new,e0,e1,e0_next,e1_next; |
387 |
|
int i,v0_id,v1_id,v2_id,p_id,t0_nid,t1_nid; |
388 |
|
FVECT v0,v1,v2,p,np,v; |
389 |
+ |
TRI *t0,*t1; |
390 |
|
|
391 |
|
FOR_ALL_EDGES(e) |
392 |
|
{ |
395 |
|
if((t0_id==INVALID) || (t1_id==INVALID)) |
396 |
|
{ |
397 |
|
#ifdef DEBUG |
398 |
< |
eputs("smFix_edges: Unassigned edge nbr\n"); |
398 |
> |
error(CONSISTENCY,"smFix_edges: Unassigned edge nbr\n"); |
399 |
|
#endif |
626 |
– |
continue; |
400 |
|
} |
401 |
< |
e0 = T_WHICH_V(SM_NTH_TRI(sm,t0_id),E_NTH_VERT(e,0)); |
402 |
< |
e1 = T_WHICH_V(SM_NTH_TRI(sm,t1_id),E_NTH_VERT(-e,0)); |
403 |
< |
e0_next = (e0+2)%3; |
404 |
< |
e1_next = (e1+2)%3; |
401 |
> |
t0 = SM_NTH_TRI(sm,t0_id); |
402 |
> |
t1 = SM_NTH_TRI(sm,t1_id); |
403 |
> |
e0 = T_NTH_NBR_PTR(t1_id,t0); |
404 |
> |
e1 = T_NTH_NBR_PTR(t0_id,t1); |
405 |
> |
|
406 |
|
v0_id = E_NTH_VERT(e,0); |
407 |
|
v1_id = E_NTH_VERT(e,1); |
408 |
< |
v2_id = T_NTH_V(SM_NTH_TRI(sm,t0_id),e0_next); |
409 |
< |
p_id = T_NTH_V(SM_NTH_TRI(sm,t1_id),e1_next); |
408 |
> |
v2_id = T_NTH_V(t0,e0); |
409 |
> |
p_id = T_NTH_V(t1,e1); |
410 |
|
|
411 |
|
smDir_in_cone(sm,v0,v0_id); |
412 |
|
smDir_in_cone(sm,v1,v1_id); |
416 |
|
VSUB(p,p,SM_VIEW_CENTER(sm)); |
417 |
|
if(point_in_cone(p,v0,v1,v2)) |
418 |
|
{ |
419 |
< |
smTris_swap_edge(sm,t0_id,t1_id,e0,e1,&t0_nid,&t1_nid,&add_list, |
646 |
< |
delptr); |
419 |
> |
smTris_swap_edge(sm,t0_id,t1_id,e0,e1,&t0_nid,&t1_nid,&add_list); |
420 |
|
|
421 |
+ |
/* Adjust the triangle pointers of the remaining edges to be |
422 |
+ |
processed |
423 |
+ |
*/ |
424 |
|
FOR_ALL_EDGES_FROM(e,i) |
425 |
|
{ |
426 |
|
if(E_NTH_TRI(i,0)==t0_id || E_NTH_TRI(i,0)==t1_id) |
448 |
|
SET_E_NTH_TRI(e_new,1,t1_id); |
449 |
|
} |
450 |
|
} |
451 |
< |
smUpdate_locator(sm,add_list,qtqueryset(*delptr)); |
451 |
> |
/* Add/Delete the appropriate triangles from the stree */ |
452 |
> |
smUpdate_locator(sm,add_list); |
453 |
|
} |
454 |
|
|
455 |
+ |
/* Remove vertex "id" from the mesh- and retriangulate the resulting |
456 |
+ |
hole: Returns TRUE if successful, FALSE otherwise. |
457 |
+ |
*/ |
458 |
|
int |
459 |
< |
smMesh_remove_vertex(sm,id) |
459 |
> |
smRemoveVertex(sm,id) |
460 |
|
SM *sm; |
461 |
|
int id; |
462 |
|
{ |
463 |
< |
int t_id; |
464 |
< |
LIST *elist,*add_list; |
465 |
< |
int cnt,debug; |
466 |
< |
QUADTREE delnode; |
467 |
< |
/* generate list of vertices that form the boundary of the |
468 |
< |
star polygon formed by vertex id and all of its adjacent |
689 |
< |
triangles |
463 |
> |
LIST *b_list,*add_list,*del_list; |
464 |
> |
int t_id,i; |
465 |
> |
static int cnt=0; |
466 |
> |
OBJECT *optr,*os; |
467 |
> |
/* generate list of edges that form the boundary of the |
468 |
> |
polygon formed by the triangles adjacent to vertex 'id' |
469 |
|
*/ |
470 |
< |
eClear_edges(); |
471 |
< |
elist = smVertex_star_polygon(sm,id,&delnode); |
472 |
< |
|
694 |
< |
if(!elist) |
470 |
> |
del_list = NULL; |
471 |
> |
b_list = smVertexPolygon(sm,id,&del_list); |
472 |
> |
if(!b_list) |
473 |
|
{ |
474 |
< |
#ifdef DEBUG |
475 |
< |
eputs("smMesh_remove_vertex(): Unable to remove vertex"); |
698 |
< |
#endif |
699 |
< |
qtfreeleaf(delnode); |
474 |
> |
if(del_list) |
475 |
> |
free_list(del_list); |
476 |
|
return(FALSE); |
477 |
|
} |
478 |
|
add_list = NULL; |
479 |
< |
/* Triangulate spherical polygon */ |
480 |
< |
if(!smTriangulate(sm,id,elist,&add_list)) |
479 |
> |
/* Triangulate polygonal hole */ |
480 |
> |
if(!smTriangulate(sm,id,b_list,&add_list)) |
481 |
|
{ |
482 |
< |
while(add_list) |
707 |
< |
{ |
708 |
< |
t_id = pop_list(&add_list); |
709 |
< |
smDelete_tri(sm,t_id); |
710 |
< |
} |
711 |
< |
qtfreeleaf(delnode); |
482 |
> |
free_list(del_list); |
483 |
|
return(FALSE); |
484 |
|
} |
485 |
< |
/* Fix up new triangles to be Delaunay */ |
486 |
< |
smFix_edges(sm,add_list,&delnode); |
485 |
> |
else |
486 |
> |
{ |
487 |
> |
while(del_list) |
488 |
> |
{ |
489 |
> |
t_id = pop_list(&del_list); |
490 |
> |
smDelete_tri(sm,t_id); |
491 |
> |
} |
492 |
> |
} |
493 |
> |
/* Fix up new triangles to be Delaunay-delnode contains set of |
494 |
> |
triangles to delete,add_list is the set of new triangles to add |
495 |
> |
*/ |
496 |
> |
smFixEdges(sm,add_list); |
497 |
|
|
717 |
– |
qtfreeleaf(delnode); |
498 |
|
return(TRUE); |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
|
|
503 |
< |
|
503 |
> |
|
504 |
|
|
505 |
|
|
506 |
|
|