18 |
|
|
19 |
|
SM *smMesh = NULL; |
20 |
|
double smDist_sum=0; |
21 |
+ |
#define S_INC 1000 |
22 |
|
int smNew_tri_cnt=0; |
23 |
< |
double smMinSampDiff = 4.25e-4; /* min edge length in radians */ |
23 |
> |
int smNew_tri_size=0; |
24 |
> |
T_DEPTH *smNew_tris= NULL; |
25 |
|
|
26 |
+ |
#define SM_MIN_SAMP_DIFF 1e-3 /* min edge length in radians */ |
27 |
+ |
|
28 |
|
/* Each edge extends .5536 radians - 31.72 degrees */ |
29 |
|
static FVECT icosa_verts[162] = |
30 |
|
{{-0.018096,0.495400,0.868477},{0.018614,-0.554780,0.831789}, |
700 |
|
SM_NTH_VERT(sm,v1_id) = t_id; |
701 |
|
SM_NTH_VERT(sm,v2_id) = t_id; |
702 |
|
|
703 |
+ |
smClear_tri_flags(sm,t_id); |
704 |
|
if(SM_BASE_ID(sm,v0_id) || SM_BASE_ID(sm,v1_id) || SM_BASE_ID(sm,v2_id)) |
705 |
|
{ |
701 |
– |
smClear_tri_flags(sm,t_id); |
706 |
|
SM_SET_NTH_T_BASE(sm,t_id); |
707 |
|
} |
708 |
|
else |
709 |
< |
{ |
710 |
< |
SM_CLR_NTH_T_BASE(sm,t_id); |
711 |
< |
SM_SET_NTH_T_ACTIVE(sm,t_id); |
712 |
< |
SM_SET_NTH_T_NEW(sm,t_id); |
713 |
< |
S_SET_FLAG(T_NTH_V(t,0)); |
714 |
< |
S_SET_FLAG(T_NTH_V(t,1)); |
711 |
< |
S_SET_FLAG(T_NTH_V(t,2)); |
712 |
< |
SM_SAMPLE_TRIS(sm)++; |
713 |
< |
smNew_tri_cnt++; |
714 |
< |
} |
709 |
> |
{ |
710 |
> |
S_SET_FLAG(T_NTH_V(t,0)); |
711 |
> |
S_SET_FLAG(T_NTH_V(t,1)); |
712 |
> |
S_SET_FLAG(T_NTH_V(t,2)); |
713 |
> |
} |
714 |
> |
SM_SET_NTH_T_ACTIVE(sm,t_id); |
715 |
|
|
716 |
+ |
SM_SAMPLE_TRIS(sm)++; |
717 |
+ |
|
718 |
|
/* return initialized triangle */ |
719 |
|
return(t_id); |
720 |
|
} |
815 |
|
|
816 |
|
remove_from_list(t_id,add_ptr); |
817 |
|
remove_from_list(t1_id,add_ptr); |
818 |
< |
#if 1 |
818 |
> |
|
819 |
|
smDelete_tri(sm,t_id); |
820 |
|
smDelete_tri(sm,t1_id); |
819 |
– |
#else |
820 |
– |
*del_ptr = push_data(*del_ptr,t_id); |
821 |
– |
*del_ptr = push_data(*del_ptr,t1_id); |
822 |
– |
#endif |
821 |
|
|
824 |
– |
|
825 |
– |
|
822 |
|
*tn_id = ta_id; |
823 |
|
*tn1_id = tb_id; |
824 |
|
|
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 |
+ |
|
860 |
|
smUpdate_locator(sm,add_list) |
861 |
|
SM *sm; |
862 |
|
LIST *add_list; |
864 |
|
int t_id,i; |
865 |
|
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 |
+ |
} |
876 |
|
|
877 |
|
while(add_list) |
878 |
|
{ |
892 |
|
FVECT p,p0,p1,p2; |
893 |
|
int e,e1,swapped = 0; |
894 |
|
int t_id,t_opp_id; |
895 |
< |
LIST *del_list=NULL; |
895 |
> |
LIST *del_list=NULL,*lptr; |
896 |
|
|
897 |
|
VSUB(p,SM_NTH_WV(sm,id),SM_VIEW_CENTER(sm)); |
898 |
|
while(tlist) |
929 |
|
tlist = push_data(tlist,t_opp_id); |
930 |
|
} |
931 |
|
} |
932 |
< |
#if 0 |
915 |
< |
while(del_list) |
916 |
< |
{ |
917 |
< |
t_id = pop_list(&del_list); |
918 |
< |
smDelete_tri(sm,t_id); |
919 |
< |
} |
920 |
< |
#endif |
932 |
> |
|
933 |
|
smUpdate_locator(sm,add_list); |
934 |
|
|
935 |
|
return(swapped); |
981 |
|
FVECT npt; |
982 |
|
TRI *tri,*nbr,*topp; |
983 |
|
|
984 |
< |
|
984 |
> |
if(tri_id==18611 && s_id == 2243) |
985 |
> |
sleep(1); |
986 |
> |
if(s_id == 2649 && tri_id == 13302) |
987 |
> |
sleep(1); |
988 |
|
add_list = NULL; |
989 |
|
for(i=0; i<3;i++) |
990 |
|
v_id[i] = T_NTH_V(SM_NTH_TRI(sm,tri_id),i); |
1243 |
|
optr = qtqueryset(qt); |
1244 |
|
tri_id = smTri_in_set(sm,tpt,optr,onptr,whichptr); |
1245 |
|
|
1231 |
– |
#ifdef DEBUG |
1232 |
– |
if(!T_IS_VALID(SM_NTH_TRI(sm,T_NTH_NBR(SM_NTH_TRI(sm,tri_id),0))) || |
1233 |
– |
!T_IS_VALID(SM_NTH_TRI(sm,T_NTH_NBR(SM_NTH_TRI(sm,tri_id),1))) || |
1234 |
– |
!T_IS_VALID(SM_NTH_TRI(sm,T_NTH_NBR(SM_NTH_TRI(sm,tri_id),2)))) |
1235 |
– |
eputs("Invalid tri nbrs smPointLocateTri()\n"); |
1236 |
– |
#endif |
1246 |
|
return(tri_id); |
1247 |
|
} |
1248 |
|
|
1296 |
|
|
1297 |
|
for(i=0; i<3; i++) |
1298 |
|
{ |
1299 |
< |
if(SM_BASE_ID(sm,vid[i])) |
1300 |
< |
{ |
1301 |
< |
bcnt++; |
1302 |
< |
continue; |
1303 |
< |
} |
1295 |
< |
if(SM_DIR_ID(sm,vid[i])) |
1296 |
< |
dcnt++; |
1297 |
< |
VSUB(diff[i],SM_NTH_WV(sm,vid[i]),p); |
1298 |
< |
/* If same world point: replace */ |
1299 |
> |
if(SM_BASE_ID(sm,vid[i])) |
1300 |
> |
bcnt++; |
1301 |
> |
if(SM_DIR_ID(sm,vid[i])) |
1302 |
> |
dcnt++; |
1303 |
> |
|
1304 |
|
} |
1305 |
|
/* TEST 1: If the new sample is close in ws, and close in the spherical |
1306 |
|
projection to one of the triangle vertex samples |
1307 |
|
*/ |
1308 |
+ |
#if 0 |
1309 |
|
norm = FALSE; |
1304 |
– |
if(bcnt + dcnt != 3) |
1305 |
– |
{ |
1310 |
|
VSUB(spt,p,SM_VIEW_CENTER(sm)); |
1311 |
|
ds = DOT(spt,spt); |
1312 |
|
dnear = FHUGE; |
1313 |
|
for(i=0; i<3; i++) |
1314 |
|
{ |
1311 |
– |
if(SM_BASE_ID(sm,vid[i]) || SM_DIR_ID(sm,vid[i])) |
1312 |
– |
continue; |
1315 |
|
d = DOT(diff[i],diff[i])/ds; |
1316 |
|
if(d < dnear) |
1317 |
|
{ |
1320 |
|
} |
1321 |
|
} |
1322 |
|
|
1323 |
< |
if(dnear <= smMinSampDiff*smMinSampDiff) |
1323 |
> |
if(dnear <= SM_MIN_SAMP_DIFF*SM_MIN_SAMP_DIFF) |
1324 |
|
{ |
1325 |
|
/* Pick the point with dir closest to that of the canonical view |
1326 |
|
if it is the new sample: mark existing point for deletion |
1327 |
|
*/ |
1328 |
+ |
if(SM_BASE_ID(sm,nearid)) |
1329 |
+ |
{ |
1330 |
+ |
*rptr = nearid; |
1331 |
+ |
return(TRUE); |
1332 |
+ |
} |
1333 |
+ |
if(SM_DIR_ID(sm,nearid)) |
1334 |
+ |
return(FALSE); |
1335 |
+ |
if(!dir) |
1336 |
+ |
{ |
1337 |
+ |
*rptr = nearid; |
1338 |
+ |
return(TRUE); |
1339 |
+ |
} |
1340 |
|
normalize(spt); |
1341 |
|
norm = TRUE; |
1342 |
|
VSUB(npt,SM_NTH_WV(sm,nearid),SM_VIEW_CENTER(sm)); |
1344 |
|
d = fdir2diff(SM_NTH_W_DIR(sm,nearid), npt); |
1345 |
|
d2 = 2. - 2.*DOT(dir,spt); |
1346 |
|
/* The existing sample is a better sample:punt */ |
1347 |
< |
if(d2 > d) |
1347 |
> |
if(d2 > d) |
1348 |
|
return(FALSE); |
1349 |
< |
else |
1350 |
< |
{ |
1351 |
< |
/* The new sample is better: mark the existing one |
1349 |
> |
else |
1350 |
> |
{ |
1351 |
> |
/* The new sample is better: mark the existing one |
1352 |
|
for deletion after the new one is added*/ |
1353 |
< |
*rptr = nearid; |
1354 |
< |
return(TRUE); |
1341 |
< |
} |
1353 |
> |
*rptr = nearid; |
1354 |
> |
return(TRUE); |
1355 |
|
} |
1356 |
< |
} |
1356 |
> |
} |
1357 |
> |
|
1358 |
|
/* TEST 3: If the spherical projection of new is < S_REPLACE_EPS |
1359 |
|
from a base point: Edge length is constrained to subtend <45 degrees: |
1360 |
|
original base mesh edges are approx 32 degrees- so have about 13 degrees |
1361 |
|
to work in: S_REPLACE_EPS is the square of the radian value |
1362 |
|
*/ |
1363 |
+ |
|
1364 |
|
if(bcnt) |
1365 |
|
{ |
1366 |
|
dnear = FHUGE; |
1352 |
– |
if(bcnt + dcnt ==3) |
1353 |
– |
VSUB(spt,p,SM_VIEW_CENTER(sm)); |
1367 |
|
if(!norm) |
1368 |
|
normalize(spt); |
1369 |
|
|
1373 |
|
continue; |
1374 |
|
VSUB(npt,SM_NTH_WV(sm,vid[i]),SM_VIEW_CENTER(sm)); |
1375 |
|
d = DIST_SQ(npt,spt); |
1376 |
< |
if(d < S_REPLACE_EPS && d < dnear) |
1376 |
> |
if(dnear <= SM_MIN_SAMP_DIFF*SM_MIN_SAMP_DIFF && d< near) |
1377 |
|
{ |
1378 |
|
dnear = d; |
1379 |
|
nearid = vid[i]; |
1386 |
|
return(TRUE); |
1387 |
|
} |
1388 |
|
} |
1389 |
+ |
#else |
1390 |
+ |
{ |
1391 |
+ |
FVECT nearpt; |
1392 |
+ |
dnear = FHUGE; |
1393 |
+ |
VSUB(spt,p,SM_VIEW_CENTER(sm)); |
1394 |
+ |
ds = DOT(spt,spt); |
1395 |
+ |
normalize(spt); |
1396 |
+ |
|
1397 |
+ |
for(i=0; i<3; i++) |
1398 |
+ |
{ |
1399 |
|
|
1400 |
+ |
VSUB(npt,SM_NTH_WV(sm,vid[i]),SM_VIEW_CENTER(sm)); |
1401 |
+ |
|
1402 |
+ |
if(!SM_BASE_ID(sm,vid[i]) || !SM_DIR_ID(sm,vid[i])) |
1403 |
+ |
normalize(npt); |
1404 |
+ |
|
1405 |
+ |
d = DIST_SQ(npt,spt); |
1406 |
+ |
if(d < SM_MIN_SAMP_DIFF*SM_MIN_SAMP_DIFF && d < dnear) |
1407 |
+ |
{ |
1408 |
+ |
dnear = d; |
1409 |
+ |
nearid = vid[i]; |
1410 |
+ |
VCOPY(nearpt,npt); |
1411 |
+ |
} |
1412 |
+ |
|
1413 |
+ |
} |
1414 |
+ |
if(dnear != FHUGE) |
1415 |
+ |
{ |
1416 |
+ |
/* Pick the point with dir closest to that of the canonical view |
1417 |
+ |
if it is the new sample: mark existing point for deletion |
1418 |
+ |
*/ |
1419 |
+ |
if(SM_BASE_ID(sm,nearid)) |
1420 |
+ |
{ |
1421 |
+ |
*rptr = nearid; |
1422 |
+ |
return(TRUE); |
1423 |
+ |
} |
1424 |
+ |
if(SM_DIR_ID(sm,nearid)) |
1425 |
+ |
return(FALSE); |
1426 |
+ |
if(!dir) |
1427 |
+ |
{ |
1428 |
+ |
*rptr = nearid; |
1429 |
+ |
return(TRUE); |
1430 |
+ |
} |
1431 |
+ |
d = fdir2diff(SM_NTH_W_DIR(sm,nearid), nearpt); |
1432 |
+ |
d2 = 2. - 2.*DOT(dir,spt); |
1433 |
+ |
/* The existing sample is a better sample:punt */ |
1434 |
+ |
if(d2 > d) |
1435 |
+ |
return(FALSE); |
1436 |
+ |
else |
1437 |
+ |
{ |
1438 |
+ |
/* The new sample is better: mark the existing one |
1439 |
+ |
for deletion after the new one is added*/ |
1440 |
+ |
*rptr = nearid; |
1441 |
+ |
return(TRUE); |
1442 |
+ |
} |
1443 |
+ |
} |
1444 |
+ |
} |
1445 |
+ |
#endif |
1446 |
|
/* TEST 4: |
1447 |
|
If the addition of the new sample point would introduce a "puncture" |
1448 |
|
or cause new triangles with large depth differences:dont add: |
1449 |
|
*/ |
1450 |
|
if(bcnt || dcnt) |
1451 |
|
return(TRUE); |
1452 |
+ |
|
1453 |
|
/* If the new point is in front of the existing points- add */ |
1454 |
|
dv = DIST_SQ(SM_NTH_WV(sm,vid[0]),SM_VIEW_CENTER(sm)); |
1455 |
|
if(ds < dv) |
1456 |
|
return(TRUE); |
1457 |
|
|
1458 |
|
d01 = DIST_SQ(SM_NTH_WV(sm,vid[1]),SM_NTH_WV(sm,vid[0])); |
1459 |
+ |
VSUB(diff[0],SM_NTH_WV(sm,vid[0]),p); |
1460 |
|
s0 = DOT(diff[0],diff[0]); |
1461 |
|
if(s0 < S_REPLACE_SCALE*d01) |
1462 |
|
return(TRUE); |
1463 |
+ |
|
1464 |
|
d12 = DIST_SQ(SM_NTH_WV(sm,vid[2]),SM_NTH_WV(sm,vid[1])); |
1465 |
|
if(s0 < S_REPLACE_SCALE*d12) |
1466 |
|
return(TRUE); |
1468 |
|
if(s0 < S_REPLACE_SCALE*d20) |
1469 |
|
return(TRUE); |
1470 |
|
d = MIN3(d01,d12,d20); |
1471 |
< |
s1 = DOT(diff[1],diff[1]); |
1471 |
> |
VSUB(diff[1],SM_NTH_WV(sm,vid[1]),p); |
1472 |
> |
s1 = DOT(diff[1],diff[1]); |
1473 |
|
if(s1 < S_REPLACE_SCALE*d) |
1474 |
|
return(TRUE); |
1475 |
+ |
VSUB(diff[2],SM_NTH_WV(sm,vid[2]),p); |
1476 |
|
s2 = DOT(diff[2],diff[2]); |
1477 |
|
if(s2 < S_REPLACE_SCALE*d) |
1478 |
|
return(TRUE); |
1491 |
|
|
1492 |
|
|
1493 |
|
int |
1420 |
– |
smAlloc_samp(sm) |
1421 |
– |
SM *sm; |
1422 |
– |
{ |
1423 |
– |
int s_id,replaced,cnt; |
1424 |
– |
SAMP *s; |
1425 |
– |
FVECT p; |
1426 |
– |
|
1427 |
– |
s = SM_SAMP(sm); |
1428 |
– |
s_id = sAlloc_samp(s,&replaced); |
1429 |
– |
|
1430 |
– |
cnt=0; |
1431 |
– |
while(replaced) |
1432 |
– |
{ |
1433 |
– |
if(smRemoveVertex(sm,s_id)) |
1434 |
– |
break; |
1435 |
– |
s_id = sAlloc_samp(s,&replaced); |
1436 |
– |
cnt++; |
1437 |
– |
if(cnt > S_MAX_SAMP(s)) |
1438 |
– |
error(CONSISTENCY,"smAlloc_samp():unable to find free samp\n"); |
1439 |
– |
} |
1440 |
– |
return(s_id); |
1441 |
– |
} |
1442 |
– |
|
1443 |
– |
int |
1494 |
|
smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which) |
1495 |
|
SM *sm; |
1496 |
|
COLR c; |
1497 |
|
FVECT dir,p; |
1498 |
|
int s_id,t_id,o_id,on,which; |
1499 |
|
{ |
1500 |
< |
int tonemap,v_id; |
1500 |
> |
int tonemap,v_id,tri_id; |
1501 |
|
TRI *t,*tri; |
1502 |
|
|
1503 |
|
tri = SM_NTH_TRI(sm,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 |
|
{ |
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 |
< |
SM_CLR_NTH_T_BASE(sm,t_id); |
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 |
|
} |
1535 |
|
return(s_id); |
1536 |
|
} |
1537 |
< |
else |
1538 |
< |
if(on == ON_V || !p) |
1537 |
> |
if(dir) |
1538 |
> |
{ |
1539 |
> |
/* If world point */ |
1540 |
> |
/* if existing point is a dir: leave */ |
1541 |
> |
if(SM_DIR_ID(sm,v_id)) |
1542 |
> |
return(INVALID); |
1543 |
> |
if(on == ON_V) |
1544 |
|
{ |
1545 |
|
tonemap = (SM_TONE_MAP(sm) > v_id); |
1546 |
|
sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id,tonemap); |
1547 |
+ |
add_new_tri(t_id); |
1548 |
+ |
tri_id = smTri_next_ccw_nbr(sm,tri,v_id); |
1549 |
+ |
while(tri_id != t_id) |
1550 |
+ |
{ |
1551 |
+ |
t = SM_NTH_TRI(sm,tri_id); |
1552 |
+ |
add_new_tri(tri_id); |
1553 |
+ |
tri_id = smTri_next_ccw_nbr(sm,t,v_id); |
1554 |
+ |
} |
1555 |
|
return(v_id); |
1556 |
|
} |
1557 |
< |
else /* on == ON_P */ |
1558 |
< |
{ |
1559 |
< |
FVECT spt,npt; |
1560 |
< |
double d,d2; |
1557 |
> |
/* on == ON_P */ |
1558 |
> |
else |
1559 |
> |
{ |
1560 |
> |
FVECT spt,npt; |
1561 |
> |
double d,d2; |
1562 |
|
|
1563 |
< |
/* Need to check which sample is preferable */ |
1564 |
< |
VSUB(spt,p,SM_VIEW_CENTER(sm)); |
1565 |
< |
normalize(spt); |
1563 |
> |
/* Need to check which sample is preferable */ |
1564 |
> |
VSUB(spt,p,SM_VIEW_CENTER(sm)); |
1565 |
> |
normalize(spt); |
1566 |
|
|
1567 |
< |
VSUB(npt,SM_NTH_WV(sm,v_id),SM_VIEW_CENTER(sm)); |
1568 |
< |
normalize(npt); |
1569 |
< |
d = fdir2diff(SM_NTH_W_DIR(sm,v_id), npt); |
1570 |
< |
d2 = 2. - 2.*DOT(dir,spt); |
1567 |
> |
VSUB(npt,SM_NTH_WV(sm,v_id),SM_VIEW_CENTER(sm)); |
1568 |
> |
normalize(npt); |
1569 |
> |
d = fdir2diff(SM_NTH_W_DIR(sm,v_id), npt); |
1570 |
> |
d2 = 2. - 2.*DOT(dir,spt); |
1571 |
|
/* The existing sample is a better sample:punt */ |
1572 |
< |
if(d2 < d) |
1573 |
< |
{ |
1574 |
< |
/* The new sample has better information- replace values */ |
1575 |
< |
tonemap = (SM_TONE_MAP(sm) > v_id); |
1576 |
< |
sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id,tonemap); |
1577 |
< |
} |
1578 |
< |
return(v_id); |
1572 |
> |
if(d2 < d) |
1573 |
> |
{ |
1574 |
> |
/* The new sample has better information- replace values */ |
1575 |
> |
tonemap = (SM_TONE_MAP(sm) > v_id); |
1576 |
> |
sInit_samp(SM_SAMP(sm),v_id,c,dir,p,o_id,tonemap); |
1577 |
> |
add_new_tri(t_id); |
1578 |
> |
tri_id = smTri_next_ccw_nbr(sm,tri,v_id); |
1579 |
> |
while(tri_id != t_id) |
1580 |
> |
{ |
1581 |
> |
t = SM_NTH_TRI(sm,tri_id); |
1582 |
> |
add_new_tri(tri_id); |
1583 |
> |
tri_id = smTri_next_ccw_nbr(sm,t,v_id); |
1584 |
> |
} |
1585 |
> |
} |
1586 |
> |
return(v_id); |
1587 |
> |
} |
1588 |
> |
} |
1589 |
> |
else |
1590 |
> |
{ /* New point is a dir */ |
1591 |
> |
return(INVALID); |
1592 |
|
} |
1593 |
|
} |
1594 |
|
|
1595 |
+ |
int |
1596 |
+ |
smAlloc_samp(sm) |
1597 |
+ |
SM *sm; |
1598 |
+ |
{ |
1599 |
+ |
int s_id,replaced,cnt; |
1600 |
+ |
SAMP *s; |
1601 |
+ |
FVECT p; |
1602 |
+ |
|
1603 |
+ |
s = SM_SAMP(sm); |
1604 |
+ |
s_id = sAlloc_samp(s,&replaced); |
1605 |
+ |
|
1606 |
+ |
cnt=0; |
1607 |
+ |
while(replaced) |
1608 |
+ |
{ |
1609 |
+ |
if(smRemoveVertex(sm,s_id)) |
1610 |
+ |
break; |
1611 |
+ |
s_id = sAlloc_samp(s,&replaced); |
1612 |
+ |
cnt++; |
1613 |
+ |
if(cnt > S_MAX_SAMP(s)) |
1614 |
+ |
error(CONSISTENCY,"smAlloc_samp():unable to find free samp\n"); |
1615 |
+ |
} |
1616 |
+ |
return(s_id); |
1617 |
+ |
} |
1618 |
+ |
|
1619 |
+ |
|
1620 |
|
/* Add sample to the mesh: |
1621 |
|
|
1622 |
|
the sample can be a world space or directional point. If o_id !=INVALID, |
1645 |
|
|
1646 |
|
/* Must do this first-as may change mesh */ |
1647 |
|
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 |
|
{ |
1653 |
< |
t_id = smPointLocateTri(sm,p,&on,&which); |
1654 |
< |
if(t_id == INVALID) |
1653 |
> |
while(1) |
1654 |
> |
{ |
1655 |
> |
t_id = smPointLocateTri(sm,p,&on,&which); |
1656 |
> |
if(t_id == INVALID) |
1657 |
|
{ |
1658 |
|
#ifdef DEBUG |
1659 |
< |
eputs("smAddSamp(): unable to locate tri containing sample \n"); |
1659 |
> |
eputs("smAddSamp(): unable to locate tri containing sample \n"); |
1660 |
|
#endif |
1661 |
+ |
smUnalloc_samp(sm,s_id); |
1662 |
+ |
return(INVALID); |
1663 |
+ |
} |
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); |
1670 |
+ |
} |
1671 |
+ |
if((!(smTest_sample(sm,t_id,dir,p,&r_id)))) |
1672 |
+ |
{ |
1673 |
|
smUnalloc_samp(sm,s_id); |
1674 |
|
return(INVALID); |
1675 |
|
} |
1676 |
< |
/* If spherical projection coincides with existing sample: replace */ |
1677 |
< |
if((on == ON_V || on == ON_P)) |
1678 |
< |
{ |
1679 |
< |
if((n_id = smReplace_samp(sm,c,dir,p,s_id,t_id,o_id,on,which))!= s_id) |
1680 |
< |
smUnalloc_samp(sm,s_id); |
1681 |
< |
return(n_id); |
1676 |
> |
if(r_id != INVALID) |
1677 |
> |
{ |
1678 |
> |
smRemoveVertex(sm,r_id); |
1679 |
> |
sDelete_samp(SM_SAMP(sm),r_id); |
1680 |
> |
} |
1681 |
> |
else |
1682 |
> |
break; |
1683 |
|
} |
1558 |
– |
if((!(smTest_sample(sm,t_id,dir,p,&r_id)))) |
1559 |
– |
{ |
1560 |
– |
smUnalloc_samp(sm,s_id); |
1561 |
– |
return(INVALID); |
1562 |
– |
} |
1684 |
|
/* If sample is being added in the middle of the sample array: tone |
1685 |
|
map individually |
1686 |
|
*/ |
1692 |
|
else |
1693 |
|
{ |
1694 |
|
VADD(wpt,dir,SM_VIEW_CENTER(sm)); |
1695 |
< |
t_id = smPointLocateTri(sm,wpt,&on,&which); |
1696 |
< |
if(t_id == INVALID) |
1695 |
> |
while(1) |
1696 |
> |
{ if(s_id == 2299) |
1697 |
> |
t_id = INVALID; |
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"); |
1704 |
|
smUnalloc_samp(sm,s_id); |
1705 |
|
return(INVALID); |
1706 |
|
} |
1707 |
< |
if(on == ON_V || on == ON_P) |
1708 |
< |
{ |
1709 |
< |
if((n_id = smReplace_samp(sm,c,wpt,NULL,s_id,t_id,o_id,on,which))!= s_id) |
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(n_id); |
1717 |
< |
} |
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,wpt,NULL,o_id,(SM_TONE_MAP(sm)>s_id)); |
1728 |
> |
sInit_samp(SM_SAMP(sm),s_id,c,NULL,wpt,o_id,(SM_TONE_MAP(sm)>s_id)); |
1729 |
|
} |
1730 |
|
if(!SM_DIR_ID(sm,s_id)) |
1731 |
|
{ |
1736 |
|
} |
1737 |
|
smInsert_samp(sm,s_id,t_id,on,which); |
1738 |
|
|
1601 |
– |
/* If new sample replaces existing one- remove that vertex now */ |
1602 |
– |
if(r_id != INVALID) |
1603 |
– |
{ |
1604 |
– |
smRemoveVertex(sm,r_id); |
1605 |
– |
sDelete_samp(SM_SAMP(sm),r_id); |
1606 |
– |
} |
1739 |
|
return(s_id); |
1740 |
|
} |
1741 |
|
|
1758 |
|
{ |
1759 |
|
int s_id; |
1760 |
|
|
1629 |
– |
|
1761 |
|
/* First check if this the first sample: if so initialize mesh */ |
1631 |
– |
|
1762 |
|
if(SM_NUM_SAMP(smMesh) == 0) |
1763 |
|
{ |
1764 |
|
smInit_sm(smMesh,odev.v.vp); |
1939 |
|
} |
1940 |
|
|
1941 |
|
} |
1942 |
< |
|
1942 |
> |
#if 0 |
1943 |
|
smNew_tri_cnt = SM_SAMPLE_TRIS(sm); |
1944 |
+ |
#endif |
1945 |
+ |
|
1946 |
|
#ifdef DEBUG |
1947 |
|
fprintf(stderr,"smRebuild_mesh():done\n"); |
1948 |
|
#endif |
2279 |
|
t_id = QT_SET_NEXT_ELEM(optr); |
2280 |
|
/* Set the render flag */ |
2281 |
|
tri = SM_NTH_TRI(smMesh,t_id); |
2282 |
< |
if(!T_IS_VALID(tri) || SM_IS_NTH_T_BASE(smMesh,t_id)) |
2282 |
> |
if(!T_IS_VALID(tri)) |
2283 |
|
continue; |
2284 |
|
SM_SET_NTH_T_ACTIVE(smMesh,t_id); |
2285 |
|
/* Set the Active bits of the Vertices */ |
2286 |
< |
S_SET_FLAG(T_NTH_V(tri,0)); |
2287 |
< |
S_SET_FLAG(T_NTH_V(tri,1)); |
2288 |
< |
S_SET_FLAG(T_NTH_V(tri,2)); |
2289 |
< |
} |
2286 |
> |
if(!SM_IS_NTH_T_BASE(smMesh,t_id)) |
2287 |
> |
{ |
2288 |
> |
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 |
> |
} |
2292 |
> |
} |
2293 |
|
} |
2294 |
|
|
2295 |
|
|