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.19 by greg, Mon Aug 21 10:29:20 1995 UTC vs.
Revision 2.29 by greg, Fri Apr 18 17:29:22 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 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 26 | Line 23 | static char SCCSid[] = "$SunId$ LBL";
23  
24   #include  "ray.h"
25  
29 #include  "octree.h"
30
26   #include  "otypes.h"
27  
28   #include  "resolu.h"
29  
30 + CUBE  thescene;                         /* our scene */
31 + OBJECT  nsceneobjs;                     /* number of objects in our scene */
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 + int  lim_dist = 0;                      /* limit distance? */
39  
40   int  inform = 'a';                      /* input format */
41   int  outform = 'a';                     /* output format */
42   char  *outvals = "v";                   /* output specification */
43  
44 + int  do_irrad = 0;                      /* compute irradiance? */
45 +
46 + void  (*trace)() = NULL;                /* trace call */
47 +
48 + extern void  ambnotify(), tranotify();
49 + void  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
50   char  *tralist[128];                    /* list of modifers to trace (or no) */
51   int  traincl = -1;                      /* include == 1, exclude == 0 */
52   #define  MAXTSET        511             /* maximum number in trace set */
# Line 58 | Line 63 | int  vspretest = 512;                  /* virtual source pretest dens
63   int  directvis = 1;                     /* sources visible? */
64   double  srcsizerat = .2;                /* maximum ratio source size/dist. */
65  
66 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
67 + COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
68 + double  seccg = 0.;                     /* global scattering eccentricity */
69 + double  ssampdist = 0.;                 /* scatter sampling distance */
70 +
71   double  specthresh = .15;               /* specular sampling threshold */
72   double  specjitter = 1.;                /* specular sampling jitter */
73  
# Line 66 | Line 76 | int  backvis = 1;                      /* back face visibility */
76   int  maxdepth = 6;                      /* maximum recursion depth */
77   double  minweight = 4e-3;               /* minimum ray weight */
78  
79 + char  *ambfile = NULL;                  /* ambient file name */
80   COLOR  ambval = BLKCOLOR;               /* ambient value */
81 + int  ambvwt = 0;                        /* initial weight for ambient value */
82   double  ambacc = 0.2;                   /* ambient accuracy */
83   int  ambres = 128;                      /* ambient resolution */
84   int  ambdiv = 512;                      /* ambient divisions */
# Line 75 | Line 87 | int  ambounce = 0;                     /* ambient bounces */
87   char  *amblist[128];                    /* ambient include/exclude list */
88   int  ambincl = -1;                      /* include == 1, exclude == 0 */
89  
78 extern OBJREC  Lamb;                    /* a Lambertian surface */
90  
91   static RAY  thisray;                    /* for our convenience */
92  
93 < static int  oputo(), oputd(), oputv(), oputl(), oputL(),
93 > static void  oputo(), oputd(), oputv(), oputl(), oputL(), oputc(),
94                  oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
95  
96 < static int  ourtrace(), tabin();
97 < static int  (*ray_out[16])(), (*every_out[16])();
96 > static void  ourtrace(), tabin();
97 > static void  (*ray_out[16])(), (*every_out[16])();
98   static int  castonly = 0;
99  
100 < static int  puta(), putf(), putd();
100 > static void  puta(), putf(), putd();
101  
102 < static int  (*putreal)();
102 > static void  (*putreal)();
103  
104 + void    bogusray(), rad(), irrad(), printvals();
105  
106 +
107 + void
108   quit(code)                      /* quit program */
109   int  code;
110   {
# Line 116 | Line 130 | int  f;
130   }
131  
132  
133 + void
134   rtrace(fname)                           /* trace rays from file */
135   char  *fname;
136   {
137          long  vcount = hresolu>1 ? hresolu*vresolu : vresolu;
138          long  nextflush = hresolu;
139          FILE  *fp;
140 +        double  d;
141          FVECT  orig, direc;
142                                          /* set up input */
143          if (fname == NULL)
# Line 156 | Line 172 | char  *fname;
172          while (getvec(orig, inform, fp) == 0 &&
173                          getvec(direc, inform, fp) == 0) {
174  
175 <                if (normalize(direc) == 0.0) {          /* zero ==> flush */
176 <                        fflush(stdout);
177 <                        continue;
178 <                }
179 <                samplendx++;
175 >                d = normalize(direc);
176 >                if (d == 0.0) {                         /* zero ==> flush */
177 >                        bogusray();
178 >                        if (--nextflush <= 0 || vcount <= 0) {
179 >                                fflush(stdout);
180 >                                nextflush = hresolu;
181 >                        }
182 >                } else {
183 >                        samplendx++;
184                                                          /* compute and print */
185 <                if (imm_irrad)
186 <                        irrad(orig, direc);
187 <                else
188 <                        rad(orig, direc);
185 >                        if (imm_irrad)
186 >                                irrad(orig, direc);
187 >                        else
188 >                                rad(orig, direc, lim_dist ? d : 0.0);
189                                                          /* flush if time */
190 <                if (--nextflush == 0) {
191 <                        fflush(stdout);
192 <                        nextflush = hresolu;
190 >                        if (--nextflush == 0) {
191 >                                fflush(stdout);
192 >                                nextflush = hresolu;
193 >                        }
194                  }
195                  if (ferror(stdout))
196                          error(SYSTEM, "write error");
# Line 187 | Line 208 | char  *fname;
208   setoutput(vs)                           /* set up output tables */
209   register char  *vs;
210   {
211 <        extern int  (*trace)();
212 <        register int (**table)() = ray_out;
211 >        extern void  (*trace)();
212 >        register void (**table)() = ray_out;
213  
214          castonly = 1;
215          while (*vs)
# Line 213 | Line 234 | register char  *vs;
234                          *table++ = oputl;
235                          castonly = 0;
236                          break;
237 +                case 'c':                               /* local coordinates */
238 +                        *table++ = oputc;
239 +                        break;
240                  case 'L':                               /* single ray length */
241                          *table++ = oputL;
242                          break;
# Line 240 | Line 264 | register char  *vs;
264   }
265  
266  
267 < rad(org, dir)                   /* compute and print ray value(s) */
267 > void
268 > bogusray()                      /* print out empty record */
269 > {
270 >        thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
271 >        thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
272 >        rayorigin(&thisray, NULL, PRIMARY, 1.0);
273 >        printvals(&thisray);
274 > }
275 >
276 >
277 > void
278 > rad(org, dir, dmax)             /* compute and print ray value(s) */
279   FVECT  org, dir;
280 + double  dmax;
281   {
282          VCOPY(thisray.rorg, org);
283          VCOPY(thisray.rdir, dir);
284 <        thisray.rmax = 0.0;
284 >        thisray.rmax = dmax;
285          rayorigin(&thisray, NULL, PRIMARY, 1.0);
286 <        if (castonly)
287 <                localhit(&thisray, &thescene) || sourcehit(&thisray);
288 <        else
286 >        if (castonly) {
287 >                if (!localhit(&thisray, &thescene))
288 >                        if (thisray.ro == &Aftplane) {  /* clipped */
289 >                                thisray.ro = NULL;
290 >                                thisray.rot = FHUGE;
291 >                        } else
292 >                                sourcehit(&thisray);
293 >        } else
294                  rayvalue(&thisray);
295          printvals(&thisray);
296   }
297  
298  
299 + void
300   irrad(org, dir)                 /* compute immediate irradiance value */
301   FVECT  org, dir;
302   {
# Line 277 | Line 319 | FVECT  org, dir;
319   }
320  
321  
322 + void
323   printvals(r)                    /* print requested ray values */
324   RAY  *r;
325   {
326 <        register int  (**tp)();
326 >        register void  (**tp)();
327  
328          if (ray_out[0] == NULL)
329                  return;
# Line 291 | Line 334 | RAY  *r;
334   }
335  
336  
337 + int
338   getvec(vec, fmt, fp)            /* get a vector from fp */
339   register FVECT  vec;
340   int  fmt;
341   FILE  *fp;
342   {
299        extern char  *fgetword();
343          static float  vf[3];
344          static double  vd[3];
345          char  buf[32];
# Line 328 | Line 371 | FILE  *fp;
371   }
372  
373  
374 + void
375   tranotify(obj)                  /* record new modifier */
376   OBJECT  obj;
377   {
# Line 335 | Line 379 | OBJECT obj;
379          register OBJREC  *o = objptr(obj);
380          register char  **tralp;
381  
382 +        if (obj == OVOID) {             /* starting over */
383 +                traset[0] = 0;
384 +                hitlimit = 0;
385 +                return;
386 +        }
387          if (hitlimit || !ismodifier(o->otype))
388                  return;
389          for (tralp = tralist; *tralp != NULL; tralp++)
# Line 350 | Line 399 | OBJECT obj;
399   }
400  
401  
402 < static
402 > static void
403   ourtrace(r)                             /* print ray values */
404   RAY  *r;
405   {
406 <        register int  (**tp)();
406 >        register void  (**tp)();
407  
408          if (every_out[0] == NULL)
409                  return;
# Line 370 | Line 419 | RAY  *r;
419   }
420  
421  
422 < static
422 > static void
423   tabin(r)                                /* tab in appropriate amount */
424   RAY  *r;
425   {
# Line 381 | Line 430 | RAY  *r;
430   }
431  
432  
433 < static
433 > static void
434   oputo(r)                                /* print origin */
435 < register RAY  *r;
435 > RAY  *r;
436   {
437          (*putreal)(r->rorg[0]);
438          (*putreal)(r->rorg[1]);
# Line 391 | Line 440 | register RAY  *r;
440   }
441  
442  
443 < static
443 > static void
444   oputd(r)                                /* print direction */
445 < register RAY  *r;
445 > RAY  *r;
446   {
447          (*putreal)(r->rdir[0]);
448          (*putreal)(r->rdir[1]);
# Line 401 | Line 450 | register RAY  *r;
450   }
451  
452  
453 < static
453 > static void
454   oputv(r)                                /* print value */
455 < register RAY  *r;
455 > RAY  *r;
456   {
457          COLR  cout;
458          
# Line 420 | Line 469 | register RAY  *r;
469   }
470  
471  
472 < static
472 > static void
473   oputl(r)                                /* print effective distance */
474 < register RAY  *r;
474 > RAY  *r;
475   {
476          (*putreal)(r->rt);
477   }
478  
479  
480 < static
480 > static void
481   oputL(r)                                /* print single ray length */
482 < register RAY  *r;
482 > RAY  *r;
483   {
484          (*putreal)(r->rot);
485   }
486  
487  
488 < static
488 > static void
489 > oputc(r)                                /* print local coordinates */
490 > RAY  *r;
491 > {
492 >        (*putreal)(r->uv[0]);
493 >        (*putreal)(r->uv[1]);
494 > }
495 >
496 >
497 > static void
498   oputp(r)                                /* print point */
499 < register RAY  *r;
499 > RAY  *r;
500   {
501          if (r->rot < FHUGE) {
502                  (*putreal)(r->rop[0]);
# Line 452 | Line 510 | register RAY  *r;
510   }
511  
512  
513 < static
513 > static void
514   oputN(r)                                /* print unperturbed normal */
515 < register RAY  *r;
515 > RAY  *r;
516   {
517          if (r->rot < FHUGE) {
518                  (*putreal)(r->ron[0]);
# Line 468 | Line 526 | register RAY  *r;
526   }
527  
528  
529 < static
529 > static void
530   oputn(r)                                /* print perturbed normal */
531   RAY  *r;
532   {
# Line 487 | Line 545 | RAY  *r;
545   }
546  
547  
548 < static
548 > static void
549   oputs(r)                                /* print name */
550 < register RAY  *r;
550 > RAY  *r;
551   {
552          if (r->ro != NULL)
553                  fputs(r->ro->oname, stdout);
# Line 499 | Line 557 | register RAY  *r;
557   }
558  
559  
560 < static
560 > static void
561   oputw(r)                                /* print weight */
562 < register RAY  *r;
562 > RAY  *r;
563   {
564          (*putreal)(r->rweight);
565   }
566  
567  
568 < static
568 > static void
569   oputm(r)                                /* print modifier */
570 < register RAY  *r;
570 > RAY  *r;
571   {
572          if (r->ro != NULL)
573 <                fputs(objptr(r->ro->omod)->oname, stdout);
573 >                if (r->ro->omod != OVOID)
574 >                        fputs(objptr(r->ro->omod)->oname, stdout);
575 >                else
576 >                        fputs(VOIDID, stdout);
577          else
578                  putchar('*');
579          putchar('\t');
580   }
581  
582  
583 < static
583 > static void
584   puta(v)                         /* print ascii value */
585   double  v;
586   {
# Line 527 | Line 588 | double  v;
588   }
589  
590  
591 < static
591 > static void
592   putd(v)                         /* print binary double */
593   double  v;
594   {
# Line 535 | Line 596 | double  v;
596   }
597  
598  
599 < static
599 > static void
600   putf(v)                         /* print binary float */
601   double  v;
602   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines