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.12 by gwlarson, Tue Jan 5 16:52:37 1999 UTC vs.
Revision 3.14 by gwlarson, Fri Mar 5 16:33:17 1999 UTC

# Line 21 | Line 21 | double smDist_sum=0;
21   #define S_INC 1000
22   int smNew_tri_cnt=0;
23   int smNew_tri_size=0;
24 T_DEPTH *smNew_tris= NULL;
24  
25 < #define SM_MIN_SAMP_DIFF 1e-3   /* min edge length in radians */
25 > #define SM_MIN_SAMP_DIFF 1e-4/* min edge length in radians */
26  
27   /* Each edge extends .5536 radians - 31.72 degrees */
28   static FVECT icosa_verts[162] =
# Line 243 | Line 242 | smDir(sm,ps,id)
242      normalize(ps);
243   }
244  
246 smDir_in_cone(sm,ps,id)
247   SM *sm;
248   FVECT ps;
249   int id;
250 {
251    
252    VSUB(ps,SM_NTH_WV(sm,id),SM_VIEW_CENTER(sm));
253    normalize(ps);
254 }
255
245   smClear_flags(sm,which)
246   SM *sm;
247   int which;
# Line 449 | Line 438 | smAlloc(max_samples)
438  
439    total_points = n + SM_EXTRA_POINTS;
440  
441 <  max_tris = total_points*4;
441 >  max_tris = total_points*2;
442    /* Now allocate space for mesh vertices and triangles */
443    max_tris = smAlloc_mesh(smMesh, total_points, max_tris);
444  
# Line 492 | Line 481 | smInit(n)
481   {
482    int max_vertices;
483  
495
484    /* If n <=0, Just clear the existing structures */
485    if(n <= 0)
486    {
# Line 521 | Line 509 | smInit(n)
509   }
510  
511  
512 < smLocator_apply(sm,v0,v1,v2,func)
512 > smLocator_apply(sm,v0,v1,v2,func,n)
513     SM *sm;
514     FVECT v0,v1,v2;
515     FUNC func;
516 +   int n;
517   {
518    STREE *st;
519    FVECT tri[3];
# Line 534 | Line 523 | smLocator_apply(sm,v0,v1,v2,func)
523    VSUB(tri[0],v0,SM_VIEW_CENTER(sm));
524    VSUB(tri[1],v1,SM_VIEW_CENTER(sm));
525    VSUB(tri[2],v2,SM_VIEW_CENTER(sm));
526 <  stVisit(st,tri,func);
526 >  stVisit(st,tri,func,n);
527  
528   }
529  
541
542 /* NEW INSERTION!!! ******************************************************/
530   QUADTREE
531   insert_tri(argptr,root,qt,q0,q1,q2,t0,t1,t2,dt10,dt21,dt02,scale,
532                 s0,s1,s2,sq0,sq1,sq2,rev,f,n)
# Line 700 | Line 687 | int v0_id,v1_id,v2_id;
687      SM_NTH_VERT(sm,v1_id) = t_id;
688      SM_NTH_VERT(sm,v2_id) = t_id;
689  
703    smClear_tri_flags(sm,t_id);
690      if(SM_BASE_ID(sm,v0_id) || SM_BASE_ID(sm,v1_id) || SM_BASE_ID(sm,v2_id))
705    {
691        SM_SET_NTH_T_BASE(sm,t_id);
692 <    }
693 <    else
694 <      {
695 <        S_SET_FLAG(T_NTH_V(t,0));
696 <        S_SET_FLAG(T_NTH_V(t,1));
697 <        S_SET_FLAG(T_NTH_V(t,2));
698 <      }
692 >
693 >    if(SM_DIR_ID(sm,v0_id) || SM_DIR_ID(sm,v1_id) || SM_DIR_ID(sm,v2_id))
694 >      SM_SET_NTH_T_BG(sm,t_id);
695 >
696 >    S_SET_FLAG(T_NTH_V(t,0));
697 >    S_SET_FLAG(T_NTH_V(t,1));
698 >    S_SET_FLAG(T_NTH_V(t,2));
699 >
700      SM_SET_NTH_T_ACTIVE(sm,t_id);
701 +    SM_SET_NTH_T_NEW(sm,t_id);
702  
703      SM_SAMPLE_TRIS(sm)++;
704 +    smNew_tri_cnt++;
705  
706      /* return initialized triangle */
707      return(t_id);
# Line 844 | Line 832 | Ltri_error:
832      error(CONSISTENCY,"Invalid tri: smTris_swap_edge()\n");
833   }
834  
847 add_new_tri(id)
848 int id;
849 {
850  if(smNew_tri_cnt == smNew_tri_size)
851   {
852     smNew_tri_size += S_INC;
853     smNew_tris=(T_DEPTH *)realloc(smNew_tris,sizeof(T_DEPTH)*smNew_tri_size);
854     if(!smNew_tris)
855       error(SYSTEM,"Out of memory in add_new_tris()\n");
856   }
857  smNew_tris[smNew_tri_cnt++].tri = id;
858 }
859
835   smUpdate_locator(sm,add_list)
836   SM *sm;
837   LIST *add_list;
838   {
839 <  int t_id,i;
839 >  int t_id;
840    TRI *t;
866  OBJECT *optr;
867  LIST *list;
868
869  list = add_list;
870  while(list)
871  {
872    t_id = LIST_DATA(list);
873    add_new_tri(t_id);
874    list = LIST_NEXT(list);
875  }
841    
842    while(add_list)
843    {
# Line 914 | Line 879 | LIST *tlist,*add_list;
879          if(!T_IS_VALID(t_opp))
880            error(CONSISTENCY,"Invalid trismFix_tris()\n");
881   #endif
882 <        smDir_in_cone(sm,p0,T_NTH_V(t_opp,0));
883 <        smDir_in_cone(sm,p1,T_NTH_V(t_opp,1));
884 <        smDir_in_cone(sm,p2,T_NTH_V(t_opp,2));
882 >        smDir(sm,p0,T_NTH_V(t_opp,0));
883 >        smDir(sm,p1,T_NTH_V(t_opp,1));
884 >        smDir(sm,p2,T_NTH_V(t_opp,2));
885          if(point_in_cone(p,p0,p1,p2))
886          {
887              swapped = 1;
# Line 981 | Line 946 | smInsert_samp(sm,s_id,tri_id,on,which)
946      FVECT npt;
947      TRI *tri,*nbr,*topp;
948  
984    if(tri_id==18611 && s_id == 2243)
985      sleep(1);
986    if(s_id == 2649 && tri_id == 13302)
987      sleep(1);
949      add_list = NULL;
950      for(i=0; i<3;i++)
951        v_id[i] = T_NTH_V(SM_NTH_TRI(sm,tri_id),i);
# Line 1399 | Line 1360 | smTest_sample(sm,tri_id,dir,p,rptr)
1360          
1361        VSUB(npt,SM_NTH_WV(sm,vid[i]),SM_VIEW_CENTER(sm));
1362        
1363 <      if(!SM_BASE_ID(sm,vid[i]) || !SM_DIR_ID(sm,vid[i]))
1363 >      if(!SM_BASE_ID(sm,vid[i]) && !SM_DIR_ID(sm,vid[i]))
1364          normalize(npt);
1365  
1366        d = DIST_SQ(npt,spt);
# Line 1489 | Line 1450 | smTest_sample(sm,tri_id,dir,p,rptr)
1450      return(FALSE);
1451   }
1452  
1453 + smReplace_base_samp(sm,b_id,s_id,tri,t_id,which)
1454 + SM *sm;
1455 + int b_id,s_id;
1456 + TRI *tri;
1457 + int t_id,which;
1458 + {
1459 +  TRI *t;
1460  
1461 +  SM_NTH_VERT(sm,s_id) = t_id;
1462 +  T_NTH_V(tri,which) = s_id;
1463 +  if(!(SM_BASE_ID(sm,T_NTH_V(tri,(which+1)%3)) ||
1464 +       SM_BASE_ID(sm,T_NTH_V(tri,(which+2)%3))))
1465 +    SM_CLR_NTH_T_BASE(sm,t_id);
1466 +  if(!SM_IS_NTH_T_NEW(sm,t_id))
1467 +  {
1468 +    smNew_tri_cnt++;
1469 +    SM_SET_NTH_T_NEW(sm,t_id);
1470 +  }
1471 +  t_id = smTri_next_ccw_nbr(sm,tri,b_id);
1472 +  while(t_id != INVALID)
1473 +  {
1474 +    t = SM_NTH_TRI(sm,t_id);
1475 +    which = T_WHICH_V(t,b_id);
1476 +    T_NTH_V(t,which) = s_id;
1477 +    /* Check if still a base triangle */
1478 +    if(!(SM_BASE_ID(sm,T_NTH_V(t,(which+1)%3)) ||
1479 +         SM_BASE_ID(sm,T_NTH_V(t,(which+2)%3))))
1480 +      SM_CLR_NTH_T_BASE(sm,t_id);
1481 +     if(!SM_IS_NTH_T_NEW(sm,t_id))
1482 +        {
1483 +          smNew_tri_cnt++;
1484 +          SM_SET_NTH_T_NEW(sm,t_id);
1485 +        }
1486 +     t_id = smTri_next_ccw_nbr(sm,t,b_id);
1487 +    }
1488 + }
1489 +
1490   int
1491   smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which)
1492       SM *sm;
# Line 1497 | Line 1494 | smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which)
1494       FVECT dir,p;
1495       int s_id,t_id,o_id,on,which;
1496   {
1497 <  int tonemap,v_id,tri_id;
1497 >  int v_id,tri_id;
1498    TRI *t,*tri;
1499  
1500    tri = SM_NTH_TRI(sm,t_id);
# Line 1506 | Line 1503 | smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which)
1503    /* If it is a base id, need new sample */
1504    if(SM_BASE_ID(sm,v_id))
1505    {
1506 <    tonemap = (SM_TONE_MAP(sm) > s_id);
1507 <    sInit_samp(SM_SAMP(sm),s_id,c,dir,p,o_id,tonemap);
1511 <    SM_NTH_VERT(sm,s_id) = t_id;
1512 <    T_NTH_V(tri,which) = s_id;
1513 <    if(!(SM_BASE_ID(sm,T_NTH_V(tri,(which+1)%3)) ||
1514 <         SM_BASE_ID(sm,T_NTH_V(tri,(which+2)%3))))
1515 <    {
1516 <      SM_CLR_NTH_T_BASE(sm,t_id);
1517 <      
1518 <    }
1519 <    add_new_tri(t_id);
1520 <    t_id = smTri_next_ccw_nbr(sm,tri,v_id);
1521 <    while(t_id != INVALID)
1522 <    {
1523 <      t = SM_NTH_TRI(sm,t_id);
1524 <      which = T_WHICH_V(t,v_id);
1525 <      T_NTH_V(t,which) = s_id;
1526 <      /* Check if still a base triangle */
1527 <      if(!(SM_BASE_ID(sm,T_NTH_V(t,(which+1)%3)) ||
1528 <           SM_BASE_ID(sm,T_NTH_V(t,(which+2)%3))))
1529 <        {
1530 <          SM_CLR_NTH_T_BASE(sm,t_id);
1531 <        }
1532 <      add_new_tri(t_id);
1533 <      t_id = smTri_next_ccw_nbr(sm,t,v_id);
1534 <    }
1506 >    sInit_samp(SM_SAMP(sm),s_id,c,dir,p,o_id);
1507 >    smReplace_base_samp(sm,v_id,s_id,tri,t_id,which);
1508      return(s_id);
1509    }
1510    if(dir)
# Line 1542 | Line 1515 | smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which)
1515        return(INVALID);
1516      if(on == ON_V)
1517      {
1518 <      tonemap = (SM_TONE_MAP(sm) > v_id);
1519 <      sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id,tonemap);
1520 <      add_new_tri(t_id);
1518 >      sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id);
1519 >
1520 >     if(!SM_IS_NTH_T_NEW(sm,t_id))
1521 >        {
1522 >          smNew_tri_cnt++;
1523 >          SM_SET_NTH_T_NEW(sm,t_id);
1524 >        }
1525        tri_id = smTri_next_ccw_nbr(sm,tri,v_id);
1526        while(tri_id != t_id)
1527        {
1528          t = SM_NTH_TRI(sm,tri_id);
1529 <        add_new_tri(tri_id);
1529 >     if(!SM_IS_NTH_T_NEW(sm,tri_id))
1530 >        {
1531 >          smNew_tri_cnt++;
1532 >          SM_SET_NTH_T_NEW(sm,tri_id);
1533 >        }
1534 >
1535          tri_id = smTri_next_ccw_nbr(sm,t,v_id);
1536        }
1537        return(v_id);
# Line 1572 | Line 1554 | smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which)
1554       if(d2 < d)
1555         {
1556           /* The new sample has better information- replace values */
1557 <         tonemap = (SM_TONE_MAP(sm) > v_id);
1558 <         sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id,tonemap);
1559 <         add_new_tri(t_id);
1557 >         sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id);
1558 >         if(!SM_IS_NTH_T_NEW(sm,t_id))
1559 >            {
1560 >              smNew_tri_cnt++;
1561 >              SM_SET_NTH_T_NEW(sm,t_id);
1562 >            }
1563 >
1564           tri_id = smTri_next_ccw_nbr(sm,tri,v_id);
1565           while(tri_id != t_id)
1566             {
1567               t = SM_NTH_TRI(sm,tri_id);
1568 <             add_new_tri(tri_id);
1568 >             if(!SM_IS_NTH_T_NEW(sm,tri_id))
1569 >            {
1570 >              smNew_tri_cnt++;
1571 >              SM_SET_NTH_T_NEW(sm,tri_id);
1572 >            }
1573               tri_id = smTri_next_ccw_nbr(sm,t,v_id);
1574             }
1575         }
# Line 1645 | Line 1635 | smAdd_samp(sm,c,dir,p,o_id)
1635  
1636    /* Must do this first-as may change mesh */
1637    s_id = smAlloc_samp(sm);
1648 if(s_id== 2649)
1649        r_id = INVALID;
1638    /* If sample is a world space point */
1639    if(p)
1640    {
# Line 1664 | Line 1652 | smAdd_samp(sm,c,dir,p,o_id)
1652        /* If spherical projection coincides with existing sample: replace */
1653        if((on == ON_V || on == ON_P))
1654        {
1655 <        if((n_id = smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which))!= s_id)
1656 <          smUnalloc_samp(sm,s_id);
1657 <        return(n_id);
1655 >          n_id = smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which);
1656 >          if(n_id!= s_id)
1657 >             smUnalloc_samp(sm,s_id);
1658 >          return(n_id);
1659        }
1660        if((!(smTest_sample(sm,t_id,dir,p,&r_id))))
1661       {
# Line 1685 | Line 1674 | smAdd_samp(sm,c,dir,p,o_id)
1674         map individually
1675         */
1676      /* Initialize sample */
1677 <    sInit_samp(SM_SAMP(sm),s_id,c,dir,p,o_id,(SM_TONE_MAP(sm)>s_id));    
1677 >    sInit_samp(SM_SAMP(sm),s_id,c,dir,p,o_id);
1678      
1679    }
1680      /* If sample is a direction vector */
# Line 1693 | Line 1682 | smAdd_samp(sm,c,dir,p,o_id)
1682      {
1683        VADD(wpt,dir,SM_VIEW_CENTER(sm));
1684        while(1)
1685 <        { if(s_id == 2299)
1686 <          t_id = INVALID;
1687 <        t_id = smPointLocateTri(sm,wpt,&on,&which);
1688 <        if(t_id == INVALID)
1700 <        {
1685 >        {
1686 >            t_id = smPointLocateTri(sm,wpt,&on,&which);
1687 >            if(t_id == INVALID)
1688 >               {
1689   #ifdef DEBUG
1690 <          eputs("smAddSamp(): unable to locate tri containing sample \n");
1690 >                   eputs("smAddSamp(): can'tlocate tri containing samp\n");
1691   #endif
1692 <          smUnalloc_samp(sm,s_id);
1693 <          return(INVALID);
1692 >                   smUnalloc_samp(sm,s_id);
1693 >                   return(INVALID);
1694 >               }
1695 >            if(on == ON_V || on == ON_P)
1696 >            {
1697 >                n_id=smReplace_samp(sm,c,NULL,wpt,s_id,t_id,o_id,on,which);
1698 >                if(n_id !=s_id)
1699 >                   smUnalloc_samp(sm,s_id);
1700 >                return(n_id);
1701 >            }
1702 >            if((!(smTest_sample(sm,t_id,NULL,wpt,&r_id))))
1703 >            {
1704 >                smUnalloc_samp(sm,s_id);
1705 >                return(INVALID);
1706 >            }
1707 >            if(r_id != INVALID)
1708 >            {
1709 >                smRemoveVertex(sm,r_id);
1710 >                sDelete_samp(SM_SAMP(sm),r_id);
1711 >            }
1712 >            else
1713 >               break;
1714          }
1707        if(on == ON_V || on == ON_P)
1708        {
1709         if((n_id=smReplace_samp(sm,c,NULL,wpt,s_id,t_id,o_id,on,which))!=s_id)
1710           smUnalloc_samp(sm,s_id);
1711         return(n_id);
1712        }
1713      if((!(smTest_sample(sm,t_id,NULL,wpt,&r_id))))
1714      {
1715        smUnalloc_samp(sm,s_id);
1716        return(INVALID);
1717      }
1718
1719      if(r_id != INVALID)
1720      {
1721        smRemoveVertex(sm,r_id);
1722        sDelete_samp(SM_SAMP(sm),r_id);
1723      }
1724      else
1725        break;
1726      }
1715        /* Allocate space for a sample and initialize */
1716 <      sInit_samp(SM_SAMP(sm),s_id,c,NULL,wpt,o_id,(SM_TONE_MAP(sm)>s_id));
1716 >      sInit_samp(SM_SAMP(sm),s_id,c,NULL,wpt,o_id);
1717      }
1718    if(!SM_DIR_ID(sm,s_id))
1719      {
# Line 1832 | Line 1820 | int type;
1820  
1821   }
1822  
1835
1836 int
1837 smNext_tri_flag_set(sm,i,which,b)
1838     SM *sm;
1839     int i,which;
1840     int b;
1841 {
1842
1843  for(; i < SM_NUM_TRI(sm);i++)
1844  {
1845
1846    if(!T_IS_VALID(SM_NTH_TRI(sm,i)))
1847         continue;
1848    if(!SM_IS_NTH_T_FLAG(sm,i,which))
1849        continue;
1850    if(!b)
1851      break;
1852    if((b==1) && !SM_BG_TRI(sm,i))
1853      break;
1854    if((b==2) && SM_BG_TRI(sm,i))
1855      break;
1856  }
1857    
1858  return(i);
1859 }
1860
1861
1862 int
1863 smNext_valid_tri(sm,i)
1864     SM *sm;
1865     int i;
1866 {
1867
1868  while( i < SM_NUM_TRI(sm) && !T_IS_VALID(SM_NTH_TRI(sm,i)))
1869     i++;
1870    
1871  return(i);
1872 }
1873
1874
1875
1876 qtTri_from_id(t_id,v0,v1,v2)
1877 int t_id;
1878 FVECT v0,v1,v2;
1879 {
1880  TRI *t;
1881  
1882  t = SM_NTH_TRI(smMesh,t_id);
1883  if(!T_IS_VALID(t))
1884    return(0);
1885  VSUB(v0,SM_T_NTH_WV(smMesh,t,0),SM_VIEW_CENTER(smMesh));
1886  VSUB(v1,SM_T_NTH_WV(smMesh,t,1),SM_VIEW_CENTER(smMesh));
1887  VSUB(v2,SM_T_NTH_WV(smMesh,t,2),SM_VIEW_CENTER(smMesh));
1888  return(1);
1889 }
1890
1891
1823   smRebuild_mesh(sm,v)
1824     SM *sm;
1825     VIEW *v;
# Line 1900 | Line 1831 | smRebuild_mesh(sm,v)
1831   #ifdef DEBUG
1832      fprintf(stderr,"smRebuild_mesh(): rebuilding....");
1833   #endif
1834 +    smCull(sm,v,SM_ALL_LEVELS);
1835      /* Clear the mesh- and rebuild using the current sample array */
1836      /* Remember the current number of samples */
1837      cnt = SM_NUM_SAMP(sm);
# Line 1939 | Line 1871 | smRebuild_mesh(sm,v)
1871          }
1872  
1873      }
1942 #if 0
1943   smNew_tri_cnt = SM_SAMPLE_TRIS(sm);
1944 #endif
1945
1874   #ifdef DEBUG
1875      fprintf(stderr,"smRebuild_mesh():done\n");
1876   #endif
# Line 1965 | Line 1893 | intersect_tri_set(t_set,orig,dir,pt)
1893      {
1894          t_id = QT_SET_NEXT_ELEM(optr);
1895          t = SM_NTH_TRI(smMesh,t_id);
1896 <        if(!T_IS_VALID(t))
1896 >        if(!T_IS_VALID(t) || SM_IS_NTH_T_BASE(smMesh,t_id)||
1897 >               SM_IS_NTH_T_BG(smMesh,t_id))
1898            continue;
1899          pid0 = T_NTH_V(t,0);
1900          pid1 = T_NTH_V(t,1);
1901          pid2 = T_NTH_V(t,2);
1973        if(base = SM_IS_NTH_T_BASE(smMesh,t_id))
1974          if(SM_BASE_ID(smMesh,pid0) && SM_BASE_ID(smMesh,pid1) &&
1975             SM_BASE_ID(smMesh,pid2))
1976            continue;
1902          VCOPY(p0,SM_NTH_WV(smMesh,pid0));
1903          VCOPY(p1,SM_NTH_WV(smMesh,pid1));
1904          VCOPY(p2,SM_NTH_WV(smMesh,pid2));
1905          if(ray_intersect_tri(orig,dir,p0,p1,p2,p))
1906          {
1907 <          if(!base)
1908 <          {
1909 <            d =  DIST_SQ(p,p0);
1910 <            d1 = DIST_SQ(p,p1);
1911 <            if(d < d1)
1912 <              {
1913 <                d1 = DIST_SQ(p,p2);
1989 <                id = (d1 < d)?pid2:pid0;
1990 <              }
1991 <            else
1992 <              {
1993 <                d = DIST_SQ(p,p2);
1994 <                id = (d < d1)? pid2:pid1;
1995 <              }
1996 <          }
1907 >          d =  DIST_SQ(p,p0);
1908 >          d1 = DIST_SQ(p,p1);
1909 >          if(d < d1)
1910 >           {
1911 >             d1 = DIST_SQ(p,p2);
1912 >             id = (d1 < d)?pid2:pid0;
1913 >           }
1914            else
1915              {
1916 <              if(SM_BASE_ID(smMesh,pid0))
1917 <              {
2001 <                if(SM_BASE_ID(smMesh,pid1))
2002 <                  id = pid2;
2003 <                else
2004 <                  if(SM_BASE_ID(smMesh,pid2))
2005 <                    id = pid1;
2006 <                  else
2007 <                  {
2008 <                    d =  DIST_SQ(p,p1);
2009 <                    d1 = DIST_SQ(p,p2);
2010 <                    if(d < d1)
2011 <                      id = pid1;
2012 <                    else
2013 <                      id = pid2;
2014 <                  }
2015 <              }
2016 <              else
2017 <              {
2018 <                if(SM_BASE_ID(smMesh,pid1))
2019 <                {
2020 <                  if(SM_BASE_ID(smMesh,pid2))
2021 <                    id = pid0;
2022 <                  else
2023 <                  {
2024 <                    d =  DIST_SQ(p,p0);
2025 <                    d1 = DIST_SQ(p,p2);
2026 <                    if(d < d1)
2027 <                      id = pid0;
2028 <                    else
2029 <                      id = pid2;
2030 <                  }
2031 <                }
2032 <                else
2033 <                {
2034 <                  d =  DIST_SQ(p,p0);
2035 <                  d1 = DIST_SQ(p,p1);
2036 <                  if(d < d1)
2037 <                    id = pid0;
2038 <                  else
2039 <                    id = pid1;
2040 <                }
2041 <              }
1916 >              d = DIST_SQ(p,p2);
1917 >              id = (d < d1)? pid2:pid1;
1918              }
1919            if(pt)
1920              VCOPY(pt,p);
# Line 2175 | Line 2051 | FVECT orig,dir;
2051   #ifdef DEBUG_TEST_DRIVER
2052      VCOPY(Pick_point[0],p);
2053   #endif
2178 #ifdef DEBUG
2179    fprintf(stderr,"Simple pick returning %d\n",s_id);
2180 #endif
2181
2054      return(s_id);
2055    }
2056    d = point_on_sphere(b,orig,SM_VIEW_CENTER(smMesh));
# Line 2192 | Line 2064 | FVECT orig,dir;
2064   #ifdef DEBUG_TEST_DRIVER
2065          VCOPY(Pick_point[0],p);
2066   #endif
2195 #ifdef DEBUG
2196    fprintf(stderr,"Simple pick2 returning %d\n",s_id);
2197 #endif
2067          return(s_id);
2068    }
2069    if(OPP_EQUAL_VEC3(b,dir))
# Line 2244 | Line 2113 | FVECT orig,dir;
2113      F_ARGS(func) = (int *)(&rt);
2114      stTrace_ray(SM_LOCATOR(smMesh),o,dir,func);
2115      s_id = rt.t_id;
2116 +
2117    }    
2248 #ifdef DEBUG
2249    fprintf(stderr,"Trace pick returning %d\n",s_id);
2250 #endif
2118    return(s_id);
2119  
2120   Lerror:
# Line 2258 | Line 2125 | Lerror:
2125  
2126   }
2127  
2128 + null_func(argptr,root,qt,n)
2129 +     int *argptr;
2130 +     int root;
2131 +     QUADTREE qt;
2132 +     int n;
2133 + {
2134 +  /* do nothing */
2135 + }
2136  
2137 < mark_active_tris(argptr,root,qt)
2137 > mark_active_tris(argptr,root,qt,n)
2138       int *argptr;
2139       int root;
2140       QUADTREE qt;
2141 +     int n;
2142   {
2143    OBJECT *os,*optr;
2144    register int i,t_id;
# Line 2283 | Line 2159 | mark_active_tris(argptr,root,qt)
2159              continue;
2160       SM_SET_NTH_T_ACTIVE(smMesh,t_id);
2161       /* Set the Active bits of the Vertices */
2162 <     if(!SM_IS_NTH_T_BASE(smMesh,t_id))
2163 <     {
2164 <       S_SET_FLAG(T_NTH_V(tri,0));
2289 <       S_SET_FLAG(T_NTH_V(tri,1));
2290 <       S_SET_FLAG(T_NTH_V(tri,2));
2291 <     }
2162 >     S_SET_FLAG(T_NTH_V(tri,0));
2163 >     S_SET_FLAG(T_NTH_V(tri,1));
2164 >     S_SET_FLAG(T_NTH_V(tri,2));
2165    }
2166   }
2167  
2168  
2169 < mark_tris_in_frustum(view)
2169 > smCull(sm,view,n)
2170 > SM *sm;
2171   VIEW *view;
2172 + int n;
2173   {
2174       FVECT nr[4],far[4];
2175       FPEQ peq;
2176       int debug=0;
2177       FUNC f;
2178  
2179 <     F_FUNC(f) = mark_active_tris;
2180 <     F_ARGS(f) = NULL;
2179 >     /* First clear all the quadtree node flags */
2180 >     qtClearAllFlags();
2181  
2182 +     F_ARGS(f) = NULL;
2183 +     /* If marking samples down to leaves */
2184 +     if(n == SM_ALL_LEVELS)
2185 +     {
2186       /* Mark triangles in approx. view frustum as being active:set
2187          LRU counter: for use in discarding samples when out
2188          of space
2189 +        */
2190 +       F_FUNC(f) = mark_active_tris;
2191 +       smClear_flags(sm,T_ACTIVE_FLAG);
2192 +       /* Clear all of the active sample flags*/
2193 +       sClear_all_flags(SM_SAMP(sm));
2194 +     }
2195 +     else
2196 +       /* Just mark qtree flags */
2197 +       F_FUNC(f) = null_func;
2198 +
2199 +     /* calculate the world space coordinates of the view frustum:
2200          Radiance often has no far clipping plane: but driver will set
2201          dev_zmin,dev_zmax to satisfy OGL
2202 <     */
2313 <
2314 <     /* First clear all the quadtree node and triangle active flags */
2315 <     qtClearAllFlags();
2316 <     smClear_flags(smMesh,T_ACTIVE_FLAG);
2317 <     /* Clear all of the active sample flags*/
2318 <     sClear_all_flags(SM_SAMP(smMesh));
2319 <
2320 <
2321 <     /* calculate the world space coordinates of the view frustum */
2202 >    */
2203       calculate_view_frustum(view->vp,view->hvec,view->vvec,view->horiz,
2204                              view->vert, dev_zmin,dev_zmax,nr,far);
2205  
# Line 2339 | Line 2220 | mark_tris_in_frustum(view)
2220          Also set the triangles LRU clock counter
2221          */
2222  
2223 <     if(EQUAL_VEC3(view->vp,SM_VIEW_CENTER(smMesh)))
2223 >     if(EQUAL_VEC3(view->vp,SM_VIEW_CENTER(sm)))
2224       {/* Near face triangles */
2225  
2226 <       smLocator_apply(smMesh,nr[0],nr[2],nr[3],f);
2227 <       smLocator_apply(smMesh,nr[2],nr[0],nr[1],f);
2226 >       smLocator_apply(sm,nr[0],nr[2],nr[3],f,n);
2227 >       smLocator_apply(sm,nr[2],nr[0],nr[1],f,n);
2228         return;
2229       }
2230       /* Test the view against the planes: and swap orientation if inside:*/
2231       tri_plane_equation(nr[0],nr[2],nr[3], &peq,FALSE);
2232 <     if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
2232 >     if(PT_ON_PLANE(SM_VIEW_CENTER(sm),peq) < 0.0)
2233       {/* Near face triangles */
2234 <       smLocator_apply(smMesh,nr[3],nr[2],nr[0],f);
2235 <       smLocator_apply(smMesh,nr[1],nr[0],nr[2],f);
2234 >       smLocator_apply(sm,nr[3],nr[2],nr[0],f,n);
2235 >       smLocator_apply(sm,nr[1],nr[0],nr[2],f,n);
2236       }
2237       else
2238       {/* Near face triangles */
2239 <       smLocator_apply(smMesh,nr[0],nr[2],nr[3],f);
2240 <       smLocator_apply(smMesh,nr[2],nr[0],nr[1],f);
2239 >       smLocator_apply(sm,nr[0],nr[2],nr[3],f,n);
2240 >       smLocator_apply(sm,nr[2],nr[0],nr[1],f,n);
2241       }
2242       tri_plane_equation(nr[0],far[3],far[0], &peq,FALSE);
2243 <     if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
2243 >     if(PT_ON_PLANE(SM_VIEW_CENTER(sm),peq) < 0.0)
2244       { /* Right face triangles */
2245 <       smLocator_apply(smMesh,far[0],far[3],nr[0],f);
2246 <       smLocator_apply(smMesh,nr[3],nr[0],far[3],f);
2245 >       smLocator_apply(sm,far[0],far[3],nr[0],f,n);
2246 >       smLocator_apply(sm,nr[3],nr[0],far[3],f,n);
2247       }
2248       else
2249       {/* Right face triangles */
2250 <       smLocator_apply(smMesh,nr[0],far[3],far[0],f);
2251 <       smLocator_apply(smMesh,far[3],nr[0],nr[3],f);
2250 >       smLocator_apply(sm,nr[0],far[3],far[0],f,n);
2251 >       smLocator_apply(sm,far[3],nr[0],nr[3],f,n);
2252       }
2253  
2254       tri_plane_equation(nr[1],far[2],nr[2], &peq,FALSE);
2255       if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
2256       { /* Left face triangles */
2257 <       smLocator_apply(smMesh,nr[2],far[2],nr[1],f);
2258 <       smLocator_apply(smMesh,far[1],nr[1],far[2],f);
2257 >       smLocator_apply(sm,nr[2],far[2],nr[1],f,n);
2258 >       smLocator_apply(sm,far[1],nr[1],far[2],f,n);
2259       }
2260       else
2261       { /* Left face triangles */
2262 <       smLocator_apply(smMesh,nr[1],far[2],nr[2],f);
2263 <       smLocator_apply(smMesh,far[2],nr[1],far[1],f);
2262 >       smLocator_apply(sm,nr[1],far[2],nr[2],f,n);
2263 >       smLocator_apply(sm,far[2],nr[1],far[1],f,n);
2264       }
2265       tri_plane_equation(nr[0],far[0],nr[1], &peq,FALSE);
2266 <     if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
2266 >     if(PT_ON_PLANE(SM_VIEW_CENTER(sm),peq) < 0.0)
2267       {/* Top face triangles */
2268 <       smLocator_apply(smMesh,nr[1],far[0],nr[0],f);
2269 <       smLocator_apply(smMesh,far[1],far[0],nr[1],f);
2268 >       smLocator_apply(sm,nr[1],far[0],nr[0],f,n);
2269 >       smLocator_apply(sm,far[1],far[0],nr[1],f,n);
2270       }
2271       else
2272       {/* Top face triangles */
2273 <       smLocator_apply(smMesh,nr[0],far[0],nr[1],f);
2274 <       smLocator_apply(smMesh,nr[1],far[0],far[1],f);
2273 >       smLocator_apply(sm,nr[0],far[0],nr[1],f,n);
2274 >       smLocator_apply(sm,nr[1],far[0],far[1],f,n);
2275       }
2276       tri_plane_equation(nr[3],nr[2],far[3], &peq,FALSE);
2277 <     if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
2277 >     if(PT_ON_PLANE(SM_VIEW_CENTER(sm),peq) < 0.0)
2278       {/* Bottom face triangles */
2279 <       smLocator_apply(smMesh,far[3],nr[2],nr[3],f);
2280 <       smLocator_apply(smMesh,far[3],far[2],nr[2],f);
2279 >       smLocator_apply(sm,far[3],nr[2],nr[3],f,n);
2280 >       smLocator_apply(sm,far[3],far[2],nr[2],f,n);
2281       }
2282       else
2283       { /* Bottom face triangles */
2284 <       smLocator_apply(smMesh,nr[3],nr[2],far[3],f);
2285 <       smLocator_apply(smMesh,nr[2],far[2],far[3],f);
2284 >       smLocator_apply(sm,nr[3],nr[2],far[3],f,n);
2285 >       smLocator_apply(sm,nr[2],far[2],far[3],f,n);
2286       }
2287        tri_plane_equation(far[2],far[0],far[1], &peq,FALSE);
2288 <     if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
2288 >     if(PT_ON_PLANE(SM_VIEW_CENTER(sm),peq) < 0.0)
2289       {/* Far face triangles */
2290 <       smLocator_apply(smMesh,far[0],far[2],far[1],f);
2291 <       smLocator_apply(smMesh,far[2],far[0],far[3],f);
2290 >       smLocator_apply(sm,far[0],far[2],far[1],f,n);
2291 >       smLocator_apply(sm,far[2],far[0],far[3],f,n);
2292       }
2293       else
2294       {/* Far face triangles */
2295 <       smLocator_apply(smMesh,far[1],far[2],far[0],f);
2296 <       smLocator_apply(smMesh,far[3],far[0],far[2],f);
2295 >       smLocator_apply(sm,far[1],far[2],far[0],f,n);
2296 >       smLocator_apply(sm,far[3],far[0],far[2],f,n);
2297       }
2298  
2299   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines