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.4 by greg, Tue May 30 09:57:13 1989 UTC vs.
Revision 1.19 by greg, Mon Feb 5 09:57:45 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 87 | Line 63 | char  *s;
63                  }
64                  fputs(progname, fp);
65                  fprintview(&ourview, fp);
66 +                fputs(sskip(s), fp);
67                  fputs("\n", fp);
68                  fclose(fp);
69                  return;
70          }
71          sprintf(buf, "view type (%c): ", ourview.type);
72          (*dev->comout)(buf);
73 <        (*dev->comin)(buf);
73 >        (*dev->comin)(buf, NULL);
74          if (buf[0] == CTRL(C)) return;
75          if (buf[0] && buf[0] != ourview.type) {
76                  nv.type = buf[0];
# Line 103 | Line 80 | char  *s;
80          sprintf(buf, "view point (%.6g %.6g %.6g): ",
81                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
82          (*dev->comout)(buf);
83 <        (*dev->comin)(buf);
83 >        (*dev->comin)(buf, NULL);
84          if (buf[0] == CTRL(C)) return;
85          if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
86                  change++;
# Line 112 | Line 89 | char  *s;
89          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
90                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
91          (*dev->comout)(buf);
92 <        (*dev->comin)(buf);
92 >        (*dev->comin)(buf, NULL);
93          if (buf[0] == CTRL(C)) return;
94          if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
95                  change++;
# Line 121 | Line 98 | char  *s;
98          sprintf(buf, "view up (%.6g %.6g %.6g): ",
99                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
100          (*dev->comout)(buf);
101 <        (*dev->comin)(buf);
101 >        (*dev->comin)(buf, NULL);
102          if (buf[0] == CTRL(C)) return;
103          if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
104                  change++;
# Line 130 | Line 107 | char  *s;
107          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
108                          ourview.horiz, ourview.vert);
109          (*dev->comout)(buf);
110 <        (*dev->comin)(buf);
110 >        (*dev->comin)(buf, NULL);
111          if (buf[0] == CTRL(C)) return;
112          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
113                  change++;
114          else {
115                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
116          }
117 <        sprintf(buf, "x and y resolution (%d %d): ",
118 <                        ourview.hresolu, ourview.vresolu);
117 >        sprintf(buf, "view shift and lift (%.6g %.6g): ",
118 >                        ourview.hoff, ourview.voff);
119          (*dev->comout)(buf);
120 <        (*dev->comin)(buf);
120 >        (*dev->comin)(buf, NULL);
121          if (buf[0] == CTRL(C)) return;
122 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
122 >        if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
123                  change++;
124          else {
125 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
125 >                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
126          }
127          if (change)
128                  newview(&nv);
# Line 156 | Line 133 | lastview(s)                            /* return to a previous view */
133   char  *s;
134   {
135          char  buf[128];
136 <        char  *fname, *getpath();
136 >        char  *fname;
137          int  success;
138          VIEW  nv;
139  
140          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
141 <                bcopy(&stdview, &nv, sizeof(VIEW));
142 <                if ((fname = getpath(buf, NULL)) == NULL ||
143 <                                (success = viewfile(fname, &nv)) == -1) {
141 >                copystruct(&nv, &stdview);
142 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
143 >                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
144                          sprintf(errmsg, "cannot open \"%s\"", buf);
145                          error(COMMAND, errmsg);
146                          return;
# Line 174 | Line 151 | char  *s;
151                          newview(&nv);
152                  return;
153          }
154 <        if (oldview.hresolu == 0) {     /* no old view! */
154 >        if (oldview.horiz == 0) {       /* no old view! */
155                  error(COMMAND, "no previous view");
156                  return;
157          }
158 <        bcopy(&ourview, &nv, sizeof(VIEW));
159 <        bcopy(&oldview, &ourview, sizeof(VIEW));
160 <        bcopy(&nv, &oldview, sizeof(VIEW));
158 >        copystruct(&nv, &ourview);
159 >        copystruct(&ourview, &oldview);
160 >        copystruct(&oldview, &nv);
161          newimage();
162   }
163  
164  
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
165   getaim(s)                               /* aim camera */
166   char  *s;
167   {
# Line 243 | Line 173 | char  *s;
173                  return;
174          VCOPY(nv.vp, ourview.vp);
175          VCOPY(nv.vup, ourview.vup);
176 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
176 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
177          if ((nv.type = ourview.type) == VT_PAR) {
178                  nv.horiz = ourview.horiz / zfact;
179                  nv.vert = ourview.vert / zfact;
# Line 284 | Line 214 | char  *s;
214          }
215          VCOPY(nv.vp, ourview.vp);
216          VCOPY(nv.vup, ourview.vup);
217 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
217 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
218          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
219          if (elev != 0.0) {
220                  fcross(v1, nv.vdir, ourview.vup);
# Line 341 | Line 271 | char  *s;
271                  if ((*dev->getcur)(&x, &y) == ABORT)
272                          return;
273                  r.l = r.d = 0;
274 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
274 >                r.r = hresolu; r.u = vresolu;
275                  p = findrect(x, y, &ptrunk, &r, -1);
276                  e = 1.0;
277          } else {
# Line 353 | Line 283 | char  *s;
283                          if (*cp == '\0') {      /* interactive */
284                                  sprintf(buf, "exposure (%lf): ", exposure);
285                                  (*dev->comout)(buf);
286 <                                (*dev->comin)(buf);
286 >                                (*dev->comin)(buf, NULL);
287                                  for (cp = buf; isspace(*cp); cp++)
288                                          ;
289                                  if (*cp == '\0')
# Line 369 | Line 299 | char  *s;
299                          e *= atof(cp);
300          }
301          if (p != NULL) {                /* relative setting */
302 <                if (intens(p->v) <= FTINY) {
302 >                if (bright(p->v) <= FTINY) {
303                          error(COMMAND, "cannot normalize to zero");
304                          return;
305                  }
306 <                e *= 0.5 / intens(p->v);
306 >                e *= 0.5 / bright(p->v);
307          }
308          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
309                  return;
# Line 391 | Line 321 | register char  *s;
321          extern double  minweight;
322          extern int  maxdepth;
323          extern double  dstrsrc;
324 +        extern double  shadthresh;
325 +        extern double  shadcert;
326          extern COLOR  ambval;
327          extern double  ambacc;
328          extern double  minarad;
# Line 403 | Line 335 | register char  *s;
335          char  buf[128];
336          
337          if (s[0] == '\0') {
338 <                (*dev->comout)("aa ab ad ar as av ds lr lw sd sp: ");
339 <                (*dev->comin)(buf);
338 >                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
339 >                (*dev->comin)(buf, NULL);
340                  s = buf;
341          }
342          switch (s[0]) {
# Line 415 | Line 347 | register char  *s;
347                                  sprintf(buf, "limit weight (%.6g): ",
348                                                  minweight);
349                                  (*dev->comout)(buf);
350 <                                (*dev->comin)(buf);
350 >                                (*dev->comin)(buf, NULL);
351                                  if (sscanf(buf, "%lf", &d0) != 1)
352                                          break;
353                          }
# Line 426 | Line 358 | register char  *s;
358                                  sprintf(buf, "limit reflection (%d): ",
359                                                  maxdepth);
360                                  (*dev->comout)(buf);
361 <                                (*dev->comin)(buf);
361 >                                (*dev->comin)(buf, NULL);
362                                  if (sscanf(buf, "%d", &i0) != 1)
363                                          break;
364                          }
# Line 436 | Line 368 | register char  *s;
368                          goto badparam;
369                  }
370                  break;
371 <        case 'd':                       /* distribute source */
372 <                if (s[1] != 's')
371 >        case 'd':                       /* direct */
372 >                switch (s[1]) {
373 >                case 'j':                       /* jitter */
374 >                        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;
383 >                        break;
384 >                case 'c':                       /* certainty */
385 >                        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;
394 >                        break;
395 >                case 't':                       /* threshold */
396 >                        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;
405 >                        break;
406 >                default:
407                          goto badparam;
442                if (sscanf(s+2, "%lf", &d0) != 1) {
443                        sprintf(buf, "distribute source (%.6g): ", dstrsrc);
444                        (*dev->comout)(buf);
445                        (*dev->comin)(buf);
446                        if (sscanf(buf, "%lf", &d0) != 1)
447                                break;
408                  }
449                dstrsrc = d0;
409                  break;
410          case 'a':                       /* ambient */
411                  switch (s[1]) {
# Line 458 | Line 417 | register char  *s;
417                                                  colval(ambval,GRN),
418                                                  colval(ambval,BLU));
419                                  (*dev->comout)(buf);
420 <                                (*dev->comin)(buf);
420 >                                (*dev->comin)(buf, NULL);
421                                  if (sscanf(buf, "%lf %lf %lf",
422                                                  &d0, &d1, &d2) != 3)
423                                          break;
# Line 470 | Line 429 | register char  *s;
429                                  sprintf(buf, "ambient accuracy (%.6g): ",
430                                                  ambacc);
431                                  (*dev->comout)(buf);
432 <                                (*dev->comin)(buf);
432 >                                (*dev->comin)(buf, NULL);
433                                  if (sscanf(buf, "%lf", &d0) != 1)
434                                          break;
435                          }
# Line 481 | Line 440 | register char  *s;
440                                  sprintf(buf, "ambient divisions (%d): ",
441                                                  ambdiv);
442                                  (*dev->comout)(buf);
443 <                                (*dev->comin)(buf);
443 >                                (*dev->comin)(buf, NULL);
444                                  if (sscanf(buf, "%d", &i0) != 1)
445                                          break;
446                          }
# Line 492 | Line 451 | register char  *s;
451                                  sprintf(buf, "ambient super-samples (%d): ",
452                                                  ambssamp);
453                                  (*dev->comout)(buf);
454 <                                (*dev->comin)(buf);
454 >                                (*dev->comin)(buf, NULL);
455                                  if (sscanf(buf, "%d", &i0) != 1)
456                                          break;
457                          }
# Line 503 | Line 462 | register char  *s;
462                                  sprintf(buf, "ambient bounces (%d): ",
463                                                  ambounce);
464                                  (*dev->comout)(buf);
465 <                                (*dev->comin)(buf);
465 >                                (*dev->comin)(buf, NULL);
466                                  if (sscanf(buf, "%d", &i0) != 1)
467                                          break;
468                          }
# Line 514 | Line 473 | register char  *s;
473                                  sprintf(buf, "ambient resolution (%d): ",
474                                                  ambres);
475                                  (*dev->comout)(buf);
476 <                                (*dev->comin)(buf);
476 >                                (*dev->comin)(buf, NULL);
477                                  if (sscanf(buf, "%d", &i0) != 1)
478                                          break;
479                          }
# Line 531 | Line 490 | register char  *s;
490                          if (sscanf(s+2, "%d", &i0) != 1) {
491                                  sprintf(buf, "sample pixel (%d): ", psample);
492                                  (*dev->comout)(buf);
493 <                                (*dev->comin)(buf);
493 >                                (*dev->comin)(buf, NULL);
494                                  if (sscanf(buf, "%d", &i0) != 1)
495                                          break;
496                          }
497                          psample = i0;
498                          pdepth = 0;
499                          break;
500 <                case 'd':                       /* difference */
500 >                case 't':                       /* threshold */
501                          if (sscanf(s+2, "%lf", &d0) != 1) {
502 <                                sprintf(buf, "sample difference (%.6g): ",
502 >                                sprintf(buf, "sample threshold (%.6g): ",
503                                                  maxdiff);
504                                  (*dev->comout)(buf);
505 <                                (*dev->comin)(buf);
505 >                                (*dev->comin)(buf, NULL);
506                                  if (sscanf(buf, "%lf", &d0) != 1)
507                                          break;
508                          }
# Line 582 | Line 541 | char  *s;
541                  if ((*dev->getcur)(&x, &y) == ABORT)
542                          return;
543  
544 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
544 >                viewray(thisray.rorg, thisray.rdir, &ourview,
545 >                                (x+.5)/hresolu, (y+.5)/vresolu);
546                  
547          } else if (normalize(thisray.rdir) == 0.0) {
548                  error(COMMAND, "zero ray direction");
# Line 601 | Line 561 | char  *s;
561                                  ofun[thisray.ro->otype].funame,
562                                  thisray.ro->oname);
563                  (*dev->comout)(buf);
564 <                (*dev->comin)(buf);
564 >                (*dev->comin)(buf, NULL);
565                  if (thisray.rot >= FHUGE)
566                          (*dev->comout)("at infinity");
567                  else {
# Line 609 | Line 569 | char  *s;
569                                          thisray.rop[1], thisray.rop[2]);
570                          (*dev->comout)(buf);
571                  }
572 <                (*dev->comin)(buf);
572 >                (*dev->comin)(buf, NULL);
573                  sprintf(buf, "with value (%.6g %.6g %.6g)",
574                                  colval(thisray.rcol,RED),
575                                  colval(thisray.rcol,GRN),
576                                  colval(thisray.rcol,BLU));
577                  (*dev->comout)(buf);
578          }
579 <        (*dev->comin)(buf);
579 >        (*dev->comin)(buf, NULL);
580   }
581  
582  
# Line 624 | Line 584 | writepict(s)                           /* write the picture to a file */
584   char  *s;
585   {
586          static char  buf[128];
587 <        char  *fname, *getpath();
587 >        char  *fname;
588          FILE  *fp;
589          COLR  *scanline;
590          int  y;
# Line 633 | Line 593 | char  *s;
593                  error(COMMAND, "no file");
594                  return;
595          }
596 <        if ((fname = getpath(buf, NULL)) == NULL ||
596 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
597                          (fp = fopen(fname, "w")) == NULL) {
598                  sprintf(errmsg, "cannot open \"%s\"", buf);
599                  error(COMMAND, errmsg);
# Line 645 | Line 605 | char  *s;
605                                                  /* write header */
606          fputs(progname, fp);
607          fprintview(&ourview, fp);
608 <        fputs("\n", fp);
608 >        putc('\n', fp);
609          if (exposure != 1.0)
610 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
611 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
610 >                fputexpos(exposure, fp);
611 >        if (dev->pixaspect != 1.0)
612 >                fputaspect(dev->pixaspect, fp);
613 >        putc('\n', fp);
614 >        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
615  
616 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
616 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
617          if (scanline == NULL)
618                  error(SYSTEM, "out of memory in writepict");
619 <        for (y = ourview.vresolu-1; y >= 0; y--) {
620 <                getpictcolrs(y, scanline, &ptrunk,
621 <                                ourview.hresolu, ourview.vresolu);
659 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
619 >        for (y = vresolu-1; y >= 0; y--) {
620 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
621 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
622                          break;
623          }
624          if (fclose(fp) < 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines