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.6 by greg, Wed Jun 7 08:38:35 1989 UTC vs.
Revision 1.18 by greg, Tue Jan 30 11:37:37 1990 UTC

# Line 28 | Line 28 | extern char  *progname;
28   getframe(s)                             /* get a new frame */
29   char  *s;
30   {
31 <        int  x0, y0, x1, y1;
32 <
33 <        if (!strcmp("all", s)) {
34 <                pframe.l = pframe.d = 0;
35 <                pframe.r = ourview.hresolu;
36 <                pframe.u = ourview.vresolu;
37 <                pdepth = 0;
31 >        if (getrect(s, &pframe) < 0)
32                  return;
39        }
40        if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) {
41                if (dev->getcur == NULL)
42                        return;
43                (*dev->comout)("Pick first corner\n");
44                if ((*dev->getcur)(&x0, &y0) == ABORT)
45                        return;
46                (*dev->comout)("Pick second corner\n");
47                if ((*dev->getcur)(&x1, &y1) == ABORT)
48                        return;
49        }
50        if (x0 < x1) {
51                pframe.l = x0;
52                pframe.r = x1;
53        } else {
54                pframe.l = x1;
55                pframe.r = x0;
56        }
57        if (y0 < y1) {
58                pframe.d = y0;
59                pframe.u = y1;
60        } else {
61                pframe.d = y1;
62                pframe.u = y0;
63        }
64        if (pframe.l < 0) pframe.l = 0;
65        if (pframe.d < 0) pframe.d = 0;
66        if (pframe.r > ourview.hresolu) pframe.r = ourview.hresolu;
67        if (pframe.u > ourview.vresolu) pframe.u = ourview.vresolu;
33          pdepth = 0;
34   }
35  
36  
37 + getrepaint(s)                           /* get area and repaint */
38 + char  *s;
39 + {
40 +        RECT  box;
41 +
42 +        if (getrect(s, &box) < 0)
43 +                return;
44 +        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box);
45 + }
46 +
47 +
48   getview(s)                              /* get/show view parameters */
49   char  *s;
50   {
51          FILE  *fp;
52          char  buf[128];
53 <        char  *fname, *getpath();
53 >        char  *fname;
54          int  change = 0;
55          VIEW  nv;
56  
57          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
58 <                if ((fname = getpath(buf, NULL)) == NULL ||
58 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
59                                  (fp = fopen(fname, "a")) == NULL) {
60                          sprintf(errmsg, "cannot open \"%s\"", buf);
61                          error(COMMAND, errmsg);
# Line 93 | Line 69 | char  *s;
69          }
70          sprintf(buf, "view type (%c): ", ourview.type);
71          (*dev->comout)(buf);
72 <        (*dev->comin)(buf);
72 >        (*dev->comin)(buf, NULL);
73          if (buf[0] == CTRL(C)) return;
74          if (buf[0] && buf[0] != ourview.type) {
75                  nv.type = buf[0];
# Line 103 | Line 79 | char  *s;
79          sprintf(buf, "view point (%.6g %.6g %.6g): ",
80                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
81          (*dev->comout)(buf);
82 <        (*dev->comin)(buf);
82 >        (*dev->comin)(buf, NULL);
83          if (buf[0] == CTRL(C)) return;
84          if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
85                  change++;
# Line 112 | Line 88 | char  *s;
88          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
89                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
90          (*dev->comout)(buf);
91 <        (*dev->comin)(buf);
91 >        (*dev->comin)(buf, NULL);
92          if (buf[0] == CTRL(C)) return;
93          if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
94                  change++;
# Line 121 | Line 97 | char  *s;
97          sprintf(buf, "view up (%.6g %.6g %.6g): ",
98                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
99          (*dev->comout)(buf);
100 <        (*dev->comin)(buf);
100 >        (*dev->comin)(buf, NULL);
101          if (buf[0] == CTRL(C)) return;
102          if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
103                  change++;
# Line 130 | Line 106 | char  *s;
106          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
107                          ourview.horiz, ourview.vert);
108          (*dev->comout)(buf);
109 <        (*dev->comin)(buf);
109 >        (*dev->comin)(buf, NULL);
110          if (buf[0] == CTRL(C)) return;
111          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
112                  change++;
113          else {
114                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
115          }
116 <        sprintf(buf, "x and y resolution (%d %d): ",
117 <                        ourview.hresolu, ourview.vresolu);
116 >        sprintf(buf, "view shift and lift (%.6g %.6g): ",
117 >                        ourview.hoff, ourview.voff);
118          (*dev->comout)(buf);
119 <        (*dev->comin)(buf);
119 >        (*dev->comin)(buf, NULL);
120          if (buf[0] == CTRL(C)) return;
121 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
121 >        if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
122                  change++;
123          else {
124 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
124 >                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
125          }
126          if (change)
127                  newview(&nv);
# Line 156 | Line 132 | lastview(s)                            /* return to a previous view */
132   char  *s;
133   {
134          char  buf[128];
135 <        char  *fname, *getpath();
135 >        char  *fname;
136          int  success;
137          VIEW  nv;
138  
139          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
140 <                bcopy(&stdview, &nv, sizeof(VIEW));
141 <                if ((fname = getpath(buf, NULL)) == NULL ||
142 <                                (success = viewfile(fname, &nv)) == -1) {
140 >                copystruct(&nv, &stdview);
141 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
142 >                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
143                          sprintf(errmsg, "cannot open \"%s\"", buf);
144                          error(COMMAND, errmsg);
145                          return;
# Line 174 | Line 150 | char  *s;
150                          newview(&nv);
151                  return;
152          }
153 <        if (oldview.hresolu == 0) {     /* no old view! */
153 >        if (oldview.horiz == 0) {       /* no old view! */
154                  error(COMMAND, "no previous view");
155                  return;
156          }
157 <        bcopy(&ourview, &nv, sizeof(VIEW));
158 <        bcopy(&oldview, &ourview, sizeof(VIEW));
159 <        bcopy(&nv, &oldview, sizeof(VIEW));
157 >        copystruct(&nv, &ourview);
158 >        copystruct(&ourview, &oldview);
159 >        copystruct(&oldview, &nv);
160          newimage();
161   }
162  
163  
188 getinterest(s, direc, vec, mp)          /* get area of interest */
189 char  *s;
190 int  direc;
191 FVECT  vec;
192 double  *mp;
193 {
194        int  x, y;
195        RAY  thisray;
196        register int  i;
197
198        if (sscanf(s, "%lf", mp) != 1)
199                *mp = 1.0;
200        else if (*mp < -FTINY)          /* negative zoom is reduction */
201                *mp = -1.0 / *mp;
202        else if (*mp <= FTINY) {        /* too small */
203                error(COMMAND, "illegal magnification");
204                return(-1);
205        }
206        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
207                if (dev->getcur == NULL)
208                        return(-1);
209                (*dev->comout)("Pick view center\n");
210                if ((*dev->getcur)(&x, &y) == ABORT)
211                        return(-1);
212                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
213                if (!direc || ourview.type == VT_PAR) {
214                        rayorigin(&thisray, NULL, PRIMARY, 1.0);
215                        if (!localhit(&thisray, &thescene)) {
216                                error(COMMAND, "not a local object");
217                                return(-1);
218                        }
219                }
220                if (direc)
221                        if (ourview.type == VT_PAR)
222                                for (i = 0; i < 3; i++)
223                                        vec[i] = thisray.rop[i] - ourview.vp[i];
224                        else
225                                VCOPY(vec, thisray.rdir);
226                else
227                        VCOPY(vec, thisray.rop);
228        } else if (direc)
229                        for (i = 0; i < 3; i++)
230                                vec[i] -= ourview.vp[i];
231        return(0);
232 }
233
234
164   getaim(s)                               /* aim camera */
165   char  *s;
166   {
# Line 243 | Line 172 | char  *s;
172                  return;
173          VCOPY(nv.vp, ourview.vp);
174          VCOPY(nv.vup, ourview.vup);
175 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
175 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
176          if ((nv.type = ourview.type) == VT_PAR) {
177                  nv.horiz = ourview.horiz / zfact;
178                  nv.vert = ourview.vert / zfact;
# Line 284 | Line 213 | char  *s;
213          }
214          VCOPY(nv.vp, ourview.vp);
215          VCOPY(nv.vup, ourview.vup);
216 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
216 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
217          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
218          if (elev != 0.0) {
219                  fcross(v1, nv.vdir, ourview.vup);
# Line 341 | Line 270 | char  *s;
270                  if ((*dev->getcur)(&x, &y) == ABORT)
271                          return;
272                  r.l = r.d = 0;
273 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
273 >                r.r = hresolu; r.u = vresolu;
274                  p = findrect(x, y, &ptrunk, &r, -1);
275                  e = 1.0;
276          } else {
# Line 353 | Line 282 | char  *s;
282                          if (*cp == '\0') {      /* interactive */
283                                  sprintf(buf, "exposure (%lf): ", exposure);
284                                  (*dev->comout)(buf);
285 <                                (*dev->comin)(buf);
285 >                                (*dev->comin)(buf, NULL);
286                                  for (cp = buf; isspace(*cp); cp++)
287                                          ;
288                                  if (*cp == '\0')
# Line 392 | Line 321 | register char  *s;
321          extern int  maxdepth;
322          extern double  dstrsrc;
323          extern double  shadthresh;
324 +        extern double  shadcert;
325          extern COLOR  ambval;
326          extern double  ambacc;
327          extern double  minarad;
# Line 404 | Line 334 | register char  *s;
334          char  buf[128];
335          
336          if (s[0] == '\0') {
337 <                (*dev->comout)("aa ab ad ar as av dj dt lr lw sd sp: ");
338 <                (*dev->comin)(buf);
337 >                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
338 >                (*dev->comin)(buf, NULL);
339                  s = buf;
340          }
341          switch (s[0]) {
# Line 416 | Line 346 | register char  *s;
346                                  sprintf(buf, "limit weight (%.6g): ",
347                                                  minweight);
348                                  (*dev->comout)(buf);
349 <                                (*dev->comin)(buf);
349 >                                (*dev->comin)(buf, NULL);
350                                  if (sscanf(buf, "%lf", &d0) != 1)
351                                          break;
352                          }
# Line 427 | Line 357 | register char  *s;
357                                  sprintf(buf, "limit reflection (%d): ",
358                                                  maxdepth);
359                                  (*dev->comout)(buf);
360 <                                (*dev->comin)(buf);
360 >                                (*dev->comin)(buf, NULL);
361                                  if (sscanf(buf, "%d", &i0) != 1)
362                                          break;
363                          }
# Line 444 | Line 374 | register char  *s;
374                                  sprintf(buf, "direct jitter (%.6g): ",
375                                                  dstrsrc);
376                                  (*dev->comout)(buf);
377 <                                (*dev->comin)(buf);
377 >                                (*dev->comin)(buf, NULL);
378                                  if (sscanf(buf, "%lf", &d0) != 1)
379                                          break;
380                          }
381                          dstrsrc = d0;
382                          break;
383 +                case 'c':                       /* certainty */
384 +                        if (sscanf(s+2, "%lf", &d0) != 1) {
385 +                                sprintf(buf, "direct certainty (%.6g): ",
386 +                                                shadcert);
387 +                                (*dev->comout)(buf);
388 +                                (*dev->comin)(buf, NULL);
389 +                                if (sscanf(buf, "%lf", &d0) != 1)
390 +                                        break;
391 +                        }
392 +                        shadcert = d0;
393 +                        break;
394                  case 't':                       /* threshold */
395                          if (sscanf(s+2, "%lf", &d0) != 1) {
396                                  sprintf(buf, "direct threshold (%.6g): ",
397                                                  shadthresh);
398                                  (*dev->comout)(buf);
399 <                                (*dev->comin)(buf);
399 >                                (*dev->comin)(buf, NULL);
400                                  if (sscanf(buf, "%lf", &d0) != 1)
401                                          break;
402                          }
# Line 475 | Line 416 | register char  *s;
416                                                  colval(ambval,GRN),
417                                                  colval(ambval,BLU));
418                                  (*dev->comout)(buf);
419 <                                (*dev->comin)(buf);
419 >                                (*dev->comin)(buf, NULL);
420                                  if (sscanf(buf, "%lf %lf %lf",
421                                                  &d0, &d1, &d2) != 3)
422                                          break;
# Line 487 | Line 428 | register char  *s;
428                                  sprintf(buf, "ambient accuracy (%.6g): ",
429                                                  ambacc);
430                                  (*dev->comout)(buf);
431 <                                (*dev->comin)(buf);
431 >                                (*dev->comin)(buf, NULL);
432                                  if (sscanf(buf, "%lf", &d0) != 1)
433                                          break;
434                          }
# Line 498 | Line 439 | register char  *s;
439                                  sprintf(buf, "ambient divisions (%d): ",
440                                                  ambdiv);
441                                  (*dev->comout)(buf);
442 <                                (*dev->comin)(buf);
442 >                                (*dev->comin)(buf, NULL);
443                                  if (sscanf(buf, "%d", &i0) != 1)
444                                          break;
445                          }
# Line 509 | Line 450 | register char  *s;
450                                  sprintf(buf, "ambient super-samples (%d): ",
451                                                  ambssamp);
452                                  (*dev->comout)(buf);
453 <                                (*dev->comin)(buf);
453 >                                (*dev->comin)(buf, NULL);
454                                  if (sscanf(buf, "%d", &i0) != 1)
455                                          break;
456                          }
# Line 520 | Line 461 | register char  *s;
461                                  sprintf(buf, "ambient bounces (%d): ",
462                                                  ambounce);
463                                  (*dev->comout)(buf);
464 <                                (*dev->comin)(buf);
464 >                                (*dev->comin)(buf, NULL);
465                                  if (sscanf(buf, "%d", &i0) != 1)
466                                          break;
467                          }
# Line 531 | Line 472 | register char  *s;
472                                  sprintf(buf, "ambient resolution (%d): ",
473                                                  ambres);
474                                  (*dev->comout)(buf);
475 <                                (*dev->comin)(buf);
475 >                                (*dev->comin)(buf, NULL);
476                                  if (sscanf(buf, "%d", &i0) != 1)
477                                          break;
478                          }
# Line 548 | Line 489 | register char  *s;
489                          if (sscanf(s+2, "%d", &i0) != 1) {
490                                  sprintf(buf, "sample pixel (%d): ", psample);
491                                  (*dev->comout)(buf);
492 <                                (*dev->comin)(buf);
492 >                                (*dev->comin)(buf, NULL);
493                                  if (sscanf(buf, "%d", &i0) != 1)
494                                          break;
495                          }
496                          psample = i0;
497                          pdepth = 0;
498                          break;
499 <                case 'd':                       /* difference */
499 >                case 't':                       /* threshold */
500                          if (sscanf(s+2, "%lf", &d0) != 1) {
501 <                                sprintf(buf, "sample difference (%.6g): ",
501 >                                sprintf(buf, "sample threshold (%.6g): ",
502                                                  maxdiff);
503                                  (*dev->comout)(buf);
504 <                                (*dev->comin)(buf);
504 >                                (*dev->comin)(buf, NULL);
505                                  if (sscanf(buf, "%lf", &d0) != 1)
506                                          break;
507                          }
# Line 599 | Line 540 | char  *s;
540                  if ((*dev->getcur)(&x, &y) == ABORT)
541                          return;
542  
543 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
543 >                viewray(thisray.rorg, thisray.rdir, &ourview,
544 >                                (x+.5)/hresolu, (y+.5)/vresolu);
545                  
546          } else if (normalize(thisray.rdir) == 0.0) {
547                  error(COMMAND, "zero ray direction");
# Line 618 | Line 560 | char  *s;
560                                  ofun[thisray.ro->otype].funame,
561                                  thisray.ro->oname);
562                  (*dev->comout)(buf);
563 <                (*dev->comin)(buf);
563 >                (*dev->comin)(buf, NULL);
564                  if (thisray.rot >= FHUGE)
565                          (*dev->comout)("at infinity");
566                  else {
# Line 626 | Line 568 | char  *s;
568                                          thisray.rop[1], thisray.rop[2]);
569                          (*dev->comout)(buf);
570                  }
571 <                (*dev->comin)(buf);
571 >                (*dev->comin)(buf, NULL);
572                  sprintf(buf, "with value (%.6g %.6g %.6g)",
573                                  colval(thisray.rcol,RED),
574                                  colval(thisray.rcol,GRN),
575                                  colval(thisray.rcol,BLU));
576                  (*dev->comout)(buf);
577          }
578 <        (*dev->comin)(buf);
578 >        (*dev->comin)(buf, NULL);
579   }
580  
581  
# Line 641 | Line 583 | writepict(s)                           /* write the picture to a file */
583   char  *s;
584   {
585          static char  buf[128];
586 <        char  *fname, *getpath();
586 >        char  *fname;
587          FILE  *fp;
588          COLR  *scanline;
589          int  y;
# Line 650 | Line 592 | char  *s;
592                  error(COMMAND, "no file");
593                  return;
594          }
595 <        if ((fname = getpath(buf, NULL)) == NULL ||
595 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
596                          (fp = fopen(fname, "w")) == NULL) {
597                  sprintf(errmsg, "cannot open \"%s\"", buf);
598                  error(COMMAND, errmsg);
# Line 662 | Line 604 | char  *s;
604                                                  /* write header */
605          fputs(progname, fp);
606          fprintview(&ourview, fp);
607 <        fputs("\n", fp);
607 >        putc('\n', fp);
608          if (exposure != 1.0)
609 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
610 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
609 >                fputexpos(exposure, fp);
610 >        if (dev->pixaspect != 1.0)
611 >                fputaspect(dev->pixaspect, fp);
612 >        putc('\n', fp);
613 >        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
614  
615 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
615 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
616          if (scanline == NULL)
617                  error(SYSTEM, "out of memory in writepict");
618 <        for (y = ourview.vresolu-1; y >= 0; y--) {
619 <                getpictcolrs(y, scanline, &ptrunk,
620 <                                ourview.hresolu, ourview.vresolu);
676 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
618 >        for (y = vresolu-1; y >= 0; y--) {
619 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
620 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
621                          break;
622          }
623          if (fclose(fp) < 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines