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.4 by greg, Mon Dec 23 23:18:31 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 24 | Line 24 | static char SCCSid[] = "$SunId$ LBL";
24  
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 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          }
# Line 86 | Line 106 | char  *s;
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)
109 >        if (sscanvec(buf, nv.vp))
110                  change++;
111          else
112                  VCOPY(nv.vp, ourview.vp);
# Line 95 | Line 115 | char  *s;
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)
118 >        if (sscanvec(buf, nv.vdir))
119                  change++;
120          else
121                  VCOPY(nv.vdir, ourview.vdir);
# Line 104 | Line 124 | char  *s;
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)
127 >        if (sscanvec(buf, nv.vup))
128                  change++;
129          else
130                  VCOPY(nv.vup, ourview.vup);
# 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 +        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   {
172        extern double  tan(), atan();
263          double  zfact;
264          VIEW  nv;
265  
# Line 200 | Line 290 | char  *s;
290   getrotate(s)                            /* rotate camera */
291   char  *s;
292   {
203        extern double  normalize(), tan(), atan();
293          VIEW  nv;
294          FVECT  v1;
295          double  angle, elev, zfact;
# Line 248 | Line 337 | char  *s;
337   {
338          char  buf[128];
339          register char  *cp;
251        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 264 | 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);
267                e = 1.0;
361          } else {
362                  if (*cp == '=') {       /* absolute setting */
363                          p = NULL;
# Line 272 | 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 280 | Line 373 | char  *s;
373                                  if (*cp == '\0')
374                                          return;
375                          }
283                } else {                /* normalize to average */
284                        p = &ptrunk;
285                        e = 1.0;
376                  }
377                  if (*cp == '+' || *cp == '-')   /* f-stops */
378                          e *= pow(2.0, atof(cp));
# Line 290 | 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 379 | Line 472 | register char  *s;
472          extern double  shadcert;
473          extern COLOR  ambval;
474          extern double  ambacc;
382        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 ds 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 419 | 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 439 | 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 455 | Line 550 | register char  *s;
550                          break;
551                  case 'r':
552                          if (getparam(s+2, "ambient resolution", 'i', &ambres))
553 <                                minarad = ambres > 0 ?
459 <                                                thescene.cusize/ambres : 0.0;
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 <                        if (getparam(s+2, "sample pixel", 'i', &psample))
561 >                case 's':                       /* sample */
562 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
563                                  pdepth = 0;
564                          break;
565                  case 't':                       /* threshold */
566 <                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
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 495 | 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],
500 <                &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 567 | 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");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines