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 1.30 by greg, Mon Oct 21 13:30:43 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 22 | Line 22 | static char SCCSid[] = "$SunId$ LBL";
22  
23   #define  CTRL(c)        ('c'-'@')
24  
25 + extern char  VersionID[];
26   extern char  *progname;
27 + extern char  *octname;
28  
29  
30   getframe(s)                             /* get a new frame */
# Line 301 | Line 303 | char  *s;
303   }
304  
305  
306 + getparam(str, dsc, typ, ptr)            /* get variable from user */
307 + char  *str, *dsc;
308 + int  typ;
309 + register union {int i; double d; COLOR C;}  *ptr;
310 + {
311 +        extern char  *index();
312 +        int  i0;
313 +        double  d0, d1, d2;
314 +        char  buf[48];
315 +
316 +        switch (typ) {
317 +        case 'i':                       /* integer */
318 +                if (sscanf(str, "%d", &i0) != 1) {
319 +                        (*dev->comout)(dsc);
320 +                        sprintf(buf, " (%d): ", ptr->i);
321 +                        (*dev->comout)(buf);
322 +                        (*dev->comin)(buf, NULL);
323 +                        if (sscanf(buf, "%d", &i0) != 1)
324 +                                break;
325 +                }
326 +                ptr->i = i0;
327 +                break;
328 +        case 'r':                       /* real */
329 +                if (sscanf(str, "%lf", &d0) != 1) {
330 +                        (*dev->comout)(dsc);
331 +                        sprintf(buf, " (%.6g): ", ptr->d);
332 +                        (*dev->comout)(buf);
333 +                        (*dev->comin)(buf, NULL);
334 +                        if (sscanf(buf, "%lf", &d0) != 1)
335 +                                break;
336 +                }
337 +                ptr->d = d0;
338 +                break;
339 +        case 'b':                       /* boolean */
340 +                if (sscanf(str, "%1s", buf) != 1) {
341 +                        (*dev->comout)(dsc);
342 +                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
343 +                        (*dev->comout)(buf);
344 +                        (*dev->comin)(buf, NULL);
345 +                        if (buf[0] == '\0' ||
346 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
347 +                                break;
348 +                }
349 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
350 +                break;
351 +        case 'C':                       /* color */
352 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
353 +                        (*dev->comout)(dsc);
354 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
355 +                                        colval(ptr->C,RED),
356 +                                        colval(ptr->C,GRN),
357 +                                        colval(ptr->C,BLU));
358 +                        (*dev->comout)(buf);
359 +                        (*dev->comin)(buf, NULL);
360 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
361 +                                break;
362 +                }
363 +                setcolor(ptr->C, d0, d1, d2);
364 +                break;
365 +        }
366 + }
367 +
368 +
369   setparam(s)                             /* get/set program parameter */
370   register char  *s;
371   {
# Line 319 | Line 384 | register char  *s;
384          extern int  ambssamp;
385          extern int  ambounce;
386          extern int  directinvis;
387 +        extern double  srcsizerat;
388          extern int  do_irrad;
389 <        int  i0;
324 <        double  d0, d1, d2;
325 <        char  buf[128], ans[4];
389 >        char  buf[128];
390          
391          if (s[0] == '\0') {
392                  (*dev->comout)(
393 <                        "aa ab ad ar as av b dc dj di dt i lr lw sp st: ");
393 >                        "aa ab ad ar as av b dc di dj dt i lr lw sp st: ");
394                  (*dev->comin)(buf, NULL);
395                  s = buf;
396          }
# Line 334 | Line 398 | register char  *s;
398          case 'l':                       /* limit */
399                  switch (s[1]) {
400                  case 'w':                       /* weight */
401 <                        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;
401 >                        getparam(s+2, "limit weight", 'r', &minweight);
402                          break;
403                  case 'r':                       /* reflection */
404 <                        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;
404 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
405                          break;
406                  default:
407                          goto badparam;
# Line 362 | Line 410 | register char  *s;
410          case 'd':                       /* direct */
411                  switch (s[1]) {
412                  case 'j':                       /* jitter */
413 <                        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;
413 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
414                          break;
415                  case 'c':                       /* certainty */
416 <                        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;
416 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
417                          break;
418                  case 't':                       /* threshold */
419 <                        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;
419 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
420                          break;
421                  case 'i':                       /* invisibility */
422 <                        if (sscanf(s+2, "%1s", ans) != 1) {
423 <                                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';
422 >                        getparam(s+2, "direct invisibility",
423 >                                        'b', &directinvis);
424                          break;
425 +                case 's':                       /* sampling */
426 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
427 +                        break;
428                  default:
429                          goto badparam;
430                  }
431                  break;
432          case 'b':                       /* black and white */
433 <                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';
433 >                getparam(s+1, "black and white", 'b', &greyscale);
434                  break;
435          case 'i':                       /* irradiance */
436 <                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';
436 >                getparam(s+1, "irradiance", 'b', &do_irrad);
437                  break;
438          case 'a':                       /* ambient */
439                  switch (s[1]) {
440                  case 'v':                       /* value */
441 <                        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);
441 >                        getparam(s+2, "ambient value", 'C', ambval);
442                          break;
443                  case 'a':                       /* accuracy */
444 <                        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;
444 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
445                          break;
446                  case 'd':                       /* divisions */
447 <                        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;
447 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
448                          break;
449                  case 's':                       /* samples */
450 <                        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;
450 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
451                          break;
452                  case 'b':                       /* bounces */
453 <                        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;
453 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
454                          break;
455                  case 'r':
456 <                        if (sscanf(s+2, "%d", &i0) != 1) {
497 <                                sprintf(buf, "ambient resolution (%d): ",
498 <                                                ambres);
499 <                                (*dev->comout)(buf);
500 <                                (*dev->comin)(buf, NULL);
501 <                                if (sscanf(buf, "%d", &i0) != 1)
502 <                                        break;
503 <                        }
504 <                        ambres = i0;
456 >                        getparam(s+2, "ambient resolution", 'i', &ambres);
457                          minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
458                          break;
459                  default:
# Line 511 | Line 463 | register char  *s;
463          case 's':                       /* sample */
464                  switch (s[1]) {
465                  case 'p':                       /* pixel */
466 <                        if (sscanf(s+2, "%d", &i0) != 1) {
515 <                                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;
466 >                        getparam(s+2, "sample pixel", 'i', &psample);
467                          pdepth = 0;
468                          break;
469                  case 't':                       /* threshold */
470 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
526 <                                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;
470 >                        getparam(s+2, "sample threshold", 'r', &maxdiff);
471                          pdepth = 0;
472                          break;
473                  default:
# Line 541 | Line 478 | register char  *s;
478                  break;
479          default:;
480   badparam:
481 +                *sskip(s) = '\0';
482                  sprintf(errmsg, "%s: unknown variable", s);
483                  error(COMMAND, errmsg);
484                  break;
# Line 632 | Line 570 | char  *s;
570                                                  /* write header */
571          fputs(progname, fp);
572          fprintview(&ourview, fp);
573 <        putc('\n', fp);
573 >        if (octname != NULL)
574 >                fprintf(fp, " %s\n", octname);
575 >        else
576 >                putc('\n', fp);
577 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
578          if (exposure != 1.0)
579                  fputexpos(exposure, fp);
580          if (dev->pixaspect != 1.0)
# Line 642 | Line 584 | char  *s;
584          fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
585  
586          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
587 <        if (scanline == NULL)
588 <                error(SYSTEM, "out of memory in writepict");
587 >        if (scanline == NULL) {
588 >                error(COMMAND, "not enough memory!");
589 >                fclose(fp);
590 >                unlink(fname);
591 >                return;
592 >        }
593          for (y = vresolu-1; y >= 0; y--) {
594                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
595                  if (fwritecolrs(scanline, hresolu, fp) < 0)
596                          break;
597          }
598 +        free((char *)scanline);
599          if (fclose(fp) < 0)
600                  error(COMMAND, "write error");
654        free((char *)scanline);
601   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines