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.33 by greg, Mon Nov 11 17:42:19 1991 UTC vs.
Revision 2.25 by greg, Tue Jul 12 15:24:28 1994 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 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;
# Line 58 | 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 68 | 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 85 | 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 94 | 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 103 | 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 112 | 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 122 | 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 143 | 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 ||
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);
# Line 166 | 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   {
172        extern double  tan(), atan();
271          double  zfact;
272          VIEW  nv;
273  
# Line 200 | Line 298 | char  *s;
298   getrotate(s)                            /* rotate camera */
299   char  *s;
300   {
203        extern double  normalize(), tan(), atan();
301          VIEW  nv;
302          FVECT  v1;
303          double  angle, elev, zfact;
# Line 246 | Line 343 | register char  *s;
343   getexposure(s)                          /* get new exposure */
344   char  *s;
345   {
249        double  atof(), pow(), fabs();
346          char  buf[128];
347          register char  *cp;
252        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 265 | 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);
268                e = 1.0;
370          } else {
371                  if (*cp == '=') {       /* absolute setting */
372                          p = NULL;
# Line 273 | 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 281 | Line 382 | char  *s;
382                                  if (*cp == '\0')
383                                          return;
384                          }
284                } else {                /* normalize to average */
285                        p = &ptrunk;
286                        e = 1.0;
385                  }
386                  if (*cp == '+' || *cp == '-')   /* f-stops */
387                          e *= pow(2.0, atof(cp));
# Line 291 | 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 341 | Line 442 | register union {int i; double d; COLOR C;}  *ptr;
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' ||
# Line 380 | Line 481 | register char  *s;
481          extern double  shadcert;
482          extern COLOR  ambval;
483          extern double  ambacc;
383        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 ds 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 420 | 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);
# Line 440 | 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 456 | Line 559 | register char  *s;
559                          break;
560                  case 'r':
561                          if (getparam(s+2, "ambient resolution", 'i', &ambres))
562 <                                minarad = ambres > 0 ?
460 <                                                thescene.cusize/ambres : 0.0;
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 <                        if (getparam(s+2, "sample pixel", 'i', &psample))
570 >                case 's':                       /* sample */
571 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
572                                  pdepth = 0;
573                          break;
574                  case 't':                       /* threshold */
575 <                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
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:;
# Line 496 | 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],
501 <                &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 524 | 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 558 | 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 568 | 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          if (octname != NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines