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 2.14 by greg, Tue May 4 13:26:52 1993 UTC vs.
Revision 2.31 by schorsch, Mon Jun 30 14:59:12 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  rtrace.c - program and variables for individual ray tracing.
9 *
10 *     6/11/86
6   */
7  
8 + #include "copyright.h"
9 +
10   /*
11   *  Input is in the form:
12   *
# Line 24 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21   *  irradiance values are desired.
22   */
23  
24 + #include  "platform.h"
25   #include  "ray.h"
28
29 #include  "octree.h"
30
26   #include  "otypes.h"
32
27   #include  "resolu.h"
28  
29 + CUBE  thescene;                         /* our scene */
30 + OBJECT  nsceneobjs;                     /* number of objects in our scene */
31 +
32   int  dimlist[MAXDIM];                   /* sampling dimensions */
33   int  ndims = 0;                         /* number of sampling dimensions */
34   int  samplendx = 0;                     /* index for this sample */
35  
36   int  imm_irrad = 0;                     /* compute immediate irradiance? */
37 + int  lim_dist = 0;                      /* limit distance? */
38  
39   int  inform = 'a';                      /* input format */
40   int  outform = 'a';                     /* output format */
41   char  *outvals = "v";                   /* output specification */
42  
43 + int  do_irrad = 0;                      /* compute irradiance? */
44 +
45 + void  (*trace)() = NULL;                /* trace call */
46 +
47 + extern void  ambnotify(), tranotify();
48 + void  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
49 + char  *tralist[128];                    /* list of modifers to trace (or no) */
50 + int  traincl = -1;                      /* include == 1, exclude == 0 */
51 + #define  MAXTSET        511             /* maximum number in trace set */
52 + OBJECT  traset[MAXTSET+1]={0};          /* trace include/exclude set */
53 +
54   int  hresolu = 0;                       /* horizontal (scan) size */
55   int  vresolu = 0;                       /* vertical resolution */
56  
57   double  dstrsrc = 0.0;                  /* square source distribution */
58   double  shadthresh = .05;               /* shadow threshold */
59   double  shadcert = .5;                  /* shadow certainty */
60 < int  directrelay = 1;                   /* number of source relays */
60 > int  directrelay = 2;                   /* number of source relays */
61   int  vspretest = 512;                   /* virtual source pretest density */
62   int  directvis = 1;                     /* sources visible? */
63 < double  srcsizerat = .25;               /* maximum ratio source size/dist. */
63 > double  srcsizerat = .2;                /* maximum ratio source size/dist. */
64  
65 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
66 + COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
67 + double  seccg = 0.;                     /* global scattering eccentricity */
68 + double  ssampdist = 0.;                 /* scatter sampling distance */
69 +
70   double  specthresh = .15;               /* specular sampling threshold */
71   double  specjitter = 1.;                /* specular sampling jitter */
72  
73 + int  backvis = 1;                       /* back face visibility */
74 +
75   int  maxdepth = 6;                      /* maximum recursion depth */
76   double  minweight = 4e-3;               /* minimum ray weight */
77  
78 + char  *ambfile = NULL;                  /* ambient file name */
79   COLOR  ambval = BLKCOLOR;               /* ambient value */
80 + int  ambvwt = 0;                        /* initial weight for ambient value */
81   double  ambacc = 0.2;                   /* ambient accuracy */
82 < int  ambres = 32;                       /* ambient resolution */
83 < int  ambdiv = 128;                      /* ambient divisions */
82 > int  ambres = 128;                      /* ambient resolution */
83 > int  ambdiv = 512;                      /* ambient divisions */
84   int  ambssamp = 0;                      /* ambient super-samples */
85   int  ambounce = 0;                      /* ambient bounces */
86   char  *amblist[128];                    /* ambient include/exclude list */
87   int  ambincl = -1;                      /* include == 1, exclude == 0 */
88  
71 extern OBJREC  Lamb;                    /* a Lambertian surface */
89  
90   static RAY  thisray;                    /* for our convenience */
91  
92 < static int  oputo(), oputd(), oputv(), oputl(), oputL(),
92 > static void  oputo(), oputd(), oputv(), oputl(), oputL(), oputc(),
93                  oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
94  
95 < static int  ourtrace(), tabin();
96 < static int  (*ray_out[16])(), (*every_out[16])();
95 > static void  ourtrace(), tabin();
96 > static void  (*ray_out[16])(), (*every_out[16])();
97   static int  castonly = 0;
98  
99 < static int  puta(), putf(), putd();
99 > static void  puta(), putf(), putd();
100  
101 < static int  (*putreal)();
101 > static void  (*putreal)();
102  
103 + void    bogusray(), rad(), irrad(), printvals();
104  
105 +
106 + void
107   quit(code)                      /* quit program */
108   int  code;
109   {
110 < #ifndef  NIX
110 > #ifndef  NON_POSIX /* XXX we don't clean up elsewhere? */
111          headclean();            /* delete header file */
112          pfclean();              /* clean up persist files */
113   #endif
# Line 109 | Line 129 | int  f;
129   }
130  
131  
132 + void
133   rtrace(fname)                           /* trace rays from file */
134   char  *fname;
135   {
136          long  vcount = hresolu>1 ? hresolu*vresolu : vresolu;
137          long  nextflush = hresolu;
138          FILE  *fp;
139 +        double  d;
140          FVECT  orig, direc;
141                                          /* set up input */
142          if (fname == NULL)
# Line 123 | Line 145 | char  *fname;
145                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
146                  error(SYSTEM, errmsg);
147          }
148 < #ifdef MSDOS
148 > #ifdef _WIN32
149          if (inform != 'a')
150 <                setmode(fileno(fp), O_BINARY);
150 >                SET_FILE_BINARY(fp);
151   #endif
152                                          /* set up output */
153 <        if (imm_irrad)
132 <                outvals = "v";
133 <        else
134 <                setoutput(outvals);
153 >        setoutput(outvals);
154          switch (outform) {
155          case 'a': putreal = puta; break;
156          case 'f': putreal = putf; break;
# Line 152 | Line 171 | char  *fname;
171          while (getvec(orig, inform, fp) == 0 &&
172                          getvec(direc, inform, fp) == 0) {
173  
174 <                if (normalize(direc) == 0.0) {          /* zero ==> flush */
175 <                        fflush(stdout);
176 <                        continue;
177 <                }
178 <                samplendx++;
174 >                d = normalize(direc);
175 >                if (d == 0.0) {                         /* zero ==> flush */
176 >                        bogusray();
177 >                        if (--nextflush <= 0 || vcount <= 0) {
178 >                                fflush(stdout);
179 >                                nextflush = hresolu;
180 >                        }
181 >                } else {
182 >                        samplendx++;
183                                                          /* compute and print */
184 <                if (imm_irrad)
185 <                        irrad(orig, direc);
186 <                else
187 <                        traceray(orig, direc);
184 >                        if (imm_irrad)
185 >                                irrad(orig, direc);
186 >                        else
187 >                                rad(orig, direc, lim_dist ? d : 0.0);
188                                                          /* flush if time */
189 <                if (--nextflush == 0) {
190 <                        fflush(stdout);
191 <                        nextflush = hresolu;
189 >                        if (--nextflush == 0) {
190 >                                fflush(stdout);
191 >                                nextflush = hresolu;
192 >                        }
193                  }
194                  if (ferror(stdout))
195                          error(SYSTEM, "write error");
# Line 183 | Line 207 | char  *fname;
207   setoutput(vs)                           /* set up output tables */
208   register char  *vs;
209   {
210 <        extern int  (*trace)();
211 <        register int (**table)() = ray_out;
210 >        extern void  (*trace)();
211 >        register void (**table)() = ray_out;
212  
213          castonly = 1;
214          while (*vs)
# Line 209 | Line 233 | register char  *vs;
233                          *table++ = oputl;
234                          castonly = 0;
235                          break;
236 +                case 'c':                               /* local coordinates */
237 +                        *table++ = oputc;
238 +                        break;
239                  case 'L':                               /* single ray length */
240                          *table++ = oputL;
241                          break;
# Line 236 | Line 263 | register char  *vs;
263   }
264  
265  
266 < traceray(org, dir)              /* compute and print ray value(s) */
267 < FVECT  org, dir;
266 > void
267 > bogusray()                      /* print out empty record */
268   {
269 <        register int  (**tp)();
269 >        thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
270 >        thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
271 >        rayorigin(&thisray, NULL, PRIMARY, 1.0);
272 >        printvals(&thisray);
273 > }
274  
275 +
276 + void
277 + rad(org, dir, dmax)             /* compute and print ray value(s) */
278 + FVECT  org, dir;
279 + double  dmax;
280 + {
281          VCOPY(thisray.rorg, org);
282          VCOPY(thisray.rdir, dir);
283 +        thisray.rmax = dmax;
284          rayorigin(&thisray, NULL, PRIMARY, 1.0);
285 <        if (castonly)
286 <                localhit(&thisray, &thescene) || sourcehit(&thisray);
287 <        else
285 >        if (castonly) {
286 >                if (!localhit(&thisray, &thescene))
287 >                        if (thisray.ro == &Aftplane) {  /* clipped */
288 >                                thisray.ro = NULL;
289 >                                thisray.rot = FHUGE;
290 >                        } else
291 >                                sourcehit(&thisray);
292 >        } else
293                  rayvalue(&thisray);
294 <
252 <        if (ray_out[0] == NULL)
253 <                return;
254 <        for (tp = ray_out; *tp != NULL; tp++)
255 <                (**tp)(&thisray);
256 <        if (outform == 'a')
257 <                putchar('\n');
294 >        printvals(&thisray);
295   }
296  
297  
298 + void
299   irrad(org, dir)                 /* compute immediate irradiance value */
300   FVECT  org, dir;
301   {
# Line 269 | Line 307 | FVECT  org, dir;
307          }
308          rayorigin(&thisray, NULL, PRIMARY, 1.0);
309                                          /* pretend we hit surface */
310 <        thisray.rot = 1.0;
310 >        thisray.rot = 1.0-1e-4;
311          thisray.rod = 1.0;
312          VCOPY(thisray.ron, dir);
313          for (i = 0; i < 3; i++)         /* fudge factor */
314                  thisray.rop[i] = org[i] + 1e-4*dir[i];
315                                          /* compute and print */
316          (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
317 <        oputv(&thisray);
317 >        printvals(&thisray);
318 > }
319 >
320 >
321 > void
322 > printvals(r)                    /* print requested ray values */
323 > RAY  *r;
324 > {
325 >        register void  (**tp)();
326 >
327 >        if (ray_out[0] == NULL)
328 >                return;
329 >        for (tp = ray_out; *tp != NULL; tp++)
330 >                (**tp)(r);
331          if (outform == 'a')
332                  putchar('\n');
333   }
334  
335  
336 + int
337   getvec(vec, fmt, fp)            /* get a vector from fp */
338   register FVECT  vec;
339   int  fmt;
340   FILE  *fp;
341   {
290        extern char  *fgetword();
342          static float  vf[3];
343          static double  vd[3];
344          char  buf[32];
# Line 319 | Line 370 | FILE  *fp;
370   }
371  
372  
373 < static
373 > void
374 > tranotify(obj)                  /* record new modifier */
375 > OBJECT  obj;
376 > {
377 >        static int  hitlimit = 0;
378 >        register OBJREC  *o = objptr(obj);
379 >        register char  **tralp;
380 >
381 >        if (obj == OVOID) {             /* starting over */
382 >                traset[0] = 0;
383 >                hitlimit = 0;
384 >                return;
385 >        }
386 >        if (hitlimit || !ismodifier(o->otype))
387 >                return;
388 >        for (tralp = tralist; *tralp != NULL; tralp++)
389 >                if (!strcmp(o->oname, *tralp)) {
390 >                        if (traset[0] >= MAXTSET) {
391 >                                error(WARNING, "too many modifiers in trace list");
392 >                                hitlimit++;
393 >                                return;         /* should this be fatal? */
394 >                        }
395 >                        insertelem(traset, obj);
396 >                        return;
397 >                }
398 > }
399 >
400 >
401 > static void
402   ourtrace(r)                             /* print ray values */
403   RAY  *r;
404   {
405 <        register int  (**tp)();
405 >        register void  (**tp)();
406  
407          if (every_out[0] == NULL)
408                  return;
409 +        if (r->ro == NULL) {
410 +                if (traincl == 1)
411 +                        return;
412 +        } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
413 +                return;
414          tabin(r);
415          for (tp = every_out; *tp != NULL; tp++)
416                  (**tp)(r);
# Line 334 | Line 418 | RAY  *r;
418   }
419  
420  
421 < static
421 > static void
422   tabin(r)                                /* tab in appropriate amount */
423   RAY  *r;
424   {
# Line 345 | Line 429 | RAY  *r;
429   }
430  
431  
432 < static
432 > static void
433   oputo(r)                                /* print origin */
434 < register RAY  *r;
434 > RAY  *r;
435   {
436          (*putreal)(r->rorg[0]);
437          (*putreal)(r->rorg[1]);
# Line 355 | Line 439 | register RAY  *r;
439   }
440  
441  
442 < static
442 > static void
443   oputd(r)                                /* print direction */
444 < register RAY  *r;
444 > RAY  *r;
445   {
446          (*putreal)(r->rdir[0]);
447          (*putreal)(r->rdir[1]);
# Line 365 | Line 449 | register RAY  *r;
449   }
450  
451  
452 < static
452 > static void
453   oputv(r)                                /* print value */
454 < register RAY  *r;
454 > RAY  *r;
455   {
456          COLR  cout;
457          
# Line 384 | Line 468 | register RAY  *r;
468   }
469  
470  
471 < static
471 > static void
472   oputl(r)                                /* print effective distance */
473 < register RAY  *r;
473 > RAY  *r;
474   {
475          (*putreal)(r->rt);
476   }
477  
478  
479 < static
479 > static void
480   oputL(r)                                /* print single ray length */
481 < register RAY  *r;
481 > RAY  *r;
482   {
483          (*putreal)(r->rot);
484   }
485  
486  
487 < static
487 > static void
488 > oputc(r)                                /* print local coordinates */
489 > RAY  *r;
490 > {
491 >        (*putreal)(r->uv[0]);
492 >        (*putreal)(r->uv[1]);
493 > }
494 >
495 >
496 > static void
497   oputp(r)                                /* print point */
498 < register RAY  *r;
498 > RAY  *r;
499   {
500          if (r->rot < FHUGE) {
501                  (*putreal)(r->rop[0]);
# Line 416 | Line 509 | register RAY  *r;
509   }
510  
511  
512 < static
512 > static void
513   oputN(r)                                /* print unperturbed normal */
514 < register RAY  *r;
514 > RAY  *r;
515   {
516          if (r->rot < FHUGE) {
517                  (*putreal)(r->ron[0]);
# Line 432 | Line 525 | register RAY  *r;
525   }
526  
527  
528 < static
528 > static void
529   oputn(r)                                /* print perturbed normal */
530   RAY  *r;
531   {
# Line 451 | Line 544 | RAY  *r;
544   }
545  
546  
547 < static
547 > static void
548   oputs(r)                                /* print name */
549 < register RAY  *r;
549 > RAY  *r;
550   {
551          if (r->ro != NULL)
552                  fputs(r->ro->oname, stdout);
# Line 463 | Line 556 | register RAY  *r;
556   }
557  
558  
559 < static
559 > static void
560   oputw(r)                                /* print weight */
561 < register RAY  *r;
561 > RAY  *r;
562   {
563          (*putreal)(r->rweight);
564   }
565  
566  
567 < static
567 > static void
568   oputm(r)                                /* print modifier */
569 < register RAY  *r;
569 > RAY  *r;
570   {
571          if (r->ro != NULL)
572 <                fputs(objptr(r->ro->omod)->oname, stdout);
572 >                if (r->ro->omod != OVOID)
573 >                        fputs(objptr(r->ro->omod)->oname, stdout);
574 >                else
575 >                        fputs(VOIDID, stdout);
576          else
577                  putchar('*');
578          putchar('\t');
579   }
580  
581  
582 < static
582 > static void
583   puta(v)                         /* print ascii value */
584   double  v;
585   {
# Line 491 | Line 587 | double  v;
587   }
588  
589  
590 < static
590 > static void
591   putd(v)                         /* print binary double */
592   double  v;
593   {
# Line 499 | Line 595 | double  v;
595   }
596  
597  
598 < static
598 > static void
599   putf(v)                         /* print binary float */
600   double  v;
601   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines