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.55 by greg, Thu Aug 21 07:05:59 2008 UTC vs.
Revision 2.80 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
13   #include  <string.h>
14  
15   #include  "platform.h"
16 + #include  "rtprocess.h" /* win_popen() */
17   #include  "ray.h"
17 #include  "source.h"
18   #include  "ambient.h"
19   #include  "otypes.h"
20 + #include  "otspecial.h"
21   #include  "rpaint.h"
22  
23   extern int  psample;                    /* pixel sample size */
# Line 24 | Line 25 | extern double  maxdiff;                        /* max. sample difference */
25  
26   #define  CTRL(c)        ((c)-'@')
27  
28 < #ifdef  SMLFLT
28 < #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
29 < #else
30 < #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
31 < #endif
28 > #define  sscanvec(s,v)  (sscanf(s,FVFORMAT,v,v+1,v+2)==3)
29  
30   extern char  rifname[128];              /* rad input file name */
31  
# Line 61 | Line 58 | getrepaint(                            /* get area and repaint */
58  
59  
60   void
61 < getview(                                /* get/show view parameters */
61 > getview(                                /* get/show/save view parameters */
62          char  *s
63   )
64   {
# Line 80 | Line 77 | getview(                               /* get/show view parameters */
77                          error(COMMAND, "bad view option(s)");
78                  return;
79          }
80 <        if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
80 >        if (nextword(buf, sizeof(buf), s) != NULL) {    /* write to a file */
81                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
82                                  (fp = fopen(fname, "a")) == NULL) {
83                          sprintf(errmsg, "cannot open \"%s\"", buf);
# Line 162 | Line 159 | lastview(                              /* return to a previous view */
159          char  *fname;
160          int  success;
161          VIEW  nv;
162 <
163 <        if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
162 >                                        /* get parameters from a file */
163 >        if (nextword(buf, sizeof(buf), s) != NULL) {
164                  nv = stdview;
165                  if ((fname = getpath(buf, "", R_OK)) == NULL ||
166                                  (success = viewfile(fname, &nv, NULL)) == -1) {
# Line 204 | Line 201 | saveview(                              /* save view to rad file */
201                  }
202                  s = sskip(s);
203          }
204 <        while (isspace(*s))
208 <                s++;
209 <        if (*s)
210 <                atos(rifname, sizeof(rifname), s);
211 <        else if (rifname[0] == '\0') {
204 >        if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
205                  error(COMMAND, "no previous rad file");
206                  return;
207          }
# Line 241 | Line 234 | loadview(                              /* load view from rad file */
234                  s = sskip(s);
235          else
236                  strcat(buf, "1");
237 <        if (*s)
245 <                atos(rifname, sizeof(rifname), s);
246 <        else if (rifname[0] == '\0') {
237 >        if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
238                  error(COMMAND, "no previous rad file");
239                  return;
240          }
# Line 341 | Line 332 | getrotate(                             /* rotate camera */
332   )
333   {
334          VIEW  nv = ourview;
344        FVECT  v1;
335          double  angle, elev, zfact;
336          
337          elev = 0.0; zfact = 1.0;
# Line 350 | Line 340 | getrotate(                             /* rotate camera */
340                  return;
341          }
342          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
343 <        if (elev != 0.0) {
344 <                fcross(v1, nv.vdir, ourview.vup);
345 <                normalize(v1);
356 <                spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
357 <        }
343 >        if (elev != 0.0)
344 >                geodesic(nv.vdir, nv.vdir, nv.vup, elev*(PI/180.), GEOD_RAD);
345 >        
346          zoomview(&nv, zfact);
347          newview(&nv);
348   }
# Line 380 | Line 368 | getpivot(                              /* pivot viewpoint */
368  
369  
370   void
371 + getorigin(                              /* origin viewpoint */
372 +        char  *s
373 + )
374 + {
375 +        VIEW    nv = ourview;
376 +        FVECT   voff;
377 +        int     i;
378 +        double  d;
379 +                                        /* check for view origin shift */
380 +        if (sscanf(s, "%lf", &d) == 1) {
381 +                double  d_fore=d, d_right=0, d_up=0;
382 +                sscanf(s, "%*f %lf %lf", &d_right, &d_up);
383 +                d_right /= sqrt(nv.hn2);
384 +                for (i = 3; i--; )
385 +                        nv.vp[i] += d_fore*nv.vdir[i] +
386 +                                        d_right*nv.hvec[i] +
387 +                                        d_up*nv.vup[i];
388 +        } else {                        /* else pick new origin */
389 +                int     x, y;
390 +                RAY     thisray;
391 +                if (dev->getcur == NULL)
392 +                        return;
393 +                (*dev->comout)("Pick point on surface for new origin\n");
394 +                if ((*dev->getcur)(&x, &y) == ABORT)
395 +                        return;
396 +                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
397 +                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
398 +                        error(COMMAND, "not on image");
399 +                        return;
400 +                }
401 +                rayorigin(&thisray, PRIMARY, NULL, NULL);
402 +                if (!localhit(&thisray, &thescene)) {
403 +                        error(COMMAND, "not a local object");
404 +                        return;
405 +                }
406 +                if (thisray.rod < 0.0)  /* don't look through other side */
407 +                        flipsurface(&thisray);
408 +                VSUM(nv.vp, thisray.rop, thisray.ron, 20.0*FTINY);
409 +                VCOPY(nv.vdir, thisray.ron);
410 +                d = DOT(nv.vdir, nv.vup);
411 +                if (d*d >= 1.-2.*FTINY) {
412 +                                        /* need different up vector */
413 +                        nv.vup[0] = nv.vup[1] = nv.vup[2] = 0.0;
414 +                        for (i = 3; i--; )
415 +                                if (nv.vdir[i]*nv.vdir[i] < 0.34)
416 +                                        break;
417 +                        nv.vup[i] = 1.;
418 +                }
419 +        }
420 +        newview(&nv);
421 + }
422 +
423 +
424 + void
425   getexposure(                            /* get new exposure */
426          char  *s
427   )
# Line 421 | Line 463 | getexposure(                           /* get new exposure */
463                                          return;
464                          }
465                  }
466 <                if (*cp == '+' || *cp == '-')   /* f-stops */
466 >                if ((*cp == '+') | (*cp == '-'))        /* f-stops */
467                          e *= pow(2.0, atof(cp));
468                  else                            /* multiplier */
469                          e *= atof(cp);
470          }
471          if (p != NULL) {                /* relative setting */
472 +                compavg(p);
473                  if (bright(p->v) < 1e-15) {
474                          error(COMMAND, "cannot normalize to zero");
475                          return;
# Line 468 | Line 511 | getparam(              /* get variable from user */
511                          if (sscanf(buf, "%d", &i0) != 1)
512                                  return(0);
513                  }
514 +                if (ptr->i == i0)
515 +                        return(0);
516                  ptr->i = i0;
517                  break;
518          case 'r':                       /* real */
# Line 479 | Line 524 | getparam(              /* get variable from user */
524                          if (sscanf(buf, "%lf", &d0) != 1)
525                                  return(0);
526                  }
527 +                if (FRELEQ(ptr->d, d0))
528 +                        return(0);
529                  ptr->d = d0;
530                  break;
531          case 'b':                       /* boolean */
# Line 487 | Line 534 | getparam(              /* get variable from user */
534                          sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
535                          (*dev->comout)(buf);
536                          (*dev->comin)(buf, NULL);
537 <                        if (buf[0] == '\0' ||
491 <                                        strchr("yY+1tTnN-0fF", buf[0]) == NULL)
537 >                        if (buf[0] == '\0')
538                                  return(0);
539                  }
540 <                ptr->i = strchr("yY+1tT", buf[0]) != NULL;
540 >                if (strchr("yY+1tTnN-0fF", buf[0]) == NULL)
541 >                        return(0);
542 >                i0 = strchr("yY+1tT", buf[0]) != NULL;
543 >                if (ptr->i == i0)
544 >                        return(0);
545 >                ptr->i = i0;
546                  break;
547          case 'C':                       /* color */
548                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
# Line 505 | Line 556 | getparam(              /* get variable from user */
556                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
557                                  return(0);
558                  }
559 +                if (FRELEQ(colval(ptr->C,RED), d0) &&
560 +                                FRELEQ(colval(ptr->C,GRN), d1) &&
561 +                                FRELEQ(colval(ptr->C,BLU), d2))
562 +                        return(0);
563                  setcolor(ptr->C, d0, d1, d2);
564                  break;
565          default:
# Line 520 | Line 575 | setparam(                              /* get/set program parameter */
575          char  *s
576   )
577   {
578 +        int  prev_newp = newparam;
579          char  buf[128];
580          
581          if (s[0] == '\0') {
582                  (*dev->comout)(
583 <                "aa ab ad ar as av aw b bv dc dv dj ds dt i lr lw me ma mg ms ps pt sj st u: ");
583 >                "aa ab ad ar as av aw b bv dc dv dj ds dt i lr lw me ma mg ms ps pt ss st u: ");
584                  (*dev->comin)(buf, NULL);
585                  s = buf;
586          }
# Line 536 | Line 592 | setparam(                              /* get/set program parameter */
592          case 'l':                       /* limit */
593                  switch (s[1]) {
594                  case 'w':                       /* weight */
595 <                        getparam(s+2, "limit weight", 'r',
540 <                                        (void *)&minweight);
595 >                        getparam(s+2, "limit weight", 'r', &minweight);
596                          break;
597                  case 'r':                       /* reflection */
598 <                        getparam(s+2, "limit reflection", 'i',
544 <                                        (void *)&maxdepth);
598 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
599                          break;
600                  default:
601                          goto badparam;
# Line 550 | Line 604 | setparam(                              /* get/set program parameter */
604          case 'd':                       /* direct */
605                  switch (s[1]) {
606                  case 'j':                       /* jitter */
607 <                        getparam(s+2, "direct jitter", 'r',
554 <                                        (void *)&dstrsrc);
607 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
608                          break;
609                  case 'c':                       /* certainty */
610 <                        getparam(s+2, "direct certainty", 'r',
558 <                                        (void *)&shadcert);
610 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
611                          break;
612                  case 't':                       /* threshold */
613 <                        getparam(s+2, "direct threshold", 'r',
562 <                                        (void *)&shadthresh);
613 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
614                          break;
615                  case 'v':                       /* visibility */
616 <                        getparam(s+2, "direct visibility", 'b',
566 <                                        (void *)&directvis);
616 >                        getparam(s+2, "direct visibility", 'b', &directvis);
617                          break;
618                  case 's':                       /* sampling */
619 <                        getparam(s+2, "direct sampling", 'r',
570 <                                        (void *)&srcsizerat);
619 >                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
620                          break;
621                  default:
622                          goto badparam;
# Line 583 | Line 632 | setparam(                              /* get/set program parameter */
632                  case ' ':
633                  case 'y': case 'Y': case 't': case 'T': case '1': case '+':
634                  case 'n': case 'N': case 'f': case 'F': case '0': case '-':
635 <                        getparam(s+1, "black and white", 'b',
636 <                                        (void *)&greyscale);
635 >                        getparam(s+1, "black and white", 'b', &greyscale);
636 >                        newparam = prev_newp;
637                          break;
638                  default:
639                          goto badparam;
640                  }
641                  break;
642          case 'i':                       /* irradiance */
643 <                getparam(s+1, "irradiance", 'b',
595 <                                (void *)&do_irrad);
643 >                getparam(s+1, "irradiance", 'b', &do_irrad);
644                  break;
645          case 'a':                       /* ambient */
646                  switch (s[1]) {
647                  case 'v':                       /* value */
648 <                        getparam(s+2, "ambient value", 'C',
601 <                                        (void *)ambval);
648 >                        getparam(s+2, "ambient value", 'C', ambval);
649                          break;
650                  case 'w':                       /* weight */
651 <                        getparam(s+2, "ambient value weight", 'i',
605 <                                        (void *)&ambvwt);
651 >                        getparam(s+2, "ambient value weight", 'i', &ambvwt);
652                          break;
653                  case 'a':                       /* accuracy */
654 <                        if (getparam(s+2, "ambient accuracy", 'r',
609 <                                        (void *)&ambacc))
654 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
655                                  setambacc(ambacc);
656                          break;
657                  case 'd':                       /* divisions */
658 <                        getparam(s+2, "ambient divisions", 'i',
614 <                                        (void *)&ambdiv);
658 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
659                          break;
660                  case 's':                       /* samples */
661 <                        getparam(s+2, "ambient super-samples", 'i',
618 <                                        (void *)&ambssamp);
661 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
662                          break;
663                  case 'b':                       /* bounces */
664 <                        getparam(s+2, "ambient bounces", 'i',
622 <                                        (void *)&ambounce);
664 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
665                          break;
666                  case 'r':
667 <                        if (getparam(s+2, "ambient resolution", 'i',
626 <                                        (void *)&ambres))
667 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
668                                  setambres(ambres);
669                          break;
670                  default:
# Line 633 | Line 674 | setparam(                              /* get/set program parameter */
674          case 'm':                       /* medium */
675                  switch (s[1]) {
676                  case 'e':                       /* extinction coefficient */
677 <                        getparam(s+2, "extinction coefficient", 'C',
637 <                                        (void *)cextinction);
677 >                        getparam(s+2, "extinction coefficient", 'C', cextinction);
678                          break;
679                  case 'a':                       /* scattering albedo */
680 <                        getparam(s+2, "scattering albedo", 'C',
641 <                                        (void *)salbedo);
680 >                        getparam(s+2, "scattering albedo", 'C', salbedo);
681                          break;
682                  case 'g':                       /* scattering eccentricity */
683 <                        getparam(s+2, "scattering eccentricity", 'r',
645 <                                        (void *)&seccg);
683 >                        getparam(s+2, "scattering eccentricity", 'r', &seccg);
684                          break;
685                  case 's':                       /* sampling distance */
686 <                        getparam(s+2, "mist sampling distance", 'r',
649 <                                        (void *)&ssampdist);
686 >                        getparam(s+2, "mist sampling distance", 'r', &ssampdist);
687                          break;
688                  default:
689                          goto badparam;
# Line 655 | Line 692 | setparam(                              /* get/set program parameter */
692          case 'p':                       /* pixel */
693                  switch (s[1]) {
694                  case 's':                       /* sample */
695 <                        if (getparam(s+2, "pixel sample", 'i',
659 <                                        (void *)&psample))
695 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
696                                  pdepth = 0;
697                          break;
698                  case 't':                       /* threshold */
699 <                        if (getparam(s+2, "pixel threshold", 'r',
664 <                                        (void *)&maxdiff))
699 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
700                                  pdepth = 0;
701                          break;
702                  default:
703                          goto badparam;
704                  }
705 +                newparam = prev_newp;
706                  break;
707          case 's':                       /* specular */
708                  switch (s[1]) {
709 <                case 'j':                       /* jitter */
710 <                        getparam(s+2, "specular jitter", 'r',
675 <                                        (void *)&specjitter);
709 >                case 's':                       /* sampling */
710 >                        getparam(s+2, "specular sampling", 'r', &specjitter);
711                          break;
712                  case 't':                       /* threshold */
713 <                        getparam(s+2, "specular threshold", 'r',
679 <                                        (void *)&specthresh);
713 >                        getparam(s+2, "specular threshold", 'r', &specthresh);
714                          break;
715                  default:
716                          goto badparam;
# Line 699 | Line 733 | traceray(                              /* trace a single ray */
733          char  *s
734   )
735   {
736 <        char  buf[128];
737 <        int  x, y;
738 <        OBJREC  *ino;
705 <        RAY  thisray;
736 >        RAY     thisray;
737 >        char    buf[512];
738 >        COLOR   col;
739  
740          thisray.rmax = 0.0;
741  
742          if (!sscanvec(s, thisray.rorg) ||
743                          !sscanvec(sskip2(s,3), thisray.rdir)) {
744 +                int  x, y;
745  
746                  if (dev->getcur == NULL)
747                          return;
# Line 726 | Line 760 | traceray(                              /* trace a single ray */
760                  return;
761          }
762  
763 <        rayorigin(&thisray, PRIMARY, NULL, NULL);
730 <        
731 <        rayvalue(&thisray);
763 >        ray_trace(&thisray);
764  
765          if (thisray.ro == NULL)
766                  (*dev->comout)("ray hit nothing");
# Line 736 | Line 768 | traceray(                              /* trace a single ray */
768                  OBJREC  *mat = NULL;
769                  OBJREC  *mod = NULL;
770                  char    matspec[256];
771 +                OBJREC  *ino;
772 +
773                  matspec[0] = '\0';
774                  if (thisray.ro->omod != OVOID) {
775                          mod = objptr(thisray.ro->omod);
776 <                        mat = findmaterial(mod);
776 >                        mat = findmaterial(thisray.ro);
777                  }
778                  if (thisray.rod < 0.0)
779                          strcpy(matspec, "back of ");
# Line 758 | Line 792 | traceray(                              /* trace a single ray */
792                                          ofun[ino->otype].funame, ino->oname);
793                  (*dev->comout)(buf);
794                  (*dev->comin)(buf, NULL);
795 <                if (thisray.rot >= FHUGE)
795 >                if (thisray.rot >= FHUGE*.99)
796                          (*dev->comout)("at infinity");
797                  else {
798 <                        sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)",
798 >                        sprintf(buf, "at (%.3f %.3f %.3f) (%.6g)",
799                                          thisray.rop[0], thisray.rop[1],
800 <                                        thisray.rop[2], thisray.rt);
800 >                                        thisray.rop[2], raydistance(&thisray));
801                          (*dev->comout)(buf);
802                  }
803                  (*dev->comin)(buf, NULL);
804 <                sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)",
805 <                                colval(thisray.rcol,RED),
806 <                                colval(thisray.rcol,GRN),
807 <                                colval(thisray.rcol,BLU),
808 <                                luminance(thisray.rcol));
804 >                scolor_rgb(col, thisray.rcol);
805 >                sprintf(buf, "value (%.4g %.4g %.4g) (%.3gL)",
806 >                                colval(col,RED),
807 >                                colval(col,GRN),
808 >                                colval(col,BLU),
809 >                                luminance(col));
810                  (*dev->comout)(buf);
811          }
812          (*dev->comin)(buf, NULL);
# Line 788 | Line 823 | writepict(                             /* write the picture to a file */
823          FILE  *fp;
824          COLR  *scanline;
825          int  y;
826 <
827 <        while (isspace(*s))
793 <                s++;
794 <        if (*s)
795 <                atos(buf, sizeof(buf), s);
796 <        else if (buf[0] == '\0') {
826 >                                /* XXX relies on words.c 2.11 behavior */
827 >        if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) {
828                  error(COMMAND, "no file");
829                  return;
830          }
# Line 821 | Line 852 | writepict(                             /* write the picture to a file */
852                  fputexpos(exposure, fp);
853          if (dev->pixaspect != 1.0)
854                  fputaspect(dev->pixaspect, fp);
855 +        fputprims(stdprims, fp);
856          fputformat(COLRFMT, fp);
857          putc('\n', fp);
858          fprtresolu(hresolu, vresolu, fp);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines