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.25 by gregl, Fri Oct 17 10:14:37 1997 UTC vs.
Revision 2.46 by greg, Fri Jun 10 20:44:00 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
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$ SGI";
21   *  irradiance values are desired.
22   */
23  
24 < #include  "ray.h"
24 > #include  <time.h>
25  
26 < #include  "octree.h"
27 <
26 > #include  "platform.h"
27 > #include  "ray.h"
28 > #include  "ambient.h"
29 > #include  "source.h"
30   #include  "otypes.h"
32
31   #include  "resolu.h"
32  
33 + CUBE  thescene;                         /* our scene */
34 + OBJECT  nsceneobjs;                     /* number of objects in our scene */
35 +
36   int  dimlist[MAXDIM];                   /* sampling dimensions */
37   int  ndims = 0;                         /* number of sampling dimensions */
38   int  samplendx = 0;                     /* index for this sample */
# Line 43 | Line 44 | int  inform = 'a';                     /* input format */
44   int  outform = 'a';                     /* output format */
45   char  *outvals = "v";                   /* output specification */
46  
47 + int  do_irrad = 0;                      /* compute irradiance? */
48 +
49 + void  (*trace)() = NULL;                /* trace call */
50 +
51   char  *tralist[128];                    /* list of modifers to trace (or no) */
52   int  traincl = -1;                      /* include == 1, exclude == 0 */
53 < #define  MAXTSET        511             /* maximum number in trace set */
53 > #ifndef  MAXTSET
54 > #define  MAXTSET        1024            /* maximum number in trace set */
55 > #endif
56   OBJECT  traset[MAXTSET+1]={0};          /* trace include/exclude set */
57  
58   int  hresolu = 0;                       /* horizontal (scan) size */
59   int  vresolu = 0;                       /* vertical resolution */
60  
61   double  dstrsrc = 0.0;                  /* square source distribution */
62 < double  shadthresh = .05;               /* shadow threshold */
63 < double  shadcert = .5;                  /* shadow certainty */
62 > double  shadthresh = .03;               /* shadow threshold */
63 > double  shadcert = .75;                 /* shadow certainty */
64   int  directrelay = 2;                   /* number of source relays */
65   int  vspretest = 512;                   /* virtual source pretest density */
66   int  directvis = 1;                     /* sources visible? */
# Line 69 | Line 76 | double  specjitter = 1.;               /* specular sampling jitter
76  
77   int  backvis = 1;                       /* back face visibility */
78  
79 < int  maxdepth = 6;                      /* maximum recursion depth */
80 < double  minweight = 4e-3;               /* minimum ray weight */
79 > int  maxdepth = -10;                    /* maximum recursion depth */
80 > double  minweight = 2e-3;               /* minimum ray weight */
81  
82 + char  *ambfile = NULL;                  /* ambient file name */
83   COLOR  ambval = BLKCOLOR;               /* ambient value */
84   int  ambvwt = 0;                        /* initial weight for ambient value */
85 < double  ambacc = 0.2;                   /* ambient accuracy */
86 < int  ambres = 128;                      /* ambient resolution */
87 < int  ambdiv = 512;                      /* ambient divisions */
88 < int  ambssamp = 0;                      /* ambient super-samples */
85 > double  ambacc = 0.15;                  /* ambient accuracy */
86 > int  ambres = 256;                      /* ambient resolution */
87 > int  ambdiv = 1024;                     /* ambient divisions */
88 > int  ambssamp = 512;                    /* ambient super-samples */
89   int  ambounce = 0;                      /* ambient bounces */
90 < char  *amblist[128];                    /* ambient include/exclude list */
90 > char  *amblist[AMBLLEN];                /* ambient include/exclude list */
91   int  ambincl = -1;                      /* include == 1, exclude == 0 */
92  
93 < extern OBJREC  Lamb;                    /* a Lambertian surface */
86 < extern OBJREC  Aftplane;                /* aft clipping object */
93 > static int  castonly = 0;
94  
88
95   static RAY  thisray;                    /* for our convenience */
96  
97 < static int  oputo(), oputd(), oputv(), oputl(), oputL(),
98 <                oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
97 > typedef void putf_t(double v);
98 > static putf_t puta, putd, putf;
99  
100 < static int  ourtrace(), tabin();
101 < static int  (*ray_out[16])(), (*every_out[16])();
102 < static int  castonly = 0;
100 > typedef void oputf_t(RAY *r);
101 > static oputf_t  oputo, oputd, oputv, oputl, oputL, oputc, oputp,
102 >                oputn, oputN, oputs, oputw, oputW, oputm, oputM, oputtilde;
103  
104 < static int  puta(), putf(), putd();
104 > static void setoutput(char *vs);
105 > static void tranotify(OBJECT obj);
106 > static void bogusray(void);
107 > static void rad(FVECT  org, FVECT  dir, double  dmax);
108 > static void irrad(FVECT  org, FVECT  dir);
109 > static void printvals(RAY  *r);
110 > static int getvec(FVECT  vec, int  fmt, FILE  *fp);
111 > static void tabin(RAY  *r);
112 > static void ourtrace(RAY  *r);
113  
114 < static int  (*putreal)();
114 > static oputf_t *ray_out[16], *every_out[16];
115 > static putf_t *putreal;
116  
117 + void  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
118  
119 < quit(code)                      /* quit program */
120 < int  code;
119 >
120 > void
121 > quit(                   /* quit program */
122 >        int  code
123 > )
124   {
125 < #ifndef  NIX
125 > #ifndef  NON_POSIX /* XXX we don't clean up elsewhere? */
126          headclean();            /* delete header file */
127          pfclean();              /* clean up persist files */
128   #endif
# Line 111 | Line 130 | int  code;
130   }
131  
132  
133 < char *
134 < formstr(f)                              /* return format identifier */
135 < int  f;
133 > extern char *
134 > formstr(                                /* return format identifier */
135 >        int  f
136 > )
137   {
138          switch (f) {
139          case 'a': return("ascii");
# Line 125 | Line 145 | int  f;
145   }
146  
147  
148 < rtrace(fname)                           /* trace rays from file */
149 < char  *fname;
148 > extern void
149 > rtrace(                         /* trace rays from file */
150 >        char  *fname
151 > )
152   {
153 <        long  vcount = hresolu>1 ? hresolu*vresolu : vresolu;
153 >        unsigned long  vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu
154 >                                              : vresolu;
155          long  nextflush = hresolu;
156          FILE  *fp;
157          double  d;
# Line 140 | Line 163 | char  *fname;
163                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
164                  error(SYSTEM, errmsg);
165          }
143 #ifdef MSDOS
166          if (inform != 'a')
167 <                setmode(fileno(fp), O_BINARY);
146 < #endif
167 >                SET_FILE_BINARY(fp);
168                                          /* set up output */
169          setoutput(outvals);
170          switch (outform) {
# Line 169 | Line 190 | char  *fname;
190                  d = normalize(direc);
191                  if (d == 0.0) {                         /* zero ==> flush */
192                          bogusray();
193 <                        if (--nextflush <= 0) {
193 >                        if (--nextflush <= 0 || !vcount) {
194                                  fflush(stdout);
195                                  nextflush = hresolu;
196                          }
# Line 181 | Line 202 | char  *fname;
202                          else
203                                  rad(orig, direc, lim_dist ? d : 0.0);
204                                                          /* flush if time */
205 <                        if (--nextflush == 0) {
205 >                        if (!--nextflush) {
206                                  fflush(stdout);
207                                  nextflush = hresolu;
208                          }
209                  }
210                  if (ferror(stdout))
211                          error(SYSTEM, "write error");
212 <                if (--vcount == 0)                      /* check for end */
212 >                if (vcount && !--vcount)                /* check for end */
213                          break;
214          }
215          fflush(stdout);
216 <        if (vcount > 0)
217 <                error(USER, "read error");
216 >        if (vcount)
217 >                error(USER, "unexpected EOF on input");
218          if (fname != NULL)
219                  fclose(fp);
220   }
221  
222  
223 < setoutput(vs)                           /* set up output tables */
224 < register char  *vs;
223 > static void
224 > trace_sources(void)                     /* trace rays to light sources, also */
225   {
226 <        extern int  (*trace)();
227 <        register int (**table)() = ray_out;
226 >        int     sn;
227 >        
228 >        for (sn = 0; sn < nsources; sn++)
229 >                source[sn].sflags |= SFOLLOW;
230 > }
231  
232 +
233 + static void
234 + setoutput(                              /* set up output tables */
235 +        register char  *vs
236 + )
237 + {
238 +        register oputf_t **table = ray_out;
239 +
240          castonly = 1;
241          while (*vs)
242                  switch (*vs++) {
243 +                case 'T':                               /* trace sources */
244 +                        if (!*vs) break;
245 +                        trace_sources();
246 +                        /* fall through */
247                  case 't':                               /* trace */
248 +                        if (!*vs) break;
249                          *table = NULL;
250                          table = every_out;
251                          trace = ourtrace;
# Line 228 | Line 265 | register char  *vs;
265                          *table++ = oputl;
266                          castonly = 0;
267                          break;
268 +                case 'c':                               /* local coordinates */
269 +                        *table++ = oputc;
270 +                        break;
271                  case 'L':                               /* single ray length */
272                          *table++ = oputL;
273                          break;
# Line 247 | Line 287 | register char  *vs;
287                  case 'w':                               /* weight */
288                          *table++ = oputw;
289                          break;
290 +                case 'W':                               /* coefficient */
291 +                        *table++ = oputW;
292 +                        if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
293 +                                error(WARNING,
294 +                                        "-otW accuracy depends on -aa 0 -as 0");
295 +                        break;
296                  case 'm':                               /* modifier */
297                          *table++ = oputm;
298                          break;
299 +                case 'M':                               /* material */
300 +                        *table++ = oputM;
301 +                        break;
302 +                case '~':                               /* tilde */
303 +                        *table++ = oputtilde;
304 +                        break;
305                  }
306          *table = NULL;
307   }
308  
309  
310 < bogusray()                      /* print out empty record */
310 > static void
311 > bogusray(void)                  /* print out empty record */
312   {
313          thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
314          thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
315 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
315 >        thisray.rmax = 0.0;
316 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
317          printvals(&thisray);
318   }
319  
320  
321 < rad(org, dir, dmax)             /* compute and print ray value(s) */
322 < FVECT  org, dir;
323 < double  dmax;
321 > static void
322 > rad(            /* compute and print ray value(s) */
323 >        FVECT  org,
324 >        FVECT  dir,
325 >        double  dmax
326 > )
327   {
328          VCOPY(thisray.rorg, org);
329          VCOPY(thisray.rdir, dir);
330          thisray.rmax = dmax;
331 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
331 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
332          if (castonly) {
333 <                if (!localhit(&thisray, &thescene))
333 >                if (!localhit(&thisray, &thescene)) {
334                          if (thisray.ro == &Aftplane) {  /* clipped */
335                                  thisray.ro = NULL;
336                                  thisray.rot = FHUGE;
337                          } else
338                                  sourcehit(&thisray);
339 +                }
340          } else
341                  rayvalue(&thisray);
342          printvals(&thisray);
343   }
344  
345  
346 < irrad(org, dir)                 /* compute immediate irradiance value */
347 < FVECT  org, dir;
346 > static void
347 > irrad(                  /* compute immediate irradiance value */
348 >        FVECT  org,
349 >        FVECT  dir
350 > )
351   {
352          register int  i;
353  
# Line 294 | Line 355 | FVECT  org, dir;
355                  thisray.rorg[i] = org[i] + dir[i];
356                  thisray.rdir[i] = -dir[i];
357          }
358 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
358 >        thisray.rmax = 0.0;
359 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
360                                          /* pretend we hit surface */
361          thisray.rot = 1.0-1e-4;
362          thisray.rod = 1.0;
# Line 307 | Line 369 | FVECT  org, dir;
369   }
370  
371  
372 < printvals(r)                    /* print requested ray values */
373 < RAY  *r;
372 > static void
373 > printvals(                      /* print requested ray values */
374 >        RAY  *r
375 > )
376   {
377 <        register int  (**tp)();
377 >        register oputf_t **tp;
378  
379          if (ray_out[0] == NULL)
380                  return;
# Line 321 | Line 385 | RAY  *r;
385   }
386  
387  
388 < getvec(vec, fmt, fp)            /* get a vector from fp */
389 < register FVECT  vec;
390 < int  fmt;
391 < FILE  *fp;
388 > static int
389 > getvec(         /* get a vector from fp */
390 >        register FVECT  vec,
391 >        int  fmt,
392 >        FILE  *fp
393 > )
394   {
329        extern char  *fgetword();
395          static float  vf[3];
396          static double  vd[3];
397          char  buf[32];
# Line 358 | Line 423 | FILE  *fp;
423   }
424  
425  
426 < tranotify(obj)                  /* record new modifier */
427 < OBJECT  obj;
426 > static void
427 > tranotify(                      /* record new modifier */
428 >        OBJECT  obj
429 > )
430   {
431          static int  hitlimit = 0;
432          register OBJREC  *o = objptr(obj);
433          register char  **tralp;
434  
435 +        if (obj == OVOID) {             /* starting over */
436 +                traset[0] = 0;
437 +                hitlimit = 0;
438 +                return;
439 +        }
440          if (hitlimit || !ismodifier(o->otype))
441                  return;
442          for (tralp = tralist; *tralp != NULL; tralp++)
# Line 380 | Line 452 | OBJECT obj;
452   }
453  
454  
455 < static
456 < ourtrace(r)                             /* print ray values */
457 < RAY  *r;
455 > static void
456 > ourtrace(                               /* print ray values */
457 >        RAY  *r
458 > )
459   {
460 <        register int  (**tp)();
460 >        register oputf_t **tp;
461  
462          if (every_out[0] == NULL)
463                  return;
# Line 396 | Line 469 | RAY  *r;
469          tabin(r);
470          for (tp = every_out; *tp != NULL; tp++)
471                  (**tp)(r);
472 <        putchar('\n');
472 >        if (outform == 'a')
473 >                putchar('\n');
474   }
475  
476  
477 < static
478 < tabin(r)                                /* tab in appropriate amount */
479 < RAY  *r;
477 > static void
478 > tabin(                          /* tab in appropriate amount */
479 >        RAY  *r
480 > )
481   {
482 <        register RAY  *rp;
482 >        const RAY  *rp;
483  
484          for (rp = r->parent; rp != NULL; rp = rp->parent)
485                  putchar('\t');
486   }
487  
488  
489 < static
490 < oputo(r)                                /* print origin */
491 < register RAY  *r;
489 > static void
490 > oputo(                          /* print origin */
491 >        RAY  *r
492 > )
493   {
494          (*putreal)(r->rorg[0]);
495          (*putreal)(r->rorg[1]);
# Line 421 | Line 497 | register RAY  *r;
497   }
498  
499  
500 < static
501 < oputd(r)                                /* print direction */
502 < register RAY  *r;
500 > static void
501 > oputd(                          /* print direction */
502 >        RAY  *r
503 > )
504   {
505          (*putreal)(r->rdir[0]);
506          (*putreal)(r->rdir[1]);
# Line 431 | Line 508 | register RAY  *r;
508   }
509  
510  
511 < static
512 < oputv(r)                                /* print value */
513 < register RAY  *r;
511 > static void
512 > oputv(                          /* print value */
513 >        RAY  *r
514 > )
515   {
438        COLR  cout;
439        
516          if (outform == 'c') {
517 +                COLR  cout;
518                  setcolr(cout,   colval(r->rcol,RED),
519                                  colval(r->rcol,GRN),
520                                  colval(r->rcol,BLU));
# Line 450 | Line 527 | register RAY  *r;
527   }
528  
529  
530 < static
531 < oputl(r)                                /* print effective distance */
532 < register RAY  *r;
530 > static void
531 > oputl(                          /* print effective distance */
532 >        RAY  *r
533 > )
534   {
535          (*putreal)(r->rt);
536   }
537  
538  
539 < static
540 < oputL(r)                                /* print single ray length */
541 < register RAY  *r;
539 > static void
540 > oputL(                          /* print single ray length */
541 >        RAY  *r
542 > )
543   {
544          (*putreal)(r->rot);
545   }
546  
547  
548 < static
549 < oputp(r)                                /* print point */
550 < register RAY  *r;
548 > static void
549 > oputc(                          /* print local coordinates */
550 >        RAY  *r
551 > )
552   {
553 +        (*putreal)(r->uv[0]);
554 +        (*putreal)(r->uv[1]);
555 + }
556 +
557 +
558 + static void
559 + oputp(                          /* print point */
560 +        RAY  *r
561 + )
562 + {
563          if (r->rot < FHUGE) {
564                  (*putreal)(r->rop[0]);
565                  (*putreal)(r->rop[1]);
# Line 482 | Line 572 | register RAY  *r;
572   }
573  
574  
575 < static
576 < oputN(r)                                /* print unperturbed normal */
577 < register RAY  *r;
575 > static void
576 > oputN(                          /* print unperturbed normal */
577 >        RAY  *r
578 > )
579   {
580          if (r->rot < FHUGE) {
581                  (*putreal)(r->ron[0]);
# Line 498 | Line 589 | register RAY  *r;
589   }
590  
591  
592 < static
593 < oputn(r)                                /* print perturbed normal */
594 < RAY  *r;
592 > static void
593 > oputn(                          /* print perturbed normal */
594 >        RAY  *r
595 > )
596   {
597          FVECT  pnorm;
598  
# Line 517 | Line 609 | RAY  *r;
609   }
610  
611  
612 < static
613 < oputs(r)                                /* print name */
614 < register RAY  *r;
612 > static void
613 > oputs(                          /* print name */
614 >        RAY  *r
615 > )
616   {
617          if (r->ro != NULL)
618                  fputs(r->ro->oname, stdout);
# Line 529 | Line 622 | register RAY  *r;
622   }
623  
624  
625 < static
626 < oputw(r)                                /* print weight */
627 < register RAY  *r;
625 > static void
626 > oputw(                          /* print weight */
627 >        RAY  *r
628 > )
629   {
630          (*putreal)(r->rweight);
631   }
632  
633  
634 < static
635 < oputm(r)                                /* print modifier */
636 < register RAY  *r;
634 > static void
635 > oputW(                          /* print contribution */
636 >        RAY  *r
637 > )
638   {
639 +        COLOR   contr;
640 +
641 +        raycontrib(contr, r, PRIMARY);
642 +        (*putreal)(colval(contr,RED));
643 +        (*putreal)(colval(contr,GRN));
644 +        (*putreal)(colval(contr,BLU));
645 + }
646 +
647 +
648 + static void
649 + oputm(                          /* print modifier */
650 +        RAY  *r
651 + )
652 + {
653          if (r->ro != NULL)
654                  if (r->ro->omod != OVOID)
655                          fputs(objptr(r->ro->omod)->oname, stdout);
# Line 552 | Line 661 | register RAY  *r;
661   }
662  
663  
664 < static
665 < puta(v)                         /* print ascii value */
666 < double  v;
664 > static void
665 > oputM(                          /* print material */
666 >        RAY  *r
667 > )
668   {
669 +        OBJREC  *mat;
670 +
671 +        if (r->ro != NULL) {
672 +                if ((mat = findmaterial(r->ro)) != NULL)
673 +                        fputs(mat->oname, stdout);
674 +                else
675 +                        fputs(VOIDID, stdout);
676 +        } else
677 +                putchar('*');
678 +        putchar('\t');
679 + }
680 +
681 +
682 + static void
683 + oputtilde(                      /* output tilde (spacer) */
684 +        RAY  *r
685 + )
686 + {
687 +        fputs("~\t", stdout);
688 + }
689 +
690 +
691 + static void
692 + puta(                           /* print ascii value */
693 +        double  v
694 + )
695 + {
696          printf("%e\t", v);
697   }
698  
699  
700 < static
700 > static void
701   putd(v)                         /* print binary double */
702   double  v;
703   {
# Line 568 | Line 705 | double  v;
705   }
706  
707  
708 < static
708 > static void
709   putf(v)                         /* print binary float */
710   double  v;
711   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines