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.13 by greg, Mon Mar 8 12:37:33 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 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 */
# Line 38 | Line 48 | int  vresolu = 0;                      /* vertical resolution */
48   double  dstrsrc = 0.0;                  /* square source distribution */
49   double  shadthresh = .05;               /* shadow threshold */
50   double  shadcert = .5;                  /* shadow certainty */
51 + int  directrelay = 1;                   /* number of source relays */
52 + int  vspretest = 512;                   /* virtual source pretest density */
53 + int  directvis = 1;                     /* sources visible? */
54 + double  srcsizerat = .25;               /* maximum ratio source size/dist. */
55  
56 + double  specthresh = .15;               /* specular sampling threshold */
57 + double  specjitter = 1.;                /* specular sampling jitter */
58 +
59   int  maxdepth = 6;                      /* maximum recursion depth */
60   double  minweight = 4e-3;               /* minimum ray weight */
61  
# Line 51 | Line 68 | int  ambounce = 0;                     /* ambient bounces */
68   char  *amblist[128];                    /* ambient include/exclude list */
69   int  ambincl = -1;                      /* include == 1, exclude == 0 */
70  
71 + extern OBJREC  Lamb;                    /* a Lambertian surface */
72 +
73   static RAY  thisray;                    /* for our convenience */
74  
75 < extern int  oputo(), oputd(), oputv(), oputl(),
76 <                oputp(), oputn(), oputs(), oputw(), oputm();
75 > static int  oputo(), oputd(), oputv(), oputl(), oputL(),
76 >                oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
77  
78 + static int  ourtrace(), tabin();
79   static int  (*ray_out[10])(), (*every_out[10])();
80 + static int  castonly;
81  
82 < extern int  puta(), putf(), putd();
82 > static int  puta(), putf(), putd();
83  
84   static int  (*putreal)();
85  
# Line 66 | Line 87 | static int  (*putreal)();
87   quit(code)                      /* quit program */
88   int  code;
89   {
90 + #ifndef  NIX
91 +        headclean();            /* delete header file */
92 +        pfclean();              /* clean up persist files */
93 + #endif
94          exit(code);
95   }
96  
97  
98 + char *
99 + formstr(f)                              /* return format identifier */
100 + int  f;
101 + {
102 +        switch (f) {
103 +        case 'a': return("ascii");
104 +        case 'f': return("float");
105 +        case 'd': return("double");
106 +        case 'c': return(COLRFMT);
107 +        }
108 +        return("unknown");
109 + }
110 +
111 +
112   rtrace(fname)                           /* trace rays from file */
113   char  *fname;
114   {
# Line 84 | Line 123 | char  *fname;
123                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
124                  error(SYSTEM, errmsg);
125          }
126 + #ifdef MSDOS
127 +        if (inform != 'a')
128 +                setmode(fileno(fp), O_BINARY);
129 + #endif
130                                          /* set up output */
131          setoutput(outvals);
132          switch (outform) {
133          case 'a': putreal = puta; break;
134          case 'f': putreal = putf; break;
135          case 'd': putreal = putd; break;
136 +        case 'c':
137 +                if (strcmp(outvals, "v"))
138 +                        error(USER, "color format with value output only");
139 +                break;
140 +        default:
141 +                error(CONSISTENCY, "botched output format");
142          }
143 +        if (hresolu > 0) {
144 +                if (vresolu > 0)
145 +                        fprtresolu(hresolu, vresolu, stdout);
146 +                fflush(stdout);
147 +        }
148                                          /* process file */
149          while (getvec(orig, inform, fp) == 0 &&
150                          getvec(direc, inform, fp) == 0) {
# Line 99 | Line 153 | char  *fname;
153                          fflush(stdout);
154                          continue;
155                  }
156 +                samplendx++;
157                                                          /* compute and print */
158 <                if (outvals[0] == 'i')
158 >                if (imm_irrad)
159                          irrad(orig, direc);
160                  else
161 <                        radiance(orig, direc);
161 >                        traceray(orig, direc);
162                                                          /* flush if time */
163                  if (--nextflush == 0) {
164                          fflush(stdout);
# Line 114 | Line 169 | char  *fname;
169                  if (--vcount == 0)                      /* check for end */
170                          break;
171          }
172 +        fflush(stdout);
173          if (vcount > 0)
174                  error(USER, "read error");
175 <        fclose(fp);
175 >        if (fname != NULL)
176 >                fclose(fp);
177   }
178  
179  
180   setoutput(vs)                           /* set up output tables */
181   register char  *vs;
182   {
183 <        extern int  ourtrace(), (*trace)();
183 >        extern int  (*trace)();
184          register int (**table)() = ray_out;
185  
186 +        castonly = 1;
187          while (*vs)
188                  switch (*vs++) {
189                  case 't':                               /* trace */
190                          *table = NULL;
191                          table = every_out;
192                          trace = ourtrace;
193 +                        castonly = 0;
194                          break;
195                  case 'o':                               /* origin */
196                          *table++ = oputo;
# Line 141 | Line 200 | register char  *vs;
200                          break;
201                  case 'v':                               /* value */
202                          *table++ = oputv;
203 +                        castonly = 0;
204                          break;
205 <                case 'l':                               /* length */
205 >                case 'l':                               /* effective distance */
206                          *table++ = oputl;
207 +                        castonly = 0;
208                          break;
209 +                case 'L':                               /* single ray length */
210 +                        *table++ = oputL;
211 +                        break;
212                  case 'p':                               /* point */
213                          *table++ = oputp;
214                          break;
215 <                case 'n':                               /* normal */
215 >                case 'n':                               /* perturbed normal */
216                          *table++ = oputn;
217 +                        castonly = 0;
218                          break;
219 +                case 'N':                               /* unperturbed normal */
220 +                        *table++ = oputN;
221 +                        break;
222                  case 's':                               /* surface */
223                          *table++ = oputs;
224                          break;
# Line 165 | Line 233 | register char  *vs;
233   }
234  
235  
236 < radiance(org, dir)              /* compute radiance value */
236 > traceray(org, dir)              /* compute and print ray value(s) */
237   FVECT  org, dir;
238   {
239          register int  (**tp)();
# Line 173 | Line 241 | FVECT  org, dir;
241          VCOPY(thisray.rorg, org);
242          VCOPY(thisray.rdir, dir);
243          rayorigin(&thisray, NULL, PRIMARY, 1.0);
244 <        rayvalue(&thisray);
244 >        if (castonly)
245 >                localhit(&thisray, &thescene) || sourcehit(&thisray);
246 >        else
247 >                rayvalue(&thisray);
248  
249          if (ray_out[0] == NULL)
250                  return;
# Line 184 | Line 255 | FVECT  org, dir;
255   }
256  
257  
258 < irrad(org, dir)                 /* compute irradiance value */
258 > irrad(org, dir)                 /* compute immediate irradiance value */
259   FVECT  org, dir;
260   {
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        };
261          register int  i;
262  
263          for (i = 0; i < 3; i++) {
# Line 218 | Line 284 | register FVECT  vec;
284   int  fmt;
285   FILE  *fp;
286   {
287 +        extern char  *fgetword();
288          static float  vf[3];
289 +        static double  vd[3];
290 +        char  buf[32];
291 +        register int  i;
292  
293          switch (fmt) {
294          case 'a':                                       /* ascii */
295 <                if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3)
296 <                        return(-1);
295 >                for (i = 0; i < 3; i++) {
296 >                        if (fgetword(buf, sizeof(buf), fp) == NULL ||
297 >                                        !isflt(buf))
298 >                                return(-1);
299 >                        vec[i] = atof(buf);
300 >                }
301                  break;
302          case 'f':                                       /* binary float */
303                  if (fread((char *)vf, sizeof(float), 3, fp) != 3)
# Line 231 | Line 305 | FILE  *fp;
305                  vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2];
306                  break;
307          case 'd':                                       /* binary double */
308 <                if (fread((char *)vec, sizeof(double), 3, fp) != 3)
308 >                if (fread((char *)vd, sizeof(double), 3, fp) != 3)
309                          return(-1);
310 +                vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2];
311                  break;
312 +        default:
313 +                error(CONSISTENCY, "botched input format");
314          }
315          return(0);
316   }
# Line 289 | Line 366 | static
366   oputv(r)                                /* print value */
367   register RAY  *r;
368   {
369 +        COLR  cout;
370 +        
371 +        if (outform == 'c') {
372 +                setcolr(cout,   colval(r->rcol,RED),
373 +                                colval(r->rcol,GRN),
374 +                                colval(r->rcol,BLU));
375 +                fwrite((char *)cout, sizeof(cout), 1, stdout);
376 +                return;
377 +        }
378          (*putreal)(colval(r->rcol,RED));
379          (*putreal)(colval(r->rcol,GRN));
380          (*putreal)(colval(r->rcol,BLU));
# Line 296 | Line 382 | register RAY  *r;
382  
383  
384   static
385 < oputl(r)                                /* print length */
385 > oputl(r)                                /* print effective distance */
386   register RAY  *r;
387   {
388          (*putreal)(r->rt);
# Line 304 | Line 390 | register RAY  *r;
390  
391  
392   static
393 + oputL(r)                                /* print single ray length */
394 + register RAY  *r;
395 + {
396 +        (*putreal)(r->rot);
397 + }
398 +
399 +
400 + static
401   oputp(r)                                /* print point */
402   register RAY  *r;
403   {
# Line 320 | Line 414 | register RAY  *r;
414  
415  
416   static
417 < oputn(r)                                /* print normal */
417 > oputN(r)                                /* print unperturbed normal */
418   register RAY  *r;
419   {
420          if (r->rot < FHUGE) {
# Line 332 | Line 426 | register RAY  *r;
426                  (*putreal)(0.0);
427                  (*putreal)(0.0);
428          }
429 + }
430 +
431 +
432 + static
433 + oputn(r)                                /* print perturbed normal */
434 + RAY  *r;
435 + {
436 +        FVECT  pnorm;
437 +
438 +        if (r->rot >= FHUGE) {
439 +                (*putreal)(0.0);
440 +                (*putreal)(0.0);
441 +                (*putreal)(0.0);
442 +                return;
443 +        }
444 +        raynormal(pnorm, r);
445 +        (*putreal)(pnorm[0]);
446 +        (*putreal)(pnorm[1]);
447 +        (*putreal)(pnorm[2]);
448   }
449  
450  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines