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.20 by greg, Tue Feb 27 09:50:56 1990 UTC vs.
Revision 1.31 by greg, Tue Oct 22 11:58:17 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 171 | Line 173 | char  *s;
173  
174          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
175                  return;
176 +        nv.type = ourview.type;
177          VCOPY(nv.vp, ourview.vp);
178          VCOPY(nv.vup, ourview.vup);
179          nv.hoff = ourview.hoff; nv.voff = ourview.voff;
180 <        if ((nv.type = ourview.type) == VT_PAR) {
181 <                nv.horiz = ourview.horiz / zfact;
179 <                nv.vert = ourview.vert / zfact;
180 <        } else {
181 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
182 <                                (PI/180./2.);
183 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
184 <                                (PI/180./2.);
185 <        }
180 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
181 >        zoomview(&nv, zfact);
182          newview(&nv);
183   }
184  
# Line 212 | Line 208 | char  *s;
208                  error(COMMAND, "missing angle");
209                  return;
210          }
211 +        nv.type = ourview.type;
212          VCOPY(nv.vp, ourview.vp);
213          VCOPY(nv.vup, ourview.vup);
214          nv.hoff = ourview.hoff; nv.voff = ourview.voff;
# Line 221 | Line 218 | char  *s;
218                  normalize(v1);
219                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
220          }
221 <        if ((nv.type = ourview.type) == VT_PAR) {
222 <                nv.horiz = ourview.horiz / zfact;
226 <                nv.vert = ourview.vert / zfact;
227 <        } else {
228 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
229 <                                (PI/180./2.);
230 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
231 <                                (PI/180./2.);
232 <        }
221 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
222 >        zoomview(&nv, zfact);
223          newview(&nv);
224   }
225  
# Line 313 | 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 +                                return(0);
325 +                }
326 +                ptr->i = i0;
327 +                return(1);
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 +                                return(0);
336 +                }
337 +                ptr->d = d0;
338 +                return(1);
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 +                                return(0);
348 +                }
349 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
350 +                return(1);
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 +                                return(0);
362 +                }
363 +                setcolor(ptr->C, d0, d1, d2);
364 +                return(1);
365 +        }
366 + }
367 +
368 +
369   setparam(s)                             /* get/set program parameter */
370   register char  *s;
371   {
# Line 330 | Line 383 | register char  *s;
383          extern int  ambdiv;
384          extern int  ambssamp;
385          extern int  ambounce;
386 <        int  i0;
387 <        double  d0, d1, d2;
386 >        extern int  directinvis;
387 >        extern double  srcsizerat;
388 >        extern int  do_irrad;
389          char  buf[128];
390          
391          if (s[0] == '\0') {
392 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
392 >                (*dev->comout)(
393 >                        "aa ab ad ar as av b dc di dj ds dt i lr lw sp st: ");
394                  (*dev->comin)(buf, NULL);
395                  s = buf;
396          }
# Line 343 | 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) {
347 <                                sprintf(buf, "limit weight (%.6g): ",
348 <                                                minweight);
349 <                                (*dev->comout)(buf);
350 <                                (*dev->comin)(buf, NULL);
351 <                                if (sscanf(buf, "%lf", &d0) != 1)
352 <                                        break;
353 <                        }
354 <                        minweight = d0;
401 >                        getparam(s+2, "limit weight", 'r', &minweight);
402                          break;
403                  case 'r':                       /* reflection */
404 <                        if (sscanf(s+2, "%d", &i0) != 1) {
358 <                                sprintf(buf, "limit reflection (%d): ",
359 <                                                maxdepth);
360 <                                (*dev->comout)(buf);
361 <                                (*dev->comin)(buf, NULL);
362 <                                if (sscanf(buf, "%d", &i0) != 1)
363 <                                        break;
364 <                        }
365 <                        maxdepth = i0;
404 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
405                          break;
406                  default:
407                          goto badparam;
# Line 371 | 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) {
375 <                                sprintf(buf, "direct jitter (%.6g): ",
376 <                                                dstrsrc);
377 <                                (*dev->comout)(buf);
378 <                                (*dev->comin)(buf, NULL);
379 <                                if (sscanf(buf, "%lf", &d0) != 1)
380 <                                        break;
381 <                        }
382 <                        dstrsrc = d0;
413 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
414                          break;
415                  case 'c':                       /* certainty */
416 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
386 <                                sprintf(buf, "direct certainty (%.6g): ",
387 <                                                shadcert);
388 <                                (*dev->comout)(buf);
389 <                                (*dev->comin)(buf, NULL);
390 <                                if (sscanf(buf, "%lf", &d0) != 1)
391 <                                        break;
392 <                        }
393 <                        shadcert = d0;
416 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
417                          break;
418                  case 't':                       /* threshold */
419 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
397 <                                sprintf(buf, "direct threshold (%.6g): ",
398 <                                                shadthresh);
399 <                                (*dev->comout)(buf);
400 <                                (*dev->comin)(buf, NULL);
401 <                                if (sscanf(buf, "%lf", &d0) != 1)
402 <                                        break;
403 <                        }
404 <                        shadthresh = d0;
419 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
420                          break;
421 +                case 'i':                       /* invisibility */
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 +                getparam(s+1, "black and white", 'b', &greyscale);
434 +                break;
435 +        case 'i':                       /* irradiance */
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) {
414 <                                sprintf(buf,
415 <                                        "ambient value (%.6g %.6g %.6g): ",
416 <                                                colval(ambval,RED),
417 <                                                colval(ambval,GRN),
418 <                                                colval(ambval,BLU));
419 <                                (*dev->comout)(buf);
420 <                                (*dev->comin)(buf, NULL);
421 <                                if (sscanf(buf, "%lf %lf %lf",
422 <                                                &d0, &d1, &d2) != 3)
423 <                                        break;
424 <                        }
425 <                        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) {
429 <                                sprintf(buf, "ambient accuracy (%.6g): ",
430 <                                                ambacc);
431 <                                (*dev->comout)(buf);
432 <                                (*dev->comin)(buf, NULL);
433 <                                if (sscanf(buf, "%lf", &d0) != 1)
434 <                                        break;
435 <                        }
436 <                        ambacc = d0;
444 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
445                          break;
446                  case 'd':                       /* divisions */
447 <                        if (sscanf(s+2, "%d", &i0) != 1) {
440 <                                sprintf(buf, "ambient divisions (%d): ",
441 <                                                ambdiv);
442 <                                (*dev->comout)(buf);
443 <                                (*dev->comin)(buf, NULL);
444 <                                if (sscanf(buf, "%d", &i0) != 1)
445 <                                        break;
446 <                        }
447 <                        ambdiv = i0;
447 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
448                          break;
449                  case 's':                       /* samples */
450 <                        if (sscanf(s+2, "%d", &i0) != 1) {
451 <                                sprintf(buf, "ambient super-samples (%d): ",
452 <                                                ambssamp);
453 <                                (*dev->comout)(buf);
454 <                                (*dev->comin)(buf, NULL);
455 <                                if (sscanf(buf, "%d", &i0) != 1)
456 <                                        break;
457 <                        }
458 <                        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) {
462 <                                sprintf(buf, "ambient bounces (%d): ",
463 <                                                ambounce);
464 <                                (*dev->comout)(buf);
465 <                                (*dev->comin)(buf, NULL);
466 <                                if (sscanf(buf, "%d", &i0) != 1)
467 <                                        break;
468 <                        }
469 <                        ambounce = i0;
453 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
454                          break;
455                  case 'r':
456 <                        if (sscanf(s+2, "%d", &i0) != 1) {
457 <                                sprintf(buf, "ambient resolution (%d): ",
458 <                                                ambres);
475 <                                (*dev->comout)(buf);
476 <                                (*dev->comin)(buf, NULL);
477 <                                if (sscanf(buf, "%d", &i0) != 1)
478 <                                        break;
479 <                        }
480 <                        ambres = i0;
481 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
456 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
457 >                                minarad = ambres > 0 ?
458 >                                                thescene.cusize/ambres : 0.0;
459                          break;
460                  default:
461                          goto badparam;
# Line 487 | Line 464 | register char  *s;
464          case 's':                       /* sample */
465                  switch (s[1]) {
466                  case 'p':                       /* pixel */
467 <                        if (sscanf(s+2, "%d", &i0) != 1) {
468 <                                sprintf(buf, "sample pixel (%d): ", psample);
492 <                                (*dev->comout)(buf);
493 <                                (*dev->comin)(buf, NULL);
494 <                                if (sscanf(buf, "%d", &i0) != 1)
495 <                                        break;
496 <                        }
497 <                        psample = i0;
498 <                        pdepth = 0;
467 >                        if (getparam(s+2, "sample pixel", 'i', &psample))
468 >                                pdepth = 0;
469                          break;
470                  case 't':                       /* threshold */
471 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
472 <                                sprintf(buf, "sample threshold (%.6g): ",
503 <                                                maxdiff);
504 <                                (*dev->comout)(buf);
505 <                                (*dev->comin)(buf, NULL);
506 <                                if (sscanf(buf, "%lf", &d0) != 1)
507 <                                        break;
508 <                        }
509 <                        maxdiff = d0;
510 <                        pdepth = 0;
471 >                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
472 >                                pdepth = 0;
473                          break;
474                  default:
475                          goto badparam;
# Line 517 | Line 479 | register char  *s;
479                  break;
480          default:;
481   badparam:
482 +                *sskip(s) = '\0';
483                  sprintf(errmsg, "%s: unknown variable", s);
484                  error(COMMAND, errmsg);
485                  break;
# Line 541 | Line 504 | char  *s;
504                  if ((*dev->getcur)(&x, &y) == ABORT)
505                          return;
506  
507 <                viewray(thisray.rorg, thisray.rdir, &ourview,
508 <                                (x+.5)/hresolu, (y+.5)/vresolu);
509 <                
507 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
508 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
509 >                        error(COMMAND, "not on image");
510 >                        return;
511 >                }
512 >
513          } else if (normalize(thisray.rdir) == 0.0) {
514                  error(COMMAND, "zero ray direction");
515                  return;
# Line 605 | Line 571 | char  *s;
571                                                  /* write header */
572          fputs(progname, fp);
573          fprintview(&ourview, fp);
574 <        putc('\n', fp);
574 >        if (octname != NULL)
575 >                fprintf(fp, " %s\n", octname);
576 >        else
577 >                putc('\n', fp);
578 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
579          if (exposure != 1.0)
580                  fputexpos(exposure, fp);
581          if (dev->pixaspect != 1.0)
582                  fputaspect(dev->pixaspect, fp);
583 +        fputformat(COLRFMT, fp);
584          putc('\n', fp);
585          fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
586  
587          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
588 <        if (scanline == NULL)
589 <                error(SYSTEM, "out of memory in writepict");
588 >        if (scanline == NULL) {
589 >                error(COMMAND, "not enough memory!");
590 >                fclose(fp);
591 >                unlink(fname);
592 >                return;
593 >        }
594          for (y = vresolu-1; y >= 0; y--) {
595                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
596                  if (fwritecolrs(scanline, hresolu, fp) < 0)
597                          break;
598          }
599 +        free((char *)scanline);
600          if (fclose(fp) < 0)
601                  error(COMMAND, "write error");
626        free((char *)scanline);
602   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines