ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/source.h
Revision: 2.14
Committed: Wed Sep 8 06:07:52 2004 UTC (20 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.13: +2 -2 lines
Log Message:
Made source obstructor cache initialization more robust

File Contents

# Content
1 /* RCSid $Id: source.h,v 2.13 2004/03/30 16:13:01 schorsch Exp $ */
2 /*
3 * source.h - header file for ray tracing sources.
4 *
5 * Include after ray.h
6 */
7 #ifndef _RAD_SOURCE_H_
8 #define _RAD_SOURCE_H_
9
10 #include <string.h>
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #ifndef AIMREQT
17 #define AIMREQT 100 /* required aim success/failure */
18 #endif
19 #ifndef SHADCACHE
20 #define SHADCACHE 20 /* shadow cache resolution */
21 #endif
22
23 #define SDISTANT 01 /* source distant flag */
24 #define SSKIP 02 /* source skip flag */
25 #define SPROX 04 /* source proximity flag */
26 #define SSPOT 010 /* source spotlight flag */
27 #define SVIRTUAL 020 /* source virtual flag */
28 #define SFLAT 040 /* source flat flag */
29 #define SCYL 0100 /* source cylindrical flag */
30 #define SFOLLOW 0200 /* source follow path flag */
31
32 typedef struct {
33 FVECT aim; /* aim direction or center */
34 float siz; /* output solid angle or area */
35 float flen; /* focal length (negative if distant source) */
36 } SPOT; /* spotlight */
37
38 typedef struct {
39 union {
40 struct {
41 FVECT u, v; /* unit vectors */
42 } f; /* flat source indexing */
43 struct {
44 FVECT o; /* origin position */
45 RREAL e1, e2; /* 1/extent */
46 int ax; /* major direction */
47 } d; /* distant source indexing */
48 } p; /* indexing parameters */
49 OBJECT obs[1]; /* cache obstructors (extends struct) */
50 } OBSCACHE; /* obstructor cache */
51
52 typedef struct {
53 int sflags; /* source flags */
54 FVECT sloc; /* direction or position of source */
55 FVECT ss[3]; /* source dimension vectors, U, V, and W */
56 float srad; /* maximum source radius */
57 float ss2; /* solid angle or projected area */
58 OBJREC *so; /* source destination object */
59 struct {
60 float prox; /* proximity */
61 SPOT *s; /* spot */
62 } sl; /* localized source information */
63 union {
64 long success; /* successes - AIMREQT*failures */
65 struct {
66 short pn; /* projection number */
67 int sn; /* next source to aim for */
68 } sv; /* virtual source */
69 } sa; /* source aiming information */
70 unsigned long
71 ntests, nhits; /* shadow tests and hits */
72 #ifdef SHADCACHE
73 OBSCACHE *obscache; /* obstructor cache */
74 #endif
75 } SRCREC; /* light source */
76
77 #define MAXSPART 64 /* maximum partitions per source */
78
79 #define SU 0 /* U vector or partition */
80 #define SV 1 /* V vector or partition */
81 #define SW 2 /* W vector or partition */
82 #define S0 3 /* leaf partition */
83
84 #define snorm ss[SW] /* normal vector for flat source */
85
86 typedef struct {
87 int sn; /* source number */
88 short np; /* number of partitions */
89 short sp; /* this partition number */
90 double dom; /* solid angle of partition */
91 unsigned char spt[MAXSPART/2]; /* source partitioning */
92 } SRCINDEX; /* source index structure */
93
94 #define initsrcindex(s) ((s)->sn = (s)->sp = -1, (s)->np = 0)
95
96 #define clrpart(pt) memset((char *)(pt), '\0', MAXSPART/2)
97 #define setpart(pt,i,v) ((pt)[(i)>>2] |= (v)<<(((i)&3)<<1))
98 #define spart(pt,pi) ((pt)[(pi)>>2] >> (((pi)&3)<<1) & 3)
99
100 /*
101 * Special support functions for sources
102 */
103
104 /*
105 * Virtual source materials must define the following.
106 *
107 * vproj(pm, op, sp, i) Compute i'th virtual projection
108 * of source sp in object op and assign
109 * the 4x4 transformation matrix pm.
110 * Return 1 on success, 0 if no i'th projection.
111 *
112 * nproj The number of projections. The value of
113 * i passed to vproj runs from 0 to nproj-1.
114 */
115
116 typedef struct {
117 int (*vproj)(); /* project virtual sources */
118 int nproj; /* number of possible projections */
119 } VSMATERIAL; /* virtual source material functions */
120
121 typedef struct {
122 void (*setsrc)(); /* set light source for object */
123 void (*partit)(); /* partition light source object */
124 double (*getpleq)(); /* plane equation for surface */
125 double (*getdisk)(); /* maximum disk for surface */
126 } SOBJECT; /* source object functions */
127
128 typedef union {
129 VSMATERIAL *mf; /* material functions */
130 SOBJECT *of; /* object functions */
131 } SRCFUNC; /* source functions */
132
133 extern SRCFUNC sfun[]; /* source dispatch table */
134
135 extern SRCREC *source; /* our source list */
136 extern int nsources; /* the number of sources */
137
138 #define sflatform(sn,dir) -DOT(source[sn].snorm, dir)
139
140 #define getplaneq(c,o) (*sfun[(o)->otype].of->getpleq)(c,o)
141 #define getmaxdisk(c,o) (*sfun[(o)->otype].of->getdisk)(c,o)
142 #define setsource(s,o) (*sfun[(o)->otype].of->setsrc)(s,o)
143
144 /* defined in source.c */
145 extern OBJREC *findmaterial(OBJREC *o);
146 extern void marksources(void);
147 extern void freesources(void);
148 extern int srcray(RAY *sr, RAY *r, SRCINDEX *si);
149 extern void srcvalue(RAY *r);
150 extern int sourcehit(RAY *r);
151 typedef void srcdirf_t(COLOR cv, void *np, FVECT ldir, double omega);
152 extern void direct(RAY *r, srcdirf_t *f, void *p);
153 extern void srcscatter(RAY *r);
154 extern int m_light(OBJREC *m, RAY *r);
155 extern int srcblocker(RAY *r);
156 extern int srcblocked(RAY *r);
157 extern void freeobscache(SRCREC *s);
158 /* defined in srcsamp.c */
159 extern double nextssamp(RAY *r, SRCINDEX *si);
160 extern int skipparts(int ct[3], int sz[3], int pp[2], unsigned char *pt);
161 extern void nopart(SRCINDEX *si, RAY *r);
162 extern void cylpart(SRCINDEX *si, RAY *r);
163 extern void flatpart(SRCINDEX *si, RAY *r);
164 extern double scylform(int sn, FVECT dir);
165 /* defined in srcsupp.c */
166 extern void initstypes(void);
167 extern int newsource(void);
168 extern void setflatss(SRCREC *src);
169 extern void fsetsrc(SRCREC *src, OBJREC *so);
170 extern void ssetsrc(SRCREC *src, OBJREC *so);
171 extern void sphsetsrc(SRCREC *src, OBJREC *so);
172 extern void rsetsrc(SRCREC *src, OBJREC *so);
173 extern void cylsetsrc(SRCREC *src, OBJREC *so);
174 extern SPOT *makespot(OBJREC *m);
175 extern int spotout(RAY *r, SPOT *s);
176 extern double fgetmaxdisk(FVECT ocent, OBJREC *op);
177 extern double rgetmaxdisk(FVECT ocent, OBJREC *op);
178 extern double fgetplaneq(FVECT nvec, OBJREC *op);
179 extern double rgetplaneq(FVECT nvec, OBJREC *op);
180 extern int commonspot(SPOT *sp1, SPOT *sp2, FVECT org);
181 extern int commonbeam(SPOT *sp1, SPOT *sp2, FVECT org);
182 extern int checkspot(SPOT *sp, FVECT nrm);
183 extern double spotdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT pos);
184 extern double beamdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT dir);
185 extern double intercircle(FVECT cc, FVECT c1, FVECT c2,
186 double r1s, double r2s);
187 /* defined in virtuals.c */
188 extern void markvirtuals(void);
189 extern void addvirtuals(int sn, int nr);
190 extern void vproject(OBJREC *o, int sn, int n);
191 extern OBJREC *vsmaterial(OBJREC *o);
192 extern int makevsrc(OBJREC *op, int sn, MAT4 pm);
193 extern double getdisk(FVECT oc, OBJREC *op, int sn);
194 extern int vstestvis(int f, OBJREC *o, FVECT oc, double or2, int sn);
195 extern void virtverb(int sn, FILE *fp);
196
197
198 #ifdef __cplusplus
199 }
200 #endif
201 #endif /* _RAD_SOURCE_H_ */
202