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.9 by greg, Tue Mar 27 11:40:10 1990 UTC vs.
Revision 2.17 by greg, Tue Dec 20 20:18:34 1994 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 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20   *  All values default to ascii representation of real
21   *  numbers.  Binary representations can be selected
22   *  with '-ff' for float or '-fd' for double.  By default,
23 < *  radiance is computed.  The '-i' option indicates that
23 > *  radiance is computed.  The '-i' or '-I' options indicate that
24   *  irradiance values are desired.
25   */
26  
27   #include  "ray.h"
28  
29 + #include  "octree.h"
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 */
38 +
39 + int  imm_irrad = 0;                     /* compute immediate irradiance? */
40 +
41   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 = 1;                   /* number of source relays */
57 + int  vspretest = 512;                   /* virtual source pretest density */
58 + int  directvis = 1;                     /* sources visible? */
59 + double  srcsizerat = .25;               /* maximum ratio source size/dist. */
60  
61 + double  specthresh = .15;               /* specular sampling threshold */
62 + double  specjitter = 1.;                /* specular sampling jitter */
63 +
64   int  maxdepth = 6;                      /* maximum recursion depth */
65   double  minweight = 4e-3;               /* minimum ray weight */
66  
# Line 51 | Line 73 | int  ambounce = 0;                     /* ambient bounces */
73   char  *amblist[128];                    /* ambient include/exclude list */
74   int  ambincl = -1;                      /* include == 1, exclude == 0 */
75  
76 + extern OBJREC  Lamb;                    /* a Lambertian surface */
77 +
78   static RAY  thisray;                    /* for our convenience */
79  
80 < extern int  oputo(), oputd(), oputv(), oputl(),
81 <                oputp(), oputn(), oputs(), oputw(), oputm();
80 > static int  oputo(), oputd(), oputv(), oputl(), oputL(),
81 >                oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
82  
83 < static int  (*ray_out[10])(), (*every_out[10])();
83 > static int  ourtrace(), tabin();
84 > static int  (*ray_out[16])(), (*every_out[16])();
85 > static int  castonly = 0;
86  
87 < extern int  puta(), putf(), putd();
87 > static int  puta(), putf(), putd();
88  
89   static int  (*putreal)();
90  
# Line 66 | Line 92 | static int  (*putreal)();
92   quit(code)                      /* quit program */
93   int  code;
94   {
95 + #ifndef  NIX
96 +        headclean();            /* delete header file */
97 +        pfclean();              /* clean up persist files */
98 + #endif
99          exit(code);
100   }
101  
102  
103 + char *
104 + formstr(f)                              /* return format identifier */
105 + int  f;
106 + {
107 +        switch (f) {
108 +        case 'a': return("ascii");
109 +        case 'f': return("float");
110 +        case 'd': return("double");
111 +        case 'c': return(COLRFMT);
112 +        }
113 +        return("unknown");
114 + }
115 +
116 +
117   rtrace(fname)                           /* trace rays from file */
118   char  *fname;
119   {
# Line 84 | Line 128 | char  *fname;
128                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
129                  error(SYSTEM, errmsg);
130          }
131 + #ifdef MSDOS
132 +        if (inform != 'a')
133 +                setmode(fileno(fp), O_BINARY);
134 + #endif
135                                          /* set up output */
136          setoutput(outvals);
137          switch (outform) {
138          case 'a': putreal = puta; break;
139          case 'f': putreal = putf; break;
140          case 'd': putreal = putd; break;
141 +        case 'c':
142 +                if (strcmp(outvals, "v"))
143 +                        error(USER, "color format with value output only");
144 +                break;
145 +        default:
146 +                error(CONSISTENCY, "botched output format");
147          }
148 +        if (hresolu > 0) {
149 +                if (vresolu > 0)
150 +                        fprtresolu(hresolu, vresolu, stdout);
151 +                fflush(stdout);
152 +        }
153                                          /* process file */
154          while (getvec(orig, inform, fp) == 0 &&
155                          getvec(direc, inform, fp) == 0) {
# Line 99 | Line 158 | char  *fname;
158                          fflush(stdout);
159                          continue;
160                  }
161 +                samplendx++;
162                                                          /* compute and print */
163 <                if (outvals[0] == 'i')
163 >                if (imm_irrad)
164                          irrad(orig, direc);
165                  else
166 <                        radiance(orig, direc);
166 >                        rad(orig, direc);
167                                                          /* flush if time */
168                  if (--nextflush == 0) {
169                          fflush(stdout);
# Line 114 | Line 174 | char  *fname;
174                  if (--vcount == 0)                      /* check for end */
175                          break;
176          }
177 +        fflush(stdout);
178          if (vcount > 0)
179                  error(USER, "read error");
180 <        fclose(fp);
180 >        if (fname != NULL)
181 >                fclose(fp);
182   }
183  
184  
185   setoutput(vs)                           /* set up output tables */
186   register char  *vs;
187   {
188 <        extern int  ourtrace(), (*trace)();
188 >        extern int  (*trace)();
189          register int (**table)() = ray_out;
190  
191 +        castonly = 1;
192          while (*vs)
193                  switch (*vs++) {
194                  case 't':                               /* trace */
195                          *table = NULL;
196                          table = every_out;
197                          trace = ourtrace;
198 +                        castonly = 0;
199                          break;
200                  case 'o':                               /* origin */
201                          *table++ = oputo;
# Line 141 | Line 205 | register char  *vs;
205                          break;
206                  case 'v':                               /* value */
207                          *table++ = oputv;
208 +                        castonly = 0;
209                          break;
210 <                case 'l':                               /* length */
210 >                case 'l':                               /* effective distance */
211                          *table++ = oputl;
212 +                        castonly = 0;
213                          break;
214 +                case 'L':                               /* single ray length */
215 +                        *table++ = oputL;
216 +                        break;
217                  case 'p':                               /* point */
218                          *table++ = oputp;
219                          break;
220 <                case 'n':                               /* normal */
220 >                case 'n':                               /* perturbed normal */
221                          *table++ = oputn;
222 +                        castonly = 0;
223                          break;
224 +                case 'N':                               /* unperturbed normal */
225 +                        *table++ = oputN;
226 +                        break;
227                  case 's':                               /* surface */
228                          *table++ = oputs;
229                          break;
# Line 165 | Line 238 | register char  *vs;
238   }
239  
240  
241 < radiance(org, dir)              /* compute radiance value */
241 > rad(org, dir)                   /* compute and print ray value(s) */
242   FVECT  org, dir;
243   {
171        register int  (**tp)();
172
244          VCOPY(thisray.rorg, org);
245          VCOPY(thisray.rdir, dir);
246 +        thisray.rmax = 0.0;
247          rayorigin(&thisray, NULL, PRIMARY, 1.0);
248 <        rayvalue(&thisray);
249 <
250 <        if (ray_out[0] == NULL)
251 <                return;
252 <        for (tp = ray_out; *tp != NULL; tp++)
181 <                (**tp)(&thisray);
182 <        if (outform == 'a')
183 <                putchar('\n');
248 >        if (castonly)
249 >                localhit(&thisray, &thescene) || sourcehit(&thisray);
250 >        else
251 >                rayvalue(&thisray);
252 >        printvals(&thisray);
253   }
254  
255  
256 < irrad(org, dir)                 /* compute irradiance value */
256 > irrad(org, dir)                 /* compute immediate irradiance value */
257   FVECT  org, dir;
258   {
190        static double  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
191        static OBJREC  Lamb = {
192                OVOID, MAT_PLASTIC, "Lambertian",
193                {0, 5, NULL, Lambfa}, NULL, -1,
194        };
259          register int  i;
260  
261          for (i = 0; i < 3; i++) {
# Line 200 | Line 264 | FVECT  org, dir;
264          }
265          rayorigin(&thisray, NULL, PRIMARY, 1.0);
266                                          /* pretend we hit surface */
267 <        thisray.rot = 1.0;
267 >        thisray.rot = 1.0-1e-4;
268          thisray.rod = 1.0;
269          VCOPY(thisray.ron, dir);
270          for (i = 0; i < 3; i++)         /* fudge factor */
271                  thisray.rop[i] = org[i] + 1e-4*dir[i];
272                                          /* compute and print */
273          (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
274 <        oputv(&thisray);
274 >        printvals(&thisray);
275 > }
276 >
277 >
278 > printvals(r)                    /* print requested ray values */
279 > RAY  *r;
280 > {
281 >        register int  (**tp)();
282 >
283 >        if (ray_out[0] == NULL)
284 >                return;
285 >        for (tp = ray_out; *tp != NULL; tp++)
286 >                (**tp)(r);
287          if (outform == 'a')
288                  putchar('\n');
289   }
# Line 218 | Line 294 | register FVECT  vec;
294   int  fmt;
295   FILE  *fp;
296   {
297 +        extern char  *fgetword();
298          static float  vf[3];
299 +        static double  vd[3];
300 +        char  buf[32];
301 +        register int  i;
302  
303          switch (fmt) {
304          case 'a':                                       /* ascii */
305 <                if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3)
306 <                        return(-1);
305 >                for (i = 0; i < 3; i++) {
306 >                        if (fgetword(buf, sizeof(buf), fp) == NULL ||
307 >                                        !isflt(buf))
308 >                                return(-1);
309 >                        vec[i] = atof(buf);
310 >                }
311                  break;
312          case 'f':                                       /* binary float */
313                  if (fread((char *)vf, sizeof(float), 3, fp) != 3)
# Line 231 | Line 315 | FILE  *fp;
315                  vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2];
316                  break;
317          case 'd':                                       /* binary double */
318 <                if (fread((char *)vec, sizeof(double), 3, fp) != 3)
318 >                if (fread((char *)vd, sizeof(double), 3, fp) != 3)
319                          return(-1);
320 +                vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2];
321                  break;
322 +        default:
323 +                error(CONSISTENCY, "botched input format");
324          }
325          return(0);
326   }
327  
328  
329 + tranotify(obj)                  /* record new modifier */
330 + OBJECT  obj;
331 + {
332 +        static int  hitlimit = 0;
333 +        register OBJREC  *o = objptr(obj);
334 +        register char  **tralp;
335 +
336 +        if (hitlimit || !ismodifier(o->otype))
337 +                return;
338 +        for (tralp = tralist; *tralp != NULL; tralp++)
339 +                if (!strcmp(o->oname, *tralp)) {
340 +                        if (traset[0] >= MAXTSET) {
341 +                                error(WARNING, "too many modifiers in trace list");
342 +                                hitlimit++;
343 +                                return;         /* should this be fatal? */
344 +                        }
345 +                        insertelem(traset, obj);
346 +                        return;
347 +                }
348 + }
349 +
350 +
351   static
352   ourtrace(r)                             /* print ray values */
353   RAY  *r;
# Line 247 | Line 356 | RAY  *r;
356  
357          if (every_out[0] == NULL)
358                  return;
359 +        if (r->ro == NULL) {
360 +                if (traincl == 1)
361 +                        return;
362 +        } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
363 +                return;
364          tabin(r);
365          for (tp = every_out; *tp != NULL; tp++)
366                  (**tp)(r);
# Line 289 | Line 403 | static
403   oputv(r)                                /* print value */
404   register RAY  *r;
405   {
406 +        COLR  cout;
407 +        
408 +        if (outform == 'c') {
409 +                setcolr(cout,   colval(r->rcol,RED),
410 +                                colval(r->rcol,GRN),
411 +                                colval(r->rcol,BLU));
412 +                fwrite((char *)cout, sizeof(cout), 1, stdout);
413 +                return;
414 +        }
415          (*putreal)(colval(r->rcol,RED));
416          (*putreal)(colval(r->rcol,GRN));
417          (*putreal)(colval(r->rcol,BLU));
# Line 296 | Line 419 | register RAY  *r;
419  
420  
421   static
422 < oputl(r)                                /* print length */
422 > oputl(r)                                /* print effective distance */
423   register RAY  *r;
424   {
425          (*putreal)(r->rt);
# Line 304 | Line 427 | register RAY  *r;
427  
428  
429   static
430 + oputL(r)                                /* print single ray length */
431 + register RAY  *r;
432 + {
433 +        (*putreal)(r->rot);
434 + }
435 +
436 +
437 + static
438   oputp(r)                                /* print point */
439   register RAY  *r;
440   {
# Line 320 | Line 451 | register RAY  *r;
451  
452  
453   static
454 < oputn(r)                                /* print normal */
454 > oputN(r)                                /* print unperturbed normal */
455   register RAY  *r;
456   {
457          if (r->rot < FHUGE) {
# Line 332 | Line 463 | register RAY  *r;
463                  (*putreal)(0.0);
464                  (*putreal)(0.0);
465          }
466 + }
467 +
468 +
469 + static
470 + oputn(r)                                /* print perturbed normal */
471 + RAY  *r;
472 + {
473 +        FVECT  pnorm;
474 +
475 +        if (r->rot >= FHUGE) {
476 +                (*putreal)(0.0);
477 +                (*putreal)(0.0);
478 +                (*putreal)(0.0);
479 +                return;
480 +        }
481 +        raynormal(pnorm, r);
482 +        (*putreal)(pnorm[0]);
483 +        (*putreal)(pnorm[1]);
484 +        (*putreal)(pnorm[2]);
485   }
486  
487  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines