19 |
|
#include "sm_qtree.h" |
20 |
|
#include "sm_stree.h" |
21 |
|
|
22 |
+ |
|
23 |
|
#ifdef TEST_DRIVER |
24 |
|
extern FVECT Pick_point[500],Pick_v0[500],Pick_v1[500],Pick_v2[500]; |
25 |
|
extern int Pick_cnt; |
64 |
|
{ |
65 |
|
int i,j; |
66 |
|
|
67 |
< |
ST_TOP_QT(st) = qtAlloc(); |
67 |
< |
ST_BOTTOM_QT(st) = qtAlloc(); |
68 |
< |
/* Clear the children */ |
67 |
> |
qtDone(); |
68 |
|
|
69 |
+ |
ST_TOP_QT(st) = qtAlloc(); |
70 |
+ |
ST_BOTTOM_QT(st) = qtAlloc(); |
71 |
+ |
/* Clear the children */ |
72 |
+ |
|
73 |
|
QT_CLEAR_CHILDREN(ST_TOP_QT(st)); |
74 |
|
QT_CLEAR_CHILDREN(ST_BOTTOM_QT(st)); |
75 |
|
} |
76 |
|
|
77 |
< |
/* Frees the children of the 2 quadtrees rooted at st, |
78 |
< |
Does not free root nodes: just clears |
76 |
< |
*/ |
77 |
< |
stClear(st) |
78 |
< |
STREE *st; |
77 |
> |
stFree(st) |
78 |
> |
STREE *st; |
79 |
|
{ |
80 |
< |
qtDone(); |
81 |
< |
stInit(st); |
80 |
> |
qtDone(); |
81 |
> |
free(st); |
82 |
|
} |
83 |
|
|
84 |
|
/* Allocates a stree structure and creates octahedron base */ |
97 |
|
/* Allocate the top and bottom quadtree root nodes */ |
98 |
|
stInit(st); |
99 |
|
|
100 |
– |
|
101 |
– |
/* will go ********************************************/ |
102 |
– |
/* Set the octahedron base */ |
103 |
– |
ST_SET_BASE(st,stDefault_base); |
104 |
– |
|
105 |
– |
/* Calculate octahedron face and edge normals */ |
106 |
– |
for(i=0; i < ST_NUM_ROOT_NODES; i++) |
107 |
– |
{ |
108 |
– |
VCOPY(v0,ST_NTH_V(st,i,0)); |
109 |
– |
VCOPY(v1,ST_NTH_V(st,i,1)); |
110 |
– |
VCOPY(v2,ST_NTH_V(st,i,2)); |
111 |
– |
tri_plane_equation(v0,v1,v2, &ST_NTH_PLANE(st,i),FALSE); |
112 |
– |
m = max_index(FP_N(ST_NTH_PLANE(st,i)),NULL); |
113 |
– |
FP_X(ST_NTH_PLANE(st,i)) = (m+1)%3; |
114 |
– |
FP_Y(ST_NTH_PLANE(st,i)) = (m+2)%3; |
115 |
– |
FP_Z(ST_NTH_PLANE(st,i)) = m; |
116 |
– |
VCROSS(ST_EDGE_NORM(st,i,0),v0,v1); |
117 |
– |
VCROSS(ST_EDGE_NORM(st,i,1),v1,v2); |
118 |
– |
VCROSS(ST_EDGE_NORM(st,i,2),v2,v0); |
119 |
– |
} |
120 |
– |
|
121 |
– |
/*****************************************************************/ |
100 |
|
return(st); |
101 |
|
} |
102 |
|
|
401 |
|
|
402 |
|
if(QT_FLAG_IS_DONE(f)) |
403 |
|
return(TRUE); |
404 |
< |
/* |
404 |
> |
/* |
405 |
|
d = DOT(orig,dir)/sqrt(DOT(orig,orig)); |
406 |
|
VSUM(v,orig,dir,-d); |
407 |
|
*/ |
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
< |
stVisit_poly(st,verts,l,root,func) |
430 |
> |
stVisit_poly(st,verts,l,root,func,n) |
431 |
|
STREE *st; |
432 |
|
FVECT *verts; |
433 |
|
LIST *l; |
434 |
|
unsigned int root; |
435 |
|
FUNC func; |
436 |
+ |
int n; |
437 |
|
{ |
438 |
|
int id0,id1,id2; |
439 |
|
FVECT tri[3]; |
446 |
|
VCOPY(tri[0],verts[id0]); |
447 |
|
VCOPY(tri[1],verts[id1]); |
448 |
|
VCOPY(tri[2],verts[id2]); |
449 |
< |
stRoot_visit_tri(st,root,tri,func); |
449 |
> |
stRoot_visit_tri(st,root,tri,func,n); |
450 |
|
id1 = id2; |
451 |
|
} |
452 |
|
} |
453 |
|
|
454 |
< |
stVisit_clip(st,i,verts,vcnt,l,cell,func) |
454 |
> |
stVisit_clip(st,i,verts,vcnt,l,cell,func,n) |
455 |
|
STREE *st; |
456 |
|
int i; |
457 |
|
FVECT *verts; |
459 |
|
LIST *l; |
460 |
|
unsigned int cell; |
461 |
|
FUNC func; |
462 |
+ |
int n; |
463 |
|
{ |
464 |
|
|
465 |
|
LIST *labove,*lbelow,*endb,*enda; |
551 |
|
if(LIST_NEXT(lbelow) && LIST_NEXT(LIST_NEXT(lbelow))) |
552 |
|
{ |
553 |
|
cellb = cell | (1 << i); |
554 |
< |
stVisit_poly(st,verts,lbelow,cellb,func); |
554 |
> |
stVisit_poly(st,verts,lbelow,cellb,func,n); |
555 |
|
} |
556 |
|
else |
557 |
|
free_list(lbelow); |
559 |
|
if(labove) |
560 |
|
{ |
561 |
|
if(LIST_NEXT(labove) && LIST_NEXT(LIST_NEXT(labove))) |
562 |
< |
stVisit_poly(st,verts,labove,cell,func); |
562 |
> |
stVisit_poly(st,verts,labove,cell,func,n); |
563 |
|
else |
564 |
|
free_list(labove); |
565 |
|
} |
571 |
|
if(LIST_NEXT(lbelow) && LIST_NEXT(LIST_NEXT(lbelow))) |
572 |
|
{ |
573 |
|
cellb = cell | (1 << i); |
574 |
< |
stVisit_clip(st,i+1,verts,vcnt,lbelow,cellb,func); |
574 |
> |
stVisit_clip(st,i+1,verts,vcnt,lbelow,cellb,func,n); |
575 |
|
} |
576 |
|
else |
577 |
|
free_list(lbelow); |
579 |
|
if(labove) |
580 |
|
{ |
581 |
|
if(LIST_NEXT(labove) && LIST_NEXT(LIST_NEXT(labove))) |
582 |
< |
stVisit_clip(st,i+1,verts,vcnt,labove,cell,func); |
582 |
> |
stVisit_clip(st,i+1,verts,vcnt,labove,cell,func,n); |
583 |
|
else |
584 |
|
free_list(labove); |
585 |
|
} |
587 |
|
|
588 |
|
} |
589 |
|
|
590 |
< |
stVisit(st,tri,func) |
590 |
> |
stVisit(st,tri,func,n) |
591 |
|
STREE *st; |
592 |
|
FVECT tri[3]; |
593 |
|
FUNC func; |
594 |
+ |
int n; |
595 |
|
{ |
596 |
|
int r0,r1,r2; |
597 |
|
LIST *l; |
600 |
|
r1 = stLocate_root(tri[1]); |
601 |
|
r2 = stLocate_root(tri[2]); |
602 |
|
if(r0 == r1 && r1==r2) |
603 |
< |
stRoot_visit_tri(st,r0,tri,func); |
603 |
> |
stRoot_visit_tri(st,r0,tri,func,n); |
604 |
|
else |
605 |
|
{ |
606 |
|
FVECT verts[ST_CLIP_VERTS]; |
614 |
|
l = add_data(l,1,NULL); |
615 |
|
l = add_data(l,2,NULL); |
616 |
|
cnt = 3; |
617 |
< |
stVisit_clip(st,0,verts,&cnt,l,0,func); |
617 |
> |
stVisit_clip(st,0,verts,&cnt,l,0,func,n); |
618 |
|
} |
619 |
|
} |
620 |
|
|
670 |
|
return(qt); |
671 |
|
} |
672 |
|
|
673 |
< |
stRoot_visit_tri(st,root,tri,f) |
673 |
> |
stRoot_visit_tri(st,root,tri,f,n) |
674 |
|
STREE *st; |
675 |
|
int root; |
676 |
|
FVECT tri[3]; |
677 |
|
FUNC f; |
678 |
+ |
int n; |
679 |
|
{ |
680 |
|
BCOORD b0[3],b1[3],b2[3]; |
681 |
|
BCOORD db10[3],db21[3],db02[3]; |
693 |
|
QT_SET_FLAG(ST_QT(st,root)); |
694 |
|
/* Visit cells that triangle intersects */ |
695 |
|
qtVisit_tri(root,qt,qtRoot[0],qtRoot[1],qtRoot[2], |
696 |
< |
b0,b1,b2,db10,db21,db02,MAXBCOORD2 >> 1,s0,s1,s2, sq0,sq1,sq2,f); |
696 |
> |
b0,b1,b2,db10,db21,db02,MAXBCOORD2 >> 1,s0,s1,s2, sq0,sq1,sq2,f,n); |
697 |
|
|
698 |
|
} |
699 |
|
|
723 |
|
} |
724 |
|
} |
725 |
|
|
726 |
+ |
stInsert_samp(st,p,f) |
727 |
+ |
STREE *st; |
728 |
+ |
FVECT p; |
729 |
+ |
FUNC f; |
730 |
+ |
{ |
731 |
+ |
|
732 |
+ |
QUADTREE qt; |
733 |
+ |
BCOORD bcoordi[3]; |
734 |
+ |
int i,done; |
735 |
+ |
|
736 |
+ |
/* Find root quadtree that contains p */ |
737 |
+ |
i = stLocate_root(p); |
738 |
+ |
qt = ST_ROOT_QT(st,i); |
739 |
+ |
|
740 |
+ |
/* Will return lowest level triangle containing point: It the |
741 |
+ |
point is on an edge or vertex: will return first associated |
742 |
+ |
triangle encountered in the child traversal- the others can |
743 |
+ |
be derived using triangle adjacency information |
744 |
+ |
*/ |
745 |
+ |
vert_to_qt_frame(i,p,bcoordi); |
746 |
+ |
ST_ROOT_QT(st,i) = qtInsert_point(i,qt,EMPTY,qtRoot[0],qtRoot[1], |
747 |
+ |
qtRoot[2],bcoordi,MAXBCOORD2>>1,f,0,&done); |
748 |
+ |
|
749 |
+ |
} |
750 |
|
|
751 |
|
|
752 |
|
|