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.21 by greg, Sun Oct 14 11:04:56 1990 UTC vs.
Revision 2.9 by greg, Mon Apr 6 18:04:19 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1992 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 +
34 + extern char  VersionID[];
35   extern char  *progname;
36 + extern char  *octname;
37  
38  
39   getframe(s)                             /* get a new frame */
# Line 54 | Line 65 | char  *s;
65          int  change = 0;
66          VIEW  nv;
67  
68 +        while (isspace(*s))
69 +                s++;
70 +        if (*s == '-') {                        /* command line parameters */
71 +                copystruct(&nv, &ourview);
72 +                if (sscanview(&nv, s))
73 +                        newview(&nv);
74 +                else
75 +                        error(COMMAND, "bad view option(s)");
76 +                return;
77 +        }
78          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
79                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
80                                  (fp = fopen(fname, "a")) == NULL) {
# Line 71 | Line 92 | char  *s;
92          sprintf(buf, "view type (%c): ", ourview.type);
93          (*dev->comout)(buf);
94          (*dev->comin)(buf, NULL);
95 <        if (buf[0] == CTRL(C)) return;
95 >        if (buf[0] == CTRL('C')) return;
96          if (buf[0] && buf[0] != ourview.type) {
97                  nv.type = buf[0];
98                  change++;
# Line 81 | Line 102 | char  *s;
102                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
103          (*dev->comout)(buf);
104          (*dev->comin)(buf, NULL);
105 <        if (buf[0] == CTRL(C)) return;
106 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
105 >        if (buf[0] == CTRL('C')) return;
106 >        if (sscanvec(buf, nv.vp))
107                  change++;
108          else
109                  VCOPY(nv.vp, ourview.vp);
# Line 90 | Line 111 | char  *s;
111                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
112          (*dev->comout)(buf);
113          (*dev->comin)(buf, NULL);
114 <        if (buf[0] == CTRL(C)) return;
115 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
114 >        if (buf[0] == CTRL('C')) return;
115 >        if (sscanvec(buf, nv.vdir))
116                  change++;
117          else
118                  VCOPY(nv.vdir, ourview.vdir);
# Line 99 | Line 120 | char  *s;
120                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
121          (*dev->comout)(buf);
122          (*dev->comin)(buf, NULL);
123 <        if (buf[0] == CTRL(C)) return;
124 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
123 >        if (buf[0] == CTRL('C')) return;
124 >        if (sscanvec(buf, nv.vup))
125                  change++;
126          else
127                  VCOPY(nv.vup, ourview.vup);
# Line 108 | Line 129 | char  *s;
129                          ourview.horiz, ourview.vert);
130          (*dev->comout)(buf);
131          (*dev->comin)(buf, NULL);
132 <        if (buf[0] == CTRL(C)) return;
132 >        if (buf[0] == CTRL('C')) return;
133          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
134                  change++;
135          else {
# Line 118 | Line 139 | char  *s;
139                          ourview.hoff, ourview.voff);
140          (*dev->comout)(buf);
141          (*dev->comin)(buf, NULL);
142 <        if (buf[0] == CTRL(C)) return;
142 >        if (buf[0] == CTRL('C')) return;
143          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
144                  change++;
145          else {
# Line 140 | Line 161 | char  *s;
161          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
162                  copystruct(&nv, &stdview);
163                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
164 <                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
164 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
165                          sprintf(errmsg, "cannot open \"%s\"", buf);
166                          error(COMMAND, errmsg);
167                          return;
# Line 242 | Line 263 | register char  *s;
263   getexposure(s)                          /* get new exposure */
264   char  *s;
265   {
245        double  atof(), pow(), fabs();
266          char  buf[128];
267          register char  *cp;
268          register PNODE  *p;
# Line 287 | Line 307 | char  *s;
307                          e *= atof(cp);
308          }
309          if (p != NULL) {                /* relative setting */
310 <                if (bright(p->v) <= FTINY) {
310 >                if (bright(p->v) < 1e-25) {
311                          error(COMMAND, "cannot normalize to zero");
312                          return;
313                  }
# Line 301 | Line 321 | char  *s;
321   }
322  
323  
324 + getparam(str, dsc, typ, ptr)            /* get variable from user */
325 + char  *str, *dsc;
326 + int  typ;
327 + register union {int i; double d; COLOR C;}  *ptr;
328 + {
329 +        extern char  *index();
330 +        int  i0;
331 +        double  d0, d1, d2;
332 +        char  buf[48];
333 +
334 +        switch (typ) {
335 +        case 'i':                       /* integer */
336 +                if (sscanf(str, "%d", &i0) != 1) {
337 +                        (*dev->comout)(dsc);
338 +                        sprintf(buf, " (%d): ", ptr->i);
339 +                        (*dev->comout)(buf);
340 +                        (*dev->comin)(buf, NULL);
341 +                        if (sscanf(buf, "%d", &i0) != 1)
342 +                                return(0);
343 +                }
344 +                ptr->i = i0;
345 +                return(1);
346 +        case 'r':                       /* real */
347 +                if (sscanf(str, "%lf", &d0) != 1) {
348 +                        (*dev->comout)(dsc);
349 +                        sprintf(buf, " (%.6g): ", ptr->d);
350 +                        (*dev->comout)(buf);
351 +                        (*dev->comin)(buf, NULL);
352 +                        if (sscanf(buf, "%lf", &d0) != 1)
353 +                                return(0);
354 +                }
355 +                ptr->d = d0;
356 +                return(1);
357 +        case 'b':                       /* boolean */
358 +                if (sscanf(str, "%1s", buf) != 1) {
359 +                        (*dev->comout)(dsc);
360 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
361 +                        (*dev->comout)(buf);
362 +                        (*dev->comin)(buf, NULL);
363 +                        if (buf[0] == '\0' ||
364 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
365 +                                return(0);
366 +                }
367 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
368 +                return(1);
369 +        case 'C':                       /* color */
370 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
371 +                        (*dev->comout)(dsc);
372 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
373 +                                        colval(ptr->C,RED),
374 +                                        colval(ptr->C,GRN),
375 +                                        colval(ptr->C,BLU));
376 +                        (*dev->comout)(buf);
377 +                        (*dev->comin)(buf, NULL);
378 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
379 +                                return(0);
380 +                }
381 +                setcolor(ptr->C, d0, d1, d2);
382 +                return(1);
383 +        }
384 + }
385 +
386 +
387   setparam(s)                             /* get/set program parameter */
388   register char  *s;
389   {
# Line 313 | Line 396 | register char  *s;
396          extern double  shadcert;
397          extern COLOR  ambval;
398          extern double  ambacc;
316        extern double  minarad;
399          extern int  ambres;
400          extern int  ambdiv;
401          extern int  ambssamp;
402          extern int  ambounce;
403 <        int  i0;
404 <        double  d0, d1, d2;
403 >        extern int  directinvis;
404 >        extern double  srcsizerat;
405 >        extern int  do_irrad;
406 >        extern double  specjitter;
407 >        extern double  specthresh;
408          char  buf[128];
409          
410          if (s[0] == '\0') {
411 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
411 >                (*dev->comout)(
412 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
413                  (*dev->comin)(buf, NULL);
414                  s = buf;
415          }
# Line 331 | Line 417 | register char  *s;
417          case 'l':                       /* limit */
418                  switch (s[1]) {
419                  case 'w':                       /* weight */
420 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
335 <                                sprintf(buf, "limit weight (%.6g): ",
336 <                                                minweight);
337 <                                (*dev->comout)(buf);
338 <                                (*dev->comin)(buf, NULL);
339 <                                if (sscanf(buf, "%lf", &d0) != 1)
340 <                                        break;
341 <                        }
342 <                        minweight = d0;
420 >                        getparam(s+2, "limit weight", 'r', &minweight);
421                          break;
422                  case 'r':                       /* reflection */
423 <                        if (sscanf(s+2, "%d", &i0) != 1) {
346 <                                sprintf(buf, "limit reflection (%d): ",
347 <                                                maxdepth);
348 <                                (*dev->comout)(buf);
349 <                                (*dev->comin)(buf, NULL);
350 <                                if (sscanf(buf, "%d", &i0) != 1)
351 <                                        break;
352 <                        }
353 <                        maxdepth = i0;
423 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
424                          break;
425                  default:
426                          goto badparam;
# Line 359 | Line 429 | register char  *s;
429          case 'd':                       /* direct */
430                  switch (s[1]) {
431                  case 'j':                       /* jitter */
432 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
363 <                                sprintf(buf, "direct jitter (%.6g): ",
364 <                                                dstrsrc);
365 <                                (*dev->comout)(buf);
366 <                                (*dev->comin)(buf, NULL);
367 <                                if (sscanf(buf, "%lf", &d0) != 1)
368 <                                        break;
369 <                        }
370 <                        dstrsrc = d0;
432 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
433                          break;
434                  case 'c':                       /* certainty */
435 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
374 <                                sprintf(buf, "direct certainty (%.6g): ",
375 <                                                shadcert);
376 <                                (*dev->comout)(buf);
377 <                                (*dev->comin)(buf, NULL);
378 <                                if (sscanf(buf, "%lf", &d0) != 1)
379 <                                        break;
380 <                        }
381 <                        shadcert = d0;
435 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
436                          break;
437                  case 't':                       /* threshold */
438 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
385 <                                sprintf(buf, "direct threshold (%.6g): ",
386 <                                                shadthresh);
387 <                                (*dev->comout)(buf);
388 <                                (*dev->comin)(buf, NULL);
389 <                                if (sscanf(buf, "%lf", &d0) != 1)
390 <                                        break;
391 <                        }
392 <                        shadthresh = d0;
438 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
439                          break;
440 +                case 'i':                       /* invisibility */
441 +                        getparam(s+2, "direct invisibility",
442 +                                        'b', &directinvis);
443 +                        break;
444 +                case 's':                       /* sampling */
445 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
446 +                        break;
447                  default:
448                          goto badparam;
449                  }
450                  break;
451 +        case 'b':                       /* black and white */
452 +                getparam(s+1, "black and white", 'b', &greyscale);
453 +                break;
454 +        case 'i':                       /* irradiance */
455 +                getparam(s+1, "irradiance", 'b', &do_irrad);
456 +                break;
457          case 'a':                       /* ambient */
458                  switch (s[1]) {
459                  case 'v':                       /* value */
460 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
402 <                                sprintf(buf,
403 <                                        "ambient value (%.6g %.6g %.6g): ",
404 <                                                colval(ambval,RED),
405 <                                                colval(ambval,GRN),
406 <                                                colval(ambval,BLU));
407 <                                (*dev->comout)(buf);
408 <                                (*dev->comin)(buf, NULL);
409 <                                if (sscanf(buf, "%lf %lf %lf",
410 <                                                &d0, &d1, &d2) != 3)
411 <                                        break;
412 <                        }
413 <                        setcolor(ambval, d0, d1, d2);
460 >                        getparam(s+2, "ambient value", 'C', ambval);
461                          break;
462                  case 'a':                       /* accuracy */
463 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
417 <                                sprintf(buf, "ambient accuracy (%.6g): ",
418 <                                                ambacc);
419 <                                (*dev->comout)(buf);
420 <                                (*dev->comin)(buf, NULL);
421 <                                if (sscanf(buf, "%lf", &d0) != 1)
422 <                                        break;
423 <                        }
424 <                        ambacc = d0;
463 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
464                          break;
465                  case 'd':                       /* divisions */
466 <                        if (sscanf(s+2, "%d", &i0) != 1) {
428 <                                sprintf(buf, "ambient divisions (%d): ",
429 <                                                ambdiv);
430 <                                (*dev->comout)(buf);
431 <                                (*dev->comin)(buf, NULL);
432 <                                if (sscanf(buf, "%d", &i0) != 1)
433 <                                        break;
434 <                        }
435 <                        ambdiv = i0;
466 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
467                          break;
468                  case 's':                       /* samples */
469 <                        if (sscanf(s+2, "%d", &i0) != 1) {
439 <                                sprintf(buf, "ambient super-samples (%d): ",
440 <                                                ambssamp);
441 <                                (*dev->comout)(buf);
442 <                                (*dev->comin)(buf, NULL);
443 <                                if (sscanf(buf, "%d", &i0) != 1)
444 <                                        break;
445 <                        }
446 <                        ambssamp = i0;
469 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
470                          break;
471                  case 'b':                       /* bounces */
472 <                        if (sscanf(s+2, "%d", &i0) != 1) {
450 <                                sprintf(buf, "ambient bounces (%d): ",
451 <                                                ambounce);
452 <                                (*dev->comout)(buf);
453 <                                (*dev->comin)(buf, NULL);
454 <                                if (sscanf(buf, "%d", &i0) != 1)
455 <                                        break;
456 <                        }
457 <                        ambounce = i0;
472 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
473                          break;
474                  case 'r':
475 <                        if (sscanf(s+2, "%d", &i0) != 1) {
476 <                                sprintf(buf, "ambient resolution (%d): ",
462 <                                                ambres);
463 <                                (*dev->comout)(buf);
464 <                                (*dev->comin)(buf, NULL);
465 <                                if (sscanf(buf, "%d", &i0) != 1)
466 <                                        break;
467 <                        }
468 <                        ambres = i0;
469 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
475 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
476 >                                setambres(ambres);
477                          break;
478                  default:
479                          goto badparam;
480                  }
481                  break;
482 <        case 's':                       /* sample */
482 >        case 'p':                       /* pixel */
483                  switch (s[1]) {
484 <                case 'p':                       /* pixel */
485 <                        if (sscanf(s+2, "%d", &i0) != 1) {
486 <                                sprintf(buf, "sample pixel (%d): ", psample);
480 <                                (*dev->comout)(buf);
481 <                                (*dev->comin)(buf, NULL);
482 <                                if (sscanf(buf, "%d", &i0) != 1)
483 <                                        break;
484 <                        }
485 <                        psample = i0;
486 <                        pdepth = 0;
484 >                case 's':                       /* sample */
485 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
486 >                                pdepth = 0;
487                          break;
488                  case 't':                       /* threshold */
489 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
490 <                                sprintf(buf, "sample threshold (%.6g): ",
491 <                                                maxdiff);
492 <                                (*dev->comout)(buf);
493 <                                (*dev->comin)(buf, NULL);
494 <                                if (sscanf(buf, "%lf", &d0) != 1)
495 <                                        break;
496 <                        }
497 <                        maxdiff = d0;
498 <                        pdepth = 0;
489 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
490 >                                pdepth = 0;
491                          break;
492                  default:
493                          goto badparam;
494                  }
495                  break;
496 +        case 's':                       /* specular */
497 +                switch (s[1]) {
498 +                case 'j':                       /* jitter */
499 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
500 +                        break;
501 +                case 't':                       /* threshold */
502 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
503 +                        break;
504 +                default:
505 +                        goto badparam;
506 +                }
507 +                break;
508          case '\0':                      /* nothing */
509                  break;
510          default:;
511   badparam:
512 +                *sskip(s) = '\0';
513                  sprintf(errmsg, "%s: unknown variable", s);
514                  error(COMMAND, errmsg);
515                  break;
# Line 519 | Line 524 | char  *s;
524          int  x, y;
525          RAY  thisray;
526  
527 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
528 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
524 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
527 >        if (!sscanvec(s, thisray.rorg) ||
528 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
529  
530                  if (dev->getcur == NULL)
531                          return;
# Line 561 | Line 565 | char  *s;
565                          (*dev->comout)(buf);
566                  }
567                  (*dev->comin)(buf, NULL);
568 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
568 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
569                                  colval(thisray.rcol,RED),
570                                  colval(thisray.rcol,GRN),
571 <                                colval(thisray.rcol,BLU));
571 >                                colval(thisray.rcol,BLU),
572 >                                luminance(thisray.rcol));
573                  (*dev->comout)(buf);
574          }
575          (*dev->comin)(buf, NULL);
# Line 596 | Line 601 | char  *s;
601                                                  /* write header */
602          fputs(progname, fp);
603          fprintview(&ourview, fp);
604 <        putc('\n', fp);
604 >        if (octname != NULL)
605 >                fprintf(fp, " %s\n", octname);
606 >        else
607 >                putc('\n', fp);
608 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
609          if (exposure != 1.0)
610                  fputexpos(exposure, fp);
611          if (dev->pixaspect != 1.0)
612                  fputaspect(dev->pixaspect, fp);
613 +        fputformat(COLRFMT, fp);
614          putc('\n', fp);
615 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
615 >        fprtresolu(hresolu, vresolu, fp);
616  
617          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
618 <        if (scanline == NULL)
619 <                error(SYSTEM, "out of memory in writepict");
618 >        if (scanline == NULL) {
619 >                error(COMMAND, "not enough memory!");
620 >                fclose(fp);
621 >                unlink(fname);
622 >                return;
623 >        }
624          for (y = vresolu-1; y >= 0; y--) {
625                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
626                  if (fwritecolrs(scanline, hresolu, fp) < 0)
627                          break;
628          }
629 +        free((char *)scanline);
630          if (fclose(fp) < 0)
631                  error(COMMAND, "write error");
617        free((char *)scanline);
632   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines