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; |
85 |
|
adjacent to id. Return set of triangles adjacent to id to delete in delptr |
86 |
|
*/ |
87 |
|
LIST |
88 |
< |
*smVertexPolygon(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 e,t_id,v_next,t_next_id,b_id,v_id; |
136 |
– |
OBJECT del_set[2]; |
96 |
|
|
97 |
|
eClear_edges(); |
98 |
|
elist = end = NULL; |
102 |
|
tri = SM_NTH_TRI(sm,t_id); |
103 |
|
|
104 |
|
e = eNew_edge(); |
105 |
+ |
|
106 |
|
/* Get the next vertex on the polygon boundary */ |
107 |
|
v_id = T_WHICH_V(tri,id); |
108 |
|
b_id = (v_id + 1)%3; |
116 |
|
t_next_id = t_id; |
117 |
|
t_next = tri; |
118 |
|
|
119 |
+ |
*del_ptr = push_data(*del_ptr,t_id); |
120 |
|
/* 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); |
121 |
|
|
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); |
127 |
|
t_next = SM_NTH_TRI(sm,t_next_id); |
128 |
|
SET_E_NTH_VERT(e,0,v_next); |
129 |
|
SET_E_NTH_TRI(e,0,INVALID); |
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 |
< |
qtaddelem(*delptr,t_next_id); |
136 |
> |
*del_ptr = push_data(*del_ptr,t_next_id); |
137 |
|
} |
138 |
|
return(elist); |
139 |
|
} |
222 |
|
FVECT v0,v1,v2,n,p; |
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 |
|
VSUB(p,SM_NTH_WV(sm,id),SM_VIEW_CENTER(sm)); |
228 |
|
enew = 0; |
316 |
|
#ifdef DEBUG |
317 |
|
eputs("smTriangulate():Unable to triangulate\n"); |
318 |
|
#endif |
319 |
< |
free_list(l); |
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 |
< |
} |
326 |
> |
} |
327 |
> |
|
328 |
|
cut = FALSE; |
329 |
|
is_convex = TRUE; |
330 |
|
} |
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,delptr) |
382 |
> |
smFixEdges(sm,add_list) |
383 |
|
SM *sm; |
384 |
|
LIST *add_list; |
422 |
– |
QUADTREE *delptr; |
423 |
– |
|
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; |
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, |
459 |
< |
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 |
449 |
|
} |
450 |
|
} |
451 |
|
/* Add/Delete the appropriate triangles from the stree */ |
452 |
< |
smUpdate_locator(sm,add_list,qtqueryset(*delptr)); |
493 |
< |
|
452 |
> |
smUpdate_locator(sm,add_list); |
453 |
|
} |
454 |
|
|
455 |
|
/* Remove vertex "id" from the mesh- and retriangulate the resulting |
460 |
|
SM *sm; |
461 |
|
int id; |
462 |
|
{ |
463 |
< |
LIST *b_list,*add_list; |
464 |
< |
QUADTREE delnode=-1; |
465 |
< |
int t_id; |
466 |
< |
|
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 |
< |
b_list = smVertexPolygon(sm,id,&delnode); |
471 |
< |
|
470 |
> |
del_list = NULL; |
471 |
> |
b_list = smVertexPolygon(sm,id,&del_list); |
472 |
> |
if(!b_list) |
473 |
> |
{ |
474 |
> |
if(del_list) |
475 |
> |
free_list(del_list); |
476 |
> |
return(FALSE); |
477 |
> |
} |
478 |
|
add_list = NULL; |
479 |
|
/* Triangulate polygonal hole */ |
480 |
|
if(!smTriangulate(sm,id,b_list,&add_list)) |
481 |
|
{ |
482 |
< |
qtfreeleaf(delnode); |
482 |
> |
free_list(del_list); |
483 |
|
return(FALSE); |
484 |
|
} |
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,&delnode); |
496 |
> |
smFixEdges(sm,add_list); |
497 |
|
|
525 |
– |
|
526 |
– |
qtfreeleaf(delnode); |
498 |
|
return(TRUE); |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
|
|
503 |
< |
|
503 |
> |
|
504 |
|
|
505 |
|
|
506 |
|
|