ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rtrace.c
(Generate patch)

Comparing ray/src/rt/rtrace.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:41:37 1989 UTC vs.
Revision 2.2 by greg, Thu Dec 19 14:54:53 1991 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16   *      xorg    yorg    zorg    xdir    ydir    zdir
17   *
18   *  The direction need not be normalized.  Output is flexible.
19 + *  If the direction vector is (0,0,0), then the output is flushed.
20   *  All values default to ascii representation of real
21   *  numbers.  Binary representations can be selected
22   *  with '-ff' for float or '-fd' for double.  By default,
23 < *  radiance is computed.  The '-i' option indicates that
23 > *  radiance is computed.  The '-i' or '-I' options indicate that
24   *  irradiance values are desired.
25   */
26  
27   #include  "ray.h"
28  
29 + #include  "octree.h"
30 +
31   #include  "otypes.h"
32  
33 + int  dimlist[MAXDIM];                   /* sampling dimensions */
34 + int  ndims = 0;                         /* number of sampling dimensions */
35 + int  samplendx = 0;                     /* index for this sample */
36 +
37 + int  imm_irrad = 0;                     /* compute immediate irradiance? */
38 +
39   int  inform = 'a';                      /* input format */
40   int  outform = 'a';                     /* output format */
41   char  *outvals = "v";                   /* output specification */
# Line 35 | Line 44 | int  hresolu = 0;                      /* horizontal (scan) size */
44   int  vresolu = 0;                       /* vertical resolution */
45  
46   double  dstrsrc = 0.0;                  /* square source distribution */
47 + double  shadthresh = .05;               /* shadow threshold */
48 + double  shadcert = .5;                  /* shadow certainty */
49 + int  directrelay = 1;                   /* number of source relays */
50 + int  vspretest = 512;                   /* virtual source pretest density */
51 + int  directinvis = 0;                   /* sources invisible? */
52 + double  srcsizerat = .25;               /* maximum ratio source size/dist. */
53  
54   int  maxdepth = 6;                      /* maximum recursion depth */
55   double  minweight = 4e-3;               /* minimum ray weight */
56  
57   COLOR  ambval = BLKCOLOR;               /* ambient value */
58   double  ambacc = 0.2;                   /* ambient accuracy */
59 < int  ambres = 128;                      /* ambient resolution */
59 > int  ambres = 32;                       /* ambient resolution */
60   int  ambdiv = 128;                      /* ambient divisions */
61   int  ambssamp = 0;                      /* ambient super-samples */
62   int  ambounce = 0;                      /* ambient bounces */
63   char  *amblist[128];                    /* ambient include/exclude list */
64   int  ambincl = -1;                      /* include == 1, exclude == 0 */
65  
66 + extern OBJREC  Lamb;                    /* a Lambertian surface */
67 +
68   static RAY  thisray;                    /* for our convenience */
69  
70 < extern int  oputo(), oputd(), oputv(), oputl(),
70 > static int  oputo(), oputd(), oputv(), oputl(),
71                  oputp(), oputn(), oputs(), oputw(), oputm();
72  
73   static int  (*ray_out[10])(), (*every_out[10])();
74 + static int  castonly;
75  
76 < extern int  puta(), putf(), putd();
76 > static int  puta(), putf(), putd();
77  
78   static int  (*putreal)();
79  
# Line 73 | Line 91 | char  *fname;
91          long  vcount = hresolu>1 ? hresolu*vresolu : vresolu;
92          long  nextflush = hresolu;
93          FILE  *fp;
94 <        FVECT  orig, direc, vcol;
94 >        FVECT  orig, direc;
95                                          /* set up input */
96          if (fname == NULL)
97                  fp = stdin;
# Line 92 | Line 110 | char  *fname;
110          while (getvec(orig, inform, fp) == 0 &&
111                          getvec(direc, inform, fp) == 0) {
112  
113 <                if (normalize(direc) == 0.0)
114 <                        error(USER, "zero direction vector");
113 >                if (normalize(direc) == 0.0) {          /* zero ==> flush */
114 >                        fflush(stdout);
115 >                        continue;
116 >                }
117 >                samplendx++;
118                                                          /* compute and print */
119 <                if (outvals[0] == 'i')
119 >                if (imm_irrad)
120                          irrad(orig, direc);
121                  else
122 <                        radiance(orig, direc);
123 <                                                        /* flush if requested */
122 >                        traceray(orig, direc);
123 >                                                        /* flush if time */
124                  if (--nextflush == 0) {
125                          fflush(stdout);
126                          nextflush = hresolu;
# Line 121 | Line 142 | register char  *vs;
142          extern int  ourtrace(), (*trace)();
143          register int (**table)() = ray_out;
144  
145 +        castonly = 1;
146          while (*vs)
147                  switch (*vs++) {
148                  case 't':                               /* trace */
149                          *table = NULL;
150                          table = every_out;
151                          trace = ourtrace;
152 +                        castonly = 0;
153                          break;
154                  case 'o':                               /* origin */
155                          *table++ = oputo;
# Line 136 | Line 159 | register char  *vs;
159                          break;
160                  case 'v':                               /* value */
161                          *table++ = oputv;
162 +                        castonly = 0;
163                          break;
164                  case 'l':                               /* length */
165                          *table++ = oputl;
166 +                        castonly = 0;
167                          break;
168                  case 'p':                               /* point */
169                          *table++ = oputp;
# Line 160 | Line 185 | register char  *vs;
185   }
186  
187  
188 < radiance(org, dir)              /* compute radiance value */
188 > traceray(org, dir)              /* compute and print ray value(s) */
189   FVECT  org, dir;
190   {
191          register int  (**tp)();
# Line 168 | Line 193 | FVECT  org, dir;
193          VCOPY(thisray.rorg, org);
194          VCOPY(thisray.rdir, dir);
195          rayorigin(&thisray, NULL, PRIMARY, 1.0);
196 <        rayvalue(&thisray);
196 >        if (castonly)
197 >                localhit(&thisray, &thescene) || sourcehit(&thisray);
198 >        else
199 >                rayvalue(&thisray);
200  
201          if (ray_out[0] == NULL)
202                  return;
# Line 179 | Line 207 | FVECT  org, dir;
207   }
208  
209  
210 < irrad(org, dir)                 /* compute irradiance value */
210 > irrad(org, dir)                 /* compute immediate irradiance value */
211   FVECT  org, dir;
212   {
185        static double  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
186        static OBJREC  Lamb = {
187                OVOID, MAT_PLASTIC, "Lambertian",
188                {0, 5, NULL, Lambfa}, NULL, -1,
189        };
213          register int  i;
214  
215          for (i = 0; i < 3; i++) {
# Line 213 | Line 236 | register FVECT  vec;
236   int  fmt;
237   FILE  *fp;
238   {
239 +        extern char  *fgetword();
240          static float  vf[3];
241 +        char  buf[32];
242 +        register int  i;
243  
244          switch (fmt) {
245          case 'a':                                       /* ascii */
246 <                if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3)
247 <                        return(-1);
246 >                for (i = 0; i < 3; i++) {
247 >                        if (fgetword(buf, sizeof(buf), fp) == NULL ||
248 >                                        !isflt(buf))
249 >                                return(-1);
250 >                        vec[i] = atof(buf);
251 >                }
252                  break;
253          case 'f':                                       /* binary float */
254 <                if (fread(vf, sizeof(float), 3, fp) != 3)
254 >                if (fread((char *)vf, sizeof(float), 3, fp) != 3)
255                          return(-1);
256                  vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2];
257                  break;
258          case 'd':                                       /* binary double */
259 <                if (fread(vec, sizeof(double), 3, fp) != 3)
259 >                if (fread((char *)vec, sizeof(double), 3, fp) != 3)
260                          return(-1);
261                  break;
262          }
# Line 294 | Line 324 | static
324   oputl(r)                                /* print length */
325   register RAY  *r;
326   {
327 <        if (r->rot < FHUGE)
298 <                (*putreal)(r->rot);
299 <        else
300 <                (*putreal)(0.0);
327 >        (*putreal)(r->rt);
328   }
329  
330  
# Line 377 | Line 404 | static
404   putd(v)                         /* print binary double */
405   double  v;
406   {
407 <        fwrite(&v, sizeof(v), 1, stdout);
407 >        fwrite((char *)&v, sizeof(v), 1, stdout);
408   }
409  
410  
# Line 387 | Line 414 | double  v;
414   {
415          float f = v;
416  
417 <        fwrite(&f, sizeof(f), 1, stdout);
417 >        fwrite((char *)&f, sizeof(f), 1, stdout);
418   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines