ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm_geom.h
Revision: 3.11
Committed: Thu Jun 10 15:22:23 1999 UTC (24 years, 10 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.10: +1 -1 lines
Log Message:
Implemented sample quadtree in place of triangle quadtree
Made geometric predicates more robust
Added #define LORES which utilizes a single precision floating point
  sample array, the default is a double sample array
Added topology DEBUG commands (for DEBUG > 1)
Made code optimizations

File Contents

# Content
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
3 /* SCCSid "$SunId$ SGI" */
4
5 /*
6 * sm_geom.h
7 */
8
9 /* Assumes included after standard.h */
10
11 #include <values.h>
12
13 #define F_TINY 1e-10
14 #define FZERO(x) ((x) < F_TINY && (x) > -F_TINY)
15 #define FEQUAL(a,b) FZERO((a) - (b))
16
17 #define ZERO(x) ((x) < FTINY && (x) > -FTINY)
18 #define EQUAL(a,b) ZERO((a) - (b))
19
20 #ifndef TRUE
21 #define TRUE 1
22 #define FALSE 0
23 #endif
24
25 typedef struct _FPEQ {
26 FVECT n;
27 double d;
28 char x,y,z;
29 }FPEQ;
30
31 #define FP_N(f) ((f).n)
32 #define FP_D(f) ((f).d)
33 #define FP_X(f) ((f).x)
34 #define FP_Y(f) ((f).y)
35 #define FP_Z(f) ((f).z)
36
37 typedef long BCOORD;
38 typedef long BDIR;
39 typedef long TINT;
40
41 #define BITS_BCOORD (BITS(long)-2)
42 #define SHIFT_MAXBCOORD (BITS_BCOORD-1)
43 #define MAXBCOORD ((1L << BITS_BCOORD)-1)
44 #define MAXBCOORD2 (MAXBCOORD>>1)
45 #define MAXBCOORD4 (MAXBCOORD2>>1)
46
47 #define M_2_3_PI PI*2/3
48
49 #ifndef INVALID
50 #define INVALID -1
51 #endif
52
53 #define GT_INVALID 0
54 #define GT_VERTEX 1
55 #define GT_EDGE 2
56 #define GT_FACE 4
57 #define GT_INTERIOR 8
58 #define GT_INTERSECT 16
59 #define GT_ADJACENT 32
60 #define GT_OUT 64
61
62 #define IADDV3(v,a) ((v)[0] += (a)[0],(v)[1] += (a)[1],(v)[2] += (a)[2])
63 #define ISUBV3(v,a) ((v)[0] -= (a)[0],(v)[1] -= (a)[1],(v)[2] -= (a)[2])
64 #define ISCALEV3(v,a) ((v)[0] *= (a),(v)[1] *= (a),(v)[2] *= (a))
65 #define IDIVV3(v,a) ((v)[0] /= (a),(v)[1] /= (a),(v)[2] /= (a))
66
67
68 #define ADDV3(v,a,b) ((v)[0] = (a)[0]+(b)[0],(v)[1] = (a)[1]+(b)[1],\
69 (v)[2] = (a)[2]+(b)[2])
70 #define SUBV3(v,a,b) ((v)[0] = (a)[0]-(b)[0],(v)[1] = (a)[1]-(b)[1],\
71 (v)[2] = (a)[2]-(b)[2])
72 #define SUMV3(v,a,b,s) ((v)[0] = (a)[0]+(s)*(b)[0],(v)[1]=(a)[1]+(s)*(b)[1],\
73 (v)[2] = (a)[2]+(s)*(b)[2])
74 #define SCALEV3(v,a,s) ((v)[0]=(a)[0]*(s),(v)[1]=(a)[1]*(s),(v)[2]=(a)[2]*(s))
75 #define ZERO_VEC3(v) (ZERO(v[0]) && ZERO(v[1]) && ZERO(v[2]) )
76 #define EQUAL_VEC3(a,b) (FEQUAL(a[0],b[0])&&FEQUAL(a[1],b[1])&&FEQUAL(a[2],b[2]))
77 #define OPP_EQUAL_VEC3(a,b) (EQUAL(a[0],-b[0])&&EQUAL(a[1],-b[1])&&EQUAL(a[2],-b[2]))
78 #define FZERO_VEC3(v) (FZERO(v[0]) && FZERO(v[1]) && FZERO(v[2]) )
79 #define FEQUAL_VEC3(a,b) (FEQUAL(a[0],b[0])&&FEQUAL(a[1],b[1])&&FEQUAL(a[2],b[2]))
80 #define NEGATE_VEC3(v) ((v)[0] *= -1.0,(v)[1] *= -1.0,(v)[2] *= -1.0)
81 #define COPY_VEC2(v1,v2) ((v1)[0]=(v2)[0],(v1)[1]=(v2)[1])
82 #define DIST(a,b) (sqrt(((a)[0]-(b)[0])*((a)[0]-(b)[0]) + \
83 ((a)[1]-(b)[1])*((a)[1]-(b)[1]) + \
84 ((a)[2]-(b)[2])*((a)[2]-(b)[2])))
85 #define DIST_SQ(a,b) (((a)[0]-(b)[0])*((a)[0]-(b)[0]) + \
86 ((a)[1]-(b)[1])*((a)[1]-(b)[1]) + \
87 ((a)[2]-(b)[2])*((a)[2]-(b)[2]))
88
89 #define SIGN(x) ((x<0)?-1:1)
90 #define CROSS_VEC2(v1,v2) (((v1)[0]*(v2)[1]) - ((v1)[1]*(v2)[0]))
91 #define DOT_VEC2(v1,v2) ((v1)[0]*(v2)[0] + (v1)[1]*(v2)[1])
92
93 #define EDGE_MIDPOINT(a,v1,v2) ((a)[0]=((v1)[0]+(v2)[0])*0.5, \
94 (a)[1]=((v1)[1]+(v2)[1])*0.5,(a)[2] = ((v1)[2]+(v2)[2])*0.5)
95
96 #define MIN_VEC3(v) ((v)[0]<(v)[1]?((v)[0]<(v)[2]?(v)[0]:v[2]): \
97 (v)[1]<(v)[2]?(v)[1]:(v)[2])
98 #define MAX3(a,b,c) (((b)>(a))?((b) > (c))?(b):(c):((a)>(c))?(a):(c))
99 #define MIN3(a,b,c) (((b)<(a))?((b) < (c))?(b):(c):((a)<(c))?(a):(c))
100 #define MAX(a,b) (((b)>(a))?(b):(a))
101 #define MIN(a,b) (((b)<(a))?(b):(a))
102
103 #define SUM_3VEC3(r,a,b,c) ((r)[0]=(a)[0]+(b)[0]+(c)[0], \
104 (r)[1]=(a)[1]+(b)[1]+(c)[1],(r)[2]=(a)[2]+(b)[2]+(c)[2])
105
106 #define NTH_BIT(n,i) ((n) & (1<<(i)))
107 #define SET_NTH_BIT(n,i) ((n) |= (1<<(i)))
108
109
110 /* int convex_angle(FVECT v0,FVECT v1,FVECT v2) */
111 /* void triangle_centroid(FVECT v0,FVECT v1,FVECT v2,FVECT c) */
112 /* void triangle_plane_equation(FVECT v0,FVECT v1,FVECT v2,FVECT n,double *nd,
113 char norm) */
114 /* int vec3_equal(FVECT v1,v2) */
115 /* int point_relative_to_plane(FVECT p,FVECT n, double nd) */
116 /* int point_in_circle(FVECT p,FVECT p0,FVECT p1) */
117 /* int intersect_line_plane(FVECT r,FVECT p1,FVECT p2,float *plane) */
118 /* int point_in_cone(FVECT p,FVECT p1,FVECT p2,FVECT p3,FVECT p4) */
119 /* void point_on_sphere(FVECT ps,FVECT p,FVECT c) */
120 /* int test_point_against_spherical_tri(FVECT v0,FVECT v1,FVECT v2,FVECT p,
121 FVECT n,char *nset,char *which,char sides[3]) */
122 /* int test_single_point_against_spherical_tri(FVECT v0,FVECT v1,FVECT v2,
123 FVECT p,char *which )*/
124 /* int test_vertices_for_tri_inclusion(FVECT tri[3],FVECT pts[3],char *nset,
125 FVECT n[3],FVECT avg,char pt_sides[3][3]); */
126 /* void set_sidedness_tests(FVECT tri[3],FVECT pts[3],char test[3],
127 char sides[3][3],char nset,FVECT n[3])
128 */
129 /* int cs_spherical_edge_edge_test(FVECT n[2][3],int i,int j,FVECT avg[2]) */
130 /* int spherical_tri_tri_intersect(FVECT a1,FVECT a2,FVECT a3,
131 FVECT b1,FVECT b2,FVECT b3) */
132
133 /* void calculate_view_frustum(FVECT vp,hv,vv,double horiz,vert,near,far,
134 FVECT fnear[4],FVECT ffar[4])
135 */
136 /* double triangle_normal_Newell(FVECT v0,FVECT v1,FVECT v2,FVECT n,char n)*/
137 double tri_normal();
138 /* double spherical_edge_normal(FVECT v0,FVECT v1,FVECT n,char norm) */
139 double spherical_edge_normal();
140 double point_on_sphere();
141
142 #define point_in_stri_n(n0,n1,n2,p) \
143 ((DOT(n0,p)<=FTINY)&&(DOT(n1,p)<=FTINY)&&(DOT(n2,p)<=FTINY))
144
145 #define PT_ON_PLANE(p,peq) (DOT(FP_N(peq),p)+FP_D(peq))
146