ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm.c
(Generate patch)

Comparing ray/src/hd/sm.c (file contents):
Revision 3.1 by gwlarson, Wed Aug 19 17:45:23 1998 UTC vs.
Revision 3.4 by gwlarson, Tue Aug 25 11:03:27 1998 UTC

# Line 343 | Line 343 | TRI **tptr;
343      SM_NTH_VERT(sm,v1_id) = t_id;
344      SM_NTH_VERT(sm,v2_id) = t_id;
345  
346    /* Add triangle to the locator */
347    smLocator_add_tri(sm,t_id,v0_id,v1_id,v2_id);
346      if(t)
347         *tptr = t;
348      /* return initialized triangle */
# Line 442 | Line 440 | FVECT p;
440   }
441  
442   void
443 < smTris_swap_edge(sm,t_id,t1_id,e,e1,tn_id,tn1_id)
443 > smTris_swap_edge(sm,t_id,t1_id,e,e1,tn_id,tn1_id,add,del)
444     SM *sm;
445     int t_id,t1_id;
446     int e,e1;
447     int **tn_id,**tn1_id;
448 +   LIST **add,**del;
449  
450   {
451      TRI *t,*t1;
# Line 469 | Line 468 | smTris_swap_edge(sm,t_id,t1_id,e,e1,tn_id,tn1_id)
468      verts[enext] = T_NTH_V(t1,e1prev);
469      verts[eprev] = T_NTH_V(t,eprev);
470      ta_id = smAdd_tri(sm,verts[0],verts[1],verts[2],&ta);
471 +    *add = push_data(*add,ta_id);
472  
473      verts[e1] = T_NTH_V(t1,e1);
474      verts[e1next] = T_NTH_V(t,eprev);
475      verts[e1prev] = T_NTH_V(t1,e1prev);
476      tb_id = smAdd_tri(sm,verts[0],verts[1],verts[2],&tb);
477 <    
477 >    *add = push_data(*add,tb_id);
478 >
479      /* set the neighbors */
480      T_NTH_NBR(ta,e) = T_NTH_NBR(t1,e1next);
481      T_NTH_NBR(tb,e1) = T_NTH_NBR(t,enext);
# Line 495 | Line 496 | smTris_swap_edge(sm,t_id,t1_id,e,e1,tn_id,tn1_id)
496      T_NTH_NBR(n,T_NTH_NBR_PTR(t1_id,n)) = tb_id;
497  
498      /* Delete two parent triangles */
499 <    smDelete_tri(sm,t_id);
500 <    smDelete_tri(sm,t1_id);
499 >    *del = push_data(*del,t_id);
500 >    if(SM_IS_NTH_T_NEW(sm,t_id))
501 >      SM_CLEAR_NTH_T_NEW(sm,t_id);
502 >    else
503 >      SM_CLEAR_NTH_T_BASE(sm,t_id);
504 >    *del = push_data(*del,t1_id);
505 >    if(SM_IS_NTH_T_NEW(sm,t1_id))
506 >      SM_CLEAR_NTH_T_NEW(sm,t1_id);
507 >    else
508 >      SM_CLEAR_NTH_T_BASE(sm,t1_id);
509      *tn_id = ta_id;
510      *tn1_id = tb_id;
511   }
512  
513 + smUpdate_locator(sm,add_list,del_list)
514 + SM *sm;
515 + LIST *add_list,*del_list;
516 + {
517 +  int t_id;
518 +  TRI *t;
519 +  while(add_list)
520 +  {
521 +    t_id = pop_list(&add_list);
522 +    if(!SM_IS_NTH_T_NEW(sm,t_id) && !SM_IS_NTH_T_BASE(sm,t_id))
523 +    {
524 +      SM_SET_NTH_T_NEW(sm,t_id);
525 +      smNew_tri_cnt--;
526 +      continue;
527 +    }
528 +    t = SM_NTH_TRI(sm,t_id);
529 +    smLocator_add_tri(sm,t_id,T_NTH_V(t,0),T_NTH_V(t,1),T_NTH_V(t,2));
530 +  }
531 +  
532 +  while(del_list)
533 +  {
534 +    t_id = pop_list(&del_list);
535 +    if(SM_IS_NTH_T_NEW(sm,t_id))
536 +    {
537 +      smDelete_tri(sm,t_id);
538 +      continue;
539 +    }
540 +    smLocator_remove_tri(sm,t_id);
541 +    smDelete_tri(sm,t_id);
542 +  }
543 + }
544   /* MUST add check for constrained edges */
545 < char
545 > int
546   smFix_tris(sm,id,tlist)
547   SM *sm;
548   int id;
549   LIST *tlist;
550   {
551      TRI *t,*t_opp;
552 <    FVECT p,p1,np,p2,p3;
553 <    int swapped = 0;
514 <    int e,e1,e_id;
515 <    char debug = 0;
552 >    FVECT p,p1,p2,p3;
553 >    int e,e1,swapped = 0;
554      int t_id,t_opp_id;
555 <    
556 <    VCOPY(p,SM_NTH_WV(sm,id));    
557 <    VSUB(p,p,SM_VIEW_CENTER(sm));
555 >    LIST *add_list,*del_list;
556 >
557 >
558 >    add_list = del_list = NULL;
559 >    VSUB(p,SM_NTH_WV(sm,id),SM_VIEW_CENTER(sm));
560      while(tlist)
561      {
562 <        t_id = (int)pop_list(&tlist);
562 >        t_id = pop_list(&tlist);
563          t = SM_NTH_TRI(sm,t_id);
564          e = (T_WHICH_V(t,id)+1)%3;
565          t_opp_id = T_NTH_NBR(t,e);
# Line 534 | Line 574 | LIST *tlist;
574              e1 = T_NTH_NBR_PTR(t_id,t_opp);
575              /* check list for t_opp and Remove if there */
576              remove_from_list(t_opp_id,&tlist);
577 <
578 <            smTris_swap_edge(sm,t_id,t_opp_id,e,e1,&t_id,&t_opp_id);
577 >            smTris_swap_edge(sm,t_id,t_opp_id,e,e1,&t_id,&t_opp_id,
578 >                             &add_list,&del_list);
579              tlist = push_data(tlist,t_id);
580              tlist = push_data(tlist,t_opp_id);
581          }
582      }
583 +    smUpdate_locator(sm,add_list,del_list);
584 +
585      return(swapped);
586   }
587  
# Line 670 | Line 712 | smInsert_point_in_tri(sm,c,dir,p,s_id,tri_id)
712        n_id = smClosest_vertex_in_tri(sm,t0_id,t1_id,t2_id,npt,P_REPLACE_EPS);
713      }
714      t0_id = smAdd_tri(sm,s_id,v0_id,v1_id,&t0);
715 +    /* Add triangle to the locator */
716 +    smLocator_add_tri(sm,t0_id,s_id,v0_id,v1_id);
717 +
718      t1_id = smAdd_tri(sm,s_id,v1_id,v2_id,&t1);
719 +    smLocator_add_tri(sm,t1_id,s_id,v1_id,v2_id);
720      t2_id = smAdd_tri(sm,s_id,v2_id,v0_id,&t2);
721 <        
721 >    smLocator_add_tri(sm,t2_id,s_id,v2_id,v0_id);      
722 >
723      /* Set the neighbor pointers for the new tris */
724      T_NTH_NBR(t0,0) = t2_id;
725      T_NTH_NBR(t0,1) = T_NTH_NBR(tri,0);
# Line 692 | Line 739 | smInsert_point_in_tri(sm,c,dir,p,s_id,tri_id)
739      nbr = SM_NTH_TRI(sm,T_NTH_NBR(tri,2));
740      T_NTH_NBR(nbr,T_NTH_NBR_PTR(tri_id,nbr)) = t2_id;
741          
742 +    smLocator_remove_tri(sm,tri_id);
743      smDelete_tri(sm,tri_id);
744          
745      /* Fix up the new triangles*/
# Line 731 | Line 779 | char norm;
779   }
780  
781   QUADTREE
782 < smPointLocateCell(sm,pt,v0,v1,v2,type,which,norm)
782 > smPointLocateCell(sm,pt,norm,v0,v1,v2)
783   SM *sm;
784 < FVECT pt,v0,v1,v2;
737 < char *type,*which;
784 > FVECT pt;
785   char norm;
786 + FVECT v0,v1,v2;
787   {
788    STREE *st;
789 <  QUADTREE qt;
789 >  QUADTREE *qtptr;
790    FVECT npt;
791  
792    st = SM_LOCATOR(sm);
# Line 746 | Line 794 | char norm;
794    {
795        point_on_sphere(npt,pt,SM_VIEW_CENTER(sm));
796    
797 <      qt = stPoint_locate_cell(st,npt,v0,v1,v2,type,which);
797 >      qtptr = stPoint_locate_cell(st,npt,v0,v1,v2);
798    }
799    else
800 <     qt = stPoint_locate_cell(st,pt,v0,v1,v2,type,which);
800 >     qtptr = stPoint_locate_cell(st,pt,v0,v1,v2);
801  
802 <  return(qt);
802 >  if(qtptr)
803 >    return(*qtptr);
804 >  else
805 >    return(EMPTY);
806   }
807  
808   int
# Line 957 | Line 1008 | int type;
1008      v2_id = p[stTri_verts[i][2]];
1009      if((ids[i] = smAdd_tri(sm, v0_id,v1_id,v2_id,&(tris[i])))== -1)
1010       return(0);
1011 +    smLocator_add_tri(sm,ids[i],v0_id,v1_id,v2_id);
1012    }
1013    /* Set neighbors */
1014  
# Line 1071 | Line 1123 | smIntersectTriSet(sm,t_set,orig,dir,pt)
1123      return(-1);
1124   }
1125  
1074 /*
1075 * int
1076 * smTraceRay(SM *sm,FVECT orig, FVECT dir,FVECT v0,FVECT v1,FVECT v2,FVECT r)
1077 *
1078 *   Intersect the ray with triangle v0v1v2, return intersection point in r
1079 *
1080 *    Assumes orig,v0,v1,v2 are in spherical coordinates, and orig is
1081 *    unit
1082 */
1083 char
1084 smTraceRay(sm,orig,dir,v0,v1,v2,r)
1085  SM *sm;
1086  FVECT orig,dir;
1087  FVECT v0,v1,v2;
1088  FVECT r;
1089 {
1090  FVECT n,p[3],d;
1091  double pt[3],r_eps;
1092  char i;
1093  int which;
1126  
1095  /* Find the plane equation for the triangle defined by the edge v0v1 and
1096   the view center*/
1097  VCROSS(n,v0,v1);
1098  /* Intersect the ray with this plane */
1099  i = intersect_ray_plane(orig,dir,n,0.0,&(pt[0]),p[0]);
1100  if(i)
1101    which = 0;
1102  else
1103    which = -1;
1104
1105  VCROSS(n,v1,v2);
1106  i = intersect_ray_plane(orig,dir,n,0.0,&(pt[1]),p[1]);
1107  if(i)
1108    if((which==-1) || pt[1] < pt[0])
1109      which = 1;
1110
1111  VCROSS(n,v2,v0);
1112  i = intersect_ray_plane(orig,dir,n,0.0,&(pt[2]),p[2]);
1113  if(i)
1114    if((which==-1) || pt[2] < pt[which])
1115      which = 2;
1116
1117  if(which != -1)
1118  {
1119      /* Return point that is K*eps along projection of the ray on
1120         the sphere to push intersection point p[which] into next cell
1121      */
1122      normalize(p[which]);
1123      /* Calculate the ray perpendicular to the intersection point: approx
1124       the direction moved along the sphere a distance of K*epsilon*/
1125      r_eps = -DOT(p[which],dir);
1126      VSUM(n,dir,p[which],r_eps);
1127     /* Calculate the length along ray p[which]-dir needed to move to
1128         cause a move along the sphere of k*epsilon
1129       */
1130       r_eps = DOT(n,dir);
1131      VSUM(r,p[which],dir,(20*FTINY)/r_eps);
1132      normalize(r);
1133      return(TRUE);
1134  }
1135  else
1136  {
1137      /* Unable to find intersection: move along ray and try again */
1138      r_eps = -DOT(orig,dir);
1139      VSUM(n,dir,orig,r_eps);
1140      r_eps = DOT(n,dir);
1141      VSUM(r,orig,dir,(20*FTINY)/r_eps);
1142      normalize(r);
1143 #ifdef DEBUG
1144      eputs("smTraceRay:Ray does not intersect triangle");
1145 #endif
1146      return(FALSE);
1147  }
1148 }
1149
1150
1127   /*
1128   * int
1129   * smFindSamp(FVECT orig, FVECT dir)
# Line 1184 | Line 1160 | FVECT orig,dir;
1160    d = -DOT(b,dir);
1161    if(EQUAL_VEC3(orig,SM_VIEW_CENTER(smMesh)) || EQUAL(fabs(d),1.0))
1162    {
1163 <      qt = smPointLocateCell(smMesh,dir,v0,v1,v2,NULL,NULL,FALSE);
1163 >      qt = smPointLocateCell(smMesh,dir,FALSE,NULL,NULL,NULL);
1164        /* Test triangles in the set for intersection with Ray:returns
1165           first found
1166        */
# Line 1199 | Line 1175 | FVECT orig,dir;
1175    {
1176        /* Starting with orig, Walk along projection of ray onto sphere */
1177        point_on_sphere(r,orig,SM_VIEW_CENTER(smMesh));
1178 <      qt = smPointLocateCell(smMesh,r,v0,v1,v2,NULL,NULL,FALSE);
1178 >      qt = smPointLocateCell(smMesh,r,FALSE,v0,v1,v2);
1179        qtgetset(t_set,qt);
1180        /* os will contain all triangles seen thus far */
1181        setcopy(os,t_set);
# Line 1218 | Line 1194 | FVECT orig,dir;
1194            if(s_id != EMPTY)
1195                 return(s_id);
1196            /* Find next cell that projection of ray intersects */
1197 <          smTraceRay(smMesh,r,dir,v0,v1,v2,r);
1198 <          qt = smPointLocateCell(smMesh,r,v0,v1,v2,NULL,NULL,FALSE);
1197 >          traceRay(r,dir,v0,v1,v2,r);
1198 >          qt = smPointLocateCell(smMesh,r,FALSE,v0,v1,v2);
1199            qtgetset(t_set,qt);
1200            /* Check triangles in set against those seen so far(os):only
1201               check new triangles for intersection (t_set')
1202            */
1203            check_set(t_set,os);
1204 <          d = DOT(a,r);
1204 >          d = DOT(a,r);
1205        }
1206      }
1207   #ifdef DEBUG  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines