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.19 by greg, Thu Aug 26 11:24:04 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 141 | 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 ||
167 <                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
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);
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 +                if (isint(view)) {
198 +                        error(COMMAND, "cannot write view by number");
199 +                        return;
200 +                }
201 +                s = sskip(s);
202 +        }
203 +        if (sscanf(s, "%s", rifname) != 1 && rifname[0] == '\0') {
204 +                error(COMMAND, "no previous rad file");
205 +                return;
206 +        }
207 +        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
208 +                        (fp = fopen(fname, "a")) == NULL) {
209 +                sprintf(errmsg, "cannot open \"%s\"", rifname);
210 +                error(COMMAND, errmsg);
211 +                return;
212 +        }
213 +        fputs("view= ", fp);
214 +        fputs(view, fp);
215 +        fprintview(&ourview, fp);
216 +        putc('\n', fp);
217 +        fclose(fp);
218 + }
219 +
220 +
221 + loadview(s)                             /* load view from rad file */
222 + char  *s;
223 + {
224 +        char  buf[512];
225 +        char  *fname;
226 +        FILE  *fp;
227 +        VIEW  nv;
228 +
229 +        strcpy(buf, "rad -n -s -V -v ");
230 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
231 +                s = sskip(s);
232 +        else
233 +                strcat(buf, "1");
234 +        if (sscanf(s, "%s", rifname) != 1 && rifname[0] == '\0') {
235 +                error(COMMAND, "no previous rad file");
236 +                return;
237 +        }
238 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
239 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
240 +                error(COMMAND, errmsg);
241 +                return;
242 +        }
243 +        sprintf(buf+strlen(buf), " %s", fname);
244 +        if ((fp = popen(buf, "r")) == NULL) {
245 +                error(COMMAND, "cannot run rad");
246 +                return;
247 +        }
248 +        buf[0] = '\0';
249 +        fgets(buf, sizeof(buf), fp);
250 +        pclose(fp);
251 +        copystruct(&nv, &stdview);
252 +        if (!sscanview(&nv, buf)) {
253 +                error(COMMAND, "rad error -- no such view?");
254 +                return;
255 +        }
256 +        newview(&nv);
257 + }
258 +
259 +
260   getaim(s)                               /* aim camera */
261   char  *s;
262   {
170        extern double  tan(), atan();
263          double  zfact;
264          VIEW  nv;
265  
# Line 198 | Line 290 | char  *s;
290   getrotate(s)                            /* rotate camera */
291   char  *s;
292   {
201        extern double  normalize(), tan(), atan();
293          VIEW  nv;
294          FVECT  v1;
295          double  angle, elev, zfact;
# Line 244 | Line 335 | register char  *s;
335   getexposure(s)                          /* get new exposure */
336   char  *s;
337   {
247        double  atof(), pow(), fabs();
338          char  buf[128];
339          register char  *cp;
250        register PNODE  *p;
340          RECT  r;
341          int  x, y;
342 <        double  e;
343 <
342 >        register PNODE  *p = &ptrunk;
343 >        int  adapt = 0;
344 >        double  e = 1.0;
345 > start:
346          for (cp = s; isspace(*cp); cp++)
347                  ;
348 +        if (*cp == '@') {
349 +                adapt++;
350 +                goto start;
351 +        }
352          if (*cp == '\0') {              /* normalize to point */
353                  if (dev->getcur == NULL)
354                          return;
# Line 263 | Line 358 | char  *s;
358                  r.l = r.d = 0;
359                  r.r = hresolu; r.u = vresolu;
360                  p = findrect(x, y, &ptrunk, &r, -1);
266                e = 1.0;
361          } else {
362                  if (*cp == '=') {       /* absolute setting */
363                          p = NULL;
# Line 271 | Line 365 | char  *s;
365                          for (cp++; isspace(*cp); cp++)
366                                  ;
367                          if (*cp == '\0') {      /* interactive */
368 <                                sprintf(buf, "exposure (%lf): ", exposure);
368 >                                sprintf(buf, "exposure (%f): ", exposure);
369                                  (*dev->comout)(buf);
370                                  (*dev->comin)(buf, NULL);
371                                  for (cp = buf; isspace(*cp); cp++)
# Line 279 | Line 373 | char  *s;
373                                  if (*cp == '\0')
374                                          return;
375                          }
282                } else {                /* normalize to average */
283                        p = &ptrunk;
284                        e = 1.0;
376                  }
377                  if (*cp == '+' || *cp == '-')   /* f-stops */
378                          e *= pow(2.0, atof(cp));
# Line 289 | Line 380 | char  *s;
380                          e *= atof(cp);
381          }
382          if (p != NULL) {                /* relative setting */
383 <                if (bright(p->v) <= FTINY) {
383 >                if (bright(p->v) < 1e-15) {
384                          error(COMMAND, "cannot normalize to zero");
385                          return;
386                  }
387 <                e *= 0.5 / bright(p->v);
387 >                if (adapt)
388 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
389 >                else
390 >                        e *= 0.5 / bright(p->v);
391          }
392          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
393                  return;
# Line 321 | Line 415 | register union {int i; double d; COLOR C;}  *ptr;
415                          (*dev->comout)(buf);
416                          (*dev->comin)(buf, NULL);
417                          if (sscanf(buf, "%d", &i0) != 1)
418 <                                break;
418 >                                return(0);
419                  }
420                  ptr->i = i0;
421 <                break;
421 >                return(1);
422          case 'r':                       /* real */
423                  if (sscanf(str, "%lf", &d0) != 1) {
424                          (*dev->comout)(dsc);
# Line 332 | Line 426 | register union {int i; double d; COLOR C;}  *ptr;
426                          (*dev->comout)(buf);
427                          (*dev->comin)(buf, NULL);
428                          if (sscanf(buf, "%lf", &d0) != 1)
429 <                                break;
429 >                                return(0);
430                  }
431                  ptr->d = d0;
432 <                break;
432 >                return(1);
433          case 'b':                       /* boolean */
434                  if (sscanf(str, "%1s", buf) != 1) {
435                          (*dev->comout)(dsc);
436 <                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
436 >                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
437                          (*dev->comout)(buf);
438                          (*dev->comin)(buf, NULL);
439                          if (buf[0] == '\0' ||
440                                          index("yY+1tTnN-0fF", buf[0]) == NULL)
441 <                                break;
441 >                                return(0);
442                  }
443                  ptr->i = index("yY+1tT", buf[0]) != NULL;
444 <                break;
444 >                return(1);
445          case 'C':                       /* color */
446                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
447                          (*dev->comout)(dsc);
# Line 358 | Line 452 | register union {int i; double d; COLOR C;}  *ptr;
452                          (*dev->comout)(buf);
453                          (*dev->comin)(buf, NULL);
454                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
455 <                                break;
455 >                                return(0);
456                  }
457                  setcolor(ptr->C, d0, d1, d2);
458 <                break;
458 >                return(1);
459          }
460   }
461  
# Line 378 | Line 472 | register char  *s;
472          extern double  shadcert;
473          extern COLOR  ambval;
474          extern double  ambacc;
381        extern double  minarad;
475          extern int  ambres;
476          extern int  ambdiv;
477          extern int  ambssamp;
478          extern int  ambounce;
479 <        extern int  directinvis;
479 >        extern int  directvis;
480          extern double  srcsizerat;
481          extern int  do_irrad;
482 +        extern double  specjitter;
483 +        extern double  specthresh;
484          char  buf[128];
485          
486          if (s[0] == '\0') {
487                  (*dev->comout)(
488 <                        "aa ab ad ar as av b dc di dj dt i lr lw sp st: ");
488 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
489                  (*dev->comin)(buf, NULL);
490                  s = buf;
491          }
# Line 418 | Line 513 | register char  *s;
513                  case 't':                       /* threshold */
514                          getparam(s+2, "direct threshold", 'r', &shadthresh);
515                          break;
516 <                case 'i':                       /* invisibility */
517 <                        getparam(s+2, "direct invisibility",
518 <                                        'b', &directinvis);
516 >                case 'v':                       /* visibility */
517 >                        getparam(s+2, "direct visibility",
518 >                                        'b', &directvis);
519                          break;
520                  case 's':                       /* sampling */
521                          getparam(s+2, "direct sampling", 'r', &srcsizerat);
# Line 438 | Line 533 | register char  *s;
533          case 'a':                       /* ambient */
534                  switch (s[1]) {
535                  case 'v':                       /* value */
536 <                        getparam(s+2, "ambient value", 'C', ambval);
536 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
537                          break;
538                  case 'a':                       /* accuracy */
539 <                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
539 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
540 >                                setambacc(ambacc);
541                          break;
542                  case 'd':                       /* divisions */
543                          getparam(s+2, "ambient divisions", 'i', &ambdiv);
# Line 453 | Line 549 | register char  *s;
549                          getparam(s+2, "ambient bounces", 'i', &ambounce);
550                          break;
551                  case 'r':
552 <                        getparam(s+2, "ambient resolution", 'i', &ambres);
553 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
552 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
553 >                                setambres(ambres);
554                          break;
555                  default:
556                          goto badparam;
557                  }
558                  break;
559 <        case 's':                       /* sample */
559 >        case 'p':                       /* pixel */
560                  switch (s[1]) {
561 <                case 'p':                       /* pixel */
562 <                        getparam(s+2, "sample pixel", 'i', &psample);
563 <                        pdepth = 0;
561 >                case 's':                       /* sample */
562 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
563 >                                pdepth = 0;
564                          break;
565                  case 't':                       /* threshold */
566 <                        getparam(s+2, "sample threshold", 'r', &maxdiff);
567 <                        pdepth = 0;
566 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
567 >                                pdepth = 0;
568                          break;
569                  default:
570                          goto badparam;
571                  }
572                  break;
573 +        case 's':                       /* specular */
574 +                switch (s[1]) {
575 +                case 'j':                       /* jitter */
576 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
577 +                        break;
578 +                case 't':                       /* threshold */
579 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
580 +                        break;
581 +                default:
582 +                        goto badparam;
583 +                }
584 +                break;
585          case '\0':                      /* nothing */
586                  break;
587          default:;
# Line 493 | Line 601 | char  *s;
601          int  x, y;
602          RAY  thisray;
603  
604 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
605 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
498 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
604 >        if (!sscanvec(s, thisray.rorg) ||
605 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
606  
607                  if (dev->getcur == NULL)
608                          return;
# Line 535 | Line 642 | char  *s;
642                          (*dev->comout)(buf);
643                  }
644                  (*dev->comin)(buf, NULL);
645 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
645 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
646                                  colval(thisray.rcol,RED),
647                                  colval(thisray.rcol,GRN),
648 <                                colval(thisray.rcol,BLU));
648 >                                colval(thisray.rcol,BLU),
649 >                                luminance(thisray.rcol));
650                  (*dev->comout)(buf);
651          }
652          (*dev->comin)(buf, NULL);
# Line 564 | Line 672 | char  *s;
672                  error(COMMAND, errmsg);
673                  return;
674          }
675 + #ifdef MSDOS
676 +        setmode(fileno(fp), O_BINARY);
677 + #endif
678          (*dev->comout)("writing \"");
679          (*dev->comout)(fname);
680          (*dev->comout)("\"...\n");
# Line 581 | Line 692 | char  *s;
692                  fputaspect(dev->pixaspect, fp);
693          fputformat(COLRFMT, fp);
694          putc('\n', fp);
695 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
695 >        fprtresolu(hresolu, vresolu, fp);
696  
697          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
698          if (scanline == NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines