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.23 by greg, Thu Jan 6 15:52:17 1994 UTC vs.
Revision 2.43 by schorsch, Tue Mar 30 16:13:01 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 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];
# Line 73 | Line 73 | char  *s;
73          while (isspace(*s))
74                  s++;
75          if (*s == '-') {                        /* command line parameters */
76 <                copystruct(&nv, &ourview);
76 >                nv = ourview;
77                  if (sscanview(&nv, s))
78                          newview(&nv);
79                  else
# Line 140 | 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 155 | Line 165 | char  *s;
165   }
166  
167  
168 < lastview(s)                             /* return to a previous view */
169 < char  *s;
168 > extern void
169 > lastview(                               /* return to a previous view */
170 >        char  *s
171 > )
172   {
173          char  buf[128];
174          char  *fname;
# Line 164 | Line 176 | char  *s;
176          VIEW  nv;
177  
178          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
179 <                copystruct(&nv, &stdview);
179 >                nv = stdview;
180                  if ((fname = getpath(buf, "", R_OK)) == NULL ||
181                                  (success = viewfile(fname, &nv, NULL)) == -1) {
182                          sprintf(errmsg, "cannot open \"%s\"", buf);
# Line 181 | Line 193 | char  *s;
193                  error(COMMAND, "no previous view");
194                  return;
195          }
196 <        copystruct(&nv, &ourview);
197 <        copystruct(&ourview, &oldview);
198 <        copystruct(&oldview, &nv);
196 >        nv = ourview;
197 >        ourview = oldview;
198 >        oldview = nv;
199          newimage();
200   }
201  
202  
203 < saveview(s)                             /* save view to rad file */
204 < char  *s;
203 > extern void
204 > saveview(                               /* save view to rad file */
205 >        char  *s
206 > )
207   {
208          char  view[64];
209          char  *fname;
# Line 224 | Line 238 | char  *s;
238   }
239  
240  
241 < loadview(s)                             /* load view from rad file */
242 < char  *s;
241 > extern void
242 > loadview(                               /* load view from rad file */
243 >        char  *s
244 > )
245   {
246          char  buf[512];
247          char  *fname;
# Line 256 | Line 272 | char  *s;
272          buf[0] = '\0';
273          fgets(buf, sizeof(buf), fp);
274          pclose(fp);
275 <        copystruct(&nv, &stdview);
275 >        nv = stdview;
276          if (!sscanview(&nv, buf)) {
277                  error(COMMAND, "rad error -- no such view?");
278                  return;
# Line 265 | Line 281 | char  *s;
281   }
282  
283  
284 < getaim(s)                               /* aim camera */
285 < char  *s;
284 > extern void
285 > getaim(                         /* aim camera */
286 >        char  *s
287 > )
288   {
289          double  zfact;
290          VIEW  nv;
# Line 276 | Line 294 | char  *s;
294          nv.type = ourview.type;
295          VCOPY(nv.vp, ourview.vp);
296          VCOPY(nv.vup, ourview.vup);
279        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
297          nv.horiz = ourview.horiz; nv.vert = ourview.vert;
298 +        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
299 +        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
300          zoomview(&nv, zfact);
301          newview(&nv);
302   }
303  
304  
305 < getmove(s)                              /* move camera */
306 < char  *s;
305 > extern void
306 > getmove(                                /* move camera */
307 >        char  *s
308 > )
309   {
310          FVECT  vc;
311          double  mag;
# Line 295 | Line 316 | char  *s;
316   }
317  
318  
319 < getrotate(s)                            /* rotate camera */
320 < char  *s;
319 > extern void
320 > getrotate(                              /* rotate camera */
321 >        char  *s
322 > )
323   {
324          VIEW  nv;
325          FVECT  v1;
# Line 311 | Line 334 | char  *s;
334          VCOPY(nv.vp, ourview.vp);
335          VCOPY(nv.vup, ourview.vup);
336          nv.hoff = ourview.hoff; nv.voff = ourview.voff;
337 +        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
338          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
339          if (elev != 0.0) {
340                  fcross(v1, nv.vdir, ourview.vup);
# Line 323 | Line 347 | char  *s;
347   }
348  
349  
350 < getpivot(s)                             /* pivot viewpoint */
351 < register char  *s;
350 > extern void
351 > getpivot(                               /* pivot viewpoint */
352 >        register char  *s
353 > )
354   {
355          FVECT  vc;
356          double  angle, elev, mag;
# Line 334 | Line 360 | register char  *s;
360                  error(COMMAND, "missing angle");
361                  return;
362          }
363 <        if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0)
363 >        if (getinterest(sskip2(s,2), 0, vc, &mag) < 0)
364                  return;
365          moveview(angle, elev, mag, vc);
366   }
367  
368  
369 < getexposure(s)                          /* get new exposure */
370 < char  *s;
369 > extern void
370 > getexposure(                            /* get new exposure */
371 >        char  *s
372 > )
373   {
374          char  buf[128];
375          register char  *cp;
# Line 350 | Line 378 | char  *s;
378          register PNODE  *p = &ptrunk;
379          int  adapt = 0;
380          double  e = 1.0;
381 < start:
381 >
382          for (cp = s; isspace(*cp); cp++)
383                  ;
384          if (*cp == '@') {
385                  adapt++;
386 <                goto start;
386 >                while (isspace(*++cp))
387 >                        ;
388          }
389          if (*cp == '\0') {              /* normalize to point */
390                  if (dev->getcur == NULL)
# Line 404 | Line 433 | start:
433          redraw();
434   }
435  
436 + typedef union {int i; double d; COLOR C;}       *MyUptr;
437  
438 < getparam(str, dsc, typ, ptr)            /* get variable from user */
439 < char  *str, *dsc;
440 < int  typ;
441 < register union {int i; double d; COLOR C;}  *ptr;
438 > extern int
439 > getparam(               /* get variable from user */
440 >        char  *str,
441 >        char  *dsc,
442 >        int  typ,
443 >        void  *p
444 > )
445   {
446 <        extern char  *index();
446 >        register MyUptr  ptr = (MyUptr)p;
447          int  i0;
448          double  d0, d1, d2;
449          char  buf[48];
# Line 445 | Line 478 | register union {int i; double d; COLOR C;}  *ptr;
478                          (*dev->comout)(buf);
479                          (*dev->comin)(buf, NULL);
480                          if (buf[0] == '\0' ||
481 <                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
481 >                                        strchr("yY+1tTnN-0fF", buf[0]) == NULL)
482                                  return(0);
483                  }
484 <                ptr->i = index("yY+1tT", buf[0]) != NULL;
484 >                ptr->i = strchr("yY+1tT", buf[0]) != NULL;
485                  return(1);
486          case 'C':                       /* color */
487                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
# Line 465 | Line 498 | register union {int i; double d; COLOR C;}  *ptr;
498                  setcolor(ptr->C, d0, d1, d2);
499                  return(1);
500          }
501 +        return 0; /* nothing matched */
502   }
503  
504  
505 < setparam(s)                             /* get/set program parameter */
506 < register char  *s;
505 > extern void
506 > setparam(                               /* get/set program parameter */
507 >        register char  *s
508 > )
509   {
474        extern int  psample;
475        extern double  maxdiff;
476        extern double  minweight;
477        extern int  maxdepth;
478        extern double  dstrsrc;
479        extern double  shadthresh;
480        extern double  shadcert;
481        extern COLOR  ambval;
482        extern double  ambacc;
483        extern int  ambres;
484        extern int  ambdiv;
485        extern int  ambssamp;
486        extern int  ambounce;
487        extern int  directvis;
488        extern double  srcsizerat;
489        extern int  do_irrad;
490        extern double  specjitter;
491        extern double  specthresh;
510          char  buf[128];
511          
512          if (s[0] == '\0') {
513                  (*dev->comout)(
514 <                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
514 >                "aa ab ad ar as av aw b dc dv dj ds dt i lr lw me ma mg ms ps pt sj st bv: ");
515                  (*dev->comin)(buf, NULL);
516                  s = buf;
517          }
# Line 501 | Line 519 | register char  *s;
519          case 'l':                       /* limit */
520                  switch (s[1]) {
521                  case 'w':                       /* weight */
522 <                        getparam(s+2, "limit weight", 'r', &minweight);
522 >                        getparam(s+2, "limit weight", 'r',
523 >                                        (void *)&minweight);
524                          break;
525                  case 'r':                       /* reflection */
526 <                        getparam(s+2, "limit reflection", 'i', &maxdepth);
526 >                        getparam(s+2, "limit reflection", 'i',
527 >                                        (void *)&maxdepth);
528                          break;
529                  default:
530                          goto badparam;
# Line 513 | Line 533 | register char  *s;
533          case 'd':                       /* direct */
534                  switch (s[1]) {
535                  case 'j':                       /* jitter */
536 <                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
536 >                        getparam(s+2, "direct jitter", 'r',
537 >                                        (void *)&dstrsrc);
538                          break;
539                  case 'c':                       /* certainty */
540 <                        getparam(s+2, "direct certainty", 'r', &shadcert);
540 >                        getparam(s+2, "direct certainty", 'r',
541 >                                        (void *)&shadcert);
542                          break;
543                  case 't':                       /* threshold */
544 <                        getparam(s+2, "direct threshold", 'r', &shadthresh);
544 >                        getparam(s+2, "direct threshold", 'r',
545 >                                        (void *)&shadthresh);
546                          break;
547                  case 'v':                       /* visibility */
548 <                        getparam(s+2, "direct visibility",
549 <                                        'b', &directvis);
548 >                        getparam(s+2, "direct visibility", 'b',
549 >                                        (void *)&directvis);
550                          break;
551                  case 's':                       /* sampling */
552 <                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
552 >                        getparam(s+2, "direct sampling", 'r',
553 >                                        (void *)&srcsizerat);
554                          break;
555                  default:
556                          goto badparam;
557                  }
558                  break;
559 <        case 'b':                       /* black and white */
560 <                getparam(s+1, "black and white", 'b', &greyscale);
559 >        case 'b':                       /* back faces or black and white */
560 >                switch (s[1]) {
561 >                case 'v':                       /* back face visibility */
562 >                        getparam(s+2, "back face visibility", 'b',
563 >                                        (void *)&backvis);
564 >                        break;
565 >                case '\0':                      /* black and white */
566 >                case ' ':
567 >                case 'y': case 'Y': case 't': case 'T': case '1': case '+':
568 >                case 'n': case 'N': case 'f': case 'F': case '0': case '-':
569 >                        getparam(s+1, "black and white", 'b',
570 >                                        (void *)&greyscale);
571 >                        break;
572 >                default:
573 >                        goto badparam;
574 >                }
575                  break;
576          case 'i':                       /* irradiance */
577 <                getparam(s+1, "irradiance", 'b', &do_irrad);
577 >                getparam(s+1, "irradiance", 'b',
578 >                                (void *)&do_irrad);
579                  break;
580          case 'a':                       /* ambient */
581                  switch (s[1]) {
582                  case 'v':                       /* value */
583 <                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
583 >                        getparam(s+2, "ambient value", 'C',
584 >                                        (void *)ambval);
585                          break;
586 +                case 'w':                       /* weight */
587 +                        getparam(s+2, "ambient value weight", 'i',
588 +                                        (void *)&ambvwt);
589 +                        break;
590                  case 'a':                       /* accuracy */
591 <                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
591 >                        if (getparam(s+2, "ambient accuracy", 'r',
592 >                                        (void *)&ambacc))
593                                  setambacc(ambacc);
594                          break;
595                  case 'd':                       /* divisions */
596 <                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
596 >                        getparam(s+2, "ambient divisions", 'i',
597 >                                        (void *)&ambdiv);
598                          break;
599                  case 's':                       /* samples */
600 <                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
600 >                        getparam(s+2, "ambient super-samples", 'i',
601 >                                        (void *)&ambssamp);
602                          break;
603                  case 'b':                       /* bounces */
604 <                        getparam(s+2, "ambient bounces", 'i', &ambounce);
604 >                        getparam(s+2, "ambient bounces", 'i',
605 >                                        (void *)&ambounce);
606                          break;
607                  case 'r':
608 <                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
608 >                        if (getparam(s+2, "ambient resolution", 'i',
609 >                                        (void *)&ambres))
610                                  setambres(ambres);
611                          break;
612                  default:
613                          goto badparam;
614                  }
615                  break;
616 +        case 'm':                       /* medium */
617 +                switch (s[1]) {
618 +                case 'e':                       /* extinction coefficient */
619 +                        getparam(s+2, "extinction coefficient", 'C',
620 +                                        (void *)cextinction);
621 +                        break;
622 +                case 'a':                       /* scattering albedo */
623 +                        getparam(s+2, "scattering albedo", 'C',
624 +                                        (void *)salbedo);
625 +                        break;
626 +                case 'g':                       /* scattering eccentricity */
627 +                        getparam(s+2, "scattering eccentricity", 'r',
628 +                                        (void *)&seccg);
629 +                        break;
630 +                case 's':                       /* sampling distance */
631 +                        getparam(s+2, "mist sampling distance", 'r',
632 +                                        (void *)&ssampdist);
633 +                        break;
634 +                default:
635 +                        goto badparam;
636 +                }
637 +                break;
638          case 'p':                       /* pixel */
639                  switch (s[1]) {
640                  case 's':                       /* sample */
641 <                        if (getparam(s+2, "pixel sample", 'i', &psample))
641 >                        if (getparam(s+2, "pixel sample", 'i',
642 >                                        (void *)&psample))
643                                  pdepth = 0;
644                          break;
645                  case 't':                       /* threshold */
646 <                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
646 >                        if (getparam(s+2, "pixel threshold", 'r',
647 >                                        (void *)&maxdiff))
648                                  pdepth = 0;
649                          break;
650                  default:
# Line 581 | Line 654 | register char  *s;
654          case 's':                       /* specular */
655                  switch (s[1]) {
656                  case 'j':                       /* jitter */
657 <                        getparam(s+2, "specular jitter", 'r', &specjitter);
657 >                        getparam(s+2, "specular jitter", 'r',
658 >                                        (void *)&specjitter);
659                          break;
660                  case 't':                       /* threshold */
661 <                        getparam(s+2, "specular threshold", 'r', &specthresh);
661 >                        getparam(s+2, "specular threshold", 'r',
662 >                                        (void *)&specthresh);
663                          break;
664                  default:
665                          goto badparam;
# Line 602 | Line 677 | badparam:
677   }
678  
679  
680 + extern void
681   traceray(s)                             /* trace a single ray */
682   char  *s;
683   {
684          char  buf[128];
685          int  x, y;
686 +        OBJREC  *ino;
687          RAY  thisray;
688  
689 +        thisray.rmax = 0.0;
690 +
691          if (!sscanvec(s, thisray.rorg) ||
692 <                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
692 >                        !sscanvec(sskip2(s,3), thisray.rdir)) {
693  
694                  if (dev->getcur == NULL)
695                          return;
# Line 618 | Line 697 | char  *s;
697                  if ((*dev->getcur)(&x, &y) == ABORT)
698                          return;
699  
700 <                if (viewray(thisray.rorg, thisray.rdir, &ourview,
701 <                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
700 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
701 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
702                          error(COMMAND, "not on image");
703                          return;
704                  }
# Line 642 | Line 721 | char  *s;
721                                          objptr(thisray.ro->omod)->oname,
722                                  ofun[thisray.ro->otype].funame,
723                                  thisray.ro->oname);
724 +                if ((ino = objptr(thisray.robj)) != thisray.ro)
725 +                        sprintf(buf+strlen(buf), " in %s \"%s\"",
726 +                                        ofun[ino->otype].funame, ino->oname);
727                  (*dev->comout)(buf);
728                  (*dev->comin)(buf, NULL);
729                  if (thisray.rot >= FHUGE)
730                          (*dev->comout)("at infinity");
731                  else {
732 <                        sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0],
733 <                                        thisray.rop[1], thisray.rop[2]);
732 >                        sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)",
733 >                                        thisray.rop[0], thisray.rop[1],
734 >                                        thisray.rop[2], thisray.rt);
735                          (*dev->comout)(buf);
736                  }
737                  (*dev->comin)(buf, NULL);
738 <                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
738 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)",
739                                  colval(thisray.rcol,RED),
740                                  colval(thisray.rcol,GRN),
741                                  colval(thisray.rcol,BLU),
# Line 663 | Line 746 | char  *s;
746   }
747  
748  
749 + extern void
750   writepict(s)                            /* write the picture to a file */
751   char  *s;
752   {
# Line 686 | Line 770 | char  *s;
770                  error(COMMAND, errmsg);
771                  return;
772          }
773 < #ifdef MSDOS
690 <        setmode(fileno(fp), O_BINARY);
691 < #endif
773 >        SET_FILE_BINARY(fp);
774          (*dev->comout)("writing \"");
775          (*dev->comout)(fname);
776          (*dev->comout)("\"...\n");
777                                                  /* write header */
778 +        newheader("RADIANCE", fp);
779          fputs(progname, fp);
780          fprintview(&ourview, fp);
781          if (octname != NULL)
# Line 700 | Line 783 | char  *s;
783          else
784                  putc('\n', fp);
785          fprintf(fp, "SOFTWARE= %s\n", VersionID);
786 +        fputnow(fp);
787          if (exposure != 1.0)
788                  fputexpos(exposure, fp);
789          if (dev->pixaspect != 1.0)
# Line 720 | Line 804 | char  *s;
804                  if (fwritecolrs(scanline, hresolu, fp) < 0)
805                          break;
806          }
807 <        free((char *)scanline);
807 >        free((void *)scanline);
808          if (fclose(fp) < 0)
809                  error(COMMAND, "write error");
810   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines