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.22 by greg, Wed Apr 17 14:02:09 1996 UTC vs.
Revision 2.28 by greg, Tue Feb 25 02:47:23 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 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 71 | 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 */
# Line 81 | Line 87 | int  ambounce = 0;                     /* ambient bounces */
87   char  *amblist[128];                    /* ambient include/exclude list */
88   int  ambincl = -1;                      /* include == 1, exclude == 0 */
89  
84 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(),
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 122 | 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 162 | 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 193 | 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 246 | Line 261 | register char  *vs;
261   }
262  
263  
264 < rad(org, dir)                   /* compute and print ray value(s) */
264 > void
265 > bogusray()                      /* print out empty record */
266 > {
267 >        thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
268 >        thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
269 >        rayorigin(&thisray, NULL, PRIMARY, 1.0);
270 >        printvals(&thisray);
271 > }
272 >
273 >
274 > void
275 > rad(org, dir, dmax)             /* compute and print ray value(s) */
276   FVECT  org, dir;
277 + double  dmax;
278   {
279          VCOPY(thisray.rorg, org);
280          VCOPY(thisray.rdir, dir);
281 <        thisray.rmax = 0.0;
281 >        thisray.rmax = dmax;
282          rayorigin(&thisray, NULL, PRIMARY, 1.0);
283 <        if (castonly)
284 <                localhit(&thisray, &thescene) || sourcehit(&thisray);
285 <        else
283 >        if (castonly) {
284 >                if (!localhit(&thisray, &thescene))
285 >                        if (thisray.ro == &Aftplane) {  /* clipped */
286 >                                thisray.ro = NULL;
287 >                                thisray.rot = FHUGE;
288 >                        } else
289 >                                sourcehit(&thisray);
290 >        } else
291                  rayvalue(&thisray);
292          printvals(&thisray);
293   }
294  
295  
296 + void
297   irrad(org, dir)                 /* compute immediate irradiance value */
298   FVECT  org, dir;
299   {
# Line 283 | Line 316 | FVECT  org, dir;
316   }
317  
318  
319 + void
320   printvals(r)                    /* print requested ray values */
321   RAY  *r;
322   {
323 <        register int  (**tp)();
323 >        register void  (**tp)();
324  
325          if (ray_out[0] == NULL)
326                  return;
# Line 297 | Line 331 | RAY  *r;
331   }
332  
333  
334 + int
335   getvec(vec, fmt, fp)            /* get a vector from fp */
336   register FVECT  vec;
337   int  fmt;
338   FILE  *fp;
339   {
305        extern char  *fgetword();
340          static float  vf[3];
341          static double  vd[3];
342          char  buf[32];
# Line 334 | Line 368 | FILE  *fp;
368   }
369  
370  
371 + void
372   tranotify(obj)                  /* record new modifier */
373   OBJECT  obj;
374   {
# Line 341 | Line 376 | OBJECT obj;
376          register OBJREC  *o = objptr(obj);
377          register char  **tralp;
378  
379 +        if (obj == OVOID) {             /* starting over */
380 +                traset[0] = 0;
381 +                hitlimit = 0;
382 +                return;
383 +        }
384          if (hitlimit || !ismodifier(o->otype))
385                  return;
386          for (tralp = tralist; *tralp != NULL; tralp++)
# Line 356 | Line 396 | OBJECT obj;
396   }
397  
398  
399 < static
399 > static void
400   ourtrace(r)                             /* print ray values */
401   RAY  *r;
402   {
403 <        register int  (**tp)();
403 >        register void  (**tp)();
404  
405          if (every_out[0] == NULL)
406                  return;
# Line 376 | Line 416 | RAY  *r;
416   }
417  
418  
419 < static
419 > static void
420   tabin(r)                                /* tab in appropriate amount */
421   RAY  *r;
422   {
# Line 387 | Line 427 | RAY  *r;
427   }
428  
429  
430 < static
430 > static void
431   oputo(r)                                /* print origin */
432   register RAY  *r;
433   {
# Line 397 | Line 437 | register RAY  *r;
437   }
438  
439  
440 < static
440 > static void
441   oputd(r)                                /* print direction */
442   register RAY  *r;
443   {
# Line 407 | Line 447 | register RAY  *r;
447   }
448  
449  
450 < static
450 > static void
451   oputv(r)                                /* print value */
452   register RAY  *r;
453   {
# Line 426 | Line 466 | register RAY  *r;
466   }
467  
468  
469 < static
469 > static void
470   oputl(r)                                /* print effective distance */
471   register RAY  *r;
472   {
# Line 434 | Line 474 | register RAY  *r;
474   }
475  
476  
477 < static
477 > static void
478   oputL(r)                                /* print single ray length */
479   register RAY  *r;
480   {
# Line 442 | Line 482 | register RAY  *r;
482   }
483  
484  
485 < static
485 > static void
486   oputp(r)                                /* print point */
487   register RAY  *r;
488   {
# Line 458 | Line 498 | register RAY  *r;
498   }
499  
500  
501 < static
501 > static void
502   oputN(r)                                /* print unperturbed normal */
503   register RAY  *r;
504   {
# Line 474 | Line 514 | register RAY  *r;
514   }
515  
516  
517 < static
517 > static void
518   oputn(r)                                /* print perturbed normal */
519   RAY  *r;
520   {
# Line 493 | Line 533 | RAY  *r;
533   }
534  
535  
536 < static
536 > static void
537   oputs(r)                                /* print name */
538   register RAY  *r;
539   {
# Line 505 | Line 545 | register RAY  *r;
545   }
546  
547  
548 < static
548 > static void
549   oputw(r)                                /* print weight */
550   register RAY  *r;
551   {
# Line 513 | Line 553 | register RAY  *r;
553   }
554  
555  
556 < static
556 > static void
557   oputm(r)                                /* print modifier */
558   register RAY  *r;
559   {
560          if (r->ro != NULL)
561 <                fputs(objptr(r->ro->omod)->oname, stdout);
561 >                if (r->ro->omod != OVOID)
562 >                        fputs(objptr(r->ro->omod)->oname, stdout);
563 >                else
564 >                        fputs(VOIDID, stdout);
565          else
566                  putchar('*');
567          putchar('\t');
568   }
569  
570  
571 < static
571 > static void
572   puta(v)                         /* print ascii value */
573   double  v;
574   {
# Line 533 | Line 576 | double  v;
576   }
577  
578  
579 < static
579 > static void
580   putd(v)                         /* print binary double */
581   double  v;
582   {
# Line 541 | Line 584 | double  v;
584   }
585  
586  
587 < static
587 > static void
588   putf(v)                         /* print binary float */
589   double  v;
590   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines