Back to index

radiance  4R0+20100331
source.h
Go to the documentation of this file.
00001 /* RCSid $Id: source.h,v 2.18 2008/12/06 01:08:53 greg Exp $ */
00002 /*
00003  *  source.h - header file for ray tracing sources.
00004  *
00005  *  Include after ray.h
00006  */
00007 #ifndef _RAD_SOURCE_H_
00008 #define _RAD_SOURCE_H_
00009 
00010 #include <string.h>
00011 
00012 #ifdef __cplusplus
00013 extern "C" {
00014 #endif
00015 
00016 #ifndef  AIMREQT
00017 #define  AIMREQT     100           /* required aim success/failure */
00018 #endif
00019 #ifndef  SHADCACHE
00020 #define  SHADCACHE   20            /* shadow cache resolution */
00021 #endif
00022 
00023 #define  SDISTANT    01            /* source distant flag */
00024 #define  SSKIP              02            /* source skip flag */
00025 #define  SPROX              04            /* source proximity flag */
00026 #define  SSPOT              010           /* source spotlight flag */
00027 #define  SVIRTUAL    020           /* source virtual flag */
00028 #define  SFLAT              040           /* source flat flag */
00029 #define  SCIR        0100          /* source circular flag */
00030 #define  SCYL        0200          /* source cylindrical flag */
00031 #define  SFOLLOW     0400          /* source follow path flag */
00032 
00033 typedef struct {
00034        FVECT  aim;          /* aim direction or center */
00035        float  siz;          /* output solid angle or area */
00036        float  flen;         /* focal length (negative if distant source) */
00037 } SPOT;                     /* spotlight */
00038 
00039 typedef struct {
00040        union {
00041               struct {
00042                      FVECT   u, v;        /* unit vectors */
00043               }  f;                /* flat source indexing */
00044               struct {
00045                      FVECT   o;           /* origin position */
00046                      RREAL   e1, e2;             /* 1/extent */
00047                      int     ax;          /* major direction */
00048               }  d;                /* distant source indexing */
00049        }  p;                /* indexing parameters */
00050        OBJECT  obs[1];             /* cache obstructors (extends struct) */
00051 }  OBSCACHE;         /* obstructor cache */
00052 
00053 typedef struct {
00054        FVECT  sloc;         /* direction or position of source */
00055        FVECT  ss[3];        /* source dimension vectors, U, V, and W */
00056        float  srad;         /* maximum source radius */
00057        float  ss2;          /* solid angle or projected area */
00058        OBJREC  *so;         /* source destination object */
00059        struct {
00060               float  prox;         /* proximity */
00061               SPOT  *s;            /* spot */
00062        } sl;                /* localized source information */
00063        union {
00064               long  success;              /* successes - AIMREQT*failures */
00065               struct {
00066                      short  pn;           /* projection number */
00067                      int  sn;             /* next source to aim for */
00068               }  sv;               /* virtual source */
00069        } sa;                /* source aiming information */
00070        unsigned long
00071               ntests, nhits;       /* shadow tests and hits */
00072 #ifdef  SHADCACHE
00073        OBSCACHE  *obscache;    /* obstructor cache */
00074 #endif
00075        int  sflags;         /* source flags */
00076 }  SRCREC;           /* light source */
00077 
00078 #define MAXSPART     64            /* maximum partitions per source */
00079 
00080 #define SU           0             /* U vector or partition */
00081 #define SV           1             /* V vector or partition */
00082 #define SW           2             /* W vector or partition */
00083 #define S0           3             /* leaf partition */
00084 
00085 #define snorm        ss[SW]        /* normal vector for flat source */
00086 
00087 typedef struct {
00088        double  dom;                       /* solid angle of partition */
00089        int  sn;                           /* source number */
00090        short  np;                         /* number of partitions */
00091        short  sp;                         /* this partition number */
00092        unsigned char  spt[MAXSPART/2];           /* source partitioning */
00093 }  SRCINDEX;         /* source index structure */
00094 
00095 #define initsrcindex(s)     ((s)->sn = (s)->sp = -1, (s)->np = 0)
00096 
00097 #define clrpart(pt)  memset((char *)(pt), '\0', MAXSPART/2)
00098 #define setpart(pt,i,v)     ((pt)[(i)>>2] |= (v)<<(((i)&3)<<1))
00099 #define spart(pt,pi) ((pt)[(pi)>>2] >> (((pi)&3)<<1) & 3)
00100 
00101 /*
00102  * Special support functions for sources
00103  */
00104 
00105 /*
00106  * Virtual source materials must define the following.
00107  *
00108  *     vproj(pm, op, sp, i) Compute i'th virtual projection
00109  *                          of source sp in object op and assign
00110  *                          the 4x4 transformation matrix pm.
00111  *                          Return 1 on success, 0 if no i'th projection.
00112  *
00113  *     nproj                The number of projections.  The value of
00114  *                          i passed to vproj runs from 0 to nproj-1.
00115  */
00116 
00117 typedef struct {
00118        int  (*vproj)();     /* project virtual sources */
00119        int  nproj;          /* number of possible projections */
00120 } VSMATERIAL;        /* virtual source material functions */
00121 
00122 typedef struct {
00123        void   (*setsrc)();  /* set light source for object */
00124        void   (*partit)();  /* partition light source object */
00125        double  (*getpleq)();       /* plane equation for surface */
00126        double  (*getdisk)();       /* maximum disk for surface */
00127 } SOBJECT;           /* source object functions */
00128 
00129 typedef union {
00130        VSMATERIAL  *mf;     /* material functions */
00131        SOBJECT  *of;        /* object functions */
00132 } SRCFUNC;           /* source functions */
00133 
00134 extern SRCFUNC  sfun[];                   /* source dispatch table */
00135 
00136 extern SRCREC  *source;                   /* our source list */
00137 extern int  nsources;                     /* the number of sources */
00138 
00139 #define  sflatform(sn,dir)  -DOT(source[sn].snorm, dir)
00140 
00141 #define  getplaneq(c,o)            (*sfun[(o)->otype].of->getpleq)(c,o)
00142 #define  getmaxdisk(c,o)    (*sfun[(o)->otype].of->getdisk)(c,o)
00143 #define  setsource(s,o)            (*sfun[(o)->otype].of->setsrc)(s,o)
00144 
00145                                    /* defined in source.c */
00146 extern OBJREC   *findmaterial(OBJREC *o);
00147 extern void   marksources(void);
00148 extern void   freesources(void);
00149 extern int    srcray(RAY *sr, RAY *r, SRCINDEX *si);
00150 extern void   srcvalue(RAY *r);
00151 extern int    sourcehit(RAY *r);
00152 typedef void srcdirf_t(COLOR cv, void *np, FVECT ldir, double omega);
00153 extern void   direct(RAY *r, srcdirf_t *f, void *p);
00154 extern void   srcscatter(RAY *r);
00155 extern int    m_light(OBJREC *m, RAY *r);
00156                                    /* defined in srcobstr.c */
00157 extern void   initobscache(int sn);
00158 extern int    srcblocker(RAY *r);
00159 extern int      srcblocked(RAY *r);
00160 extern void     freeobscache(SRCREC *s);
00161 extern void   markclip(OBJREC *m);
00162                                    /* defined in srcsamp.c */
00163 extern double nextssamp(RAY *r, SRCINDEX *si);
00164 extern int    skipparts(int ct[3], int sz[3], int pp[2], unsigned char *pt);
00165 extern void   nopart(SRCINDEX *si, RAY *r);
00166 extern void   cylpart(SRCINDEX *si, RAY *r);
00167 extern void   flatpart(SRCINDEX *si, RAY *r);
00168 extern double scylform(int sn, FVECT dir);
00169                                    /* defined in srcsupp.c */
00170 extern void   initstypes(void);
00171 extern int    newsource(void);
00172 extern void   setflatss(SRCREC *src);
00173 extern void   fsetsrc(SRCREC *src, OBJREC *so);
00174 extern void   ssetsrc(SRCREC *src, OBJREC *so);
00175 extern void   sphsetsrc(SRCREC *src, OBJREC *so);
00176 extern void   rsetsrc(SRCREC *src, OBJREC *so);
00177 extern void   cylsetsrc(SRCREC *src, OBJREC *so);
00178 extern SPOT   *makespot(OBJREC *m);
00179 extern int    spotout(RAY *r, SPOT *s);
00180 extern double fgetmaxdisk(FVECT ocent, OBJREC *op);
00181 extern double rgetmaxdisk(FVECT ocent, OBJREC *op);
00182 extern double fgetplaneq(FVECT nvec, OBJREC *op);
00183 extern double rgetplaneq(FVECT nvec, OBJREC *op);
00184 extern int    commonspot(SPOT *sp1, SPOT *sp2, FVECT org);
00185 extern int    commonbeam(SPOT *sp1, SPOT *sp2, FVECT org);
00186 extern int    checkspot(SPOT *sp, FVECT nrm);
00187 extern double spotdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT pos);
00188 extern double beamdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT dir);
00189 extern double intercircle(FVECT cc, FVECT c1, FVECT c2,
00190                      double r1s, double r2s);
00191                                    /* defined in virtuals.c */
00192 extern void   markvirtuals(void);
00193 extern void   addvirtuals(int sn, int nr);
00194 extern void   vproject(OBJREC *o, int sn, int n);
00195 extern OBJREC *vsmaterial(OBJREC *o);
00196 extern int    makevsrc(OBJREC *op, int sn, MAT4 pm);
00197 extern double getdisk(FVECT oc, OBJREC *op, int sn);
00198 extern int    vstestvis(int f, OBJREC *o, FVECT oc, double or2, int sn);
00199 extern void   virtverb(int sn, FILE *fp);
00200 
00201 
00202 #ifdef __cplusplus
00203 }
00204 #endif
00205 #endif /* _RAD_SOURCE_H_ */
00206