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 |
+ |
|
31 |
|
T_NEXT_FREE(tri) = SM_FREE_TRIS(sm); |
32 |
|
SM_FREE_TRIS(sm) = id; |
33 |
|
T_VALID_FLAG(tri) = -1; |
56 |
|
smClear_tri_flags(sm,t_id); |
57 |
|
|
58 |
|
smFree_tri(sm,t_id); |
59 |
+ |
|
60 |
+ |
#if 0 |
61 |
+ |
{ |
62 |
+ |
int i; |
63 |
+ |
TRI *t; |
64 |
+ |
for(i=0; i < SM_NUM_TRI(sm);i++) |
65 |
+ |
{ |
66 |
+ |
t = SM_NTH_TRI(sm,i); |
67 |
+ |
if(!T_IS_VALID(t)) |
68 |
+ |
continue; |
69 |
+ |
if(T_NTH_NBR(t,0)==t_id || T_NTH_NBR(t,1)==t_id || T_NTH_NBR(t,2)==t_id) |
70 |
+ |
eputs("Stale pointer: smDelete_tri()\n"); |
71 |
+ |
} |
72 |
+ |
} |
73 |
+ |
#endif |
74 |
|
} |
75 |
|
|
76 |
|
|
99 |
|
adjacent to id. Return set of triangles adjacent to id to delete in delptr |
100 |
|
*/ |
101 |
|
LIST |
102 |
< |
*smVertexPolygon(sm,id,delptr) |
102 |
> |
*smVertexPolygon(sm,id,del_ptr) |
103 |
|
SM *sm; |
104 |
|
int id; |
105 |
< |
QUADTREE *delptr; |
105 |
> |
LIST **del_ptr; |
106 |
|
{ |
107 |
|
TRI *tri,*t_next; |
108 |
|
LIST *elist,*end; |
109 |
|
int e,t_id,v_next,t_next_id,b_id,v_id; |
136 |
– |
OBJECT del_set[2]; |
110 |
|
|
111 |
|
eClear_edges(); |
112 |
|
elist = end = NULL; |
129 |
|
t_next_id = t_id; |
130 |
|
t_next = tri; |
131 |
|
|
132 |
+ |
*del_ptr = push_data(*del_ptr,t_id); |
133 |
|
/* Create a set to hold all of the triangles for deletion later */ |
160 |
– |
del_set[0] = 1; del_set[1] = t_id; |
161 |
– |
*delptr = qtnewleaf(del_set); |
134 |
|
|
135 |
|
while((t_next_id = T_NTH_NBR(t_next,b_id)) != t_id) |
136 |
|
{ |
144 |
|
v_next = T_NTH_V(t_next,(b_id+1)%3); |
145 |
|
SET_E_NTH_VERT(e,1,v_next); |
146 |
|
elist = add_data_to_circular_list(elist,&end,e); |
147 |
< |
qtaddelem(*delptr,t_next_id); |
147 |
> |
*del_ptr = push_data(*del_ptr,t_next_id); |
148 |
|
} |
149 |
|
return(elist); |
150 |
|
} |
233 |
|
FVECT v0,v1,v2,n,p; |
234 |
|
int is_tri,is_convex,cut,t_id,id0,id1,id2,e2,e1,enew; |
235 |
|
double dp; |
236 |
+ |
static int debug=0; |
237 |
|
|
238 |
|
VSUB(p,SM_NTH_WV(sm,id),SM_VIEW_CENTER(sm)); |
239 |
|
enew = 0; |
327 |
|
#ifdef DEBUG |
328 |
|
eputs("smTriangulate():Unable to triangulate\n"); |
329 |
|
#endif |
330 |
< |
free_list(l); |
330 |
> |
free_list(l); |
331 |
|
while(*add_ptr) |
332 |
|
{ |
333 |
|
t_id = pop_list(add_ptr); |
334 |
|
smDelete_tri(sm,t_id); |
335 |
|
} |
336 |
|
return(FALSE); |
337 |
< |
} |
337 |
> |
} |
338 |
> |
|
339 |
|
cut = FALSE; |
340 |
|
is_convex = TRUE; |
341 |
|
} |
390 |
|
lies inside the circle defined by the CCW triangle- the edge is swapped |
391 |
|
for the opposite diagonal |
392 |
|
*/ |
393 |
< |
smFixEdges(sm,add_list,delptr) |
393 |
> |
smFixEdges(sm,add_list) |
394 |
|
SM *sm; |
395 |
|
LIST *add_list; |
422 |
– |
QUADTREE *delptr; |
423 |
– |
|
396 |
|
{ |
397 |
|
int e,t0_id,t1_id,e_new,e0,e1,e0_next,e1_next; |
398 |
|
int i,v0_id,v1_id,v2_id,p_id,t0_nid,t1_nid; |
427 |
|
VSUB(p,p,SM_VIEW_CENTER(sm)); |
428 |
|
if(point_in_cone(p,v0,v1,v2)) |
429 |
|
{ |
430 |
< |
smTris_swap_edge(sm,t0_id,t1_id,e0,e1,&t0_nid,&t1_nid,&add_list, |
459 |
< |
delptr); |
430 |
> |
smTris_swap_edge(sm,t0_id,t1_id,e0,e1,&t0_nid,&t1_nid,&add_list); |
431 |
|
|
432 |
|
/* Adjust the triangle pointers of the remaining edges to be |
433 |
|
processed |
460 |
|
} |
461 |
|
} |
462 |
|
/* Add/Delete the appropriate triangles from the stree */ |
463 |
< |
smUpdate_locator(sm,add_list,qtqueryset(*delptr)); |
493 |
< |
|
463 |
> |
smUpdate_locator(sm,add_list); |
464 |
|
} |
465 |
|
|
466 |
|
/* Remove vertex "id" from the mesh- and retriangulate the resulting |
471 |
|
SM *sm; |
472 |
|
int id; |
473 |
|
{ |
474 |
< |
LIST *b_list,*add_list; |
475 |
< |
QUADTREE delnode=-1; |
476 |
< |
int t_id; |
477 |
< |
|
474 |
> |
LIST *b_list,*add_list,*del_list; |
475 |
> |
int t_id,i; |
476 |
> |
static int cnt=0; |
477 |
> |
OBJECT *optr,*os; |
478 |
|
/* generate list of edges that form the boundary of the |
479 |
|
polygon formed by the triangles adjacent to vertex 'id' |
480 |
|
*/ |
481 |
< |
b_list = smVertexPolygon(sm,id,&delnode); |
481 |
> |
del_list = NULL; |
482 |
> |
b_list = smVertexPolygon(sm,id,&del_list); |
483 |
|
|
484 |
|
add_list = NULL; |
485 |
|
/* Triangulate polygonal hole */ |
486 |
|
if(!smTriangulate(sm,id,b_list,&add_list)) |
487 |
|
{ |
488 |
< |
qtfreeleaf(delnode); |
488 |
> |
free_list(del_list); |
489 |
|
return(FALSE); |
490 |
|
} |
491 |
+ |
else |
492 |
+ |
{ |
493 |
+ |
#ifdef DEBUG |
494 |
+ |
b_list = del_list; |
495 |
+ |
while(b_list) |
496 |
+ |
{ |
497 |
+ |
t_id = LIST_DATA(b_list); |
498 |
+ |
b_list = LIST_NEXT(b_list); |
499 |
+ |
T_VALID_FLAG(SM_NTH_TRI(sm,t_id))=-1; |
500 |
+ |
} |
501 |
+ |
#endif |
502 |
+ |
while(del_list) |
503 |
+ |
{ |
504 |
+ |
t_id = pop_list(&del_list); |
505 |
+ |
smDelete_tri(sm,t_id); |
506 |
+ |
} |
507 |
+ |
} |
508 |
|
/* Fix up new triangles to be Delaunay-delnode contains set of |
509 |
|
triangles to delete,add_list is the set of new triangles to add |
510 |
|
*/ |
511 |
< |
smFixEdges(sm,add_list,&delnode); |
511 |
> |
smFixEdges(sm,add_list); |
512 |
|
|
525 |
– |
|
526 |
– |
qtfreeleaf(delnode); |
513 |
|
return(TRUE); |
514 |
|
} |
515 |
|
|
516 |
|
|
517 |
|
|
518 |
< |
|
518 |
> |
|
519 |
|
|
520 |
|
|
521 |
|
|