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.36 by greg, Fri Mar 7 16:58:58 1997 UTC vs.
Revision 2.44 by greg, Tue Jan 18 00:33:16 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  rv2.c - command routines used in tracing a view.
6   *
7 < *     3/24/87
7 > *  External symbols declared in rpaint.h
8   */
9  
10 < #include  "ray.h"
10 > #include "copyright.h"
11  
12 < #include  "octree.h"
12 > #include  <ctype.h>
13 > #include  <string.h>
14  
15 + #include  "platform.h"
16 + #include  "ray.h"
17 + #include  "ambient.h"
18   #include  "otypes.h"
18
19   #include  "rpaint.h"
20  
21 < #include  "resolu.h"
21 > extern int  psample;                    /* pixel sample size */
22 > extern double  maxdiff;                 /* max. sample difference */
23  
23 #include  <ctype.h>
24
24   #define  CTRL(c)        ((c)-'@')
25  
26   #ifdef  SMLFLT
# Line 30 | Line 29 | static char SCCSid[] = "$SunId$ LBL";
29   #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
30   #endif
31  
33 extern char  *atos();
34
35 extern FILE  *popen();
36
32   extern char  rifname[128];              /* rad input file name */
33  
39 extern char  VersionID[];
34   extern char  *progname;
35   extern char  *octname;
36  
37  
38 < getframe(s)                             /* get a new frame */
39 < char  *s;
38 > extern void
39 > getframe(                               /* get a new frame */
40 >        char  *s
41 > )
42   {
43          if (getrect(s, &pframe) < 0)
44                  return;
# Line 50 | Line 46 | char  *s;
46   }
47  
48  
49 < getrepaint(s)                           /* get area and repaint */
50 < char  *s;
49 > extern void
50 > getrepaint(                             /* get area and repaint */
51 >        char  *s
52 > )
53   {
54          RECT  box;
55  
# Line 61 | Line 59 | char  *s;
59   }
60  
61  
62 < getview(s)                              /* get/show view parameters */
63 < char  *s;
62 > extern void
63 > getview(                                /* get/show view parameters */
64 >        char  *s
65 > )
66   {
67          FILE  *fp;
68          char  buf[128];
69          char  *fname;
70          int  change = 0;
71 <        VIEW  nv;
71 >        VIEW  nv = ourview;
72  
73          while (isspace(*s))
74                  s++;
75          if (*s == '-') {                        /* command line parameters */
76                copystruct(&nv, &ourview);
76                  if (sscanview(&nv, s))
77                          newview(&nv);
78                  else
# Line 101 | Line 100 | char  *s;
100          if (buf[0] && buf[0] != ourview.type) {
101                  nv.type = buf[0];
102                  change++;
103 <        } else
105 <                nv.type = ourview.type;
103 >        }
104          sprintf(buf, "view point (%.6g %.6g %.6g): ",
105                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
106          (*dev->comout)(buf);
# Line 110 | Line 108 | char  *s;
108          if (buf[0] == CTRL('C')) return;
109          if (sscanvec(buf, nv.vp))
110                  change++;
113        else
114                VCOPY(nv.vp, ourview.vp);
111          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
112                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
113          (*dev->comout)(buf);
# Line 119 | Line 115 | char  *s;
115          if (buf[0] == CTRL('C')) return;
116          if (sscanvec(buf, nv.vdir))
117                  change++;
122        else
123                VCOPY(nv.vdir, ourview.vdir);
118          sprintf(buf, "view up (%.6g %.6g %.6g): ",
119                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
120          (*dev->comout)(buf);
# Line 128 | Line 122 | char  *s;
122          if (buf[0] == CTRL('C')) return;
123          if (sscanvec(buf, nv.vup))
124                  change++;
131        else
132                VCOPY(nv.vup, ourview.vup);
125          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
126                          ourview.horiz, ourview.vert);
127          (*dev->comout)(buf);
# Line 137 | Line 129 | char  *s;
129          if (buf[0] == CTRL('C')) return;
130          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
131                  change++;
140        else {
141                nv.horiz = ourview.horiz; nv.vert = ourview.vert;
142        }
132          sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ",
133                          ourview.vfore, ourview.vaft);
134          (*dev->comout)(buf);
# Line 147 | Line 136 | char  *s;
136          if (buf[0] == CTRL('C')) return;
137          if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2)
138                  change++;
150        else {
151                nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
152        }
139          sprintf(buf, "view shift and lift (%.6g %.6g): ",
140                          ourview.hoff, ourview.voff);
141          (*dev->comout)(buf);
# Line 157 | Line 143 | char  *s;
143          if (buf[0] == CTRL('C')) return;
144          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
145                  change++;
160        else {
161                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
162        }
146          if (change)
147                  newview(&nv);
148   }
149  
150  
151 < lastview(s)                             /* return to a previous view */
152 < char  *s;
151 > extern void
152 > lastview(                               /* return to a previous view */
153 >        char  *s
154 > )
155   {
156          char  buf[128];
157          char  *fname;
# Line 174 | Line 159 | char  *s;
159          VIEW  nv;
160  
161          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
162 <                copystruct(&nv, &stdview);
162 >                nv = stdview;
163                  if ((fname = getpath(buf, "", R_OK)) == NULL ||
164                                  (success = viewfile(fname, &nv, NULL)) == -1) {
165                          sprintf(errmsg, "cannot open \"%s\"", buf);
# Line 191 | Line 176 | char  *s;
176                  error(COMMAND, "no previous view");
177                  return;
178          }
179 <        copystruct(&nv, &ourview);
180 <        copystruct(&ourview, &oldview);
181 <        copystruct(&oldview, &nv);
179 >        nv = ourview;
180 >        ourview = oldview;
181 >        oldview = nv;
182          newimage();
183   }
184  
185  
186 < saveview(s)                             /* save view to rad file */
187 < char  *s;
186 > extern void
187 > saveview(                               /* save view to rad file */
188 >        char  *s
189 > )
190   {
191          char  view[64];
192          char  *fname;
# Line 234 | Line 221 | char  *s;
221   }
222  
223  
224 < loadview(s)                             /* load view from rad file */
225 < char  *s;
224 > extern void
225 > loadview(                               /* load view from rad file */
226 >        char  *s
227 > )
228   {
229          char  buf[512];
230          char  *fname;
# Line 266 | Line 255 | char  *s;
255          buf[0] = '\0';
256          fgets(buf, sizeof(buf), fp);
257          pclose(fp);
258 <        copystruct(&nv, &stdview);
258 >        nv = stdview;
259          if (!sscanview(&nv, buf)) {
260                  error(COMMAND, "rad error -- no such view?");
261                  return;
# Line 275 | Line 264 | char  *s;
264   }
265  
266  
267 < getaim(s)                               /* aim camera */
268 < char  *s;
267 > extern void
268 > getaim(                         /* aim camera */
269 >        char  *s
270 > )
271   {
272 +        VIEW  nv = ourview;
273          double  zfact;
282        VIEW  nv;
274  
275          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
276                  return;
286        nv.type = ourview.type;
287        VCOPY(nv.vp, ourview.vp);
288        VCOPY(nv.vup, ourview.vup);
289        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
290        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
291        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
277          zoomview(&nv, zfact);
278          newview(&nv);
279   }
280  
281  
282 < getmove(s)                              /* move camera */
283 < char  *s;
282 > extern void
283 > getmove(                                /* move camera */
284 >        char  *s
285 > )
286   {
287          FVECT  vc;
288          double  mag;
# Line 306 | Line 293 | char  *s;
293   }
294  
295  
296 < getrotate(s)                            /* rotate camera */
297 < char  *s;
296 > extern void
297 > getrotate(                              /* rotate camera */
298 >        char  *s
299 > )
300   {
301 <        VIEW  nv;
301 >        VIEW  nv = ourview;
302          FVECT  v1;
303          double  angle, elev, zfact;
304          
# Line 318 | Line 307 | char  *s;
307                  error(COMMAND, "missing angle");
308                  return;
309          }
321        nv.type = ourview.type;
322        VCOPY(nv.vp, ourview.vp);
323        VCOPY(nv.vup, ourview.vup);
324        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
325        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
310          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
311          if (elev != 0.0) {
312                  fcross(v1, nv.vdir, ourview.vup);
313                  normalize(v1);
314                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
315          }
332        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
316          zoomview(&nv, zfact);
317          newview(&nv);
318   }
319  
320  
321 < getpivot(s)                             /* pivot viewpoint */
322 < register char  *s;
321 > extern void
322 > getpivot(                               /* pivot viewpoint */
323 >        register char  *s
324 > )
325   {
326          FVECT  vc;
327          double  angle, elev, mag;
# Line 352 | Line 337 | register char  *s;
337   }
338  
339  
340 < getexposure(s)                          /* get new exposure */
341 < char  *s;
340 > extern void
341 > getexposure(                            /* get new exposure */
342 >        char  *s
343 > )
344   {
345          char  buf[128];
346          register char  *cp;
# Line 417 | Line 404 | char  *s;
404          redraw();
405   }
406  
407 + typedef union {int i; double d; COLOR C;}       *MyUptr;
408  
409 < getparam(str, dsc, typ, ptr)            /* get variable from user */
410 < char  *str, *dsc;
411 < int  typ;
412 < register union {int i; double d; COLOR C;}  *ptr;
409 > extern int
410 > getparam(               /* get variable from user */
411 >        char  *str,
412 >        char  *dsc,
413 >        int  typ,
414 >        void  *p
415 > )
416   {
417 <        extern char  *index();
417 >        register MyUptr  ptr = (MyUptr)p;
418          int  i0;
419          double  d0, d1, d2;
420          char  buf[48];
# Line 458 | Line 449 | register union {int i; double d; COLOR C;}  *ptr;
449                          (*dev->comout)(buf);
450                          (*dev->comin)(buf, NULL);
451                          if (buf[0] == '\0' ||
452 <                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
452 >                                        strchr("yY+1tTnN-0fF", buf[0]) == NULL)
453                                  return(0);
454                  }
455 <                ptr->i = index("yY+1tT", buf[0]) != NULL;
455 >                ptr->i = strchr("yY+1tT", buf[0]) != NULL;
456                  return(1);
457          case 'C':                       /* color */
458                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
# Line 478 | Line 469 | register union {int i; double d; COLOR C;}  *ptr;
469                  setcolor(ptr->C, d0, d1, d2);
470                  return(1);
471          }
472 +        return 0; /* nothing matched */
473   }
474  
475  
476 < setparam(s)                             /* get/set program parameter */
477 < register char  *s;
476 > extern void
477 > setparam(                               /* get/set program parameter */
478 >        register char  *s
479 > )
480   {
487        extern int  psample;
488        extern double  maxdiff;
489        extern double  minweight;
490        extern int  maxdepth;
491        extern double  dstrsrc;
492        extern double  shadthresh;
493        extern double  shadcert;
494        extern COLOR  ambval;
495        extern int  ambvwt;
496        extern double  ambacc;
497        extern int  ambres;
498        extern int  ambdiv;
499        extern int  ambssamp;
500        extern int  ambounce;
501        extern COLOR  cextinction;
502        extern COLOR  salbedo;
503        extern double  seccg;
504        extern double  ssampdist;
505        extern int  directvis;
506        extern double  srcsizerat;
507        extern int  do_irrad;
508        extern double  specjitter;
509        extern double  specthresh;
510        extern int  backvis;
481          char  buf[128];
482          
483          if (s[0] == '\0') {
# Line 520 | Line 490 | register char  *s;
490          case 'l':                       /* limit */
491                  switch (s[1]) {
492                  case 'w':                       /* weight */
493 <                        getparam(s+2, "limit weight", 'r', &minweight);
493 >                        getparam(s+2, "limit weight", 'r',
494 >                                        (void *)&minweight);
495                          break;
496                  case 'r':                       /* reflection */
497 <                        getparam(s+2, "limit reflection", 'i', &maxdepth);
497 >                        getparam(s+2, "limit reflection", 'i',
498 >                                        (void *)&maxdepth);
499                          break;
500                  default:
501                          goto badparam;
# Line 532 | Line 504 | register char  *s;
504          case 'd':                       /* direct */
505                  switch (s[1]) {
506                  case 'j':                       /* jitter */
507 <                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
507 >                        getparam(s+2, "direct jitter", 'r',
508 >                                        (void *)&dstrsrc);
509                          break;
510                  case 'c':                       /* certainty */
511 <                        getparam(s+2, "direct certainty", 'r', &shadcert);
511 >                        getparam(s+2, "direct certainty", 'r',
512 >                                        (void *)&shadcert);
513                          break;
514                  case 't':                       /* threshold */
515 <                        getparam(s+2, "direct threshold", 'r', &shadthresh);
515 >                        getparam(s+2, "direct threshold", 'r',
516 >                                        (void *)&shadthresh);
517                          break;
518                  case 'v':                       /* visibility */
519 <                        getparam(s+2, "direct visibility",
520 <                                        'b', &directvis);
519 >                        getparam(s+2, "direct visibility", 'b',
520 >                                        (void *)&directvis);
521                          break;
522                  case 's':                       /* sampling */
523 <                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
523 >                        getparam(s+2, "direct sampling", 'r',
524 >                                        (void *)&srcsizerat);
525                          break;
526                  default:
527                          goto badparam;
# Line 554 | Line 530 | register char  *s;
530          case 'b':                       /* back faces or black and white */
531                  switch (s[1]) {
532                  case 'v':                       /* back face visibility */
533 <                        getparam(s+2, "back face visibility", 'b', &backvis);
533 >                        getparam(s+2, "back face visibility", 'b',
534 >                                        (void *)&backvis);
535                          break;
536                  case '\0':                      /* black and white */
537                  case ' ':
538                  case 'y': case 'Y': case 't': case 'T': case '1': case '+':
539                  case 'n': case 'N': case 'f': case 'F': case '0': case '-':
540 <                        getparam(s+1, "black and white", 'b', &greyscale);
540 >                        getparam(s+1, "black and white", 'b',
541 >                                        (void *)&greyscale);
542                          break;
543                  default:
544                          goto badparam;
545                  }
546                  break;
547          case 'i':                       /* irradiance */
548 <                getparam(s+1, "irradiance", 'b', &do_irrad);
548 >                getparam(s+1, "irradiance", 'b',
549 >                                (void *)&do_irrad);
550                  break;
551          case 'a':                       /* ambient */
552                  switch (s[1]) {
553                  case 'v':                       /* value */
554 <                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
554 >                        getparam(s+2, "ambient value", 'C',
555 >                                        (void *)ambval);
556                          break;
557                  case 'w':                       /* weight */
558 <                        getparam(s+2, "ambient value weight", 'i', &ambvwt);
558 >                        getparam(s+2, "ambient value weight", 'i',
559 >                                        (void *)&ambvwt);
560                          break;
561                  case 'a':                       /* accuracy */
562 <                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
562 >                        if (getparam(s+2, "ambient accuracy", 'r',
563 >                                        (void *)&ambacc))
564                                  setambacc(ambacc);
565                          break;
566                  case 'd':                       /* divisions */
567 <                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
567 >                        getparam(s+2, "ambient divisions", 'i',
568 >                                        (void *)&ambdiv);
569                          break;
570                  case 's':                       /* samples */
571 <                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
571 >                        getparam(s+2, "ambient super-samples", 'i',
572 >                                        (void *)&ambssamp);
573                          break;
574                  case 'b':                       /* bounces */
575 <                        getparam(s+2, "ambient bounces", 'i', &ambounce);
575 >                        getparam(s+2, "ambient bounces", 'i',
576 >                                        (void *)&ambounce);
577                          break;
578                  case 'r':
579 <                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
579 >                        if (getparam(s+2, "ambient resolution", 'i',
580 >                                        (void *)&ambres))
581                                  setambres(ambres);
582                          break;
583                  default:
# Line 602 | Line 588 | register char  *s;
588                  switch (s[1]) {
589                  case 'e':                       /* extinction coefficient */
590                          getparam(s+2, "extinction coefficient", 'C',
591 <                                        (COLOR *)cextinction);
591 >                                        (void *)cextinction);
592                          break;
593                  case 'a':                       /* scattering albedo */
594                          getparam(s+2, "scattering albedo", 'C',
595 <                                        (COLOR *)salbedo);
595 >                                        (void *)salbedo);
596                          break;
597                  case 'g':                       /* scattering eccentricity */
598 <                        getparam(s+2, "scattering eccentricity", 'r', &seccg);
598 >                        getparam(s+2, "scattering eccentricity", 'r',
599 >                                        (void *)&seccg);
600                          break;
601                  case 's':                       /* sampling distance */
602                          getparam(s+2, "mist sampling distance", 'r',
603 <                                        &ssampdist);
603 >                                        (void *)&ssampdist);
604                          break;
605                  default:
606                          goto badparam;
# Line 622 | Line 609 | register char  *s;
609          case 'p':                       /* pixel */
610                  switch (s[1]) {
611                  case 's':                       /* sample */
612 <                        if (getparam(s+2, "pixel sample", 'i', &psample))
612 >                        if (getparam(s+2, "pixel sample", 'i',
613 >                                        (void *)&psample))
614                                  pdepth = 0;
615                          break;
616                  case 't':                       /* threshold */
617 <                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
617 >                        if (getparam(s+2, "pixel threshold", 'r',
618 >                                        (void *)&maxdiff))
619                                  pdepth = 0;
620                          break;
621                  default:
# Line 636 | Line 625 | register char  *s;
625          case 's':                       /* specular */
626                  switch (s[1]) {
627                  case 'j':                       /* jitter */
628 <                        getparam(s+2, "specular jitter", 'r', &specjitter);
628 >                        getparam(s+2, "specular jitter", 'r',
629 >                                        (void *)&specjitter);
630                          break;
631                  case 't':                       /* threshold */
632 <                        getparam(s+2, "specular threshold", 'r', &specthresh);
632 >                        getparam(s+2, "specular threshold", 'r',
633 >                                        (void *)&specthresh);
634                          break;
635                  default:
636                          goto badparam;
# Line 657 | Line 648 | badparam:
648   }
649  
650  
651 + extern void
652   traceray(s)                             /* trace a single ray */
653   char  *s;
654   {
655          char  buf[128];
656          int  x, y;
657 <        OBJREC  *inst;
657 >        OBJREC  *ino;
658          RAY  thisray;
659  
660          thisray.rmax = 0.0;
# Line 700 | Line 692 | char  *s;
692                                          objptr(thisray.ro->omod)->oname,
693                                  ofun[thisray.ro->otype].funame,
694                                  thisray.ro->oname);
695 <                if ((inst = objptr(thisray.robj)) != thisray.ro)
696 <                        sprintf(buf+strlen(buf), " in instance \"%s\"",
697 <                                        inst->oname);
695 >                if ((ino = objptr(thisray.robj)) != thisray.ro)
696 >                        sprintf(buf+strlen(buf), " in %s \"%s\"",
697 >                                        ofun[ino->otype].funame, ino->oname);
698                  (*dev->comout)(buf);
699                  (*dev->comin)(buf, NULL);
700                  if (thisray.rot >= FHUGE)
# Line 714 | Line 706 | char  *s;
706                          (*dev->comout)(buf);
707                  }
708                  (*dev->comin)(buf, NULL);
709 <                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
709 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)",
710                                  colval(thisray.rcol,RED),
711                                  colval(thisray.rcol,GRN),
712                                  colval(thisray.rcol,BLU),
# Line 725 | Line 717 | char  *s;
717   }
718  
719  
720 + extern void
721   writepict(s)                            /* write the picture to a file */
722   char  *s;
723   {
# Line 748 | Line 741 | char  *s;
741                  error(COMMAND, errmsg);
742                  return;
743          }
744 < #ifdef MSDOS
752 <        setmode(fileno(fp), O_BINARY);
753 < #endif
744 >        SET_FILE_BINARY(fp);
745          (*dev->comout)("writing \"");
746          (*dev->comout)(fname);
747          (*dev->comout)("\"...\n");
# Line 763 | Line 754 | char  *s;
754          else
755                  putc('\n', fp);
756          fprintf(fp, "SOFTWARE= %s\n", VersionID);
757 +        fputnow(fp);
758          if (exposure != 1.0)
759                  fputexpos(exposure, fp);
760          if (dev->pixaspect != 1.0)
# Line 783 | Line 775 | char  *s;
775                  if (fwritecolrs(scanline, hresolu, fp) < 0)
776                          break;
777          }
778 <        free((char *)scanline);
778 >        free((void *)scanline);
779          if (fclose(fp) < 0)
780                  error(COMMAND, "write error");
781   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines