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.13 by greg, Thu Nov 19 20:27:03 1992 UTC vs.
Revision 2.22 by greg, Wed Dec 15 16:59:14 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1993 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 160 | Line 165 | char  *s;
165  
166          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
167                  copystruct(&nv, &stdview);
168 <                if ((fname = getpath(buf, NULL, 0)) == NULL ||
168 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
169                                  (success = viewfile(fname, &nv, NULL)) == -1) {
170                          sprintf(errmsg, "cannot open \"%s\"", buf);
171                          error(COMMAND, errmsg);
# Line 183 | Line 188 | char  *s;
188   }
189  
190  
191 + saveview(s)                             /* save view to rad file */
192 + char  *s;
193 + {
194 +        char  view[64];
195 +        char  *fname;
196 +        FILE  *fp;
197 +
198 +        if (*atos(view, sizeof(view), s)) {
199 +                if (isint(view)) {
200 +                        error(COMMAND, "cannot write view by number");
201 +                        return;
202 +                }
203 +                s = sskip(s);
204 +        }
205 +        while (isspace(*s))
206 +                s++;
207 +        if (*s)
208 +                atos(rifname, sizeof(rifname), s);
209 +        else if (rifname[0] == '\0') {
210 +                error(COMMAND, "no previous rad file");
211 +                return;
212 +        }
213 +        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
214 +                        (fp = fopen(fname, "a")) == NULL) {
215 +                sprintf(errmsg, "cannot open \"%s\"", rifname);
216 +                error(COMMAND, errmsg);
217 +                return;
218 +        }
219 +        fputs("view= ", fp);
220 +        fputs(view, fp);
221 +        fprintview(&ourview, fp);
222 +        putc('\n', fp);
223 +        fclose(fp);
224 + }
225 +
226 +
227 + loadview(s)                             /* load view from rad file */
228 + char  *s;
229 + {
230 +        char  buf[512];
231 +        char  *fname;
232 +        FILE  *fp;
233 +        VIEW  nv;
234 +
235 +        strcpy(buf, "rad -n -s -V -v ");
236 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
237 +                s = sskip(s);
238 +        else
239 +                strcat(buf, "1");
240 +        if (*s)
241 +                atos(rifname, sizeof(rifname), s);
242 +        else if (rifname[0] == '\0') {
243 +                error(COMMAND, "no previous rad file");
244 +                return;
245 +        }
246 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
247 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
248 +                error(COMMAND, errmsg);
249 +                return;
250 +        }
251 +        sprintf(buf+strlen(buf), " %s", fname);
252 +        if ((fp = popen(buf, "r")) == NULL) {
253 +                error(COMMAND, "cannot run rad");
254 +                return;
255 +        }
256 +        buf[0] = '\0';
257 +        fgets(buf, sizeof(buf), fp);
258 +        pclose(fp);
259 +        copystruct(&nv, &stdview);
260 +        if (!sscanview(&nv, buf)) {
261 +                error(COMMAND, "rad error -- no such view?");
262 +                return;
263 +        }
264 +        newview(&nv);
265 + }
266 +
267 +
268   getaim(s)                               /* aim camera */
269   char  *s;
270   {
# Line 263 | Line 345 | char  *s;
345   {
346          char  buf[128];
347          register char  *cp;
266        register PNODE  *p;
348          RECT  r;
349          int  x, y;
350 <        double  e;
351 <
350 >        register PNODE  *p = &ptrunk;
351 >        int  adapt = 0;
352 >        double  e = 1.0;
353 > start:
354          for (cp = s; isspace(*cp); cp++)
355                  ;
356 +        if (*cp == '@') {
357 +                adapt++;
358 +                goto start;
359 +        }
360          if (*cp == '\0') {              /* normalize to point */
361                  if (dev->getcur == NULL)
362                          return;
# Line 279 | Line 366 | char  *s;
366                  r.l = r.d = 0;
367                  r.r = hresolu; r.u = vresolu;
368                  p = findrect(x, y, &ptrunk, &r, -1);
282                e = 1.0;
369          } else {
370                  if (*cp == '=') {       /* absolute setting */
371                          p = NULL;
# Line 287 | Line 373 | char  *s;
373                          for (cp++; isspace(*cp); cp++)
374                                  ;
375                          if (*cp == '\0') {      /* interactive */
376 <                                sprintf(buf, "exposure (%lf): ", exposure);
376 >                                sprintf(buf, "exposure (%f): ", exposure);
377                                  (*dev->comout)(buf);
378                                  (*dev->comin)(buf, NULL);
379                                  for (cp = buf; isspace(*cp); cp++)
# Line 295 | Line 381 | char  *s;
381                                  if (*cp == '\0')
382                                          return;
383                          }
298                } else {                /* normalize to average */
299                        p = &ptrunk;
300                        e = 1.0;
384                  }
385                  if (*cp == '+' || *cp == '-')   /* f-stops */
386                          e *= pow(2.0, atof(cp));
# Line 305 | Line 388 | char  *s;
388                          e *= atof(cp);
389          }
390          if (p != NULL) {                /* relative setting */
391 <                if (bright(p->v) < 1e-25) {
391 >                if (bright(p->v) < 1e-15) {
392                          error(COMMAND, "cannot normalize to zero");
393                          return;
394                  }
395 <                e *= 0.5 / bright(p->v);
395 >                if (adapt)
396 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
397 >                else
398 >                        e *= 0.5 / bright(p->v);
399          }
400          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
401                  return;
# Line 458 | Line 544 | register char  *s;
544                          getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
545                          break;
546                  case 'a':                       /* accuracy */
547 <                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
547 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
548 >                                setambacc(ambacc);
549                          break;
550                  case 'd':                       /* divisions */
551                          getparam(s+2, "ambient divisions", 'i', &ambdiv);
# Line 550 | Line 637 | char  *s;
637                  (*dev->comout)("ray hit nothing");
638          else {
639                  sprintf(buf, "ray hit %s %s \"%s\"",
640 <                                objptr(thisray.ro->omod)->oname,
640 >                                thisray.ro->omod == OVOID ? VOIDID :
641 >                                        objptr(thisray.ro->omod)->oname,
642                                  ofun[thisray.ro->otype].funame,
643                                  thisray.ro->oname);
644                  (*dev->comout)(buf);
# Line 583 | Line 671 | char  *s;
671          COLR  *scanline;
672          int  y;
673  
674 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
674 >        while (isspace(*s))
675 >                s++;
676 >        if (*s)
677 >                atos(buf, sizeof(buf), s);
678 >        else if (buf[0] == '\0') {
679                  error(COMMAND, "no file");
680                  return;
681          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines