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.11 by greg, Sat Aug 18 10:34:47 1990 UTC vs.
Revision 2.22 by greg, Wed Apr 17 14:02:09 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1995 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  
# Line 30 | Line 30 | static char SCCSid[] = "$SunId$ LBL";
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 */
44  
45 + char  *tralist[128];                    /* list of modifers to trace (or no) */
46 + int  traincl = -1;                      /* include == 1, exclude == 0 */
47 + #define  MAXTSET        511             /* maximum number in trace set */
48 + OBJECT  traset[MAXTSET+1]={0};          /* trace include/exclude set */
49 +
50   int  hresolu = 0;                       /* horizontal (scan) size */
51   int  vresolu = 0;                       /* vertical resolution */
52  
53   double  dstrsrc = 0.0;                  /* square source distribution */
54   double  shadthresh = .05;               /* shadow threshold */
55   double  shadcert = .5;                  /* shadow certainty */
56 + int  directrelay = 2;                   /* number of source relays */
57 + int  vspretest = 512;                   /* virtual source pretest density */
58 + int  directvis = 1;                     /* sources visible? */
59 + double  srcsizerat = .2;                /* maximum ratio source size/dist. */
60  
61 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
62 + COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
63 + double  seccg = 0.;                     /* global scattering eccentricity */
64 + double  ssampdist = 0.;                 /* scatter sampling distance */
65 +
66 + double  specthresh = .15;               /* specular sampling threshold */
67 + double  specjitter = 1.;                /* specular sampling jitter */
68 +
69 + int  backvis = 1;                       /* back face visibility */
70 +
71   int  maxdepth = 6;                      /* maximum recursion depth */
72   double  minweight = 4e-3;               /* minimum ray weight */
73  
74   COLOR  ambval = BLKCOLOR;               /* ambient value */
75 + int  ambvwt = 0;                        /* initial weight for ambient value */
76   double  ambacc = 0.2;                   /* ambient accuracy */
77 < int  ambres = 32;                       /* ambient resolution */
78 < int  ambdiv = 128;                      /* ambient divisions */
77 > int  ambres = 128;                      /* ambient resolution */
78 > int  ambdiv = 512;                      /* ambient divisions */
79   int  ambssamp = 0;                      /* ambient super-samples */
80   int  ambounce = 0;                      /* ambient bounces */
81   char  *amblist[128];                    /* ambient include/exclude list */
82   int  ambincl = -1;                      /* include == 1, exclude == 0 */
83  
84 + extern OBJREC  Lamb;                    /* a Lambertian surface */
85 +
86   static RAY  thisray;                    /* for our convenience */
87  
88 < static int  oputo(), oputd(), oputv(), oputl(),
89 <                oputp(), oputn(), oputs(), oputw(), oputm();
88 > static int  oputo(), oputd(), oputv(), oputl(), oputL(),
89 >                oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
90  
91 < static int  (*ray_out[10])(), (*every_out[10])();
92 < static int  castonly;
91 > static int  ourtrace(), tabin();
92 > static int  (*ray_out[16])(), (*every_out[16])();
93 > static int  castonly = 0;
94  
95   static int  puta(), putf(), putd();
96  
# Line 69 | Line 100 | static int  (*putreal)();
100   quit(code)                      /* quit program */
101   int  code;
102   {
103 + #ifndef  NIX
104 +        headclean();            /* delete header file */
105 +        pfclean();              /* clean up persist files */
106 + #endif
107          exit(code);
108   }
109  
110  
111 + char *
112 + formstr(f)                              /* return format identifier */
113 + int  f;
114 + {
115 +        switch (f) {
116 +        case 'a': return("ascii");
117 +        case 'f': return("float");
118 +        case 'd': return("double");
119 +        case 'c': return(COLRFMT);
120 +        }
121 +        return("unknown");
122 + }
123 +
124 +
125   rtrace(fname)                           /* trace rays from file */
126   char  *fname;
127   {
# Line 87 | Line 136 | char  *fname;
136                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
137                  error(SYSTEM, errmsg);
138          }
139 + #ifdef MSDOS
140 +        if (inform != 'a')
141 +                setmode(fileno(fp), O_BINARY);
142 + #endif
143                                          /* set up output */
144          setoutput(outvals);
145          switch (outform) {
146          case 'a': putreal = puta; break;
147          case 'f': putreal = putf; break;
148          case 'd': putreal = putd; break;
149 +        case 'c':
150 +                if (strcmp(outvals, "v"))
151 +                        error(USER, "color format with value output only");
152 +                break;
153 +        default:
154 +                error(CONSISTENCY, "botched output format");
155          }
156 +        if (hresolu > 0) {
157 +                if (vresolu > 0)
158 +                        fprtresolu(hresolu, vresolu, stdout);
159 +                fflush(stdout);
160 +        }
161                                          /* process file */
162          while (getvec(orig, inform, fp) == 0 &&
163                          getvec(direc, inform, fp) == 0) {
# Line 102 | Line 166 | char  *fname;
166                          fflush(stdout);
167                          continue;
168                  }
169 +                samplendx++;
170                                                          /* compute and print */
171 <                if (outvals[0] == 'i')
171 >                if (imm_irrad)
172                          irrad(orig, direc);
173                  else
174 <                        radiance(orig, direc);
174 >                        rad(orig, direc);
175                                                          /* flush if time */
176                  if (--nextflush == 0) {
177                          fflush(stdout);
# Line 117 | Line 182 | char  *fname;
182                  if (--vcount == 0)                      /* check for end */
183                          break;
184          }
185 +        fflush(stdout);
186          if (vcount > 0)
187                  error(USER, "read error");
188 <        fclose(fp);
188 >        if (fname != NULL)
189 >                fclose(fp);
190   }
191  
192  
193   setoutput(vs)                           /* set up output tables */
194   register char  *vs;
195   {
196 <        extern int  ourtrace(), (*trace)();
196 >        extern int  (*trace)();
197          register int (**table)() = ray_out;
198  
199          castonly = 1;
# Line 148 | Line 215 | register char  *vs;
215                          *table++ = oputv;
216                          castonly = 0;
217                          break;
218 <                case 'l':                               /* length */
218 >                case 'l':                               /* effective distance */
219                          *table++ = oputl;
220                          castonly = 0;
221                          break;
222 +                case 'L':                               /* single ray length */
223 +                        *table++ = oputL;
224 +                        break;
225                  case 'p':                               /* point */
226                          *table++ = oputp;
227                          break;
228 <                case 'n':                               /* normal */
228 >                case 'n':                               /* perturbed normal */
229                          *table++ = oputn;
230 +                        castonly = 0;
231                          break;
232 +                case 'N':                               /* unperturbed normal */
233 +                        *table++ = oputN;
234 +                        break;
235                  case 's':                               /* surface */
236                          *table++ = oputs;
237                          break;
# Line 172 | Line 246 | register char  *vs;
246   }
247  
248  
249 < radiance(org, dir)              /* compute radiance value */
249 > rad(org, dir)                   /* compute and print ray value(s) */
250   FVECT  org, dir;
251   {
178        register int  (**tp)();
179
252          VCOPY(thisray.rorg, org);
253          VCOPY(thisray.rdir, dir);
254 +        thisray.rmax = 0.0;
255          rayorigin(&thisray, NULL, PRIMARY, 1.0);
256          if (castonly)
257                  localhit(&thisray, &thescene) || sourcehit(&thisray);
258          else
259                  rayvalue(&thisray);
260 <
188 <        if (ray_out[0] == NULL)
189 <                return;
190 <        for (tp = ray_out; *tp != NULL; tp++)
191 <                (**tp)(&thisray);
192 <        if (outform == 'a')
193 <                putchar('\n');
260 >        printvals(&thisray);
261   }
262  
263  
264 < irrad(org, dir)                 /* compute irradiance value */
264 > irrad(org, dir)                 /* compute immediate irradiance value */
265   FVECT  org, dir;
266   {
200        static double  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
201        static OBJREC  Lamb = {
202                OVOID, MAT_PLASTIC, "Lambertian",
203                {0, 5, NULL, Lambfa}, NULL, -1,
204        };
267          register int  i;
268  
269          for (i = 0; i < 3; i++) {
# Line 210 | Line 272 | FVECT  org, dir;
272          }
273          rayorigin(&thisray, NULL, PRIMARY, 1.0);
274                                          /* pretend we hit surface */
275 <        thisray.rot = 1.0;
275 >        thisray.rot = 1.0-1e-4;
276          thisray.rod = 1.0;
277          VCOPY(thisray.ron, dir);
278          for (i = 0; i < 3; i++)         /* fudge factor */
279                  thisray.rop[i] = org[i] + 1e-4*dir[i];
280                                          /* compute and print */
281          (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
282 <        oputv(&thisray);
282 >        printvals(&thisray);
283 > }
284 >
285 >
286 > printvals(r)                    /* print requested ray values */
287 > RAY  *r;
288 > {
289 >        register int  (**tp)();
290 >
291 >        if (ray_out[0] == NULL)
292 >                return;
293 >        for (tp = ray_out; *tp != NULL; tp++)
294 >                (**tp)(r);
295          if (outform == 'a')
296                  putchar('\n');
297   }
# Line 228 | Line 302 | register FVECT  vec;
302   int  fmt;
303   FILE  *fp;
304   {
305 +        extern char  *fgetword();
306          static float  vf[3];
307 +        static double  vd[3];
308 +        char  buf[32];
309 +        register int  i;
310  
311          switch (fmt) {
312          case 'a':                                       /* ascii */
313 <                if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3)
314 <                        return(-1);
313 >                for (i = 0; i < 3; i++) {
314 >                        if (fgetword(buf, sizeof(buf), fp) == NULL ||
315 >                                        !isflt(buf))
316 >                                return(-1);
317 >                        vec[i] = atof(buf);
318 >                }
319                  break;
320          case 'f':                                       /* binary float */
321                  if (fread((char *)vf, sizeof(float), 3, fp) != 3)
# Line 241 | Line 323 | FILE  *fp;
323                  vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2];
324                  break;
325          case 'd':                                       /* binary double */
326 <                if (fread((char *)vec, sizeof(double), 3, fp) != 3)
326 >                if (fread((char *)vd, sizeof(double), 3, fp) != 3)
327                          return(-1);
328 +                vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2];
329                  break;
330 +        default:
331 +                error(CONSISTENCY, "botched input format");
332          }
333          return(0);
334   }
335  
336  
337 + tranotify(obj)                  /* record new modifier */
338 + OBJECT  obj;
339 + {
340 +        static int  hitlimit = 0;
341 +        register OBJREC  *o = objptr(obj);
342 +        register char  **tralp;
343 +
344 +        if (hitlimit || !ismodifier(o->otype))
345 +                return;
346 +        for (tralp = tralist; *tralp != NULL; tralp++)
347 +                if (!strcmp(o->oname, *tralp)) {
348 +                        if (traset[0] >= MAXTSET) {
349 +                                error(WARNING, "too many modifiers in trace list");
350 +                                hitlimit++;
351 +                                return;         /* should this be fatal? */
352 +                        }
353 +                        insertelem(traset, obj);
354 +                        return;
355 +                }
356 + }
357 +
358 +
359   static
360   ourtrace(r)                             /* print ray values */
361   RAY  *r;
# Line 257 | Line 364 | RAY  *r;
364  
365          if (every_out[0] == NULL)
366                  return;
367 +        if (r->ro == NULL) {
368 +                if (traincl == 1)
369 +                        return;
370 +        } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
371 +                return;
372          tabin(r);
373          for (tp = every_out; *tp != NULL; tp++)
374                  (**tp)(r);
# Line 299 | Line 411 | static
411   oputv(r)                                /* print value */
412   register RAY  *r;
413   {
414 +        COLR  cout;
415 +        
416 +        if (outform == 'c') {
417 +                setcolr(cout,   colval(r->rcol,RED),
418 +                                colval(r->rcol,GRN),
419 +                                colval(r->rcol,BLU));
420 +                fwrite((char *)cout, sizeof(cout), 1, stdout);
421 +                return;
422 +        }
423          (*putreal)(colval(r->rcol,RED));
424          (*putreal)(colval(r->rcol,GRN));
425          (*putreal)(colval(r->rcol,BLU));
# Line 306 | Line 427 | register RAY  *r;
427  
428  
429   static
430 < oputl(r)                                /* print length */
430 > oputl(r)                                /* print effective distance */
431   register RAY  *r;
432   {
433          (*putreal)(r->rt);
# Line 314 | Line 435 | register RAY  *r;
435  
436  
437   static
438 + oputL(r)                                /* print single ray length */
439 + register RAY  *r;
440 + {
441 +        (*putreal)(r->rot);
442 + }
443 +
444 +
445 + static
446   oputp(r)                                /* print point */
447   register RAY  *r;
448   {
# Line 330 | Line 459 | register RAY  *r;
459  
460  
461   static
462 < oputn(r)                                /* print normal */
462 > oputN(r)                                /* print unperturbed normal */
463   register RAY  *r;
464   {
465          if (r->rot < FHUGE) {
# Line 342 | Line 471 | register RAY  *r;
471                  (*putreal)(0.0);
472                  (*putreal)(0.0);
473          }
474 + }
475 +
476 +
477 + static
478 + oputn(r)                                /* print perturbed normal */
479 + RAY  *r;
480 + {
481 +        FVECT  pnorm;
482 +
483 +        if (r->rot >= FHUGE) {
484 +                (*putreal)(0.0);
485 +                (*putreal)(0.0);
486 +                (*putreal)(0.0);
487 +                return;
488 +        }
489 +        raynormal(pnorm, r);
490 +        (*putreal)(pnorm[0]);
491 +        (*putreal)(pnorm[1]);
492 +        (*putreal)(pnorm[2]);
493   }
494  
495  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines