ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/source.h
Revision: 2.18
Committed: Sat Dec 6 01:08:53 2008 UTC (15 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2, rad4R1, rad4R0
Changes since 2.17: +4 -3 lines
Log Message:
Reduced occurrence of aiming failures for circular sources (Thanks to David G-M)

File Contents

# Content
1 /* RCSid $Id: source.h,v 2.17 2007/07/25 05:38:24 greg 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 SCIR 0100 /* source circular flag */
30 #define SCYL 0200 /* source cylindrical flag */
31 #define SFOLLOW 0400 /* source follow path flag */
32
33 typedef struct {
34 FVECT aim; /* aim direction or center */
35 float siz; /* output solid angle or area */
36 float flen; /* focal length (negative if distant source) */
37 } SPOT; /* spotlight */
38
39 typedef struct {
40 union {
41 struct {
42 FVECT u, v; /* unit vectors */
43 } f; /* flat source indexing */
44 struct {
45 FVECT o; /* origin position */
46 RREAL e1, e2; /* 1/extent */
47 int ax; /* major direction */
48 } d; /* distant source indexing */
49 } p; /* indexing parameters */
50 OBJECT obs[1]; /* cache obstructors (extends struct) */
51 } OBSCACHE; /* obstructor cache */
52
53 typedef struct {
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 int sflags; /* source flags */
76 } SRCREC; /* light source */
77
78 #define MAXSPART 64 /* maximum partitions per source */
79
80 #define SU 0 /* U vector or partition */
81 #define SV 1 /* V vector or partition */
82 #define SW 2 /* W vector or partition */
83 #define S0 3 /* leaf partition */
84
85 #define snorm ss[SW] /* normal vector for flat source */
86
87 typedef struct {
88 double dom; /* solid angle of partition */
89 int sn; /* source number */
90 short np; /* number of partitions */
91 short sp; /* this partition number */
92 unsigned char spt[MAXSPART/2]; /* source partitioning */
93 } SRCINDEX; /* source index structure */
94
95 #define initsrcindex(s) ((s)->sn = (s)->sp = -1, (s)->np = 0)
96
97 #define clrpart(pt) memset((char *)(pt), '\0', MAXSPART/2)
98 #define setpart(pt,i,v) ((pt)[(i)>>2] |= (v)<<(((i)&3)<<1))
99 #define spart(pt,pi) ((pt)[(pi)>>2] >> (((pi)&3)<<1) & 3)
100
101 /*
102 * Special support functions for sources
103 */
104
105 /*
106 * Virtual source materials must define the following.
107 *
108 * vproj(pm, op, sp, i) Compute i'th virtual projection
109 * of source sp in object op and assign
110 * the 4x4 transformation matrix pm.
111 * Return 1 on success, 0 if no i'th projection.
112 *
113 * nproj The number of projections. The value of
114 * i passed to vproj runs from 0 to nproj-1.
115 */
116
117 typedef struct {
118 int (*vproj)(); /* project virtual sources */
119 int nproj; /* number of possible projections */
120 } VSMATERIAL; /* virtual source material functions */
121
122 typedef struct {
123 void (*setsrc)(); /* set light source for object */
124 void (*partit)(); /* partition light source object */
125 double (*getpleq)(); /* plane equation for surface */
126 double (*getdisk)(); /* maximum disk for surface */
127 } SOBJECT; /* source object functions */
128
129 typedef union {
130 VSMATERIAL *mf; /* material functions */
131 SOBJECT *of; /* object functions */
132 } SRCFUNC; /* source functions */
133
134 extern SRCFUNC sfun[]; /* source dispatch table */
135
136 extern SRCREC *source; /* our source list */
137 extern int nsources; /* the number of sources */
138
139 #define sflatform(sn,dir) -DOT(source[sn].snorm, dir)
140
141 #define getplaneq(c,o) (*sfun[(o)->otype].of->getpleq)(c,o)
142 #define getmaxdisk(c,o) (*sfun[(o)->otype].of->getdisk)(c,o)
143 #define setsource(s,o) (*sfun[(o)->otype].of->setsrc)(s,o)
144
145 /* defined in source.c */
146 extern OBJREC *findmaterial(OBJREC *o);
147 extern void marksources(void);
148 extern void freesources(void);
149 extern int srcray(RAY *sr, RAY *r, SRCINDEX *si);
150 extern void srcvalue(RAY *r);
151 extern int sourcehit(RAY *r);
152 typedef void srcdirf_t(COLOR cv, void *np, FVECT ldir, double omega);
153 extern void direct(RAY *r, srcdirf_t *f, void *p);
154 extern void srcscatter(RAY *r);
155 extern int m_light(OBJREC *m, RAY *r);
156 /* defined in srcobstr.c */
157 extern void initobscache(int sn);
158 extern int srcblocker(RAY *r);
159 extern int srcblocked(RAY *r);
160 extern void freeobscache(SRCREC *s);
161 extern void markclip(OBJREC *m);
162 /* defined in srcsamp.c */
163 extern double nextssamp(RAY *r, SRCINDEX *si);
164 extern int skipparts(int ct[3], int sz[3], int pp[2], unsigned char *pt);
165 extern void nopart(SRCINDEX *si, RAY *r);
166 extern void cylpart(SRCINDEX *si, RAY *r);
167 extern void flatpart(SRCINDEX *si, RAY *r);
168 extern double scylform(int sn, FVECT dir);
169 /* defined in srcsupp.c */
170 extern void initstypes(void);
171 extern int newsource(void);
172 extern void setflatss(SRCREC *src);
173 extern void fsetsrc(SRCREC *src, OBJREC *so);
174 extern void ssetsrc(SRCREC *src, OBJREC *so);
175 extern void sphsetsrc(SRCREC *src, OBJREC *so);
176 extern void rsetsrc(SRCREC *src, OBJREC *so);
177 extern void cylsetsrc(SRCREC *src, OBJREC *so);
178 extern SPOT *makespot(OBJREC *m);
179 extern int spotout(RAY *r, SPOT *s);
180 extern double fgetmaxdisk(FVECT ocent, OBJREC *op);
181 extern double rgetmaxdisk(FVECT ocent, OBJREC *op);
182 extern double fgetplaneq(FVECT nvec, OBJREC *op);
183 extern double rgetplaneq(FVECT nvec, OBJREC *op);
184 extern int commonspot(SPOT *sp1, SPOT *sp2, FVECT org);
185 extern int commonbeam(SPOT *sp1, SPOT *sp2, FVECT org);
186 extern int checkspot(SPOT *sp, FVECT nrm);
187 extern double spotdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT pos);
188 extern double beamdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT dir);
189 extern double intercircle(FVECT cc, FVECT c1, FVECT c2,
190 double r1s, double r2s);
191 /* defined in virtuals.c */
192 extern void markvirtuals(void);
193 extern void addvirtuals(int sn, int nr);
194 extern void vproject(OBJREC *o, int sn, int n);
195 extern OBJREC *vsmaterial(OBJREC *o);
196 extern int makevsrc(OBJREC *op, int sn, MAT4 pm);
197 extern double getdisk(FVECT oc, OBJREC *op, int sn);
198 extern int vstestvis(int f, OBJREC *o, FVECT oc, double or2, int sn);
199 extern void virtverb(int sn, FILE *fp);
200
201
202 #ifdef __cplusplus
203 }
204 #endif
205 #endif /* _RAD_SOURCE_H_ */
206