ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rv2.c
(Generate patch)

Comparing ray/src/rt/rv2.c (file contents):
Revision 1.30 by greg, Mon Oct 21 13:30:43 1991 UTC vs.
Revision 2.18 by greg, Wed Aug 25 14:13:51 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1993 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "rpaint.h"
20  
21 + #include  "resolu.h"
22 +
23   #include  <ctype.h>
24  
25 < #define  CTRL(c)        ('c'-'@')
25 > #define  CTRL(c)        ((c)-'@')
26  
27 + #ifdef  SMLFLT
28 + #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
29 + #else
30 + #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
31 + #endif
32 +
33 + extern char  *atos();
34 +
35 + extern char  rifname[];                 /* rad input file name */
36 +
37   extern char  VersionID[];
38   extern char  *progname;
39   extern char  *octname;
# Line 56 | Line 68 | char  *s;
68          int  change = 0;
69          VIEW  nv;
70  
71 +        while (isspace(*s))
72 +                s++;
73 +        if (*s == '-') {                        /* command line parameters */
74 +                copystruct(&nv, &ourview);
75 +                if (sscanview(&nv, s))
76 +                        newview(&nv);
77 +                else
78 +                        error(COMMAND, "bad view option(s)");
79 +                return;
80 +        }
81          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
82                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
83                                  (fp = fopen(fname, "a")) == NULL) {
# Line 66 | Line 88 | char  *s;
88                  fputs(progname, fp);
89                  fprintview(&ourview, fp);
90                  fputs(sskip(s), fp);
91 <                fputs("\n", fp);
91 >                putc('\n', fp);
92                  fclose(fp);
93                  return;
94          }
95          sprintf(buf, "view type (%c): ", ourview.type);
96          (*dev->comout)(buf);
97          (*dev->comin)(buf, NULL);
98 <        if (buf[0] == CTRL(C)) return;
98 >        if (buf[0] == CTRL('C')) return;
99          if (buf[0] && buf[0] != ourview.type) {
100                  nv.type = buf[0];
101                  change++;
# Line 83 | Line 105 | char  *s;
105                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
106          (*dev->comout)(buf);
107          (*dev->comin)(buf, NULL);
108 <        if (buf[0] == CTRL(C)) return;
109 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
108 >        if (buf[0] == CTRL('C')) return;
109 >        if (sscanvec(buf, nv.vp))
110                  change++;
111          else
112                  VCOPY(nv.vp, ourview.vp);
# Line 92 | Line 114 | char  *s;
114                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
115          (*dev->comout)(buf);
116          (*dev->comin)(buf, NULL);
117 <        if (buf[0] == CTRL(C)) return;
118 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
117 >        if (buf[0] == CTRL('C')) return;
118 >        if (sscanvec(buf, nv.vdir))
119                  change++;
120          else
121                  VCOPY(nv.vdir, ourview.vdir);
# Line 101 | Line 123 | char  *s;
123                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
124          (*dev->comout)(buf);
125          (*dev->comin)(buf, NULL);
126 <        if (buf[0] == CTRL(C)) return;
127 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
126 >        if (buf[0] == CTRL('C')) return;
127 >        if (sscanvec(buf, nv.vup))
128                  change++;
129          else
130                  VCOPY(nv.vup, ourview.vup);
# Line 110 | Line 132 | char  *s;
132                          ourview.horiz, ourview.vert);
133          (*dev->comout)(buf);
134          (*dev->comin)(buf, NULL);
135 <        if (buf[0] == CTRL(C)) return;
135 >        if (buf[0] == CTRL('C')) return;
136          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
137                  change++;
138          else {
# Line 120 | Line 142 | char  *s;
142                          ourview.hoff, ourview.voff);
143          (*dev->comout)(buf);
144          (*dev->comin)(buf, NULL);
145 <        if (buf[0] == CTRL(C)) return;
145 >        if (buf[0] == CTRL('C')) return;
146          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
147                  change++;
148          else {
# Line 142 | Line 164 | char  *s;
164          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
165                  copystruct(&nv, &stdview);
166                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
167 <                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
167 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
168                          sprintf(errmsg, "cannot open \"%s\"", buf);
169                          error(COMMAND, errmsg);
170                          return;
# Line 164 | Line 186 | char  *s;
186   }
187  
188  
189 + saveview(s)                             /* save view to rad file */
190 + char  *s;
191 + {
192 +        char  view[64];
193 +        char  *fname;
194 +        FILE  *fp;
195 +
196 +        if (*atos(view, sizeof(view), s))
197 +                s = sskip(s);
198 +        if (sscanf(s, "%s", rifname) != 1 && rifname[0] == '\0') {
199 +                error(COMMAND, "no previous rad file");
200 +                return;
201 +        }
202 +        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
203 +                        (fp = fopen(fname, "a")) == NULL) {
204 +                sprintf(errmsg, "cannot open \"%s\"", rifname);
205 +                error(COMMAND, errmsg);
206 +                return;
207 +        }
208 +        fputs("view= ", fp);
209 +        fputs(view, fp);
210 +        fprintview(&ourview, fp);
211 +        putc('\n', fp);
212 +        fclose(fp);
213 + }
214 +
215 +
216 + loadview(s)                             /* load view from rad file */
217 + char  *s;
218 + {
219 +        char  buf[512];
220 +        char  *fname;
221 +        FILE  *fp;
222 +        VIEW  nv;
223 +
224 +        strcpy(buf, "rad -n -s -V -v ");
225 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
226 +                s = sskip(s);
227 +        else
228 +                strcat(buf, "1");
229 +        if (sscanf(s, "%s", rifname) != 1 && rifname[0] == '\0') {
230 +                error(COMMAND, "no previous rad file");
231 +                return;
232 +        }
233 +        fname = getpath(rifname, NULL, 0);
234 +        if (fname == NULL || access(fname, R_OK) == -1) {
235 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
236 +                error(COMMAND, errmsg);
237 +                return;
238 +        }
239 +        sprintf(buf+strlen(buf), " %s", fname);
240 +        if ((fp = popen(buf, "r")) == NULL) {
241 +                error(COMMAND, "cannot run rad");
242 +                return;
243 +        }
244 +        buf[0] = '\0';
245 +        fgets(buf, sizeof(buf), fp);
246 +        pclose(fp);
247 +        copystruct(&nv, &stdview);
248 +        if (!sscanview(&nv, buf)) {
249 +                error(COMMAND, "rad error -- no such view?");
250 +                return;
251 +        }
252 +        newview(&nv);
253 + }
254 +
255 +
256   getaim(s)                               /* aim camera */
257   char  *s;
258   {
170        extern double  tan(), atan();
259          double  zfact;
260          VIEW  nv;
261  
# Line 198 | Line 286 | char  *s;
286   getrotate(s)                            /* rotate camera */
287   char  *s;
288   {
201        extern double  normalize(), tan(), atan();
289          VIEW  nv;
290          FVECT  v1;
291          double  angle, elev, zfact;
# Line 244 | Line 331 | register char  *s;
331   getexposure(s)                          /* get new exposure */
332   char  *s;
333   {
247        double  atof(), pow(), fabs();
334          char  buf[128];
335          register char  *cp;
250        register PNODE  *p;
336          RECT  r;
337          int  x, y;
338 <        double  e;
339 <
338 >        register PNODE  *p = &ptrunk;
339 >        int  adapt = 0;
340 >        double  e = 1.0;
341 > start:
342          for (cp = s; isspace(*cp); cp++)
343                  ;
344 +        if (*cp == '@') {
345 +                adapt++;
346 +                goto start;
347 +        }
348          if (*cp == '\0') {              /* normalize to point */
349                  if (dev->getcur == NULL)
350                          return;
# Line 263 | Line 354 | char  *s;
354                  r.l = r.d = 0;
355                  r.r = hresolu; r.u = vresolu;
356                  p = findrect(x, y, &ptrunk, &r, -1);
266                e = 1.0;
357          } else {
358                  if (*cp == '=') {       /* absolute setting */
359                          p = NULL;
# Line 271 | Line 361 | char  *s;
361                          for (cp++; isspace(*cp); cp++)
362                                  ;
363                          if (*cp == '\0') {      /* interactive */
364 <                                sprintf(buf, "exposure (%lf): ", exposure);
364 >                                sprintf(buf, "exposure (%f): ", exposure);
365                                  (*dev->comout)(buf);
366                                  (*dev->comin)(buf, NULL);
367                                  for (cp = buf; isspace(*cp); cp++)
# Line 279 | Line 369 | char  *s;
369                                  if (*cp == '\0')
370                                          return;
371                          }
282                } else {                /* normalize to average */
283                        p = &ptrunk;
284                        e = 1.0;
372                  }
373                  if (*cp == '+' || *cp == '-')   /* f-stops */
374                          e *= pow(2.0, atof(cp));
# Line 289 | Line 376 | char  *s;
376                          e *= atof(cp);
377          }
378          if (p != NULL) {                /* relative setting */
379 <                if (bright(p->v) <= FTINY) {
379 >                if (bright(p->v) < 1e-15) {
380                          error(COMMAND, "cannot normalize to zero");
381                          return;
382                  }
383 <                e *= 0.5 / bright(p->v);
383 >                if (adapt)
384 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
385 >                else
386 >                        e *= 0.5 / bright(p->v);
387          }
388          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
389                  return;
# Line 321 | Line 411 | register union {int i; double d; COLOR C;}  *ptr;
411                          (*dev->comout)(buf);
412                          (*dev->comin)(buf, NULL);
413                          if (sscanf(buf, "%d", &i0) != 1)
414 <                                break;
414 >                                return(0);
415                  }
416                  ptr->i = i0;
417 <                break;
417 >                return(1);
418          case 'r':                       /* real */
419                  if (sscanf(str, "%lf", &d0) != 1) {
420                          (*dev->comout)(dsc);
# Line 332 | Line 422 | register union {int i; double d; COLOR C;}  *ptr;
422                          (*dev->comout)(buf);
423                          (*dev->comin)(buf, NULL);
424                          if (sscanf(buf, "%lf", &d0) != 1)
425 <                                break;
425 >                                return(0);
426                  }
427                  ptr->d = d0;
428 <                break;
428 >                return(1);
429          case 'b':                       /* boolean */
430                  if (sscanf(str, "%1s", buf) != 1) {
431                          (*dev->comout)(dsc);
432 <                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
432 >                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
433                          (*dev->comout)(buf);
434                          (*dev->comin)(buf, NULL);
435                          if (buf[0] == '\0' ||
436                                          index("yY+1tTnN-0fF", buf[0]) == NULL)
437 <                                break;
437 >                                return(0);
438                  }
439                  ptr->i = index("yY+1tT", buf[0]) != NULL;
440 <                break;
440 >                return(1);
441          case 'C':                       /* color */
442                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
443                          (*dev->comout)(dsc);
# Line 358 | Line 448 | register union {int i; double d; COLOR C;}  *ptr;
448                          (*dev->comout)(buf);
449                          (*dev->comin)(buf, NULL);
450                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
451 <                                break;
451 >                                return(0);
452                  }
453                  setcolor(ptr->C, d0, d1, d2);
454 <                break;
454 >                return(1);
455          }
456   }
457  
# Line 378 | Line 468 | register char  *s;
468          extern double  shadcert;
469          extern COLOR  ambval;
470          extern double  ambacc;
381        extern double  minarad;
471          extern int  ambres;
472          extern int  ambdiv;
473          extern int  ambssamp;
474          extern int  ambounce;
475 <        extern int  directinvis;
475 >        extern int  directvis;
476          extern double  srcsizerat;
477          extern int  do_irrad;
478 +        extern double  specjitter;
479 +        extern double  specthresh;
480          char  buf[128];
481          
482          if (s[0] == '\0') {
483                  (*dev->comout)(
484 <                        "aa ab ad ar as av b dc di dj dt i lr lw sp st: ");
484 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
485                  (*dev->comin)(buf, NULL);
486                  s = buf;
487          }
# Line 418 | Line 509 | register char  *s;
509                  case 't':                       /* threshold */
510                          getparam(s+2, "direct threshold", 'r', &shadthresh);
511                          break;
512 <                case 'i':                       /* invisibility */
513 <                        getparam(s+2, "direct invisibility",
514 <                                        'b', &directinvis);
512 >                case 'v':                       /* visibility */
513 >                        getparam(s+2, "direct visibility",
514 >                                        'b', &directvis);
515                          break;
516                  case 's':                       /* sampling */
517                          getparam(s+2, "direct sampling", 'r', &srcsizerat);
# Line 438 | Line 529 | register char  *s;
529          case 'a':                       /* ambient */
530                  switch (s[1]) {
531                  case 'v':                       /* value */
532 <                        getparam(s+2, "ambient value", 'C', ambval);
532 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
533                          break;
534                  case 'a':                       /* accuracy */
535 <                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
535 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
536 >                                setambacc(ambacc);
537                          break;
538                  case 'd':                       /* divisions */
539                          getparam(s+2, "ambient divisions", 'i', &ambdiv);
# Line 453 | Line 545 | register char  *s;
545                          getparam(s+2, "ambient bounces", 'i', &ambounce);
546                          break;
547                  case 'r':
548 <                        getparam(s+2, "ambient resolution", 'i', &ambres);
549 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
548 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
549 >                                setambres(ambres);
550                          break;
551                  default:
552                          goto badparam;
553                  }
554                  break;
555 <        case 's':                       /* sample */
555 >        case 'p':                       /* pixel */
556                  switch (s[1]) {
557 <                case 'p':                       /* pixel */
558 <                        getparam(s+2, "sample pixel", 'i', &psample);
559 <                        pdepth = 0;
557 >                case 's':                       /* sample */
558 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
559 >                                pdepth = 0;
560                          break;
561                  case 't':                       /* threshold */
562 <                        getparam(s+2, "sample threshold", 'r', &maxdiff);
563 <                        pdepth = 0;
562 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
563 >                                pdepth = 0;
564                          break;
565                  default:
566                          goto badparam;
567                  }
568                  break;
569 +        case 's':                       /* specular */
570 +                switch (s[1]) {
571 +                case 'j':                       /* jitter */
572 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
573 +                        break;
574 +                case 't':                       /* threshold */
575 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
576 +                        break;
577 +                default:
578 +                        goto badparam;
579 +                }
580 +                break;
581          case '\0':                      /* nothing */
582                  break;
583          default:;
# Line 493 | Line 597 | char  *s;
597          int  x, y;
598          RAY  thisray;
599  
600 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
601 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
498 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
600 >        if (!sscanvec(s, thisray.rorg) ||
601 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
602  
603                  if (dev->getcur == NULL)
604                          return;
# Line 535 | Line 638 | char  *s;
638                          (*dev->comout)(buf);
639                  }
640                  (*dev->comin)(buf, NULL);
641 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
641 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
642                                  colval(thisray.rcol,RED),
643                                  colval(thisray.rcol,GRN),
644 <                                colval(thisray.rcol,BLU));
644 >                                colval(thisray.rcol,BLU),
645 >                                luminance(thisray.rcol));
646                  (*dev->comout)(buf);
647          }
648          (*dev->comin)(buf, NULL);
# Line 564 | Line 668 | char  *s;
668                  error(COMMAND, errmsg);
669                  return;
670          }
671 + #ifdef MSDOS
672 +        setmode(fileno(fp), O_BINARY);
673 + #endif
674          (*dev->comout)("writing \"");
675          (*dev->comout)(fname);
676          (*dev->comout)("\"...\n");
# Line 581 | Line 688 | char  *s;
688                  fputaspect(dev->pixaspect, fp);
689          fputformat(COLRFMT, fp);
690          putc('\n', fp);
691 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
691 >        fprtresolu(hresolu, vresolu, fp);
692  
693          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
694          if (scanline == NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines