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.16 by greg, Mon Jun 24 16:16:54 1991 UTC vs.
Revision 2.19 by greg, Mon Aug 21 10:29:20 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1994 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# 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 */
# Line 40 | Line 42 | 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 = 0;                   /* number of source relays */
57 < int  vspretest = 128;                   /* virtual source pretest density */
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 + double  specthresh = .15;               /* specular sampling threshold */
62 + double  specjitter = 1.;                /* specular sampling jitter */
63 +
64 + int  backvis = 1;                       /* back face visibility */
65 +
66   int  maxdepth = 6;                      /* maximum recursion depth */
67   double  minweight = 4e-3;               /* minimum ray weight */
68  
69   COLOR  ambval = BLKCOLOR;               /* ambient value */
70   double  ambacc = 0.2;                   /* ambient accuracy */
71 < int  ambres = 32;                       /* ambient resolution */
72 < int  ambdiv = 128;                      /* ambient divisions */
71 > int  ambres = 128;                      /* ambient resolution */
72 > int  ambdiv = 512;                      /* ambient divisions */
73   int  ambssamp = 0;                      /* ambient super-samples */
74   int  ambounce = 0;                      /* ambient bounces */
75   char  *amblist[128];                    /* ambient include/exclude list */
# Line 65 | Line 79 | extern OBJREC  Lamb;                   /* a Lambertian surface */
79  
80   static RAY  thisray;                    /* for our convenience */
81  
82 < static int  oputo(), oputd(), oputv(), oputl(),
83 <                oputp(), oputn(), oputs(), oputw(), oputm();
82 > static int  oputo(), oputd(), oputv(), oputl(), oputL(),
83 >                oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
84  
85 < static int  (*ray_out[10])(), (*every_out[10])();
86 < static int  castonly;
85 > static int  ourtrace(), tabin();
86 > static int  (*ray_out[16])(), (*every_out[16])();
87 > static int  castonly = 0;
88  
89   static int  puta(), putf(), putd();
90  
# Line 79 | Line 94 | static int  (*putreal)();
94   quit(code)                      /* quit program */
95   int  code;
96   {
97 + #ifndef  NIX
98 +        headclean();            /* delete header file */
99 +        pfclean();              /* clean up persist files */
100 + #endif
101          exit(code);
102   }
103  
104  
105 + char *
106 + formstr(f)                              /* return format identifier */
107 + int  f;
108 + {
109 +        switch (f) {
110 +        case 'a': return("ascii");
111 +        case 'f': return("float");
112 +        case 'd': return("double");
113 +        case 'c': return(COLRFMT);
114 +        }
115 +        return("unknown");
116 + }
117 +
118 +
119   rtrace(fname)                           /* trace rays from file */
120   char  *fname;
121   {
# Line 97 | Line 130 | char  *fname;
130                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
131                  error(SYSTEM, errmsg);
132          }
133 + #ifdef MSDOS
134 +        if (inform != 'a')
135 +                setmode(fileno(fp), O_BINARY);
136 + #endif
137                                          /* set up output */
138          setoutput(outvals);
139          switch (outform) {
140          case 'a': putreal = puta; break;
141          case 'f': putreal = putf; break;
142          case 'd': putreal = putd; break;
143 +        case 'c':
144 +                if (strcmp(outvals, "v"))
145 +                        error(USER, "color format with value output only");
146 +                break;
147 +        default:
148 +                error(CONSISTENCY, "botched output format");
149          }
150 +        if (hresolu > 0) {
151 +                if (vresolu > 0)
152 +                        fprtresolu(hresolu, vresolu, stdout);
153 +                fflush(stdout);
154 +        }
155                                          /* process file */
156          while (getvec(orig, inform, fp) == 0 &&
157                          getvec(direc, inform, fp) == 0) {
# Line 117 | Line 165 | char  *fname;
165                  if (imm_irrad)
166                          irrad(orig, direc);
167                  else
168 <                        traceray(orig, direc);
168 >                        rad(orig, direc);
169                                                          /* flush if time */
170                  if (--nextflush == 0) {
171                          fflush(stdout);
# Line 128 | Line 176 | char  *fname;
176                  if (--vcount == 0)                      /* check for end */
177                          break;
178          }
179 +        fflush(stdout);
180          if (vcount > 0)
181                  error(USER, "read error");
182 <        fclose(fp);
182 >        if (fname != NULL)
183 >                fclose(fp);
184   }
185  
186  
187   setoutput(vs)                           /* set up output tables */
188   register char  *vs;
189   {
190 <        extern int  ourtrace(), (*trace)();
190 >        extern int  (*trace)();
191          register int (**table)() = ray_out;
192  
193          castonly = 1;
# Line 159 | Line 209 | register char  *vs;
209                          *table++ = oputv;
210                          castonly = 0;
211                          break;
212 <                case 'l':                               /* length */
212 >                case 'l':                               /* effective distance */
213                          *table++ = oputl;
214                          castonly = 0;
215                          break;
216 +                case 'L':                               /* single ray length */
217 +                        *table++ = oputL;
218 +                        break;
219                  case 'p':                               /* point */
220                          *table++ = oputp;
221                          break;
222 <                case 'n':                               /* normal */
222 >                case 'n':                               /* perturbed normal */
223                          *table++ = oputn;
224 +                        castonly = 0;
225                          break;
226 +                case 'N':                               /* unperturbed normal */
227 +                        *table++ = oputN;
228 +                        break;
229                  case 's':                               /* surface */
230                          *table++ = oputs;
231                          break;
# Line 183 | Line 240 | register char  *vs;
240   }
241  
242  
243 < traceray(org, dir)              /* compute and print ray value(s) */
243 > rad(org, dir)                   /* compute and print ray value(s) */
244   FVECT  org, dir;
245   {
189        register int  (**tp)();
190
246          VCOPY(thisray.rorg, org);
247          VCOPY(thisray.rdir, dir);
248 +        thisray.rmax = 0.0;
249          rayorigin(&thisray, NULL, PRIMARY, 1.0);
250          if (castonly)
251                  localhit(&thisray, &thescene) || sourcehit(&thisray);
252          else
253                  rayvalue(&thisray);
254 <
199 <        if (ray_out[0] == NULL)
200 <                return;
201 <        for (tp = ray_out; *tp != NULL; tp++)
202 <                (**tp)(&thisray);
203 <        if (outform == 'a')
204 <                putchar('\n');
254 >        printvals(&thisray);
255   }
256  
257  
# Line 216 | Line 266 | FVECT  org, dir;
266          }
267          rayorigin(&thisray, NULL, PRIMARY, 1.0);
268                                          /* pretend we hit surface */
269 <        thisray.rot = 1.0;
269 >        thisray.rot = 1.0-1e-4;
270          thisray.rod = 1.0;
271          VCOPY(thisray.ron, dir);
272          for (i = 0; i < 3; i++)         /* fudge factor */
273                  thisray.rop[i] = org[i] + 1e-4*dir[i];
274                                          /* compute and print */
275          (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
276 <        oputv(&thisray);
276 >        printvals(&thisray);
277 > }
278 >
279 >
280 > printvals(r)                    /* print requested ray values */
281 > RAY  *r;
282 > {
283 >        register int  (**tp)();
284 >
285 >        if (ray_out[0] == NULL)
286 >                return;
287 >        for (tp = ray_out; *tp != NULL; tp++)
288 >                (**tp)(r);
289          if (outform == 'a')
290                  putchar('\n');
291   }
# Line 234 | Line 296 | register FVECT  vec;
296   int  fmt;
297   FILE  *fp;
298   {
299 +        extern char  *fgetword();
300          static float  vf[3];
301 +        static double  vd[3];
302 +        char  buf[32];
303 +        register int  i;
304  
305          switch (fmt) {
306          case 'a':                                       /* ascii */
307 <                if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3)
308 <                        return(-1);
307 >                for (i = 0; i < 3; i++) {
308 >                        if (fgetword(buf, sizeof(buf), fp) == NULL ||
309 >                                        !isflt(buf))
310 >                                return(-1);
311 >                        vec[i] = atof(buf);
312 >                }
313                  break;
314          case 'f':                                       /* binary float */
315                  if (fread((char *)vf, sizeof(float), 3, fp) != 3)
# Line 247 | Line 317 | FILE  *fp;
317                  vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2];
318                  break;
319          case 'd':                                       /* binary double */
320 <                if (fread((char *)vec, sizeof(double), 3, fp) != 3)
320 >                if (fread((char *)vd, sizeof(double), 3, fp) != 3)
321                          return(-1);
322 +                vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2];
323                  break;
324 +        default:
325 +                error(CONSISTENCY, "botched input format");
326          }
327          return(0);
328   }
329  
330  
331 + tranotify(obj)                  /* record new modifier */
332 + OBJECT  obj;
333 + {
334 +        static int  hitlimit = 0;
335 +        register OBJREC  *o = objptr(obj);
336 +        register char  **tralp;
337 +
338 +        if (hitlimit || !ismodifier(o->otype))
339 +                return;
340 +        for (tralp = tralist; *tralp != NULL; tralp++)
341 +                if (!strcmp(o->oname, *tralp)) {
342 +                        if (traset[0] >= MAXTSET) {
343 +                                error(WARNING, "too many modifiers in trace list");
344 +                                hitlimit++;
345 +                                return;         /* should this be fatal? */
346 +                        }
347 +                        insertelem(traset, obj);
348 +                        return;
349 +                }
350 + }
351 +
352 +
353   static
354   ourtrace(r)                             /* print ray values */
355   RAY  *r;
# Line 263 | Line 358 | RAY  *r;
358  
359          if (every_out[0] == NULL)
360                  return;
361 +        if (r->ro == NULL) {
362 +                if (traincl == 1)
363 +                        return;
364 +        } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
365 +                return;
366          tabin(r);
367          for (tp = every_out; *tp != NULL; tp++)
368                  (**tp)(r);
# Line 305 | Line 405 | static
405   oputv(r)                                /* print value */
406   register RAY  *r;
407   {
408 +        COLR  cout;
409 +        
410 +        if (outform == 'c') {
411 +                setcolr(cout,   colval(r->rcol,RED),
412 +                                colval(r->rcol,GRN),
413 +                                colval(r->rcol,BLU));
414 +                fwrite((char *)cout, sizeof(cout), 1, stdout);
415 +                return;
416 +        }
417          (*putreal)(colval(r->rcol,RED));
418          (*putreal)(colval(r->rcol,GRN));
419          (*putreal)(colval(r->rcol,BLU));
# Line 312 | Line 421 | register RAY  *r;
421  
422  
423   static
424 < oputl(r)                                /* print length */
424 > oputl(r)                                /* print effective distance */
425   register RAY  *r;
426   {
427          (*putreal)(r->rt);
# Line 320 | Line 429 | register RAY  *r;
429  
430  
431   static
432 + oputL(r)                                /* print single ray length */
433 + register RAY  *r;
434 + {
435 +        (*putreal)(r->rot);
436 + }
437 +
438 +
439 + static
440   oputp(r)                                /* print point */
441   register RAY  *r;
442   {
# Line 336 | Line 453 | register RAY  *r;
453  
454  
455   static
456 < oputn(r)                                /* print normal */
456 > oputN(r)                                /* print unperturbed normal */
457   register RAY  *r;
458   {
459          if (r->rot < FHUGE) {
# Line 348 | Line 465 | register RAY  *r;
465                  (*putreal)(0.0);
466                  (*putreal)(0.0);
467          }
468 + }
469 +
470 +
471 + static
472 + oputn(r)                                /* print perturbed normal */
473 + RAY  *r;
474 + {
475 +        FVECT  pnorm;
476 +
477 +        if (r->rot >= FHUGE) {
478 +                (*putreal)(0.0);
479 +                (*putreal)(0.0);
480 +                (*putreal)(0.0);
481 +                return;
482 +        }
483 +        raynormal(pnorm, r);
484 +        (*putreal)(pnorm[0]);
485 +        (*putreal)(pnorm[1]);
486 +        (*putreal)(pnorm[2]);
487   }
488  
489  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines