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.25 by greg, Fri Jul 19 15:22:02 1991 UTC vs.
Revision 2.25 by greg, Tue Jul 12 15:24:28 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 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 FILE  *popen();
36 +
37 + extern char  rifname[128];              /* rad input file name */
38 +
39 + extern char  VersionID[];
40   extern char  *progname;
41 + extern char  *octname;
42  
43  
44   getframe(s)                             /* get a new frame */
# Line 54 | Line 70 | char  *s;
70          int  change = 0;
71          VIEW  nv;
72  
73 +        while (isspace(*s))
74 +                s++;
75 +        if (*s == '-') {                        /* command line parameters */
76 +                copystruct(&nv, &ourview);
77 +                if (sscanview(&nv, s))
78 +                        newview(&nv);
79 +                else
80 +                        error(COMMAND, "bad view option(s)");
81 +                return;
82 +        }
83          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
84                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
85                                  (fp = fopen(fname, "a")) == NULL) {
# Line 64 | Line 90 | char  *s;
90                  fputs(progname, fp);
91                  fprintview(&ourview, fp);
92                  fputs(sskip(s), fp);
93 <                fputs("\n", fp);
93 >                putc('\n', fp);
94                  fclose(fp);
95                  return;
96          }
97          sprintf(buf, "view type (%c): ", ourview.type);
98          (*dev->comout)(buf);
99          (*dev->comin)(buf, NULL);
100 <        if (buf[0] == CTRL(C)) return;
100 >        if (buf[0] == CTRL('C')) return;
101          if (buf[0] && buf[0] != ourview.type) {
102                  nv.type = buf[0];
103                  change++;
# Line 81 | Line 107 | char  *s;
107                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
108          (*dev->comout)(buf);
109          (*dev->comin)(buf, NULL);
110 <        if (buf[0] == CTRL(C)) return;
111 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
110 >        if (buf[0] == CTRL('C')) return;
111 >        if (sscanvec(buf, nv.vp))
112                  change++;
113          else
114                  VCOPY(nv.vp, ourview.vp);
# Line 90 | Line 116 | char  *s;
116                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
117          (*dev->comout)(buf);
118          (*dev->comin)(buf, NULL);
119 <        if (buf[0] == CTRL(C)) return;
120 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
119 >        if (buf[0] == CTRL('C')) return;
120 >        if (sscanvec(buf, nv.vdir))
121                  change++;
122          else
123                  VCOPY(nv.vdir, ourview.vdir);
# Line 99 | Line 125 | char  *s;
125                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
126          (*dev->comout)(buf);
127          (*dev->comin)(buf, NULL);
128 <        if (buf[0] == CTRL(C)) return;
129 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
128 >        if (buf[0] == CTRL('C')) return;
129 >        if (sscanvec(buf, nv.vup))
130                  change++;
131          else
132                  VCOPY(nv.vup, ourview.vup);
# Line 108 | Line 134 | char  *s;
134                          ourview.horiz, ourview.vert);
135          (*dev->comout)(buf);
136          (*dev->comin)(buf, NULL);
137 <        if (buf[0] == CTRL(C)) return;
137 >        if (buf[0] == CTRL('C')) return;
138          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
139                  change++;
140          else {
# Line 118 | Line 144 | char  *s;
144                          ourview.hoff, ourview.voff);
145          (*dev->comout)(buf);
146          (*dev->comin)(buf, NULL);
147 <        if (buf[0] == CTRL(C)) return;
147 >        if (buf[0] == CTRL('C')) return;
148          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
149                  change++;
150          else {
# Line 139 | Line 165 | char  *s;
165  
166          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
167                  copystruct(&nv, &stdview);
168 <                if ((fname = getpath(buf, NULL, 0)) == NULL ||
169 <                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
168 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
169 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
170                          sprintf(errmsg, "cannot open \"%s\"", buf);
171                          error(COMMAND, errmsg);
172                          return;
# Line 162 | Line 188 | char  *s;
188   }
189  
190  
191 + saveview(s)                             /* save view to rad file */
192 + char  *s;
193 + {
194 +        char  view[64];
195 +        char  *fname;
196 +        FILE  *fp;
197 +
198 +        if (*atos(view, sizeof(view), s)) {
199 +                if (isint(view)) {
200 +                        error(COMMAND, "cannot write view by number");
201 +                        return;
202 +                }
203 +                s = sskip(s);
204 +        }
205 +        while (isspace(*s))
206 +                s++;
207 +        if (*s)
208 +                atos(rifname, sizeof(rifname), s);
209 +        else if (rifname[0] == '\0') {
210 +                error(COMMAND, "no previous rad file");
211 +                return;
212 +        }
213 +        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
214 +                        (fp = fopen(fname, "a")) == NULL) {
215 +                sprintf(errmsg, "cannot open \"%s\"", rifname);
216 +                error(COMMAND, errmsg);
217 +                return;
218 +        }
219 +        fputs("view= ", fp);
220 +        fputs(view, fp);
221 +        fprintview(&ourview, fp);
222 +        putc('\n', fp);
223 +        fclose(fp);
224 + }
225 +
226 +
227 + loadview(s)                             /* load view from rad file */
228 + char  *s;
229 + {
230 +        char  buf[512];
231 +        char  *fname;
232 +        FILE  *fp;
233 +        VIEW  nv;
234 +
235 +        strcpy(buf, "rad -n -s -V -v ");
236 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
237 +                s = sskip(s);
238 +        else
239 +                strcat(buf, "1");
240 +        if (*s)
241 +                atos(rifname, sizeof(rifname), s);
242 +        else if (rifname[0] == '\0') {
243 +                error(COMMAND, "no previous rad file");
244 +                return;
245 +        }
246 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
247 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
248 +                error(COMMAND, errmsg);
249 +                return;
250 +        }
251 +        sprintf(buf+strlen(buf), " %s", fname);
252 +        if ((fp = popen(buf, "r")) == NULL) {
253 +                error(COMMAND, "cannot run rad");
254 +                return;
255 +        }
256 +        buf[0] = '\0';
257 +        fgets(buf, sizeof(buf), fp);
258 +        pclose(fp);
259 +        copystruct(&nv, &stdview);
260 +        if (!sscanview(&nv, buf)) {
261 +                error(COMMAND, "rad error -- no such view?");
262 +                return;
263 +        }
264 +        newview(&nv);
265 + }
266 +
267 +
268   getaim(s)                               /* aim camera */
269   char  *s;
270   {
168        extern double  tan(), atan();
271          double  zfact;
272          VIEW  nv;
273  
# Line 196 | Line 298 | char  *s;
298   getrotate(s)                            /* rotate camera */
299   char  *s;
300   {
199        extern double  normalize(), tan(), atan();
301          VIEW  nv;
302          FVECT  v1;
303          double  angle, elev, zfact;
# Line 242 | Line 343 | register char  *s;
343   getexposure(s)                          /* get new exposure */
344   char  *s;
345   {
245        double  atof(), pow(), fabs();
346          char  buf[128];
347          register char  *cp;
248        register PNODE  *p;
348          RECT  r;
349          int  x, y;
350 <        double  e;
350 >        register PNODE  *p = &ptrunk;
351 >        int  adapt = 0;
352 >        double  e = 1.0;
353  
354          for (cp = s; isspace(*cp); cp++)
355                  ;
356 +        if (*cp == '@') {
357 +                adapt++;
358 +                while (isspace(*++cp))
359 +                        ;
360 +        }
361          if (*cp == '\0') {              /* normalize to point */
362                  if (dev->getcur == NULL)
363                          return;
# Line 261 | Line 367 | char  *s;
367                  r.l = r.d = 0;
368                  r.r = hresolu; r.u = vresolu;
369                  p = findrect(x, y, &ptrunk, &r, -1);
264                e = 1.0;
370          } else {
371                  if (*cp == '=') {       /* absolute setting */
372                          p = NULL;
# Line 269 | Line 374 | char  *s;
374                          for (cp++; isspace(*cp); cp++)
375                                  ;
376                          if (*cp == '\0') {      /* interactive */
377 <                                sprintf(buf, "exposure (%lf): ", exposure);
377 >                                sprintf(buf, "exposure (%f): ", exposure);
378                                  (*dev->comout)(buf);
379                                  (*dev->comin)(buf, NULL);
380                                  for (cp = buf; isspace(*cp); cp++)
# Line 277 | Line 382 | char  *s;
382                                  if (*cp == '\0')
383                                          return;
384                          }
280                } else {                /* normalize to average */
281                        p = &ptrunk;
282                        e = 1.0;
385                  }
386                  if (*cp == '+' || *cp == '-')   /* f-stops */
387                          e *= pow(2.0, atof(cp));
# Line 287 | Line 389 | char  *s;
389                          e *= atof(cp);
390          }
391          if (p != NULL) {                /* relative setting */
392 <                if (bright(p->v) <= FTINY) {
392 >                if (bright(p->v) < 1e-15) {
393                          error(COMMAND, "cannot normalize to zero");
394                          return;
395                  }
396 <                e *= 0.5 / bright(p->v);
396 >                if (adapt)
397 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
398 >                else
399 >                        e *= 0.5 / bright(p->v);
400          }
401          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
402                  return;
# Line 319 | Line 424 | register union {int i; double d; COLOR C;}  *ptr;
424                          (*dev->comout)(buf);
425                          (*dev->comin)(buf, NULL);
426                          if (sscanf(buf, "%d", &i0) != 1)
427 <                                break;
427 >                                return(0);
428                  }
429                  ptr->i = i0;
430 <                break;
430 >                return(1);
431          case 'r':                       /* real */
432                  if (sscanf(str, "%lf", &d0) != 1) {
433                          (*dev->comout)(dsc);
# Line 330 | Line 435 | register union {int i; double d; COLOR C;}  *ptr;
435                          (*dev->comout)(buf);
436                          (*dev->comin)(buf, NULL);
437                          if (sscanf(buf, "%lf", &d0) != 1)
438 <                                break;
438 >                                return(0);
439                  }
440                  ptr->d = d0;
441 <                break;
441 >                return(1);
442          case 'b':                       /* boolean */
443                  if (sscanf(str, "%1s", buf) != 1) {
444                          (*dev->comout)(dsc);
445 <                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
445 >                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
446                          (*dev->comout)(buf);
447                          (*dev->comin)(buf, NULL);
448                          if (buf[0] == '\0' ||
449                                          index("yY+1tTnN-0fF", buf[0]) == NULL)
450 <                                break;
450 >                                return(0);
451                  }
452                  ptr->i = index("yY+1tT", buf[0]) != NULL;
453 <                break;
453 >                return(1);
454          case 'C':                       /* color */
455                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
456                          (*dev->comout)(dsc);
# Line 356 | Line 461 | register union {int i; double d; COLOR C;}  *ptr;
461                          (*dev->comout)(buf);
462                          (*dev->comin)(buf, NULL);
463                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
464 <                                break;
464 >                                return(0);
465                  }
466                  setcolor(ptr->C, d0, d1, d2);
467 <                break;
467 >                return(1);
468          }
469   }
470  
# Line 376 | Line 481 | register char  *s;
481          extern double  shadcert;
482          extern COLOR  ambval;
483          extern double  ambacc;
379        extern double  minarad;
484          extern int  ambres;
485          extern int  ambdiv;
486          extern int  ambssamp;
487          extern int  ambounce;
488 <        extern int  directinvis;
488 >        extern int  directvis;
489 >        extern double  srcsizerat;
490          extern int  do_irrad;
491 +        extern double  specjitter;
492 +        extern double  specthresh;
493          char  buf[128];
494          
495          if (s[0] == '\0') {
496                  (*dev->comout)(
497 <                        "aa ab ad ar as av b dc di dj dt i lr lw sp st: ");
497 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
498                  (*dev->comin)(buf, NULL);
499                  s = buf;
500          }
# Line 415 | Line 522 | register char  *s;
522                  case 't':                       /* threshold */
523                          getparam(s+2, "direct threshold", 'r', &shadthresh);
524                          break;
525 <                case 'i':                       /* invisibility */
526 <                        getparam(s+2, "direct invisibility",
527 <                                        'b', &directinvis);
525 >                case 'v':                       /* visibility */
526 >                        getparam(s+2, "direct visibility",
527 >                                        'b', &directvis);
528                          break;
529 +                case 's':                       /* sampling */
530 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
531 +                        break;
532                  default:
533                          goto badparam;
534                  }
# Line 432 | Line 542 | register char  *s;
542          case 'a':                       /* ambient */
543                  switch (s[1]) {
544                  case 'v':                       /* value */
545 <                        getparam(s+2, "ambient value", 'C', ambval);
545 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
546                          break;
547                  case 'a':                       /* accuracy */
548 <                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
548 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
549 >                                setambacc(ambacc);
550                          break;
551                  case 'd':                       /* divisions */
552                          getparam(s+2, "ambient divisions", 'i', &ambdiv);
# Line 447 | Line 558 | register char  *s;
558                          getparam(s+2, "ambient bounces", 'i', &ambounce);
559                          break;
560                  case 'r':
561 <                        getparam(s+2, "ambient resolution", 'i', &ambres);
562 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
561 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
562 >                                setambres(ambres);
563                          break;
564                  default:
565                          goto badparam;
566                  }
567                  break;
568 <        case 's':                       /* sample */
568 >        case 'p':                       /* pixel */
569                  switch (s[1]) {
570 <                case 'p':                       /* pixel */
571 <                        getparam(s+2, "sample pixel", 'i', &psample);
572 <                        pdepth = 0;
570 >                case 's':                       /* sample */
571 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
572 >                                pdepth = 0;
573                          break;
574                  case 't':                       /* threshold */
575 <                        getparam(s+2, "sample threshold", 'r', &maxdiff);
576 <                        pdepth = 0;
575 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
576 >                                pdepth = 0;
577                          break;
578                  default:
579                          goto badparam;
580                  }
581                  break;
582 +        case 's':                       /* specular */
583 +                switch (s[1]) {
584 +                case 'j':                       /* jitter */
585 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
586 +                        break;
587 +                case 't':                       /* threshold */
588 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
589 +                        break;
590 +                default:
591 +                        goto badparam;
592 +                }
593 +                break;
594          case '\0':                      /* nothing */
595                  break;
596          default:;
597   badparam:
598 +                *sskip(s) = '\0';
599                  sprintf(errmsg, "%s: unknown variable", s);
600                  error(COMMAND, errmsg);
601                  break;
# Line 486 | Line 610 | char  *s;
610          int  x, y;
611          RAY  thisray;
612  
613 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
614 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
491 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
613 >        if (!sscanvec(s, thisray.rorg) ||
614 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
615  
616                  if (dev->getcur == NULL)
617                          return;
# Line 514 | Line 637 | char  *s;
637          if (thisray.ro == NULL)
638                  (*dev->comout)("ray hit nothing");
639          else {
640 <                sprintf(buf, "ray hit %s %s \"%s\"",
641 <                                objptr(thisray.ro->omod)->oname,
640 >                sprintf(buf, "ray hit %s%s %s \"%s\"",
641 >                                thisray.rod < 0.0 ? "back of " : "",
642 >                                thisray.ro->omod == OVOID ? VOIDID :
643 >                                        objptr(thisray.ro->omod)->oname,
644                                  ofun[thisray.ro->otype].funame,
645                                  thisray.ro->oname);
646                  (*dev->comout)(buf);
# Line 528 | Line 653 | char  *s;
653                          (*dev->comout)(buf);
654                  }
655                  (*dev->comin)(buf, NULL);
656 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
656 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
657                                  colval(thisray.rcol,RED),
658                                  colval(thisray.rcol,GRN),
659 <                                colval(thisray.rcol,BLU));
659 >                                colval(thisray.rcol,BLU),
660 >                                luminance(thisray.rcol));
661                  (*dev->comout)(buf);
662          }
663          (*dev->comin)(buf, NULL);
# Line 547 | Line 673 | char  *s;
673          COLR  *scanline;
674          int  y;
675  
676 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
676 >        while (isspace(*s))
677 >                s++;
678 >        if (*s)
679 >                atos(buf, sizeof(buf), s);
680 >        else if (buf[0] == '\0') {
681                  error(COMMAND, "no file");
682                  return;
683          }
# Line 557 | Line 687 | char  *s;
687                  error(COMMAND, errmsg);
688                  return;
689          }
690 + #ifdef MSDOS
691 +        setmode(fileno(fp), O_BINARY);
692 + #endif
693          (*dev->comout)("writing \"");
694          (*dev->comout)(fname);
695          (*dev->comout)("\"...\n");
696                                                  /* write header */
697 +        newheader("RADIANCE", fp);
698          fputs(progname, fp);
699          fprintview(&ourview, fp);
700 <        putc('\n', fp);
700 >        if (octname != NULL)
701 >                fprintf(fp, " %s\n", octname);
702 >        else
703 >                putc('\n', fp);
704 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
705          if (exposure != 1.0)
706                  fputexpos(exposure, fp);
707          if (dev->pixaspect != 1.0)
708                  fputaspect(dev->pixaspect, fp);
709          fputformat(COLRFMT, fp);
710          putc('\n', fp);
711 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
711 >        fprtresolu(hresolu, vresolu, fp);
712  
713          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
714 <        if (scanline == NULL)
715 <                error(SYSTEM, "out of memory in writepict");
714 >        if (scanline == NULL) {
715 >                error(COMMAND, "not enough memory!");
716 >                fclose(fp);
717 >                unlink(fname);
718 >                return;
719 >        }
720          for (y = vresolu-1; y >= 0; y--) {
721                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
722                  if (fwritecolrs(scanline, hresolu, fp) < 0)
723                          break;
724          }
725 +        free((char *)scanline);
726          if (fclose(fp) < 0)
727                  error(COMMAND, "write error");
585        free((char *)scanline);
728   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines