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 2.9 by greg, Mon Apr 6 18:04:19 1992 UTC vs.
Revision 2.26 by greg, Tue Dec 20 20:18:37 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1994 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 30 | Line 30 | static char SCCSid[] = "$SunId$ LBL";
30   #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
31   #endif
32  
33 + extern char  *atos();
34  
35 + extern FILE  *popen();
36 +
37 + extern char  rifname[128];              /* rad input file name */
38 +
39   extern char  VersionID[];
40   extern char  *progname;
41   extern char  *octname;
# Line 85 | Line 90 | char  *s;
90                  fputs(progname, fp);
91                  fprintview(&ourview, fp);
92                  fputs(sskip(s), fp);
93 <                fputs("\n", fp);
93 >                putc('\n', fp);
94                  fclose(fp);
95                  return;
96          }
# Line 135 | Line 140 | char  *s;
140          else {
141                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
142          }
143 +        sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ",
144 +                        ourview.vfore, ourview.vaft);
145 +        (*dev->comout)(buf);
146 +        (*dev->comin)(buf, NULL);
147 +        if (buf[0] == CTRL('C')) return;
148 +        if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2)
149 +                change++;
150 +        else {
151 +                nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
152 +        }
153          sprintf(buf, "view shift and lift (%.6g %.6g): ",
154                          ourview.hoff, ourview.voff);
155          (*dev->comout)(buf);
# Line 160 | Line 175 | char  *s;
175  
176          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
177                  copystruct(&nv, &stdview);
178 <                if ((fname = getpath(buf, NULL, 0)) == NULL ||
178 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
179                                  (success = viewfile(fname, &nv, NULL)) == -1) {
180                          sprintf(errmsg, "cannot open \"%s\"", buf);
181                          error(COMMAND, errmsg);
# Line 183 | Line 198 | char  *s;
198   }
199  
200  
201 + saveview(s)                             /* save view to rad file */
202 + char  *s;
203 + {
204 +        char  view[64];
205 +        char  *fname;
206 +        FILE  *fp;
207 +
208 +        if (*atos(view, sizeof(view), s)) {
209 +                if (isint(view)) {
210 +                        error(COMMAND, "cannot write view by number");
211 +                        return;
212 +                }
213 +                s = sskip(s);
214 +        }
215 +        while (isspace(*s))
216 +                s++;
217 +        if (*s)
218 +                atos(rifname, sizeof(rifname), s);
219 +        else if (rifname[0] == '\0') {
220 +                error(COMMAND, "no previous rad file");
221 +                return;
222 +        }
223 +        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
224 +                        (fp = fopen(fname, "a")) == NULL) {
225 +                sprintf(errmsg, "cannot open \"%s\"", rifname);
226 +                error(COMMAND, errmsg);
227 +                return;
228 +        }
229 +        fputs("view= ", fp);
230 +        fputs(view, fp);
231 +        fprintview(&ourview, fp);
232 +        putc('\n', fp);
233 +        fclose(fp);
234 + }
235 +
236 +
237 + loadview(s)                             /* load view from rad file */
238 + char  *s;
239 + {
240 +        char  buf[512];
241 +        char  *fname;
242 +        FILE  *fp;
243 +        VIEW  nv;
244 +
245 +        strcpy(buf, "rad -n -s -V -v ");
246 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
247 +                s = sskip(s);
248 +        else
249 +                strcat(buf, "1");
250 +        if (*s)
251 +                atos(rifname, sizeof(rifname), s);
252 +        else if (rifname[0] == '\0') {
253 +                error(COMMAND, "no previous rad file");
254 +                return;
255 +        }
256 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
257 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
258 +                error(COMMAND, errmsg);
259 +                return;
260 +        }
261 +        sprintf(buf+strlen(buf), " %s", fname);
262 +        if ((fp = popen(buf, "r")) == NULL) {
263 +                error(COMMAND, "cannot run rad");
264 +                return;
265 +        }
266 +        buf[0] = '\0';
267 +        fgets(buf, sizeof(buf), fp);
268 +        pclose(fp);
269 +        copystruct(&nv, &stdview);
270 +        if (!sscanview(&nv, buf)) {
271 +                error(COMMAND, "rad error -- no such view?");
272 +                return;
273 +        }
274 +        newview(&nv);
275 + }
276 +
277 +
278   getaim(s)                               /* aim camera */
279   char  *s;
280   {
189        extern double  tan(), atan();
281          double  zfact;
282          VIEW  nv;
283  
# Line 217 | Line 308 | char  *s;
308   getrotate(s)                            /* rotate camera */
309   char  *s;
310   {
220        extern double  normalize(), tan(), atan();
311          VIEW  nv;
312          FVECT  v1;
313          double  angle, elev, zfact;
# Line 265 | Line 355 | char  *s;
355   {
356          char  buf[128];
357          register char  *cp;
268        register PNODE  *p;
358          RECT  r;
359          int  x, y;
360 <        double  e;
360 >        register PNODE  *p = &ptrunk;
361 >        int  adapt = 0;
362 >        double  e = 1.0;
363  
364          for (cp = s; isspace(*cp); cp++)
365                  ;
366 +        if (*cp == '@') {
367 +                adapt++;
368 +                while (isspace(*++cp))
369 +                        ;
370 +        }
371          if (*cp == '\0') {              /* normalize to point */
372                  if (dev->getcur == NULL)
373                          return;
# Line 281 | Line 377 | char  *s;
377                  r.l = r.d = 0;
378                  r.r = hresolu; r.u = vresolu;
379                  p = findrect(x, y, &ptrunk, &r, -1);
284                e = 1.0;
380          } else {
381                  if (*cp == '=') {       /* absolute setting */
382                          p = NULL;
# Line 289 | Line 384 | char  *s;
384                          for (cp++; isspace(*cp); cp++)
385                                  ;
386                          if (*cp == '\0') {      /* interactive */
387 <                                sprintf(buf, "exposure (%lf): ", exposure);
387 >                                sprintf(buf, "exposure (%f): ", exposure);
388                                  (*dev->comout)(buf);
389                                  (*dev->comin)(buf, NULL);
390                                  for (cp = buf; isspace(*cp); cp++)
# Line 297 | Line 392 | char  *s;
392                                  if (*cp == '\0')
393                                          return;
394                          }
300                } else {                /* normalize to average */
301                        p = &ptrunk;
302                        e = 1.0;
395                  }
396                  if (*cp == '+' || *cp == '-')   /* f-stops */
397                          e *= pow(2.0, atof(cp));
# Line 307 | Line 399 | char  *s;
399                          e *= atof(cp);
400          }
401          if (p != NULL) {                /* relative setting */
402 <                if (bright(p->v) < 1e-25) {
402 >                if (bright(p->v) < 1e-15) {
403                          error(COMMAND, "cannot normalize to zero");
404                          return;
405                  }
406 <                e *= 0.5 / bright(p->v);
406 >                if (adapt)
407 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
408 >                else
409 >                        e *= 0.5 / bright(p->v);
410          }
411          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
412                  return;
# Line 400 | Line 495 | register char  *s;
495          extern int  ambdiv;
496          extern int  ambssamp;
497          extern int  ambounce;
498 <        extern int  directinvis;
498 >        extern int  directvis;
499          extern double  srcsizerat;
500          extern int  do_irrad;
501          extern double  specjitter;
# Line 437 | Line 532 | register char  *s;
532                  case 't':                       /* threshold */
533                          getparam(s+2, "direct threshold", 'r', &shadthresh);
534                          break;
535 <                case 'i':                       /* invisibility */
536 <                        getparam(s+2, "direct invisibility",
537 <                                        'b', &directinvis);
535 >                case 'v':                       /* visibility */
536 >                        getparam(s+2, "direct visibility",
537 >                                        'b', &directvis);
538                          break;
539                  case 's':                       /* sampling */
540                          getparam(s+2, "direct sampling", 'r', &srcsizerat);
# Line 457 | Line 552 | register char  *s;
552          case 'a':                       /* ambient */
553                  switch (s[1]) {
554                  case 'v':                       /* value */
555 <                        getparam(s+2, "ambient value", 'C', ambval);
555 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
556                          break;
557                  case 'a':                       /* accuracy */
558 <                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
558 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
559 >                                setambacc(ambacc);
560                          break;
561                  case 'd':                       /* divisions */
562                          getparam(s+2, "ambient divisions", 'i', &ambdiv);
# Line 524 | Line 620 | char  *s;
620          int  x, y;
621          RAY  thisray;
622  
623 +        thisray.rmax = 0.0;
624 +
625          if (!sscanvec(s, thisray.rorg) ||
626                          !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
627  
# Line 533 | Line 631 | char  *s;
631                  if ((*dev->getcur)(&x, &y) == ABORT)
632                          return;
633  
634 <                if (viewray(thisray.rorg, thisray.rdir, &ourview,
635 <                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
634 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
635 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
636                          error(COMMAND, "not on image");
637                          return;
638                  }
# Line 551 | Line 649 | char  *s;
649          if (thisray.ro == NULL)
650                  (*dev->comout)("ray hit nothing");
651          else {
652 <                sprintf(buf, "ray hit %s %s \"%s\"",
653 <                                objptr(thisray.ro->omod)->oname,
652 >                sprintf(buf, "ray hit %s%s %s \"%s\"",
653 >                                thisray.rod < 0.0 ? "back of " : "",
654 >                                thisray.ro->omod == OVOID ? VOIDID :
655 >                                        objptr(thisray.ro->omod)->oname,
656                                  ofun[thisray.ro->otype].funame,
657                                  thisray.ro->oname);
658                  (*dev->comout)(buf);
# Line 585 | Line 685 | char  *s;
685          COLR  *scanline;
686          int  y;
687  
688 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
688 >        while (isspace(*s))
689 >                s++;
690 >        if (*s)
691 >                atos(buf, sizeof(buf), s);
692 >        else if (buf[0] == '\0') {
693                  error(COMMAND, "no file");
694                  return;
695          }
# Line 595 | Line 699 | char  *s;
699                  error(COMMAND, errmsg);
700                  return;
701          }
702 + #ifdef MSDOS
703 +        setmode(fileno(fp), O_BINARY);
704 + #endif
705          (*dev->comout)("writing \"");
706          (*dev->comout)(fname);
707          (*dev->comout)("\"...\n");
708                                                  /* write header */
709 +        newheader("RADIANCE", fp);
710          fputs(progname, fp);
711          fprintview(&ourview, fp);
712          if (octname != NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines