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.26 by greg, Mon Aug 26 10:12:02 1991 UTC vs.
Revision 2.6 by greg, Fri Jan 17 09:27:17 1992 UTC

# 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 71 | Line 82 | char  *s;
82          sprintf(buf, "view type (%c): ", ourview.type);
83          (*dev->comout)(buf);
84          (*dev->comin)(buf, NULL);
85 <        if (buf[0] == CTRL(C)) return;
85 >        if (buf[0] == CTRL('C')) return;
86          if (buf[0] && buf[0] != ourview.type) {
87                  nv.type = buf[0];
88                  change++;
# Line 81 | Line 92 | char  *s;
92                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
93          (*dev->comout)(buf);
94          (*dev->comin)(buf, NULL);
95 <        if (buf[0] == CTRL(C)) return;
96 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
95 >        if (buf[0] == CTRL('C')) return;
96 >        if (sscanvec(buf, nv.vp))
97                  change++;
98          else
99                  VCOPY(nv.vp, ourview.vp);
# Line 90 | Line 101 | char  *s;
101                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
102          (*dev->comout)(buf);
103          (*dev->comin)(buf, NULL);
104 <        if (buf[0] == CTRL(C)) return;
105 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
104 >        if (buf[0] == CTRL('C')) return;
105 >        if (sscanvec(buf, nv.vdir))
106                  change++;
107          else
108                  VCOPY(nv.vdir, ourview.vdir);
# Line 99 | Line 110 | char  *s;
110                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
111          (*dev->comout)(buf);
112          (*dev->comin)(buf, NULL);
113 <        if (buf[0] == CTRL(C)) return;
114 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
113 >        if (buf[0] == CTRL('C')) return;
114 >        if (sscanvec(buf, nv.vup))
115                  change++;
116          else
117                  VCOPY(nv.vup, ourview.vup);
# Line 108 | Line 119 | char  *s;
119                          ourview.horiz, ourview.vert);
120          (*dev->comout)(buf);
121          (*dev->comin)(buf, NULL);
122 <        if (buf[0] == CTRL(C)) return;
122 >        if (buf[0] == CTRL('C')) return;
123          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
124                  change++;
125          else {
# Line 118 | Line 129 | char  *s;
129                          ourview.hoff, ourview.voff);
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.hoff, &nv.voff) == 2)
134                  change++;
135          else {
# Line 140 | Line 151 | char  *s;
151          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
152                  copystruct(&nv, &stdview);
153                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
154 <                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
154 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
155                          sprintf(errmsg, "cannot open \"%s\"", buf);
156                          error(COMMAND, errmsg);
157                          return;
# Line 242 | Line 253 | register char  *s;
253   getexposure(s)                          /* get new exposure */
254   char  *s;
255   {
245        double  atof(), pow(), fabs();
256          char  buf[128];
257          register char  *cp;
258          register PNODE  *p;
# Line 319 | Line 329 | register union {int i; double d; COLOR C;}  *ptr;
329                          (*dev->comout)(buf);
330                          (*dev->comin)(buf, NULL);
331                          if (sscanf(buf, "%d", &i0) != 1)
332 <                                break;
332 >                                return(0);
333                  }
334                  ptr->i = i0;
335 <                break;
335 >                return(1);
336          case 'r':                       /* real */
337                  if (sscanf(str, "%lf", &d0) != 1) {
338                          (*dev->comout)(dsc);
# Line 330 | Line 340 | register union {int i; double d; COLOR C;}  *ptr;
340                          (*dev->comout)(buf);
341                          (*dev->comin)(buf, NULL);
342                          if (sscanf(buf, "%lf", &d0) != 1)
343 <                                break;
343 >                                return(0);
344                  }
345                  ptr->d = d0;
346 <                break;
346 >                return(1);
347          case 'b':                       /* boolean */
348                  if (sscanf(str, "%1s", buf) != 1) {
349                          (*dev->comout)(dsc);
350 <                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
350 >                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
351                          (*dev->comout)(buf);
352                          (*dev->comin)(buf, NULL);
353                          if (buf[0] == '\0' ||
354                                          index("yY+1tTnN-0fF", buf[0]) == NULL)
355 <                                break;
355 >                                return(0);
356                  }
357                  ptr->i = index("yY+1tT", buf[0]) != NULL;
358 <                break;
358 >                return(1);
359          case 'C':                       /* color */
360                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
361                          (*dev->comout)(dsc);
# Line 356 | Line 366 | register union {int i; double d; COLOR C;}  *ptr;
366                          (*dev->comout)(buf);
367                          (*dev->comin)(buf, NULL);
368                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
369 <                                break;
369 >                                return(0);
370                  }
371                  setcolor(ptr->C, d0, d1, d2);
372 <                break;
372 >                return(1);
373          }
374   }
375  
# Line 382 | Line 392 | register char  *s;
392          extern int  ambssamp;
393          extern int  ambounce;
394          extern int  directinvis;
395 +        extern double  srcsizerat;
396          extern int  do_irrad;
397 +        extern double  specjitter;
398 +        extern double  specthresh;
399          char  buf[128];
400          
401          if (s[0] == '\0') {
402                  (*dev->comout)(
403 <                        "aa ab ad ar as av b dc di dj dt i lr lw sp st: ");
403 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
404                  (*dev->comin)(buf, NULL);
405                  s = buf;
406          }
# Line 419 | Line 432 | register char  *s;
432                          getparam(s+2, "direct invisibility",
433                                          'b', &directinvis);
434                          break;
435 +                case 's':                       /* sampling */
436 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
437 +                        break;
438                  default:
439                          goto badparam;
440                  }
# Line 447 | Line 463 | register char  *s;
463                          getparam(s+2, "ambient bounces", 'i', &ambounce);
464                          break;
465                  case 'r':
466 <                        getparam(s+2, "ambient resolution", 'i', &ambres);
467 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
466 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
467 >                                minarad = ambres > 0 ?
468 >                                                thescene.cusize/ambres : 0.0;
469                          break;
470                  default:
471                          goto badparam;
472                  }
473                  break;
474 <        case 's':                       /* sample */
474 >        case 'p':                       /* pixel */
475                  switch (s[1]) {
476 <                case 'p':                       /* pixel */
477 <                        getparam(s+2, "sample pixel", 'i', &psample);
478 <                        pdepth = 0;
476 >                case 's':                       /* sample */
477 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
478 >                                pdepth = 0;
479                          break;
480                  case 't':                       /* threshold */
481 <                        getparam(s+2, "sample threshold", 'r', &maxdiff);
482 <                        pdepth = 0;
481 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
482 >                                pdepth = 0;
483                          break;
484                  default:
485                          goto badparam;
486                  }
487                  break;
488 +        case 's':                       /* specular */
489 +                switch (s[1]) {
490 +                case 'j':                       /* jitter */
491 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
492 +                        break;
493 +                case 't':                       /* threshold */
494 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
495 +                        break;
496 +                default:
497 +                        goto badparam;
498 +                }
499 +                break;
500          case '\0':                      /* nothing */
501                  break;
502          default:;
# Line 487 | Line 516 | char  *s;
516          int  x, y;
517          RAY  thisray;
518  
519 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
520 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
492 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
519 >        if (!sscanvec(s, thisray.rorg) ||
520 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
521  
522                  if (dev->getcur == NULL)
523                          return;
# Line 529 | Line 557 | char  *s;
557                          (*dev->comout)(buf);
558                  }
559                  (*dev->comin)(buf, NULL);
560 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
560 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
561                                  colval(thisray.rcol,RED),
562                                  colval(thisray.rcol,GRN),
563 <                                colval(thisray.rcol,BLU));
563 >                                colval(thisray.rcol,BLU),
564 >                                luminance(thisray.rcol));
565                  (*dev->comout)(buf);
566          }
567          (*dev->comin)(buf, NULL);
# Line 564 | Line 593 | char  *s;
593                                                  /* write header */
594          fputs(progname, fp);
595          fprintview(&ourview, fp);
596 <        putc('\n', fp);
596 >        if (octname != NULL)
597 >                fprintf(fp, " %s\n", octname);
598 >        else
599 >                putc('\n', fp);
600 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
601          if (exposure != 1.0)
602                  fputexpos(exposure, fp);
603          if (dev->pixaspect != 1.0)
604                  fputaspect(dev->pixaspect, fp);
605          fputformat(COLRFMT, fp);
606          putc('\n', fp);
607 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
607 >        fprtresolu(hresolu, vresolu, fp);
608  
609          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
610 <        if (scanline == NULL)
611 <                error(SYSTEM, "out of memory in writepict");
610 >        if (scanline == NULL) {
611 >                error(COMMAND, "not enough memory!");
612 >                fclose(fp);
613 >                unlink(fname);
614 >                return;
615 >        }
616          for (y = vresolu-1; y >= 0; y--) {
617                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
618                  if (fwritecolrs(scanline, hresolu, fp) < 0)
619                          break;
620          }
621 +        free((char *)scanline);
622          if (fclose(fp) < 0)
623                  error(COMMAND, "write error");
586        free((char *)scanline);
624   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines