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.15 by greg, Thu Jan 11 09:03:39 1990 UTC vs.
Revision 1.32 by greg, Tue Oct 29 12:06:44 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 63 | Line 65 | char  *s;
65                  }
66                  fputs(progname, fp);
67                  fprintview(&ourview, fp);
68 +                fputs(sskip(s), fp);
69                  fputs("\n", fp);
70                  fclose(fp);
71                  return;
72          }
73          sprintf(buf, "view type (%c): ", ourview.type);
74          (*dev->comout)(buf);
75 <        (*dev->comin)(buf);
75 >        (*dev->comin)(buf, NULL);
76          if (buf[0] == CTRL(C)) return;
77          if (buf[0] && buf[0] != ourview.type) {
78                  nv.type = buf[0];
# Line 79 | Line 82 | char  *s;
82          sprintf(buf, "view point (%.6g %.6g %.6g): ",
83                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
84          (*dev->comout)(buf);
85 <        (*dev->comin)(buf);
85 >        (*dev->comin)(buf, NULL);
86          if (buf[0] == CTRL(C)) return;
87          if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
88                  change++;
# Line 88 | Line 91 | char  *s;
91          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
92                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
93          (*dev->comout)(buf);
94 <        (*dev->comin)(buf);
94 >        (*dev->comin)(buf, NULL);
95          if (buf[0] == CTRL(C)) return;
96          if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
97                  change++;
# Line 97 | Line 100 | char  *s;
100          sprintf(buf, "view up (%.6g %.6g %.6g): ",
101                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
102          (*dev->comout)(buf);
103 <        (*dev->comin)(buf);
103 >        (*dev->comin)(buf, NULL);
104          if (buf[0] == CTRL(C)) return;
105          if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
106                  change++;
# Line 106 | Line 109 | char  *s;
109          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
110                          ourview.horiz, ourview.vert);
111          (*dev->comout)(buf);
112 <        (*dev->comin)(buf);
112 >        (*dev->comin)(buf, NULL);
113          if (buf[0] == CTRL(C)) return;
114          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
115                  change++;
# Line 116 | Line 119 | char  *s;
119          sprintf(buf, "view shift and lift (%.6g %.6g): ",
120                          ourview.hoff, ourview.voff);
121          (*dev->comout)(buf);
122 <        (*dev->comin)(buf);
122 >        (*dev->comin)(buf, NULL);
123          if (buf[0] == CTRL(C)) return;
124          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
125                  change++;
# Line 137 | Line 140 | char  *s;
140          VIEW  nv;
141  
142          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
143 <                copyview(&nv, &stdview);
143 >                copystruct(&nv, &stdview);
144                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
145 <                                (success = viewfile(fname, &nv)) == -1) {
145 >                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
146                          sprintf(errmsg, "cannot open \"%s\"", buf);
147                          error(COMMAND, errmsg);
148                          return;
# Line 150 | Line 153 | char  *s;
153                          newview(&nv);
154                  return;
155          }
156 <        if (oldview.horiz == 0) {       /* no old view! */
156 >        if (oldview.type == 0) {        /* no old view! */
157                  error(COMMAND, "no previous view");
158                  return;
159          }
160 <        copyview(&nv, &ourview);
161 <        copyview(&ourview, &oldview);
162 <        copyview(&oldview, &nv);
160 >        copystruct(&nv, &ourview);
161 >        copystruct(&ourview, &oldview);
162 >        copystruct(&oldview, &nv);
163          newimage();
164   }
165  
# Line 170 | 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;
178 <                nv.vert = ourview.vert / zfact;
179 <        } else {
180 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
181 <                                (PI/180./2.);
182 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
183 <                                (PI/180./2.);
184 <        }
180 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
181 >        zoomview(&nv, zfact);
182          newview(&nv);
183   }
184  
# Line 211 | 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 220 | 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;
225 <                nv.vert = ourview.vert / zfact;
226 <        } else {
227 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
228 <                                (PI/180./2.);
229 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
230 <                                (PI/180./2.);
231 <        }
221 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
222 >        zoomview(&nv, zfact);
223          newview(&nv);
224   }
225  
# Line 282 | Line 273 | char  *s;
273                          if (*cp == '\0') {      /* interactive */
274                                  sprintf(buf, "exposure (%lf): ", exposure);
275                                  (*dev->comout)(buf);
276 <                                (*dev->comin)(buf);
276 >                                (*dev->comin)(buf, NULL);
277                                  for (cp = buf; isspace(*cp); cp++)
278                                          ;
279                                  if (*cp == '\0')
# Line 312 | 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 329 | 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: ");
393 <                (*dev->comin)(buf);
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          }
397          switch (s[0]) {
398          case 'l':                       /* limit */
399                  switch (s[1]) {
400                  case 'w':                       /* weight */
401 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
346 <                                sprintf(buf, "limit weight (%.6g): ",
347 <                                                minweight);
348 <                                (*dev->comout)(buf);
349 <                                (*dev->comin)(buf);
350 <                                if (sscanf(buf, "%lf", &d0) != 1)
351 <                                        break;
352 <                        }
353 <                        minweight = d0;
401 >                        getparam(s+2, "limit weight", 'r', &minweight);
402                          break;
403                  case 'r':                       /* reflection */
404 <                        if (sscanf(s+2, "%d", &i0) != 1) {
357 <                                sprintf(buf, "limit reflection (%d): ",
358 <                                                maxdepth);
359 <                                (*dev->comout)(buf);
360 <                                (*dev->comin)(buf);
361 <                                if (sscanf(buf, "%d", &i0) != 1)
362 <                                        break;
363 <                        }
364 <                        maxdepth = i0;
404 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
405                          break;
406                  default:
407                          goto badparam;
# Line 370 | 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) {
374 <                                sprintf(buf, "direct jitter (%.6g): ",
375 <                                                dstrsrc);
376 <                                (*dev->comout)(buf);
377 <                                (*dev->comin)(buf);
378 <                                if (sscanf(buf, "%lf", &d0) != 1)
379 <                                        break;
380 <                        }
381 <                        dstrsrc = d0;
413 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
414                          break;
415                  case 'c':                       /* certainty */
416 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
385 <                                sprintf(buf, "direct certainty (%.6g): ",
386 <                                                shadcert);
387 <                                (*dev->comout)(buf);
388 <                                (*dev->comin)(buf);
389 <                                if (sscanf(buf, "%lf", &d0) != 1)
390 <                                        break;
391 <                        }
392 <                        shadcert = d0;
416 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
417                          break;
418                  case 't':                       /* threshold */
419 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
396 <                                sprintf(buf, "direct threshold (%.6g): ",
397 <                                                shadthresh);
398 <                                (*dev->comout)(buf);
399 <                                (*dev->comin)(buf);
400 <                                if (sscanf(buf, "%lf", &d0) != 1)
401 <                                        break;
402 <                        }
403 <                        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) {
413 <                                sprintf(buf,
414 <                                        "ambient value (%.6g %.6g %.6g): ",
415 <                                                colval(ambval,RED),
416 <                                                colval(ambval,GRN),
417 <                                                colval(ambval,BLU));
418 <                                (*dev->comout)(buf);
419 <                                (*dev->comin)(buf);
420 <                                if (sscanf(buf, "%lf %lf %lf",
421 <                                                &d0, &d1, &d2) != 3)
422 <                                        break;
423 <                        }
424 <                        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) {
428 <                                sprintf(buf, "ambient accuracy (%.6g): ",
429 <                                                ambacc);
430 <                                (*dev->comout)(buf);
431 <                                (*dev->comin)(buf);
432 <                                if (sscanf(buf, "%lf", &d0) != 1)
433 <                                        break;
434 <                        }
435 <                        ambacc = d0;
444 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
445                          break;
446                  case 'd':                       /* divisions */
447 <                        if (sscanf(s+2, "%d", &i0) != 1) {
439 <                                sprintf(buf, "ambient divisions (%d): ",
440 <                                                ambdiv);
441 <                                (*dev->comout)(buf);
442 <                                (*dev->comin)(buf);
443 <                                if (sscanf(buf, "%d", &i0) != 1)
444 <                                        break;
445 <                        }
446 <                        ambdiv = i0;
447 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
448                          break;
449                  case 's':                       /* samples */
450 <                        if (sscanf(s+2, "%d", &i0) != 1) {
450 <                                sprintf(buf, "ambient super-samples (%d): ",
451 <                                                ambssamp);
452 <                                (*dev->comout)(buf);
453 <                                (*dev->comin)(buf);
454 <                                if (sscanf(buf, "%d", &i0) != 1)
455 <                                        break;
456 <                        }
457 <                        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) {
461 <                                sprintf(buf, "ambient bounces (%d): ",
462 <                                                ambounce);
463 <                                (*dev->comout)(buf);
464 <                                (*dev->comin)(buf);
465 <                                if (sscanf(buf, "%d", &i0) != 1)
466 <                                        break;
467 <                        }
468 <                        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);
474 <                                (*dev->comout)(buf);
475 <                                (*dev->comin)(buf);
476 <                                if (sscanf(buf, "%d", &i0) != 1)
477 <                                        break;
478 <                        }
479 <                        ambres = i0;
480 <                        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 486 | 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);
491 <                                (*dev->comout)(buf);
492 <                                (*dev->comin)(buf);
493 <                                if (sscanf(buf, "%d", &i0) != 1)
494 <                                        break;
495 <                        }
496 <                        psample = i0;
497 <                        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): ",
502 <                                                maxdiff);
503 <                                (*dev->comout)(buf);
504 <                                (*dev->comin)(buf);
505 <                                if (sscanf(buf, "%lf", &d0) != 1)
506 <                                        break;
507 <                        }
508 <                        maxdiff = d0;
509 <                        pdepth = 0;
471 >                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
472 >                                pdepth = 0;
473                          break;
474                  default:
475                          goto badparam;
# Line 516 | 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 540 | 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 560 | Line 527 | char  *s;
527                                  ofun[thisray.ro->otype].funame,
528                                  thisray.ro->oname);
529                  (*dev->comout)(buf);
530 <                (*dev->comin)(buf);
530 >                (*dev->comin)(buf, NULL);
531                  if (thisray.rot >= FHUGE)
532                          (*dev->comout)("at infinity");
533                  else {
# Line 568 | Line 535 | char  *s;
535                                          thisray.rop[1], thisray.rop[2]);
536                          (*dev->comout)(buf);
537                  }
538 <                (*dev->comin)(buf);
539 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
538 >                (*dev->comin)(buf, NULL);
539 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
540                                  colval(thisray.rcol,RED),
541                                  colval(thisray.rcol,GRN),
542 <                                colval(thisray.rcol,BLU));
542 >                                colval(thisray.rcol,BLU),
543 >                                luminance(thisray.rcol));
544                  (*dev->comout)(buf);
545          }
546 <        (*dev->comin)(buf);
546 >        (*dev->comin)(buf, NULL);
547   }
548  
549  
# Line 604 | Line 572 | char  *s;
572                                                  /* write header */
573          fputs(progname, fp);
574          fprintview(&ourview, fp);
575 <        putc('\n', fp);
575 >        if (octname != NULL)
576 >                fprintf(fp, " %s\n", octname);
577 >        else
578 >                putc('\n', fp);
579 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
580          if (exposure != 1.0)
581                  fputexpos(exposure, fp);
582          if (dev->pixaspect != 1.0)
583                  fputaspect(dev->pixaspect, fp);
584 +        fputformat(COLRFMT, fp);
585          putc('\n', fp);
586          fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
587  
588          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
589 <        if (scanline == NULL)
590 <                error(SYSTEM, "out of memory in writepict");
589 >        if (scanline == NULL) {
590 >                error(COMMAND, "not enough memory!");
591 >                fclose(fp);
592 >                unlink(fname);
593 >                return;
594 >        }
595          for (y = vresolu-1; y >= 0; y--) {
596                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
597                  if (fwritecolrs(scanline, hresolu, fp) < 0)
598                          break;
599          }
600 +        free((char *)scanline);
601          if (fclose(fp) < 0)
602                  error(COMMAND, "write error");
625        free((char *)scanline);
603   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines