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.54 by schorsch, Wed Jun 7 17:52:04 2006 UTC vs.
Revision 2.64 by greg, Fri Oct 18 17:04:13 2013 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  "paths.h"
18   #include  "ray.h"
19   #include  "source.h"
20   #include  "ambient.h"
# Line 36 | Line 38 | extern char  *progname;
38   extern char  *octname;
39  
40  
41 < extern void
41 > void
42   getframe(                               /* get a new frame */
43          char  *s
44   )
# Line 47 | Line 49 | getframe(                              /* get a new frame */
49   }
50  
51  
52 < extern void
52 > void
53   getrepaint(                             /* get area and repaint */
54          char  *s
55   )
# Line 56 | Line 58 | getrepaint(                            /* get area and repaint */
58  
59          if (getrect(s, &box) < 0)
60                  return;
61 <        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box);
61 >        paintrect(&ptrunk, &box);
62   }
63  
64  
65 < extern void
66 < getview(                                /* get/show view parameters */
65 > void
66 > getview(                                /* get/show/save view parameters */
67          char  *s
68   )
69   {
# Line 80 | Line 82 | getview(                               /* get/show view parameters */
82                          error(COMMAND, "bad view option(s)");
83                  return;
84          }
85 <        if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
85 >        if (nextword(buf, sizeof(buf), s) != NULL) {    /* write to a file */
86                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
87                                  (fp = fopen(fname, "a")) == NULL) {
88                          sprintf(errmsg, "cannot open \"%s\"", buf);
# Line 153 | Line 155 | getview(                               /* get/show view parameters */
155   }
156  
157  
158 < extern void
158 > void
159   lastview(                               /* return to a previous view */
160          char  *s
161   )
# Line 162 | Line 164 | lastview(                              /* return to a previous view */
164          char  *fname;
165          int  success;
166          VIEW  nv;
167 <
168 <        if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
167 >                                        /* get parameters from a file */
168 >        if (nextword(buf, sizeof(buf), s) != NULL) {
169                  nv = stdview;
170                  if ((fname = getpath(buf, "", R_OK)) == NULL ||
171                                  (success = viewfile(fname, &nv, NULL)) == -1) {
# Line 184 | Line 186 | lastview(                              /* return to a previous view */
186          nv = ourview;
187          ourview = oldview;
188          oldview = nv;
189 <        newimage();
189 >        newimage(NULL);
190   }
191  
192  
193 < extern void
193 > void
194   saveview(                               /* save view to rad file */
195          char  *s
196   )
# Line 204 | Line 206 | saveview(                              /* save view to rad file */
206                  }
207                  s = sskip(s);
208          }
209 <        while (isspace(*s))
208 <                s++;
209 <        if (*s)
210 <                atos(rifname, sizeof(rifname), s);
211 <        else if (rifname[0] == '\0') {
209 >        if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
210                  error(COMMAND, "no previous rad file");
211                  return;
212          }
# Line 226 | Line 224 | saveview(                              /* save view to rad file */
224   }
225  
226  
227 < extern void
227 > void
228   loadview(                               /* load view from rad file */
229          char  *s
230   )
# Line 241 | Line 239 | loadview(                              /* load view from rad file */
239                  s = sskip(s);
240          else
241                  strcat(buf, "1");
242 <        if (*s)
245 <                atos(rifname, sizeof(rifname), s);
246 <        else if (rifname[0] == '\0') {
242 >        if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
243                  error(COMMAND, "no previous rad file");
244                  return;
245          }
# Line 269 | Line 265 | loadview(                              /* load view from rad file */
265   }
266  
267  
268 < extern void
268 > void
269   getaim(                         /* aim camera */
270          char  *s
271   )
# Line 284 | Line 280 | getaim(                                /* aim camera */
280   }
281  
282  
283 < extern void
283 > void
284   getfocus(                               /* set focus distance */
285          char *s
286   )
# Line 321 | Line 317 | getfocus(                              /* set focus distance */
317   }
318  
319  
320 < extern void
320 > void
321   getmove(                                /* move camera */
322          char  *s
323   )
# Line 335 | Line 331 | getmove(                               /* move camera */
331   }
332  
333  
334 < extern void
334 > void
335   getrotate(                              /* rotate camera */
336          char  *s
337   )
338   {
339          VIEW  nv = ourview;
344        FVECT  v1;
340          double  angle, elev, zfact;
341          
342          elev = 0.0; zfact = 1.0;
# Line 350 | Line 345 | getrotate(                             /* rotate camera */
345                  return;
346          }
347          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
348 <        if (elev != 0.0) {
349 <                fcross(v1, nv.vdir, ourview.vup);
350 <                normalize(v1);
356 <                spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
357 <        }
348 >        if (elev != 0.0)
349 >                geodesic(nv.vdir, nv.vdir, nv.vup, elev*(PI/180.), GEOD_RAD);
350 >        
351          zoomview(&nv, zfact);
352          newview(&nv);
353   }
354  
355  
356 < extern void
356 > void
357   getpivot(                               /* pivot viewpoint */
358 <        register char  *s
358 >        char  *s
359   )
360   {
361          FVECT  vc;
# Line 379 | Line 372 | getpivot(                              /* pivot viewpoint */
372   }
373  
374  
375 < extern void
375 > void
376 > getorigin(                              /* origin viewpoint */
377 >        char  *s
378 > )
379 > {
380 >        VIEW    nv = ourview;
381 >        double  d;
382 >                                        /* get new view origin */
383 >        if (!sscanvec(s, nv.vp)) {
384 >                int     x, y;
385 >                RAY     thisray;
386 >                if (dev->getcur == NULL)
387 >                        return;
388 >                (*dev->comout)("Pick point on surface for new origin\n");
389 >                if ((*dev->getcur)(&x, &y) == ABORT)
390 >                        return;
391 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
392 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
393 >                        error(COMMAND, "not on image");
394 >                        return;
395 >                }
396 >                rayorigin(&thisray, PRIMARY, NULL, NULL);
397 >                if (!localhit(&thisray, &thescene)) {
398 >                        error(COMMAND, "not a local object");
399 >                        return;
400 >                }
401 >                if (thisray.rod < 0.0)  /* don't look through other side */
402 >                        flipsurface(&thisray);
403 >                VSUM(nv.vp, thisray.rop, thisray.ron, 2.0*FTINY);
404 >                VCOPY(nv.vdir, thisray.ron);
405 >        } else if (!sscanvec(sskip2(s,3), nv.vdir) || normalize(nv.vdir) == 0.0)
406 >                VCOPY(nv.vdir, ourview.vdir);
407 >
408 >        d = DOT(nv.vdir, nv.vup);       /* need different up vector? */
409 >        if (d*d >= 1.-2.*FTINY) {
410 >                int     i;
411 >                nv.vup[0] = nv.vup[1] = nv.vup[2] = 0.0;
412 >                for (i = 3; i--; )
413 >                        if (nv.vdir[i]*nv.vdir[i] < 0.34)
414 >                                break;
415 >                nv.vup[i] = 1.;
416 >        }
417 >        newview(&nv);
418 > }
419 >
420 >
421 > void
422   getexposure(                            /* get new exposure */
423          char  *s
424   )
425   {
426          char  buf[128];
427 <        register char  *cp;
389 <        RECT  r;
427 >        char  *cp;
428          int  x, y;
429 <        register PNODE  *p = &ptrunk;
429 >        PNODE  *p = &ptrunk;
430          int  adapt = 0;
431          double  e = 1.0;
432  
# Line 405 | Line 443 | getexposure(                           /* get new exposure */
443                  (*dev->comout)("Pick point for exposure\n");
444                  if ((*dev->getcur)(&x, &y) == ABORT)
445                          return;
446 <                r.l = r.d = 0;
409 <                r.r = hresolu; r.u = vresolu;
410 <                p = findrect(x, y, &ptrunk, &r, -1);
446 >                p = findrect(x, y, &ptrunk, -1);
447          } else {
448                  if (*cp == '=') {       /* absolute setting */
449                          p = NULL;
# Line 430 | Line 466 | getexposure(                           /* get new exposure */
466                          e *= atof(cp);
467          }
468          if (p != NULL) {                /* relative setting */
469 +                compavg(p);
470                  if (bright(p->v) < 1e-15) {
471                          error(COMMAND, "cannot normalize to zero");
472                          return;
# Line 447 | Line 484 | getexposure(                           /* get new exposure */
484   }
485  
486   typedef union {int i; double d; COLOR C;}       *MyUptr;
487 + #define  FEQ(x,y)     (fabs((x)-(y)) <= FTINY)
488  
489 < extern int
489 > int
490   getparam(               /* get variable from user */
491          char  *str,
492          char  *dsc,
# Line 456 | Line 494 | getparam(              /* get variable from user */
494          void  *p
495   )
496   {
497 <        register MyUptr  ptr = (MyUptr)p;
497 >        MyUptr  ptr = (MyUptr)p;
498          int  i0;
499          double  d0, d1, d2;
500          char  buf[48];
# Line 471 | Line 509 | getparam(              /* get variable from user */
509                          if (sscanf(buf, "%d", &i0) != 1)
510                                  return(0);
511                  }
512 +                if (ptr->i == i0)
513 +                        return(0);
514                  ptr->i = i0;
515 <                return(1);
515 >                break;
516          case 'r':                       /* real */
517                  if (sscanf(str, "%lf", &d0) != 1) {
518                          (*dev->comout)(dsc);
# Line 482 | Line 522 | getparam(              /* get variable from user */
522                          if (sscanf(buf, "%lf", &d0) != 1)
523                                  return(0);
524                  }
525 +                if (FEQ(ptr->d, d0))
526 +                        return(0);
527                  ptr->d = d0;
528 <                return(1);
528 >                break;
529          case 'b':                       /* boolean */
530                  if (sscanf(str, "%1s", buf) != 1) {
531                          (*dev->comout)(dsc);
532                          sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
533                          (*dev->comout)(buf);
534                          (*dev->comin)(buf, NULL);
535 <                        if (buf[0] == '\0' ||
494 <                                        strchr("yY+1tTnN-0fF", buf[0]) == NULL)
535 >                        if (buf[0] == '\0')
536                                  return(0);
537                  }
538 <                ptr->i = strchr("yY+1tT", buf[0]) != NULL;
539 <                return(1);
538 >                if (strchr("yY+1tTnN-0fF", buf[0]) == NULL)
539 >                        return(0);
540 >                i0 = strchr("yY+1tT", buf[0]) != NULL;
541 >                if (ptr->i == i0)
542 >                        return(0);
543 >                ptr->i = i0;
544 >                break;
545          case 'C':                       /* color */
546                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
547                          (*dev->comout)(dsc);
# Line 508 | Line 554 | getparam(              /* get variable from user */
554                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
555                                  return(0);
556                  }
557 +                if (FEQ(colval(ptr->C,RED), d0) &&
558 +                                FEQ(colval(ptr->C,GRN), d1) &&
559 +                                FEQ(colval(ptr->C,BLU), d2))
560 +                        return(0);
561                  setcolor(ptr->C, d0, d1, d2);
562 <                return(1);
562 >                break;
563 >        default:
564 >                return(0);              /* shouldn't happen */
565          }
566 <        return 0; /* nothing matched */
566 >        newparam++;
567 >        return(1);
568   }
569  
570  
571 < extern void
571 > void
572   setparam(                               /* get/set program parameter */
573 <        register char  *s
573 >        char  *s
574   )
575   {
576 +        int  prev_newp = newparam;
577          char  buf[128];
578          
579          if (s[0] == '\0') {
580                  (*dev->comout)(
581 <                "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: ");
581 >                "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: ");
582                  (*dev->comin)(buf, NULL);
583                  s = buf;
584          }
# Line 585 | Line 639 | setparam(                              /* get/set program parameter */
639                  case 'n': case 'N': case 'f': case 'F': case '0': case '-':
640                          getparam(s+1, "black and white", 'b',
641                                          (void *)&greyscale);
642 +                        newparam = prev_newp;
643                          break;
644                  default:
645                          goto badparam;
# Line 667 | Line 722 | setparam(                              /* get/set program parameter */
722                  default:
723                          goto badparam;
724                  }
725 +                newparam = prev_newp;
726                  break;
727          case 's':                       /* specular */
728                  switch (s[1]) {
729 <                case 'j':                       /* jitter */
730 <                        getparam(s+2, "specular jitter", 'r',
729 >                case 's':                       /* sampling */
730 >                        getparam(s+2, "specular sampling", 'r',
731                                          (void *)&specjitter);
732                          break;
733                  case 't':                       /* threshold */
# Line 694 | Line 750 | badparam:
750   }
751  
752  
753 < extern void
754 < traceray(s)                             /* trace a single ray */
755 < char  *s;
753 > void
754 > traceray(                               /* trace a single ray */
755 >        char  *s
756 > )
757   {
758 <        char  buf[128];
759 <        int  x, y;
703 <        OBJREC  *ino;
704 <        RAY  thisray;
758 >        RAY     thisray;
759 >        char    buf[512];
760  
761          thisray.rmax = 0.0;
762  
763          if (!sscanvec(s, thisray.rorg) ||
764                          !sscanvec(sskip2(s,3), thisray.rdir)) {
765 +                int  x, y;
766  
767                  if (dev->getcur == NULL)
768                          return;
# Line 725 | Line 781 | char  *s;
781                  return;
782          }
783  
784 <        rayorigin(&thisray, PRIMARY, NULL, NULL);
729 <        
730 <        rayvalue(&thisray);
784 >        ray_trace(&thisray);
785  
786          if (thisray.ro == NULL)
787                  (*dev->comout)("ray hit nothing");
# Line 735 | Line 789 | char  *s;
789                  OBJREC  *mat = NULL;
790                  OBJREC  *mod = NULL;
791                  char    matspec[256];
792 +                OBJREC  *ino;
793 +
794                  matspec[0] = '\0';
795                  if (thisray.ro->omod != OVOID) {
796                          mod = objptr(thisray.ro->omod);
# Line 777 | Line 833 | char  *s;
833   }
834  
835  
836 < extern void
837 < writepict(s)                            /* write the picture to a file */
838 < char  *s;
836 > void
837 > writepict(                              /* write the picture to a file */
838 >        char  *s
839 > )
840   {
841          static char  buf[128];
842          char  *fname;
843          FILE  *fp;
844          COLR  *scanline;
845          int  y;
846 <
847 <        while (isspace(*s))
791 <                s++;
792 <        if (*s)
793 <                atos(buf, sizeof(buf), s);
794 <        else if (buf[0] == '\0') {
846 >                                /* XXX relies on words.c 2.11 behavior */
847 >        if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) {
848                  error(COMMAND, "no file");
849                  return;
850          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines