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

Comparing ray/src/hd/sm_stree.c (file contents):
Revision 3.4 by gwlarson, Fri Sep 11 11:52:27 1998 UTC vs.
Revision 3.5 by gwlarson, Wed Sep 16 18:16:29 1998 UTC

# Line 125 | Line 125 | stPoint_locate(st,npt)
125           {
126               /* Find the first triangle that pt falls */
127               id = QT_SET_NEXT_ELEM(optr);
128 <             qtTri_from_id(id,NULL,NULL,NULL,p0,p1,p2,NULL,NULL,NULL);
128 >             qtTri_from_id(id,p0,p1,p2,NULL,NULL,NULL,NULL,NULL,NULL);
129               d = point_in_stri(p0,p1,p2,npt);  
130               if(d)
131                 return(id);
# Line 228 | Line 228 | FVECT v0,v1,v2;
228   }
229  
230   int
231 < stVisit_tri_edges(st,t0,t1,t2,func,arg1,arg2)
231 > stVisit_tri_edges(st,t0,t1,t2,func,arg1,arg2,arg3)
232     STREE *st;
233     FVECT t0,t1,t2;
234     int (*func)();
235 <   int *arg1,arg2;
235 >   int *arg1,arg2,*arg3;
236   {
237      int id,i,w;
238      QUADTREE *rootptr;
239    FVECT q0,q1,q2,n,v[3],sdir[3],dir[3],tv,d;
240    double pd,t;
241
242    VCOPY(v[0],t0); VCOPY(v[1],t1); VCOPY(v[2],t2);
243    VSUB(dir[0],t1,t0); VSUB(dir[1],t2,t1);VSUB(dir[2],t0,t2);
244    VCOPY(sdir[0],dir[0]);VCOPY(sdir[1],dir[1]);VCOPY(sdir[2],dir[2]);
245    w = 0;
246    for(i=0; i < 4; i++)
247     {
248 #ifdef TEST_DRIVER
249 Pick_cnt = 0;
250 #endif
251         rootptr = ST_NTH_ROOT_PTR(st,i);
252         stNth_base_verts(st,i,q0,q1,q2);
253         /* Return quadtree tri that p falls in */
254         if(!point_in_stri(q0,q1,q2,v[w]))  
255           continue;
256         id = qtRoot_visit_tri_edges(rootptr,q0,q1,q2,v,dir,&w,func,arg1,arg2);
257         if(id == INVALID)
258         {
259 #ifdef DEBUG
260           eputs("stVisit_tri_edges(): Unable to trace edges\n");
261 #endif
262           return(INVALID);
263         }
264         if(id == QT_DONE)
265            return(*arg1);
266        
267         /* Crossed over to next cell: id = nbr */
268         while(1)
269         {
270             /* test if ray crosses plane between this quadtree triangle and
271                its neighbor- if it does then find intersection point with
272                ray and plane- this is the new origin
273                */
274           if(id==0)
275             VCROSS(n,q1,q2);
276           else
277             if(id==1)
278               VCROSS(n,q2,q0);
279           else
280             VCROSS(n,q0,q1);
281
282           if(w==0)
283             VCOPY(tv,t0);
284           else
285             if(w==1)
286               VCOPY(tv,t1);
287           else
288             VCOPY(tv,t2);
289           if(!intersect_ray_plane(tv,sdir[w],n,0.0,&t,v[w]))
290             return(INVALID);
291
292           VSUM(v[w],v[w],sdir[w],10.0*FTINY);
293
294           t = (1.0-t-10.0*FTINY);
295           if(t <= 0.0)
296           {
297             t = FTINY;
298 #if 0
299             eputs("stVisit_tri_edges(): edge end on plane\n");
300 #endif
301           }
302           dir[w][0] = sdir[w][0] * t;
303           dir[w][1] = sdir[w][1] * t;
304           dir[w][2] = sdir[w][2] * t;
305           i = stTri_nbrs[i][id];
306           rootptr = ST_NTH_ROOT_PTR(st,i);
307           stNth_base_verts(st,i,q0,q1,q2);
308           id=qtRoot_visit_tri_edges(rootptr,q0,q1,q2,v,dir,&w,func,arg1,arg2);
309           if(id == QT_DONE)
310             return(*arg1);
311           if(id == INVALID)
312             {
313 #if 0
314             eputs("stVisit_tri_edges(): point not found\n");
315 #endif  
316             return(INVALID);
317             }
318          
319         }
320     }    /* Point not found */
321    return(INVALID);
322 }
323
324
325 int
326 stVisit_tri_edges2(st,t0,t1,t2,func,arg1,arg2)
327   STREE *st;
328   FVECT t0,t1,t2;
329   int (*func)();
330   int *arg1,arg2;
331 {
332    int id,i,w;
333    QUADTREE *rootptr;
239      FVECT q0,q1,q2,v[3],i_pt;
240  
241      VCOPY(v[0],t0); VCOPY(v[1],t1); VCOPY(v[2],t2);
242      w = -1;
243 +    QT_SET_FLAG(ST_ROOT(st));
244      for(i=0; i < 4; i++)
245       {
246   #ifdef TEST_DRIVER
# Line 345 | Line 251 | Pick_cnt = 0;
251           /* Return quadtree tri that p falls in */
252           if(!point_in_stri(q0,q1,q2,v[0]))  
253             continue;
254 <         id = qtRoot_visit_tri_edges2(rootptr,q0,q1,q2,v,i_pt,&w,
255 <                                      func,arg1,arg2);
254 > #ifdef TEST_DRIVER
255 >         id = qtRoot_visit_tri_edges(rootptr,q0,q1,q2,v,i_pt,&w,
256 >                                      func,arg1,arg2,arg3);
257 > #else
258 >         id = qtRoot_visit_tri_edgesi(rootptr,q0,q1,q2,v,i_pt,&w,
259 >                                      func,arg1,arg2,arg3);
260 > #endif
261           if(id == INVALID)
262           {
263   #ifdef DEBUG
# Line 367 | Line 278 | Pick_cnt = 0;
278             i = stTri_nbrs[i][id];
279             rootptr = ST_NTH_ROOT_PTR(st,i);
280             stNth_base_verts(st,i,q0,q1,q2);
281 <           id=qtRoot_visit_tri_edges2(rootptr,q0,q1,q2,v,i_pt,&w,
282 <                                      func,arg1,arg2);
281 > #ifdef TEST_DRIVER
282 >           id=qtRoot_visit_tri_edges(rootptr,q0,q1,q2,v,i_pt,&w,
283 >                                      func,arg1,arg2,arg3);
284 > #else
285 >           id=qtRoot_visit_tri_edgesi(rootptr,q0,q1,q2,v,i_pt,&w,
286 >                                      func,arg1,arg2,arg3);
287 > #endif
288             if(id == QT_DONE)
289               return(*arg1);
290             if(id == INVALID)
# Line 385 | Line 301 | Pick_cnt = 0;
301   }
302  
303   int
388 stTrace_edge(st,orig,dir,max_t,func,arg1,arg2)
389   STREE *st;
390   FVECT orig,dir;
391   double max_t;
392   int (*func)();
393   int *arg1,arg2;
394 {
395    int id,i;
396    QUADTREE *rootptr;
397    FVECT q0,q1,q2,o,n,d;
398    double pd,t;
399
400 #if DEBUG
401    if(max_t > 1.0 || max_t < 0.0)
402    {
403      eputs("stTrace_edge(): max_t must be in [0,1]:adjusting\n");
404      max_t = 1.0;
405    }
406 #endif
407
408    VCOPY(o,orig);
409    for(i=0; i < 4; i++)
410     {
411 #ifdef TEST_DRIVER
412 Pick_cnt = 0;
413 #endif
414         rootptr = ST_NTH_ROOT_PTR(st,i);
415         stNth_base_verts(st,i,q0,q1,q2);
416         /* Return quadtree tri that p falls in */
417         id= qtRoot_trace_edge(rootptr,q0,q1,q2,o,dir,max_t,func,arg1,arg2);
418         if(id == INVALID)
419           continue;
420         if(id == QT_DONE)
421            return(*arg1);
422        
423         /* Crossed over to next cell: id = nbr */
424         while(1)
425         {
426             /* test if ray crosses plane between this quadtree triangle and
427                its neighbor- if it does then find intersection point with
428                ray and plane- this is the new origin
429                */
430           if(id==0)
431             VCROSS(n,q1,q2);
432           else
433             if(id==1)
434               VCROSS(n,q2,q0);
435           else
436             VCROSS(n,q0,q1);
437
438           /* Ray does not cross into next cell: done and tri not found*/
439           if(!intersect_ray_plane(orig,dir,n,0.0,&t,o))
440             return(INVALID);
441
442           VSUM(o,o,dir,10*FTINY);
443
444           d[0] = dir[0]*(1-t-10*FTINY);
445           d[1] = dir[1]*(1-t-10*FTINY);
446           d[2] = dir[2]*(1-t-10*FTINY);
447           i = stTri_nbrs[i][id];
448           rootptr = ST_NTH_ROOT_PTR(st,i);
449           stNth_base_verts(st,i,q0,q1,q2);
450           id = qtRoot_trace_edge(rootptr,q0,q1,q2,o,d,max_t,func,arg1,arg2);
451           if(id == QT_DONE)
452             return(*arg1);
453           if(id == INVALID)
454             {
455 #if 0
456             eputs("stTrace_edges(): point not found\n");
457 #endif  
458             return(INVALID);
459             }
460          
461         }
462     }    /* Point not found */
463    return(INVALID);
464 }
465
466
467
468 int
304   stTrace_ray(st,orig,dir,func,arg1,arg2)
305     STREE *st;
306     FVECT orig,dir;
# Line 528 | Line 363 | Pick_cnt = 0;
363  
364  
365  
366 < stVisit_tri_interior(st,t0,t1,t2,func,arg1,arg2)
366 > stVisit_tri_interior(st,t0,t1,t2,func,arg1,arg2,arg3)
367     STREE *st;
368     FVECT t0,t1,t2;
369     int (*func)();
370 <   int *arg1,arg2;
370 >   int *arg1,arg2,*arg3;
371   {
372    int i;
373    QUADTREE *rootptr;
# Line 542 | Line 377 | stVisit_tri_interior(st,t0,t1,t2,func,arg1,arg2)
377    {
378      rootptr = ST_NTH_ROOT_PTR(st,i);
379      stNth_base_verts(st,i,q0,q1,q2);
380 <    qtVisit_tri_interior(rootptr,q0,q1,q2,t0,t1,t2,0,func,arg1,arg2);
380 >    qtVisit_tri_interior(rootptr,q0,q1,q2,t0,t1,t2,0,func,arg1,arg2,arg3);
381    }
382   }
383  
384  
385   int
386 < stApply_to_tri(st,t0,t1,t2,func,arg1,arg2)
386 > stApply_to_tri(st,t0,t1,t2,edge_func,interior_func,arg1,arg2)
387     STREE *st;
388     FVECT t0,t1,t2;
554   int (*func)();
555   int *arg1,arg2;
556 {
557    int f;
558    FVECT dir;
559    
560  /* First add all of the leaf cells lying on the triangle perimeter:
561     mark all cells seen on the way
562   */
563    qtClearAllFlags();          /* clear all quadtree branch flags */
564    f = 0;
565    VSUB(dir,t1,t0);
566    stTrace_edge(st,t0,dir,1.0,func,arg1,arg2);
567    VSUB(dir,t2,t1);
568    stTrace_edge(st,t1,dir,1.0,func,arg1,arg2);
569    VSUB(dir,t0,t2);
570    stTrace_edge(st,t2,dir,1.0,func,arg1,arg2);
571    /* Now visit interior */
572    stVisit_tri_interior(st,t0,t1,t2,func,arg1,arg2);
573 }
574
575
576
577
578
579 int
580 stUpdate_tri(st,t_id,t0,t1,t2,edge_func,interior_func)
581   STREE *st;
582   int t_id;
583   FVECT t0,t1,t2;
389     int (*edge_func)(),(*interior_func)();
390 +   int arg1,*arg2;
391   {
392      int f;
393      FVECT dir;
# Line 589 | Line 395 | stUpdate_tri(st,t_id,t0,t1,t2,edge_func,interior_func)
395    /* First add all of the leaf cells lying on the triangle perimeter:
396       mark all cells seen on the way
397     */
592    ST_CLEAR_FLAGS(st);
398      f = 0;
399      /* Visit cells along edges of the tri */
400  
401 <    stVisit_tri_edges2(st,t0,t1,t2,edge_func,&f,t_id);
401 >    stVisit_tri_edges(st,t0,t1,t2,edge_func,&f,arg1,arg2);
402  
403      /* Now visit interior */
404      if(QT_FLAG_FILL_TRI(f) || QT_FLAG_UPDATE(f))
405 <       stVisit_tri_interior(st,t0,t1,t2,interior_func,&f,t_id);
405 >       stVisit_tri_interior(st,t0,t1,t2,interior_func,&f,arg1,arg2);
406   }
407 +
408  
409  
410  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines