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 2.1 by greg, Tue Nov 12 17:09:52 1991 UTC vs.
Revision 2.20 by greg, Thu Sep 9 13:47:55 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 22 | Line 22 | static char SCCSid[] = "$SunId$ LBL";
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[128];              /* rad input file name */
36 +
37   extern char  VersionID[];
38   extern char  *progname;
39   extern char  *octname;
# Line 58 | 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 68 | 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 85 | 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 94 | 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 103 | 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 112 | 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 122 | 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 143 | Line 163 | char  *s;
163  
164          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
165                  copystruct(&nv, &stdview);
166 <                if ((fname = getpath(buf, NULL, 0)) == NULL ||
166 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
167                                  (success = viewfile(fname, &nv, NULL)) == -1) {
168                          sprintf(errmsg, "cannot open \"%s\"", buf);
169                          error(COMMAND, errmsg);
# Line 166 | 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 +                if (isint(view)) {
198 +                        error(COMMAND, "cannot write view by number");
199 +                        return;
200 +                }
201 +                s = sskip(s);
202 +        }
203 +        while (isspace(*s))
204 +                s++;
205 +        if (*s)
206 +                atos(rifname, sizeof(rifname), s);
207 +        else if (rifname[0] == '\0') {
208 +                error(COMMAND, "no previous rad file");
209 +                return;
210 +        }
211 +        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
212 +                        (fp = fopen(fname, "a")) == NULL) {
213 +                sprintf(errmsg, "cannot open \"%s\"", rifname);
214 +                error(COMMAND, errmsg);
215 +                return;
216 +        }
217 +        fputs("view= ", fp);
218 +        fputs(view, fp);
219 +        fprintview(&ourview, fp);
220 +        putc('\n', fp);
221 +        fclose(fp);
222 + }
223 +
224 +
225 + loadview(s)                             /* load view from rad file */
226 + char  *s;
227 + {
228 +        char  buf[512];
229 +        char  *fname;
230 +        FILE  *fp;
231 +        VIEW  nv;
232 +
233 +        strcpy(buf, "rad -n -s -V -v ");
234 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
235 +                s = sskip(s);
236 +        else
237 +                strcat(buf, "1");
238 +        if (*s)
239 +                atos(rifname, sizeof(rifname), s);
240 +        else if (rifname[0] == '\0') {
241 +                error(COMMAND, "no previous rad file");
242 +                return;
243 +        }
244 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
245 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
246 +                error(COMMAND, errmsg);
247 +                return;
248 +        }
249 +        sprintf(buf+strlen(buf), " %s", fname);
250 +        if ((fp = popen(buf, "r")) == NULL) {
251 +                error(COMMAND, "cannot run rad");
252 +                return;
253 +        }
254 +        buf[0] = '\0';
255 +        fgets(buf, sizeof(buf), fp);
256 +        pclose(fp);
257 +        copystruct(&nv, &stdview);
258 +        if (!sscanview(&nv, buf)) {
259 +                error(COMMAND, "rad error -- no such view?");
260 +                return;
261 +        }
262 +        newview(&nv);
263 + }
264 +
265 +
266   getaim(s)                               /* aim camera */
267   char  *s;
268   {
172        extern double  tan(), atan();
269          double  zfact;
270          VIEW  nv;
271  
# Line 200 | Line 296 | char  *s;
296   getrotate(s)                            /* rotate camera */
297   char  *s;
298   {
203        extern double  normalize(), tan(), atan();
299          VIEW  nv;
300          FVECT  v1;
301          double  angle, elev, zfact;
# Line 246 | Line 341 | register char  *s;
341   getexposure(s)                          /* get new exposure */
342   char  *s;
343   {
249        double  atof(), pow(), fabs();
344          char  buf[128];
345          register char  *cp;
252        register PNODE  *p;
346          RECT  r;
347          int  x, y;
348 <        double  e;
349 <
348 >        register PNODE  *p = &ptrunk;
349 >        int  adapt = 0;
350 >        double  e = 1.0;
351 > start:
352          for (cp = s; isspace(*cp); cp++)
353                  ;
354 +        if (*cp == '@') {
355 +                adapt++;
356 +                goto start;
357 +        }
358          if (*cp == '\0') {              /* normalize to point */
359                  if (dev->getcur == NULL)
360                          return;
# Line 265 | Line 364 | char  *s;
364                  r.l = r.d = 0;
365                  r.r = hresolu; r.u = vresolu;
366                  p = findrect(x, y, &ptrunk, &r, -1);
268                e = 1.0;
367          } else {
368                  if (*cp == '=') {       /* absolute setting */
369                          p = NULL;
# Line 273 | Line 371 | char  *s;
371                          for (cp++; isspace(*cp); cp++)
372                                  ;
373                          if (*cp == '\0') {      /* interactive */
374 <                                sprintf(buf, "exposure (%lf): ", exposure);
374 >                                sprintf(buf, "exposure (%f): ", exposure);
375                                  (*dev->comout)(buf);
376                                  (*dev->comin)(buf, NULL);
377                                  for (cp = buf; isspace(*cp); cp++)
# Line 281 | Line 379 | char  *s;
379                                  if (*cp == '\0')
380                                          return;
381                          }
284                } else {                /* normalize to average */
285                        p = &ptrunk;
286                        e = 1.0;
382                  }
383                  if (*cp == '+' || *cp == '-')   /* f-stops */
384                          e *= pow(2.0, atof(cp));
# Line 291 | Line 386 | char  *s;
386                          e *= atof(cp);
387          }
388          if (p != NULL) {                /* relative setting */
389 <                if (bright(p->v) <= FTINY) {
389 >                if (bright(p->v) < 1e-15) {
390                          error(COMMAND, "cannot normalize to zero");
391                          return;
392                  }
393 <                e *= 0.5 / bright(p->v);
393 >                if (adapt)
394 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
395 >                else
396 >                        e *= 0.5 / bright(p->v);
397          }
398          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
399                  return;
# Line 341 | Line 439 | register union {int i; double d; COLOR C;}  *ptr;
439          case 'b':                       /* boolean */
440                  if (sscanf(str, "%1s", buf) != 1) {
441                          (*dev->comout)(dsc);
442 <                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
442 >                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
443                          (*dev->comout)(buf);
444                          (*dev->comin)(buf, NULL);
445                          if (buf[0] == '\0' ||
# Line 380 | Line 478 | register char  *s;
478          extern double  shadcert;
479          extern COLOR  ambval;
480          extern double  ambacc;
383        extern double  minarad;
481          extern int  ambres;
482          extern int  ambdiv;
483          extern int  ambssamp;
484          extern int  ambounce;
485 <        extern int  directinvis;
485 >        extern int  directvis;
486          extern double  srcsizerat;
487          extern int  do_irrad;
488 +        extern double  specjitter;
489 +        extern double  specthresh;
490          char  buf[128];
491          
492          if (s[0] == '\0') {
493                  (*dev->comout)(
494 <                        "aa ab ad ar as av b dc di dj ds dt i lr lw sp st: ");
494 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
495                  (*dev->comin)(buf, NULL);
496                  s = buf;
497          }
# Line 420 | Line 519 | register char  *s;
519                  case 't':                       /* threshold */
520                          getparam(s+2, "direct threshold", 'r', &shadthresh);
521                          break;
522 <                case 'i':                       /* invisibility */
523 <                        getparam(s+2, "direct invisibility",
524 <                                        'b', &directinvis);
522 >                case 'v':                       /* visibility */
523 >                        getparam(s+2, "direct visibility",
524 >                                        'b', &directvis);
525                          break;
526                  case 's':                       /* sampling */
527                          getparam(s+2, "direct sampling", 'r', &srcsizerat);
# Line 440 | Line 539 | register char  *s;
539          case 'a':                       /* ambient */
540                  switch (s[1]) {
541                  case 'v':                       /* value */
542 <                        getparam(s+2, "ambient value", 'C', ambval);
542 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
543                          break;
544                  case 'a':                       /* accuracy */
545 <                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
545 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
546 >                                setambacc(ambacc);
547                          break;
548                  case 'd':                       /* divisions */
549                          getparam(s+2, "ambient divisions", 'i', &ambdiv);
# Line 456 | Line 556 | register char  *s;
556                          break;
557                  case 'r':
558                          if (getparam(s+2, "ambient resolution", 'i', &ambres))
559 <                                minarad = ambres > 0 ?
460 <                                                thescene.cusize/ambres : 0.0;
559 >                                setambres(ambres);
560                          break;
561                  default:
562                          goto badparam;
563                  }
564                  break;
565 <        case 's':                       /* sample */
565 >        case 'p':                       /* pixel */
566                  switch (s[1]) {
567 <                case 'p':                       /* pixel */
568 <                        if (getparam(s+2, "sample pixel", 'i', &psample))
567 >                case 's':                       /* sample */
568 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
569                                  pdepth = 0;
570                          break;
571                  case 't':                       /* threshold */
572 <                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
572 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
573                                  pdepth = 0;
574                          break;
575                  default:
576                          goto badparam;
577                  }
578                  break;
579 +        case 's':                       /* specular */
580 +                switch (s[1]) {
581 +                case 'j':                       /* jitter */
582 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
583 +                        break;
584 +                case 't':                       /* threshold */
585 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
586 +                        break;
587 +                default:
588 +                        goto badparam;
589 +                }
590 +                break;
591          case '\0':                      /* nothing */
592                  break;
593          default:;
# Line 496 | Line 607 | char  *s;
607          int  x, y;
608          RAY  thisray;
609  
610 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
611 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
501 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
610 >        if (!sscanvec(s, thisray.rorg) ||
611 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
612  
613                  if (dev->getcur == NULL)
614                          return;
# Line 558 | Line 668 | char  *s;
668          COLR  *scanline;
669          int  y;
670  
671 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
671 >        while (isspace(*s))
672 >                s++;
673 >        if (*s)
674 >                atos(buf, sizeof(buf), s);
675 >        else if (buf[0] == '\0') {
676                  error(COMMAND, "no file");
677                  return;
678          }
# Line 568 | Line 682 | char  *s;
682                  error(COMMAND, errmsg);
683                  return;
684          }
685 + #ifdef MSDOS
686 +        setmode(fileno(fp), O_BINARY);
687 + #endif
688          (*dev->comout)("writing \"");
689          (*dev->comout)(fname);
690          (*dev->comout)("\"...\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines