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.23 by greg, Thu Jul 18 15:49:06 1991 UTC vs.
Revision 2.3 by greg, Thu Dec 19 14:54:55 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1991 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'-'@')
26  
27 + extern char  VersionID[];
28   extern char  *progname;
29 + extern char  *octname;
30  
31  
32   getframe(s)                             /* get a new frame */
# Line 140 | Line 144 | char  *s;
144          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
145                  copystruct(&nv, &stdview);
146                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
147 <                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
147 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
148                          sprintf(errmsg, "cannot open \"%s\"", buf);
149                          error(COMMAND, errmsg);
150                          return;
# Line 242 | Line 246 | register char  *s;
246   getexposure(s)                          /* get new exposure */
247   char  *s;
248   {
245        double  atof(), pow(), fabs();
249          char  buf[128];
250          register char  *cp;
251          register PNODE  *p;
# Line 301 | Line 304 | char  *s;
304   }
305  
306  
307 + getparam(str, dsc, typ, ptr)            /* get variable from user */
308 + char  *str, *dsc;
309 + int  typ;
310 + register union {int i; double d; COLOR C;}  *ptr;
311 + {
312 +        extern char  *index();
313 +        int  i0;
314 +        double  d0, d1, d2;
315 +        char  buf[48];
316 +
317 +        switch (typ) {
318 +        case 'i':                       /* integer */
319 +                if (sscanf(str, "%d", &i0) != 1) {
320 +                        (*dev->comout)(dsc);
321 +                        sprintf(buf, " (%d): ", ptr->i);
322 +                        (*dev->comout)(buf);
323 +                        (*dev->comin)(buf, NULL);
324 +                        if (sscanf(buf, "%d", &i0) != 1)
325 +                                return(0);
326 +                }
327 +                ptr->i = i0;
328 +                return(1);
329 +        case 'r':                       /* real */
330 +                if (sscanf(str, "%lf", &d0) != 1) {
331 +                        (*dev->comout)(dsc);
332 +                        sprintf(buf, " (%.6g): ", ptr->d);
333 +                        (*dev->comout)(buf);
334 +                        (*dev->comin)(buf, NULL);
335 +                        if (sscanf(buf, "%lf", &d0) != 1)
336 +                                return(0);
337 +                }
338 +                ptr->d = d0;
339 +                return(1);
340 +        case 'b':                       /* boolean */
341 +                if (sscanf(str, "%1s", buf) != 1) {
342 +                        (*dev->comout)(dsc);
343 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
344 +                        (*dev->comout)(buf);
345 +                        (*dev->comin)(buf, NULL);
346 +                        if (buf[0] == '\0' ||
347 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
348 +                                return(0);
349 +                }
350 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
351 +                return(1);
352 +        case 'C':                       /* color */
353 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
354 +                        (*dev->comout)(dsc);
355 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
356 +                                        colval(ptr->C,RED),
357 +                                        colval(ptr->C,GRN),
358 +                                        colval(ptr->C,BLU));
359 +                        (*dev->comout)(buf);
360 +                        (*dev->comin)(buf, NULL);
361 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
362 +                                return(0);
363 +                }
364 +                setcolor(ptr->C, d0, d1, d2);
365 +                return(1);
366 +        }
367 + }
368 +
369 +
370   setparam(s)                             /* get/set program parameter */
371   register char  *s;
372   {
# Line 319 | Line 385 | register char  *s;
385          extern int  ambssamp;
386          extern int  ambounce;
387          extern int  directinvis;
388 +        extern double  srcsizerat;
389          extern int  do_irrad;
390 <        int  i0;
324 <        double  d0, d1, d2;
325 <        char  buf[128], ans[4];
390 >        char  buf[128];
391          
392          if (s[0] == '\0') {
393                  (*dev->comout)(
394 <                        "aa ab ad ar as av b dc dj di dt i lr lw sp st: ");
394 >                        "aa ab ad ar as av b dc di dj ds dt i lr lw sp st: ");
395                  (*dev->comin)(buf, NULL);
396                  s = buf;
397          }
# Line 334 | Line 399 | register char  *s;
399          case 'l':                       /* limit */
400                  switch (s[1]) {
401                  case 'w':                       /* weight */
402 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
338 <                                sprintf(buf, "limit weight (%.6g): ",
339 <                                                minweight);
340 <                                (*dev->comout)(buf);
341 <                                (*dev->comin)(buf, NULL);
342 <                                if (sscanf(buf, "%lf", &d0) != 1)
343 <                                        break;
344 <                        }
345 <                        minweight = d0;
402 >                        getparam(s+2, "limit weight", 'r', &minweight);
403                          break;
404                  case 'r':                       /* reflection */
405 <                        if (sscanf(s+2, "%d", &i0) != 1) {
349 <                                sprintf(buf, "limit reflection (%d): ",
350 <                                                maxdepth);
351 <                                (*dev->comout)(buf);
352 <                                (*dev->comin)(buf, NULL);
353 <                                if (sscanf(buf, "%d", &i0) != 1)
354 <                                        break;
355 <                        }
356 <                        maxdepth = i0;
405 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
406                          break;
407                  default:
408                          goto badparam;
# Line 362 | Line 411 | register char  *s;
411          case 'd':                       /* direct */
412                  switch (s[1]) {
413                  case 'j':                       /* jitter */
414 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
366 <                                sprintf(buf, "direct jitter (%.6g): ",
367 <                                                dstrsrc);
368 <                                (*dev->comout)(buf);
369 <                                (*dev->comin)(buf, NULL);
370 <                                if (sscanf(buf, "%lf", &d0) != 1)
371 <                                        break;
372 <                        }
373 <                        dstrsrc = d0;
414 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
415                          break;
416                  case 'c':                       /* certainty */
417 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
377 <                                sprintf(buf, "direct certainty (%.6g): ",
378 <                                                shadcert);
379 <                                (*dev->comout)(buf);
380 <                                (*dev->comin)(buf, NULL);
381 <                                if (sscanf(buf, "%lf", &d0) != 1)
382 <                                        break;
383 <                        }
384 <                        shadcert = d0;
417 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
418                          break;
419                  case 't':                       /* threshold */
420 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
388 <                                sprintf(buf, "direct threshold (%.6g): ",
389 <                                                shadthresh);
390 <                                (*dev->comout)(buf);
391 <                                (*dev->comin)(buf, NULL);
392 <                                if (sscanf(buf, "%lf", &d0) != 1)
393 <                                        break;
394 <                        }
395 <                        shadthresh = d0;
420 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
421                          break;
422                  case 'i':                       /* invisibility */
423 <                        if (sscanf(s+2, "%1s", ans) != 1) {
424 <                                sprintf(buf, "direct invisibility (%c): ",
400 <                                                directinvis ? 'y' : 'n');
401 <                                (*dev->comout)(buf);
402 <                                (*dev->comin)(buf, NULL);
403 <                                if (sscanf(buf, "%1s", ans) != 1)
404 <                                        break;
405 <                        }
406 <                        directinvis = tolower(ans[0]) == 'y';
423 >                        getparam(s+2, "direct invisibility",
424 >                                        'b', &directinvis);
425                          break;
426 +                case 's':                       /* sampling */
427 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
428 +                        break;
429                  default:
430                          goto badparam;
431                  }
432                  break;
433          case 'b':                       /* black and white */
434 <                if (sscanf(s+1, "%1s", ans) != 1) {
414 <                        sprintf(buf, "black and white (%c): ",
415 <                                        greyscale ? 'y' : 'n');
416 <                        (*dev->comout)(buf);
417 <                        (*dev->comin)(buf, NULL);
418 <                        if (sscanf(buf, "%1s", ans) != 1)
419 <                                break;
420 <                }
421 <                greyscale = tolower(ans[0]) == 'y';
434 >                getparam(s+1, "black and white", 'b', &greyscale);
435                  break;
436          case 'i':                       /* irradiance */
437 <                if (sscanf(s+1, "%1s", ans) != 1) {
425 <                        sprintf(buf, "irradiance (%c): ",
426 <                                        do_irrad ? 'y' : 'n');
427 <                        (*dev->comout)(buf);
428 <                        (*dev->comin)(buf, NULL);
429 <                        if (sscanf(buf, "%1s", ans) != 1)
430 <                                break;
431 <                }
432 <                do_irrad = tolower(ans[0]) == 'y';
437 >                getparam(s+1, "irradiance", 'b', &do_irrad);
438                  break;
439          case 'a':                       /* ambient */
440                  switch (s[1]) {
441                  case 'v':                       /* value */
442 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
438 <                                sprintf(buf,
439 <                                        "ambient value (%.6g %.6g %.6g): ",
440 <                                                colval(ambval,RED),
441 <                                                colval(ambval,GRN),
442 <                                                colval(ambval,BLU));
443 <                                (*dev->comout)(buf);
444 <                                (*dev->comin)(buf, NULL);
445 <                                if (sscanf(buf, "%lf %lf %lf",
446 <                                                &d0, &d1, &d2) != 3)
447 <                                        break;
448 <                        }
449 <                        setcolor(ambval, d0, d1, d2);
442 >                        getparam(s+2, "ambient value", 'C', ambval);
443                          break;
444                  case 'a':                       /* accuracy */
445 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
453 <                                sprintf(buf, "ambient accuracy (%.6g): ",
454 <                                                ambacc);
455 <                                (*dev->comout)(buf);
456 <                                (*dev->comin)(buf, NULL);
457 <                                if (sscanf(buf, "%lf", &d0) != 1)
458 <                                        break;
459 <                        }
460 <                        ambacc = d0;
445 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
446                          break;
447                  case 'd':                       /* divisions */
448 <                        if (sscanf(s+2, "%d", &i0) != 1) {
464 <                                sprintf(buf, "ambient divisions (%d): ",
465 <                                                ambdiv);
466 <                                (*dev->comout)(buf);
467 <                                (*dev->comin)(buf, NULL);
468 <                                if (sscanf(buf, "%d", &i0) != 1)
469 <                                        break;
470 <                        }
471 <                        ambdiv = i0;
448 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
449                          break;
450                  case 's':                       /* samples */
451 <                        if (sscanf(s+2, "%d", &i0) != 1) {
475 <                                sprintf(buf, "ambient super-samples (%d): ",
476 <                                                ambssamp);
477 <                                (*dev->comout)(buf);
478 <                                (*dev->comin)(buf, NULL);
479 <                                if (sscanf(buf, "%d", &i0) != 1)
480 <                                        break;
481 <                        }
482 <                        ambssamp = i0;
451 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
452                          break;
453                  case 'b':                       /* bounces */
454 <                        if (sscanf(s+2, "%d", &i0) != 1) {
486 <                                sprintf(buf, "ambient bounces (%d): ",
487 <                                                ambounce);
488 <                                (*dev->comout)(buf);
489 <                                (*dev->comin)(buf, NULL);
490 <                                if (sscanf(buf, "%d", &i0) != 1)
491 <                                        break;
492 <                        }
493 <                        ambounce = i0;
454 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
455                          break;
456                  case 'r':
457 <                        if (sscanf(s+2, "%d", &i0) != 1) {
458 <                                sprintf(buf, "ambient resolution (%d): ",
459 <                                                ambres);
499 <                                (*dev->comout)(buf);
500 <                                (*dev->comin)(buf, NULL);
501 <                                if (sscanf(buf, "%d", &i0) != 1)
502 <                                        break;
503 <                        }
504 <                        ambres = i0;
505 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
457 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
458 >                                minarad = ambres > 0 ?
459 >                                                thescene.cusize/ambres : 0.0;
460                          break;
461                  default:
462                          goto badparam;
# Line 511 | Line 465 | register char  *s;
465          case 's':                       /* sample */
466                  switch (s[1]) {
467                  case 'p':                       /* pixel */
468 <                        if (sscanf(s+2, "%d", &i0) != 1) {
469 <                                sprintf(buf, "sample pixel (%d): ", psample);
516 <                                (*dev->comout)(buf);
517 <                                (*dev->comin)(buf, NULL);
518 <                                if (sscanf(buf, "%d", &i0) != 1)
519 <                                        break;
520 <                        }
521 <                        psample = i0;
522 <                        pdepth = 0;
468 >                        if (getparam(s+2, "sample pixel", 'i', &psample))
469 >                                pdepth = 0;
470                          break;
471                  case 't':                       /* threshold */
472 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
473 <                                sprintf(buf, "sample threshold (%.6g): ",
527 <                                                maxdiff);
528 <                                (*dev->comout)(buf);
529 <                                (*dev->comin)(buf, NULL);
530 <                                if (sscanf(buf, "%lf", &d0) != 1)
531 <                                        break;
532 <                        }
533 <                        maxdiff = d0;
534 <                        pdepth = 0;
472 >                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
473 >                                pdepth = 0;
474                          break;
475                  default:
476                          goto badparam;
# Line 541 | Line 480 | register char  *s;
480                  break;
481          default:;
482   badparam:
483 +                *sskip(s) = '\0';
484                  sprintf(errmsg, "%s: unknown variable", s);
485                  error(COMMAND, errmsg);
486                  break;
# Line 597 | Line 537 | char  *s;
537                          (*dev->comout)(buf);
538                  }
539                  (*dev->comin)(buf, NULL);
540 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
540 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
541                                  colval(thisray.rcol,RED),
542                                  colval(thisray.rcol,GRN),
543 <                                colval(thisray.rcol,BLU));
543 >                                colval(thisray.rcol,BLU),
544 >                                luminance(thisray.rcol));
545                  (*dev->comout)(buf);
546          }
547          (*dev->comin)(buf, NULL);
# Line 632 | Line 573 | char  *s;
573                                                  /* write header */
574          fputs(progname, fp);
575          fprintview(&ourview, fp);
576 <        putc('\n', fp);
576 >        if (octname != NULL)
577 >                fprintf(fp, " %s\n", octname);
578 >        else
579 >                putc('\n', fp);
580 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
581          if (exposure != 1.0)
582                  fputexpos(exposure, fp);
583          if (dev->pixaspect != 1.0)
584                  fputaspect(dev->pixaspect, fp);
585          fputformat(COLRFMT, fp);
586          putc('\n', fp);
587 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
587 >        fprtresolu(hresolu, vresolu, fp);
588  
589          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
590 <        if (scanline == NULL)
591 <                error(SYSTEM, "out of memory in writepict");
590 >        if (scanline == NULL) {
591 >                error(COMMAND, "not enough memory!");
592 >                fclose(fp);
593 >                unlink(fname);
594 >                return;
595 >        }
596          for (y = vresolu-1; y >= 0; y--) {
597                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
598                  if (fwritecolrs(scanline, hresolu, fp) < 0)
599                          break;
600          }
601 +        free((char *)scanline);
602          if (fclose(fp) < 0)
603                  error(COMMAND, "write error");
654        free((char *)scanline);
604   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines