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] = |
448 |
|
|
449 |
|
total_points = n + SM_EXTRA_POINTS; |
450 |
|
|
451 |
< |
max_tris = total_points*4; |
451 |
> |
max_tris = total_points*2; |
452 |
|
/* Now allocate space for mesh vertices and triangles */ |
453 |
|
max_tris = smAlloc_mesh(smMesh, total_points, max_tris); |
454 |
|
|
699 |
|
SM_NTH_VERT(sm,v1_id) = t_id; |
700 |
|
SM_NTH_VERT(sm,v2_id) = t_id; |
701 |
|
|
703 |
– |
smClear_tri_flags(sm,t_id); |
702 |
|
if(SM_BASE_ID(sm,v0_id) || SM_BASE_ID(sm,v1_id) || SM_BASE_ID(sm,v2_id)) |
705 |
– |
{ |
703 |
|
SM_SET_NTH_T_BASE(sm,t_id); |
707 |
– |
} |
704 |
|
else |
705 |
< |
{ |
706 |
< |
S_SET_FLAG(T_NTH_V(t,0)); |
707 |
< |
S_SET_FLAG(T_NTH_V(t,1)); |
708 |
< |
S_SET_FLAG(T_NTH_V(t,2)); |
709 |
< |
} |
705 |
> |
if(SM_DIR_ID(sm,v0_id) && SM_DIR_ID(sm,v1_id) && SM_DIR_ID(sm,v2_id)) |
706 |
> |
SM_SET_NTH_T_BG(sm,t_id); |
707 |
> |
|
708 |
> |
S_SET_FLAG(T_NTH_V(t,0)); |
709 |
> |
S_SET_FLAG(T_NTH_V(t,1)); |
710 |
> |
S_SET_FLAG(T_NTH_V(t,2)); |
711 |
> |
|
712 |
|
SM_SET_NTH_T_ACTIVE(sm,t_id); |
713 |
+ |
SM_SET_NTH_T_NEW(sm,t_id); |
714 |
|
|
715 |
|
SM_SAMPLE_TRIS(sm)++; |
716 |
+ |
smNew_tri_cnt++; |
717 |
|
|
718 |
|
/* return initialized triangle */ |
719 |
|
return(t_id); |
844 |
|
error(CONSISTENCY,"Invalid tri: smTris_swap_edge()\n"); |
845 |
|
} |
846 |
|
|
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 |
– |
|
847 |
|
smUpdate_locator(sm,add_list) |
848 |
|
SM *sm; |
849 |
|
LIST *add_list; |
850 |
|
{ |
851 |
< |
int t_id,i; |
851 |
> |
int t_id; |
852 |
|
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 |
– |
} |
853 |
|
|
854 |
|
while(add_list) |
855 |
|
{ |
958 |
|
FVECT npt; |
959 |
|
TRI *tri,*nbr,*topp; |
960 |
|
|
984 |
– |
if(tri_id==18611 && s_id == 2243) |
985 |
– |
sleep(1); |
986 |
– |
if(s_id == 2649 && tri_id == 13302) |
987 |
– |
sleep(1); |
961 |
|
add_list = NULL; |
962 |
|
for(i=0; i<3;i++) |
963 |
|
v_id[i] = T_NTH_V(SM_NTH_TRI(sm,tri_id),i); |
1372 |
|
|
1373 |
|
VSUB(npt,SM_NTH_WV(sm,vid[i]),SM_VIEW_CENTER(sm)); |
1374 |
|
|
1375 |
< |
if(!SM_BASE_ID(sm,vid[i]) || !SM_DIR_ID(sm,vid[i])) |
1375 |
> |
if(!SM_BASE_ID(sm,vid[i]) && !SM_DIR_ID(sm,vid[i])) |
1376 |
|
normalize(npt); |
1377 |
|
|
1378 |
|
d = DIST_SQ(npt,spt); |
1462 |
|
return(FALSE); |
1463 |
|
} |
1464 |
|
|
1465 |
+ |
smReplace_base_samp(sm,b_id,s_id,tri,t_id,which) |
1466 |
+ |
SM *sm; |
1467 |
+ |
int b_id,s_id; |
1468 |
+ |
TRI *tri; |
1469 |
+ |
int t_id,which; |
1470 |
+ |
{ |
1471 |
+ |
TRI *t; |
1472 |
|
|
1473 |
+ |
SM_NTH_VERT(sm,s_id) = t_id; |
1474 |
+ |
T_NTH_V(tri,which) = s_id; |
1475 |
+ |
if(!(SM_BASE_ID(sm,T_NTH_V(tri,(which+1)%3)) || |
1476 |
+ |
SM_BASE_ID(sm,T_NTH_V(tri,(which+2)%3)))) |
1477 |
+ |
SM_CLR_NTH_T_BASE(sm,t_id); |
1478 |
+ |
if(!SM_IS_NTH_T_NEW(sm,t_id)) |
1479 |
+ |
{ |
1480 |
+ |
smNew_tri_cnt++; |
1481 |
+ |
SM_SET_NTH_T_NEW(sm,t_id); |
1482 |
+ |
} |
1483 |
+ |
t_id = smTri_next_ccw_nbr(sm,tri,b_id); |
1484 |
+ |
while(t_id != INVALID) |
1485 |
+ |
{ |
1486 |
+ |
t = SM_NTH_TRI(sm,t_id); |
1487 |
+ |
which = T_WHICH_V(t,b_id); |
1488 |
+ |
T_NTH_V(t,which) = s_id; |
1489 |
+ |
/* Check if still a base triangle */ |
1490 |
+ |
if(!(SM_BASE_ID(sm,T_NTH_V(t,(which+1)%3)) || |
1491 |
+ |
SM_BASE_ID(sm,T_NTH_V(t,(which+2)%3)))) |
1492 |
+ |
SM_CLR_NTH_T_BASE(sm,t_id); |
1493 |
+ |
if(!SM_IS_NTH_T_NEW(sm,t_id)) |
1494 |
+ |
{ |
1495 |
+ |
smNew_tri_cnt++; |
1496 |
+ |
SM_SET_NTH_T_NEW(sm,t_id); |
1497 |
+ |
} |
1498 |
+ |
t_id = smTri_next_ccw_nbr(sm,t,b_id); |
1499 |
+ |
} |
1500 |
+ |
} |
1501 |
+ |
|
1502 |
|
int |
1503 |
|
smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which) |
1504 |
|
SM *sm; |
1506 |
|
FVECT dir,p; |
1507 |
|
int s_id,t_id,o_id,on,which; |
1508 |
|
{ |
1509 |
< |
int tonemap,v_id,tri_id; |
1509 |
> |
int v_id,tri_id; |
1510 |
|
TRI *t,*tri; |
1511 |
|
|
1512 |
|
tri = SM_NTH_TRI(sm,t_id); |
1515 |
|
/* If it is a base id, need new sample */ |
1516 |
|
if(SM_BASE_ID(sm,v_id)) |
1517 |
|
{ |
1518 |
< |
tonemap = (SM_TONE_MAP(sm) > s_id); |
1519 |
< |
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 |
< |
} |
1518 |
> |
sInit_samp(SM_SAMP(sm),s_id,c,dir,p,o_id); |
1519 |
> |
smReplace_base_samp(sm,v_id,s_id,tri,t_id,which); |
1520 |
|
return(s_id); |
1521 |
|
} |
1522 |
|
if(dir) |
1527 |
|
return(INVALID); |
1528 |
|
if(on == ON_V) |
1529 |
|
{ |
1530 |
< |
tonemap = (SM_TONE_MAP(sm) > v_id); |
1531 |
< |
sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id,tonemap); |
1532 |
< |
add_new_tri(t_id); |
1530 |
> |
sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id); |
1531 |
> |
|
1532 |
> |
if(!SM_IS_NTH_T_NEW(sm,t_id)) |
1533 |
> |
{ |
1534 |
> |
smNew_tri_cnt++; |
1535 |
> |
SM_SET_NTH_T_NEW(sm,t_id); |
1536 |
> |
} |
1537 |
|
tri_id = smTri_next_ccw_nbr(sm,tri,v_id); |
1538 |
|
while(tri_id != t_id) |
1539 |
|
{ |
1540 |
|
t = SM_NTH_TRI(sm,tri_id); |
1541 |
< |
add_new_tri(tri_id); |
1541 |
> |
if(!SM_IS_NTH_T_NEW(sm,tri_id)) |
1542 |
> |
{ |
1543 |
> |
smNew_tri_cnt++; |
1544 |
> |
SM_SET_NTH_T_NEW(sm,tri_id); |
1545 |
> |
} |
1546 |
> |
|
1547 |
|
tri_id = smTri_next_ccw_nbr(sm,t,v_id); |
1548 |
|
} |
1549 |
|
return(v_id); |
1566 |
|
if(d2 < d) |
1567 |
|
{ |
1568 |
|
/* The new sample has better information- replace values */ |
1569 |
< |
tonemap = (SM_TONE_MAP(sm) > v_id); |
1570 |
< |
sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id,tonemap); |
1571 |
< |
add_new_tri(t_id); |
1569 |
> |
sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id); |
1570 |
> |
if(!SM_IS_NTH_T_NEW(sm,t_id)) |
1571 |
> |
{ |
1572 |
> |
smNew_tri_cnt++; |
1573 |
> |
SM_SET_NTH_T_NEW(sm,t_id); |
1574 |
> |
} |
1575 |
> |
|
1576 |
|
tri_id = smTri_next_ccw_nbr(sm,tri,v_id); |
1577 |
|
while(tri_id != t_id) |
1578 |
|
{ |
1579 |
|
t = SM_NTH_TRI(sm,tri_id); |
1580 |
< |
add_new_tri(tri_id); |
1580 |
> |
if(!SM_IS_NTH_T_NEW(sm,tri_id)) |
1581 |
> |
{ |
1582 |
> |
smNew_tri_cnt++; |
1583 |
> |
SM_SET_NTH_T_NEW(sm,tri_id); |
1584 |
> |
} |
1585 |
|
tri_id = smTri_next_ccw_nbr(sm,t,v_id); |
1586 |
|
} |
1587 |
|
} |
1647 |
|
|
1648 |
|
/* Must do this first-as may change mesh */ |
1649 |
|
s_id = smAlloc_samp(sm); |
1648 |
– |
if(s_id== 2649) |
1649 |
– |
r_id = INVALID; |
1650 |
|
/* If sample is a world space point */ |
1651 |
|
if(p) |
1652 |
|
{ |
1664 |
|
/* If spherical projection coincides with existing sample: replace */ |
1665 |
|
if((on == ON_V || on == ON_P)) |
1666 |
|
{ |
1667 |
< |
if((n_id = smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which))!= s_id) |
1668 |
< |
smUnalloc_samp(sm,s_id); |
1669 |
< |
return(n_id); |
1667 |
> |
n_id = smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which); |
1668 |
> |
if(n_id!= s_id) |
1669 |
> |
smUnalloc_samp(sm,s_id); |
1670 |
> |
return(n_id); |
1671 |
|
} |
1672 |
|
if((!(smTest_sample(sm,t_id,dir,p,&r_id)))) |
1673 |
|
{ |
1686 |
|
map individually |
1687 |
|
*/ |
1688 |
|
/* Initialize sample */ |
1689 |
< |
sInit_samp(SM_SAMP(sm),s_id,c,dir,p,o_id,(SM_TONE_MAP(sm)>s_id)); |
1689 |
> |
sInit_samp(SM_SAMP(sm),s_id,c,dir,p,o_id); |
1690 |
|
|
1691 |
|
} |
1692 |
|
/* If sample is a direction vector */ |
1694 |
|
{ |
1695 |
|
VADD(wpt,dir,SM_VIEW_CENTER(sm)); |
1696 |
|
while(1) |
1697 |
< |
{ if(s_id == 2299) |
1698 |
< |
t_id = INVALID; |
1699 |
< |
t_id = smPointLocateTri(sm,wpt,&on,&which); |
1700 |
< |
if(t_id == INVALID) |
1700 |
< |
{ |
1697 |
> |
{ |
1698 |
> |
t_id = smPointLocateTri(sm,wpt,&on,&which); |
1699 |
> |
if(t_id == INVALID) |
1700 |
> |
{ |
1701 |
|
#ifdef DEBUG |
1702 |
< |
eputs("smAddSamp(): unable to locate tri containing sample \n"); |
1702 |
> |
eputs("smAddSamp(): can'tlocate tri containing samp\n"); |
1703 |
|
#endif |
1704 |
< |
smUnalloc_samp(sm,s_id); |
1705 |
< |
return(INVALID); |
1704 |
> |
smUnalloc_samp(sm,s_id); |
1705 |
> |
return(INVALID); |
1706 |
> |
} |
1707 |
> |
if(on == ON_V || on == ON_P) |
1708 |
> |
{ |
1709 |
> |
n_id=smReplace_samp(sm,c,NULL,wpt,s_id,t_id,o_id,on,which); |
1710 |
> |
if(n_id !=s_id) |
1711 |
> |
smUnalloc_samp(sm,s_id); |
1712 |
> |
return(n_id); |
1713 |
> |
} |
1714 |
> |
if((!(smTest_sample(sm,t_id,NULL,wpt,&r_id)))) |
1715 |
> |
{ |
1716 |
> |
smUnalloc_samp(sm,s_id); |
1717 |
> |
return(INVALID); |
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 |
|
} |
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 |
– |
} |
1727 |
|
/* Allocate space for a sample and initialize */ |
1728 |
< |
sInit_samp(SM_SAMP(sm),s_id,c,NULL,wpt,o_id,(SM_TONE_MAP(sm)>s_id)); |
1728 |
> |
sInit_samp(SM_SAMP(sm),s_id,c,NULL,wpt,o_id); |
1729 |
|
} |
1730 |
|
if(!SM_DIR_ID(sm,s_id)) |
1731 |
|
{ |
1859 |
|
} |
1860 |
|
|
1861 |
|
|
1862 |
+ |
|
1863 |
|
int |
1864 |
|
smNext_valid_tri(sm,i) |
1865 |
|
SM *sm; |
1940 |
|
} |
1941 |
|
|
1942 |
|
} |
1942 |
– |
#if 0 |
1943 |
– |
smNew_tri_cnt = SM_SAMPLE_TRIS(sm); |
1944 |
– |
#endif |
1945 |
– |
|
1943 |
|
#ifdef DEBUG |
1944 |
|
fprintf(stderr,"smRebuild_mesh():done\n"); |
1945 |
|
#endif |
2280 |
|
continue; |
2281 |
|
SM_SET_NTH_T_ACTIVE(smMesh,t_id); |
2282 |
|
/* Set the Active bits of the Vertices */ |
2283 |
< |
if(!SM_IS_NTH_T_BASE(smMesh,t_id)) |
2284 |
< |
{ |
2285 |
< |
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 |
< |
} |
2283 |
> |
S_SET_FLAG(T_NTH_V(tri,0)); |
2284 |
> |
S_SET_FLAG(T_NTH_V(tri,1)); |
2285 |
> |
S_SET_FLAG(T_NTH_V(tri,2)); |
2286 |
|
} |
2287 |
|
} |
2288 |
|
|