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.7 by greg, Thu Jan 4 11:16:05 1990 UTC vs.
Revision 2.8 by greg, Thu Oct 15 21:13:21 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
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 + #include  "resolu.h"
34 +
35 + int  dimlist[MAXDIM];                   /* sampling dimensions */
36 + int  ndims = 0;                         /* number of sampling dimensions */
37 + int  samplendx = 0;                     /* index for this sample */
38 +
39 + int  imm_irrad = 0;                     /* compute immediate irradiance? */
40 +
41   int  inform = 'a';                      /* input format */
42   int  outform = 'a';                     /* output format */
43   char  *outvals = "v";                   /* output specification */
# Line 38 | Line 48 | int  vresolu = 0;                      /* vertical resolution */
48   double  dstrsrc = 0.0;                  /* square source distribution */
49   double  shadthresh = .05;               /* shadow threshold */
50   double  shadcert = .5;                  /* shadow certainty */
51 + int  directrelay = 1;                   /* number of source relays */
52 + int  vspretest = 512;                   /* virtual source pretest density */
53 + int  directinvis = 0;                   /* sources invisible? */
54 + double  srcsizerat = .25;               /* maximum ratio source size/dist. */
55  
56 + double  specthresh = .15;               /* specular sampling threshold */
57 + double  specjitter = 1.;                /* specular sampling jitter */
58 +
59   int  maxdepth = 6;                      /* maximum recursion depth */
60   double  minweight = 4e-3;               /* minimum ray weight */
61  
# Line 51 | Line 68 | int  ambounce = 0;                     /* ambient bounces */
68   char  *amblist[128];                    /* ambient include/exclude list */
69   int  ambincl = -1;                      /* include == 1, exclude == 0 */
70  
71 + extern OBJREC  Lamb;                    /* a Lambertian surface */
72 +
73   static RAY  thisray;                    /* for our convenience */
74  
75 < extern int  oputo(), oputd(), oputv(), oputl(),
75 > static int  oputo(), oputd(), oputv(), oputl(), oputL(),
76                  oputp(), oputn(), oputs(), oputw(), oputm();
77  
78   static int  (*ray_out[10])(), (*every_out[10])();
79 + static int  castonly;
80  
81 < extern int  puta(), putf(), putd();
81 > static int  puta(), putf(), putd();
82  
83   static int  (*putreal)();
84  
# Line 70 | Line 90 | int  code;
90   }
91  
92  
93 + char *
94 + formstr(f)                              /* return format identifier */
95 + int  f;
96 + {
97 +        switch (f) {
98 +        case 'a': return("ascii");
99 +        case 'f': return("float");
100 +        case 'd': return("double");
101 +        case 'c': return(COLRFMT);
102 +        }
103 +        return("unknown");
104 + }
105 +
106 +
107   rtrace(fname)                           /* trace rays from file */
108   char  *fname;
109   {
# Line 84 | Line 118 | char  *fname;
118                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
119                  error(SYSTEM, errmsg);
120          }
121 + #ifdef MSDOS
122 +        if (inform != 'a')
123 +                setmode(fileno(fp), O_BINARY);
124 + #endif
125                                          /* set up output */
126          setoutput(outvals);
127          switch (outform) {
128          case 'a': putreal = puta; break;
129          case 'f': putreal = putf; break;
130          case 'd': putreal = putd; break;
131 +        case 'c':
132 +                if (strcmp(outvals, "v"))
133 +                        error(USER, "color format with value output only");
134 +                break;
135 +        default:
136 +                error(CONSISTENCY, "botched output format");
137          }
138 +        if (hresolu > 0 && vresolu > 0)
139 +                fprtresolu(hresolu, vresolu, stdout);
140                                          /* process file */
141          while (getvec(orig, inform, fp) == 0 &&
142                          getvec(direc, inform, fp) == 0) {
# Line 99 | Line 145 | char  *fname;
145                          fflush(stdout);
146                          continue;
147                  }
148 +                samplendx++;
149                                                          /* compute and print */
150 <                if (outvals[0] == 'i')
150 >                if (imm_irrad)
151                          irrad(orig, direc);
152                  else
153 <                        radiance(orig, direc);
153 >                        traceray(orig, direc);
154                                                          /* flush if time */
155                  if (--nextflush == 0) {
156                          fflush(stdout);
# Line 126 | Line 173 | register char  *vs;
173          extern int  ourtrace(), (*trace)();
174          register int (**table)() = ray_out;
175  
176 +        castonly = 1;
177          while (*vs)
178                  switch (*vs++) {
179                  case 't':                               /* trace */
180                          *table = NULL;
181                          table = every_out;
182                          trace = ourtrace;
183 +                        castonly = 0;
184                          break;
185                  case 'o':                               /* origin */
186                          *table++ = oputo;
# Line 141 | Line 190 | register char  *vs;
190                          break;
191                  case 'v':                               /* value */
192                          *table++ = oputv;
193 +                        castonly = 0;
194                          break;
195 <                case 'l':                               /* length */
195 >                case 'l':                               /* effective distance */
196                          *table++ = oputl;
197 +                        castonly = 0;
198                          break;
199 +                case 'L':                               /* single ray length */
200 +                        *table++ = oputL;
201 +                        break;
202                  case 'p':                               /* point */
203                          *table++ = oputp;
204                          break;
# Line 165 | Line 219 | register char  *vs;
219   }
220  
221  
222 < radiance(org, dir)              /* compute radiance value */
222 > traceray(org, dir)              /* compute and print ray value(s) */
223   FVECT  org, dir;
224   {
225          register int  (**tp)();
# Line 173 | Line 227 | FVECT  org, dir;
227          VCOPY(thisray.rorg, org);
228          VCOPY(thisray.rdir, dir);
229          rayorigin(&thisray, NULL, PRIMARY, 1.0);
230 <        rayvalue(&thisray);
230 >        if (castonly)
231 >                localhit(&thisray, &thescene) || sourcehit(&thisray);
232 >        else
233 >                rayvalue(&thisray);
234  
235          if (ray_out[0] == NULL)
236                  return;
# Line 184 | Line 241 | FVECT  org, dir;
241   }
242  
243  
244 < irrad(org, dir)                 /* compute irradiance value */
244 > irrad(org, dir)                 /* compute immediate irradiance value */
245   FVECT  org, dir;
246   {
190        static double  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
191        static OBJREC  Lamb = {
192                OVOID, MAT_PLASTIC, "Lambertian",
193                {0, 5, NULL, Lambfa}, NULL, -1,
194        };
247          register int  i;
248  
249          for (i = 0; i < 3; i++) {
# Line 218 | Line 270 | register FVECT  vec;
270   int  fmt;
271   FILE  *fp;
272   {
273 +        extern char  *fgetword();
274          static float  vf[3];
275 +        static double  vd[3];
276 +        char  buf[32];
277 +        register int  i;
278  
279          switch (fmt) {
280          case 'a':                                       /* ascii */
281 <                if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3)
282 <                        return(-1);
281 >                for (i = 0; i < 3; i++) {
282 >                        if (fgetword(buf, sizeof(buf), fp) == NULL ||
283 >                                        !isflt(buf))
284 >                                return(-1);
285 >                        vec[i] = atof(buf);
286 >                }
287                  break;
288          case 'f':                                       /* binary float */
289 <                if (fread(vf, sizeof(float), 3, fp) != 3)
289 >                if (fread((char *)vf, sizeof(float), 3, fp) != 3)
290                          return(-1);
291                  vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2];
292                  break;
293          case 'd':                                       /* binary double */
294 <                if (fread(vec, sizeof(double), 3, fp) != 3)
294 >                if (fread((char *)vd, sizeof(double), 3, fp) != 3)
295                          return(-1);
296 +                vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2];
297                  break;
298 +        default:
299 +                error(CONSISTENCY, "botched input format");
300          }
301          return(0);
302   }
# Line 289 | Line 352 | static
352   oputv(r)                                /* print value */
353   register RAY  *r;
354   {
355 +        COLR  cout;
356 +        
357 +        if (outform == 'c') {
358 +                setcolr(cout,   colval(r->rcol,RED),
359 +                                colval(r->rcol,GRN),
360 +                                colval(r->rcol,BLU));
361 +                fwrite((char *)cout, sizeof(cout), 1, stdout);
362 +                return;
363 +        }
364          (*putreal)(colval(r->rcol,RED));
365          (*putreal)(colval(r->rcol,GRN));
366          (*putreal)(colval(r->rcol,BLU));
# Line 296 | Line 368 | register RAY  *r;
368  
369  
370   static
371 < oputl(r)                                /* print length */
371 > oputl(r)                                /* print effective distance */
372   register RAY  *r;
373   {
374 <        if (r->rot < FHUGE)
303 <                (*putreal)(r->rot);
304 <        else
305 <                (*putreal)(0.0);
374 >        (*putreal)(r->rt);
375   }
376  
377  
378   static
379 + oputL(r)                                /* print single ray length */
380 + register RAY  *r;
381 + {
382 +        (*putreal)(r->rot);
383 + }
384 +
385 +
386 + static
387   oputp(r)                                /* print point */
388   register RAY  *r;
389   {
# Line 382 | Line 459 | static
459   putd(v)                         /* print binary double */
460   double  v;
461   {
462 <        fwrite(&v, sizeof(v), 1, stdout);
462 >        fwrite((char *)&v, sizeof(v), 1, stdout);
463   }
464  
465  
# Line 392 | Line 469 | double  v;
469   {
470          float f = v;
471  
472 <        fwrite(&f, sizeof(f), 1, stdout);
472 >        fwrite((char *)&f, sizeof(f), 1, stdout);
473   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines