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.51 by greg, Tue Jun 14 03:34:14 2005 UTC vs.
Revision 2.62 by greg, Wed Oct 5 17:20:55 2011 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   )
287   {
288 <        FVECT  vc;
288 >        char  buf[64];
289          double  dist;
290  
291          if (sscanf(s, "%lf", &dist) < 1) {
# Line 316 | Line 312 | getfocus(                              /* set focus distance */
312                  return;
313          }
314          ourview.vdist = dist;
315 +        sprintf(buf, "Focus distance set to %f\n", dist);
316 +        (*dev->comout)(buf);
317   }
318  
319  
320 < extern void
320 > void
321   getmove(                                /* move camera */
322          char  *s
323   )
# Line 333 | Line 331 | getmove(                               /* move camera */
331   }
332  
333  
334 < extern void
334 > void
335   getrotate(                              /* rotate camera */
336          char  *s
337   )
# Line 358 | Line 356 | getrotate(                             /* rotate camera */
356   }
357  
358  
359 < extern void
359 > void
360   getpivot(                               /* pivot viewpoint */
361 <        register char  *s
361 >        char  *s
362   )
363   {
364          FVECT  vc;
# Line 377 | Line 375 | getpivot(                              /* pivot viewpoint */
375   }
376  
377  
378 < extern void
378 > void
379   getexposure(                            /* get new exposure */
380          char  *s
381   )
382   {
383          char  buf[128];
384 <        register char  *cp;
387 <        RECT  r;
384 >        char  *cp;
385          int  x, y;
386 <        register PNODE  *p = &ptrunk;
386 >        PNODE  *p = &ptrunk;
387          int  adapt = 0;
388          double  e = 1.0;
389  
# Line 403 | Line 400 | getexposure(                           /* get new exposure */
400                  (*dev->comout)("Pick point for exposure\n");
401                  if ((*dev->getcur)(&x, &y) == ABORT)
402                          return;
403 <                r.l = r.d = 0;
407 <                r.r = hresolu; r.u = vresolu;
408 <                p = findrect(x, y, &ptrunk, &r, -1);
403 >                p = findrect(x, y, &ptrunk, -1);
404          } else {
405                  if (*cp == '=') {       /* absolute setting */
406                          p = NULL;
# Line 428 | Line 423 | getexposure(                           /* get new exposure */
423                          e *= atof(cp);
424          }
425          if (p != NULL) {                /* relative setting */
426 +                compavg(p);
427                  if (bright(p->v) < 1e-15) {
428                          error(COMMAND, "cannot normalize to zero");
429                          return;
# Line 445 | Line 441 | getexposure(                           /* get new exposure */
441   }
442  
443   typedef union {int i; double d; COLOR C;}       *MyUptr;
444 + #define  FEQ(x,y)     (fabs((x)-(y)) <= FTINY)
445  
446 < extern int
446 > int
447   getparam(               /* get variable from user */
448          char  *str,
449          char  *dsc,
# Line 454 | Line 451 | getparam(              /* get variable from user */
451          void  *p
452   )
453   {
454 <        register MyUptr  ptr = (MyUptr)p;
454 >        MyUptr  ptr = (MyUptr)p;
455          int  i0;
456          double  d0, d1, d2;
457          char  buf[48];
# Line 469 | Line 466 | getparam(              /* get variable from user */
466                          if (sscanf(buf, "%d", &i0) != 1)
467                                  return(0);
468                  }
469 +                if (ptr->i == i0)
470 +                        return(0);
471                  ptr->i = i0;
472 <                return(1);
472 >                break;
473          case 'r':                       /* real */
474                  if (sscanf(str, "%lf", &d0) != 1) {
475                          (*dev->comout)(dsc);
# Line 480 | Line 479 | getparam(              /* get variable from user */
479                          if (sscanf(buf, "%lf", &d0) != 1)
480                                  return(0);
481                  }
482 +                if (FEQ(ptr->d, d0))
483 +                        return(0);
484                  ptr->d = d0;
485 <                return(1);
485 >                break;
486          case 'b':                       /* boolean */
487                  if (sscanf(str, "%1s", buf) != 1) {
488                          (*dev->comout)(dsc);
489                          sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
490                          (*dev->comout)(buf);
491                          (*dev->comin)(buf, NULL);
492 <                        if (buf[0] == '\0' ||
492 <                                        strchr("yY+1tTnN-0fF", buf[0]) == NULL)
492 >                        if (buf[0] == '\0')
493                                  return(0);
494                  }
495 <                ptr->i = strchr("yY+1tT", buf[0]) != NULL;
496 <                return(1);
495 >                if (strchr("yY+1tTnN-0fF", buf[0]) == NULL)
496 >                        return(0);
497 >                i0 = strchr("yY+1tT", buf[0]) != NULL;
498 >                if (ptr->i == i0)
499 >                        return(0);
500 >                ptr->i = i0;
501 >                break;
502          case 'C':                       /* color */
503                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
504                          (*dev->comout)(dsc);
# Line 506 | Line 511 | getparam(              /* get variable from user */
511                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
512                                  return(0);
513                  }
514 +                if (FEQ(colval(ptr->C,RED), d0) &&
515 +                                FEQ(colval(ptr->C,GRN), d1) &&
516 +                                FEQ(colval(ptr->C,BLU), d2))
517 +                        return(0);
518                  setcolor(ptr->C, d0, d1, d2);
519 <                return(1);
519 >                break;
520 >        default:
521 >                return(0);              /* shouldn't happen */
522          }
523 <        return 0; /* nothing matched */
523 >        newparam++;
524 >        return(1);
525   }
526  
527  
528 < extern void
528 > void
529   setparam(                               /* get/set program parameter */
530 <        register char  *s
530 >        char  *s
531   )
532   {
533 +        int  prev_newp = newparam;
534          char  buf[128];
535          
536          if (s[0] == '\0') {
537                  (*dev->comout)(
538 <                "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: ");
538 >                "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: ");
539                  (*dev->comin)(buf, NULL);
540                  s = buf;
541          }
# Line 583 | Line 596 | setparam(                              /* get/set program parameter */
596                  case 'n': case 'N': case 'f': case 'F': case '0': case '-':
597                          getparam(s+1, "black and white", 'b',
598                                          (void *)&greyscale);
599 +                        newparam = prev_newp;
600                          break;
601                  default:
602                          goto badparam;
# Line 665 | Line 679 | setparam(                              /* get/set program parameter */
679                  default:
680                          goto badparam;
681                  }
682 +                newparam = prev_newp;
683                  break;
684          case 's':                       /* specular */
685                  switch (s[1]) {
686 <                case 'j':                       /* jitter */
687 <                        getparam(s+2, "specular jitter", 'r',
686 >                case 's':                       /* sampling */
687 >                        getparam(s+2, "specular sampling", 'r',
688                                          (void *)&specjitter);
689                          break;
690                  case 't':                       /* threshold */
# Line 692 | Line 707 | badparam:
707   }
708  
709  
710 < extern void
711 < traceray(s)                             /* trace a single ray */
712 < char  *s;
710 > void
711 > traceray(                               /* trace a single ray */
712 >        char  *s
713 > )
714   {
715 <        char  buf[128];
716 <        int  x, y;
701 <        OBJREC  *ino;
702 <        RAY  thisray;
715 >        RAY     thisray;
716 >        char    buf[512];
717  
718          thisray.rmax = 0.0;
719  
720          if (!sscanvec(s, thisray.rorg) ||
721                          !sscanvec(sskip2(s,3), thisray.rdir)) {
722 +                int  x, y;
723  
724                  if (dev->getcur == NULL)
725                          return;
# Line 723 | Line 738 | char  *s;
738                  return;
739          }
740  
741 <        rayorigin(&thisray, PRIMARY, NULL, NULL);
727 <        
728 <        rayvalue(&thisray);
741 >        ray_trace(&thisray);
742  
743          if (thisray.ro == NULL)
744                  (*dev->comout)("ray hit nothing");
745          else {
746                  OBJREC  *mat = NULL;
747 <                OBJREC  *mod = NULL;;
747 >                OBJREC  *mod = NULL;
748                  char    matspec[256];
749 +                OBJREC  *ino;
750 +
751                  matspec[0] = '\0';
752                  if (thisray.ro->omod != OVOID) {
753                          mod = objptr(thisray.ro->omod);
# Line 775 | Line 790 | char  *s;
790   }
791  
792  
793 < extern void
794 < writepict(s)                            /* write the picture to a file */
795 < char  *s;
793 > void
794 > writepict(                              /* write the picture to a file */
795 >        char  *s
796 > )
797   {
798          static char  buf[128];
799          char  *fname;
800          FILE  *fp;
801          COLR  *scanline;
802          int  y;
803 <
804 <        while (isspace(*s))
789 <                s++;
790 <        if (*s)
791 <                atos(buf, sizeof(buf), s);
792 <        else if (buf[0] == '\0') {
803 >                                /* XXX relies on words.c 2.11 behavior */
804 >        if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) {
805                  error(COMMAND, "no file");
806                  return;
807          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines