--- ray/src/hd/sm_del.c 1998/12/28 18:07:34 3.8 +++ ray/src/hd/sm_del.c 1999/03/05 16:32:22 3.11 @@ -27,7 +27,7 @@ int id; tri = SM_NTH_TRI(sm,id); /* Add to the free_list */ - + smClear_tri_flags(sm,id); T_NEXT_FREE(tri) = SM_FREE_TRIS(sm); SM_FREE_TRIS(sm) = id; T_VALID_FLAG(tri) = -1; @@ -47,30 +47,13 @@ int t_id; to id because the vertices can no longer point to tri id as being the first triangle pointer */ - if(!SM_IS_NTH_T_BASE(sm,t_id)) - { - SM_SAMPLE_TRIS(sm)--; - if(SM_IS_NTH_T_NEW(sm,t_id)) - smNew_tri_cnt--; - } + SM_SAMPLE_TRIS(sm)--; + if(SM_IS_NTH_T_NEW(sm,t_id)) + smNew_tri_cnt--; + smClear_tri_flags(sm,t_id); smFree_tri(sm,t_id); - -#if 0 - { - int i; - TRI *t; - for(i=0; i < SM_NUM_TRI(sm);i++) - { - t = SM_NTH_TRI(sm,i); - if(!T_IS_VALID(t)) - continue; - if(T_NTH_NBR(t,0)==t_id || T_NTH_NBR(t,1)==t_id || T_NTH_NBR(t,2)==t_id) - eputs("Stale pointer: smDelete_tri()\n"); - } - } -#endif } @@ -84,7 +67,10 @@ eNew_edge() if(Ecnt >= Max_edges) { if(Max_edges > 10000) - error(CONSISTENCY,"Too many edges in vertex loop\n"); + { + eputs("Too many edges in vertex loop\n"); + return(-1); + } Max_edges += 100; if(!(Edges = (EDGE *)realloc(Edges,(Max_edges+1)*sizeof(EDGE)))) goto memerr; @@ -99,7 +85,7 @@ memerr: adjacent to id. Return set of triangles adjacent to id to delete in delptr */ LIST -*smVertexPolygon(sm,id,del_ptr) +*smVertexStar(sm,id,del_ptr) SM *sm; int id; LIST **del_ptr; @@ -116,6 +102,7 @@ LIST **del_ptr; tri = SM_NTH_TRI(sm,t_id); e = eNew_edge(); + /* Get the next vertex on the polygon boundary */ v_id = T_WHICH_V(tri,id); b_id = (v_id + 1)%3; @@ -135,6 +122,8 @@ LIST **del_ptr; while((t_next_id = T_NTH_NBR(t_next,b_id)) != t_id) { e = eNew_edge(); + if(e== INVALID) + return(NULL); t_next = SM_NTH_TRI(sm,t_next_id); SET_E_NTH_VERT(e,0,v_next); SET_E_NTH_TRI(e,0,INVALID); @@ -419,9 +408,9 @@ smFixEdges(sm,add_list) v2_id = T_NTH_V(t0,e0); p_id = T_NTH_V(t1,e1); - smDir_in_cone(sm,v0,v0_id); - smDir_in_cone(sm,v1,v1_id); - smDir_in_cone(sm,v2,v2_id); + smDir(sm,v0,v0_id); + smDir(sm,v1,v1_id); + smDir(sm,v2,v2_id); VCOPY(p,SM_NTH_WV(sm,p_id)); VSUB(p,p,SM_VIEW_CENTER(sm)); @@ -479,8 +468,13 @@ smRemoveVertex(sm,id) polygon formed by the triangles adjacent to vertex 'id' */ del_list = NULL; - b_list = smVertexPolygon(sm,id,&del_list); - + b_list = smVertexStar(sm,id,&del_list); + if(!b_list) + { + if(del_list) + free_list(del_list); + return(FALSE); + } add_list = NULL; /* Triangulate polygonal hole */ if(!smTriangulate(sm,id,b_list,&add_list)) @@ -490,15 +484,6 @@ smRemoveVertex(sm,id) } else { -#ifdef DEBUG - b_list = del_list; - while(b_list) - { - t_id = LIST_DATA(b_list); - b_list = LIST_NEXT(b_list); - T_VALID_FLAG(SM_NTH_TRI(sm,t_id))=-1; - } -#endif while(del_list) { t_id = pop_list(&del_list);