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.41 by schorsch, Mon Jun 30 14:59:13 2003 UTC vs.
Revision 2.63 by greg, Thu Sep 6 00:07:43 2012 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"
21   #include  "otypes.h"
22   #include  "rpaint.h"
23  
# Line 35 | Line 39 | extern char  *octname;
39  
40  
41   void
42 < getframe(s)                             /* get a new frame */
43 < char  *s;
42 > getframe(                               /* get a new frame */
43 >        char  *s
44 > )
45   {
46          if (getrect(s, &pframe) < 0)
47                  return;
# Line 45 | Line 50 | char  *s;
50  
51  
52   void
53 < getrepaint(s)                           /* get area and repaint */
54 < char  *s;
53 > getrepaint(                             /* get area and repaint */
54 >        char  *s
55 > )
56   {
57          RECT  box;
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   void
66 < getview(s)                              /* get/show view parameters */
67 < char  *s;
66 > getview(                                /* get/show/save view parameters */
67 >        char  *s
68 > )
69   {
70          FILE  *fp;
71          char  buf[128];
72          char  *fname;
73          int  change = 0;
74 <        VIEW  nv;
74 >        VIEW  nv = ourview;
75  
76          while (isspace(*s))
77                  s++;
78          if (*s == '-') {                        /* command line parameters */
72                copystruct(&nv, &ourview);
79                  if (sscanview(&nv, s))
80                          newview(&nv);
81                  else
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 97 | Line 103 | char  *s;
103          if (buf[0] && buf[0] != ourview.type) {
104                  nv.type = buf[0];
105                  change++;
106 <        } else
101 <                nv.type = ourview.type;
106 >        }
107          sprintf(buf, "view point (%.6g %.6g %.6g): ",
108                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
109          (*dev->comout)(buf);
# Line 106 | Line 111 | char  *s;
111          if (buf[0] == CTRL('C')) return;
112          if (sscanvec(buf, nv.vp))
113                  change++;
109        else
110                VCOPY(nv.vp, ourview.vp);
114          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
115 <                        ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
115 >                        ourview.vdir[0]*ourview.vdist,
116 >                        ourview.vdir[1]*ourview.vdist,
117 >                        ourview.vdir[2]*ourview.vdist);
118          (*dev->comout)(buf);
119          (*dev->comin)(buf, NULL);
120          if (buf[0] == CTRL('C')) return;
121 <        if (sscanvec(buf, nv.vdir))
121 >        if (sscanvec(buf, nv.vdir)) {
122 >                nv.vdist = 1.;
123                  change++;
124 <        else
119 <                VCOPY(nv.vdir, ourview.vdir);
124 >        }
125          sprintf(buf, "view up (%.6g %.6g %.6g): ",
126                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
127          (*dev->comout)(buf);
# Line 124 | Line 129 | char  *s;
129          if (buf[0] == CTRL('C')) return;
130          if (sscanvec(buf, nv.vup))
131                  change++;
127        else
128                VCOPY(nv.vup, ourview.vup);
132          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
133                          ourview.horiz, ourview.vert);
134          (*dev->comout)(buf);
# Line 133 | Line 136 | char  *s;
136          if (buf[0] == CTRL('C')) return;
137          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
138                  change++;
136        else {
137                nv.horiz = ourview.horiz; nv.vert = ourview.vert;
138        }
139          sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ",
140                          ourview.vfore, ourview.vaft);
141          (*dev->comout)(buf);
# Line 143 | Line 143 | char  *s;
143          if (buf[0] == CTRL('C')) return;
144          if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2)
145                  change++;
146        else {
147                nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
148        }
146          sprintf(buf, "view shift and lift (%.6g %.6g): ",
147                          ourview.hoff, ourview.voff);
148          (*dev->comout)(buf);
# Line 153 | Line 150 | char  *s;
150          if (buf[0] == CTRL('C')) return;
151          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
152                  change++;
156        else {
157                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
158        }
153          if (change)
154                  newview(&nv);
155   }
156  
157  
158   void
159 < lastview(s)                             /* return to a previous view */
160 < char  *s;
159 > lastview(                               /* return to a previous view */
160 >        char  *s
161 > )
162   {
163          char  buf[128];
164          char  *fname;
165          int  success;
166          VIEW  nv;
167 <
168 <        if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
169 <                copystruct(&nv, &stdview);
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) {
172                          sprintf(errmsg, "cannot open \"%s\"", buf);
# Line 188 | Line 183 | char  *s;
183                  error(COMMAND, "no previous view");
184                  return;
185          }
186 <        copystruct(&nv, &ourview);
187 <        copystruct(&ourview, &oldview);
188 <        copystruct(&oldview, &nv);
189 <        newimage();
186 >        nv = ourview;
187 >        ourview = oldview;
188 >        oldview = nv;
189 >        newimage(NULL);
190   }
191  
192  
193   void
194 < saveview(s)                             /* save view to rad file */
195 < char  *s;
194 > saveview(                               /* save view to rad file */
195 >        char  *s
196 > )
197   {
198          char  view[64];
199          char  *fname;
# Line 210 | Line 206 | char  *s;
206                  }
207                  s = sskip(s);
208          }
209 <        while (isspace(*s))
214 <                s++;
215 <        if (*s)
216 <                atos(rifname, sizeof(rifname), s);
217 <        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 233 | Line 225 | char  *s;
225  
226  
227   void
228 < loadview(s)                             /* load view from rad file */
229 < char  *s;
228 > loadview(                               /* load view from rad file */
229 >        char  *s
230 > )
231   {
232          char  buf[512];
233          char  *fname;
# Line 246 | Line 239 | char  *s;
239                  s = sskip(s);
240          else
241                  strcat(buf, "1");
242 <        if (*s)
250 <                atos(rifname, sizeof(rifname), s);
251 <        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 265 | Line 256 | char  *s;
256          buf[0] = '\0';
257          fgets(buf, sizeof(buf), fp);
258          pclose(fp);
259 <        copystruct(&nv, &stdview);
259 >        nv = stdview;
260          if (!sscanview(&nv, buf)) {
261                  error(COMMAND, "rad error -- no such view?");
262                  return;
# Line 275 | Line 266 | char  *s;
266  
267  
268   void
269 < getaim(s)                               /* aim camera */
270 < char  *s;
269 > getaim(                         /* aim camera */
270 >        char  *s
271 > )
272   {
273 +        VIEW  nv = ourview;
274          double  zfact;
282        VIEW  nv;
275  
276          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
277                  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;
278          zoomview(&nv, zfact);
279          newview(&nv);
280   }
281  
282  
283   void
284 < getmove(s)                              /* move camera */
285 < char  *s;
284 > getfocus(                               /* set focus distance */
285 >        char *s
286 > )
287   {
288 +        char  buf[64];
289 +        double  dist;
290 +
291 +        if (sscanf(s, "%lf", &dist) < 1) {
292 +                int     x, y;
293 +                RAY     thisray;
294 +                if (dev->getcur == NULL)
295 +                        return;
296 +                (*dev->comout)("Pick focus point\n");
297 +                if ((*dev->getcur)(&x, &y) == ABORT)
298 +                        return;
299 +                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
300 +                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
301 +                        error(COMMAND, "not on image");
302 +                        return;
303 +                }
304 +                rayorigin(&thisray, PRIMARY, NULL, NULL);
305 +                if (!localhit(&thisray, &thescene)) {
306 +                        error(COMMAND, "not a local object");
307 +                        return;
308 +                }
309 +                dist = thisray.rot;
310 +        } else if (dist <= .0) {
311 +                error(COMMAND, "focus distance must be positive");
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 + void
321 + getmove(                                /* move camera */
322 +        char  *s
323 + )
324 + {
325          FVECT  vc;
326          double  mag;
327  
# Line 308 | Line 332 | char  *s;
332  
333  
334   void
335 < getrotate(s)                            /* rotate camera */
336 < char  *s;
335 > getrotate(                              /* rotate camera */
336 >        char  *s
337 > )
338   {
339 <        VIEW  nv;
315 <        FVECT  v1;
339 >        VIEW  nv = ourview;
340          double  angle, elev, zfact;
341          
342          elev = 0.0; zfact = 1.0;
# Line 320 | Line 344 | char  *s;
344                  error(COMMAND, "missing angle");
345                  return;
346          }
323        nv.type = ourview.type;
324        VCOPY(nv.vp, ourview.vp);
325        VCOPY(nv.vup, ourview.vup);
326        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
327        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
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);
332 <                spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
333 <        }
334 <        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
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   void
357 < getpivot(s)                             /* pivot viewpoint */
358 < register char  *s;
357 > getpivot(                               /* pivot viewpoint */
358 >        char  *s
359 > )
360   {
361          FVECT  vc;
362          double  angle, elev, mag;
# Line 356 | Line 373 | register char  *s;
373  
374  
375   void
376 < getexposure(s)                          /* get new exposure */
377 < char  *s;
376 > getexposure(                            /* get new exposure */
377 >        char  *s
378 > )
379   {
380          char  buf[128];
381 <        register char  *cp;
364 <        RECT  r;
381 >        char  *cp;
382          int  x, y;
383 <        register PNODE  *p = &ptrunk;
383 >        PNODE  *p = &ptrunk;
384          int  adapt = 0;
385          double  e = 1.0;
386  
# Line 380 | Line 397 | char  *s;
397                  (*dev->comout)("Pick point for exposure\n");
398                  if ((*dev->getcur)(&x, &y) == ABORT)
399                          return;
400 <                r.l = r.d = 0;
384 <                r.r = hresolu; r.u = vresolu;
385 <                p = findrect(x, y, &ptrunk, &r, -1);
400 >                p = findrect(x, y, &ptrunk, -1);
401          } else {
402                  if (*cp == '=') {       /* absolute setting */
403                          p = NULL;
# Line 405 | Line 420 | char  *s;
420                          e *= atof(cp);
421          }
422          if (p != NULL) {                /* relative setting */
423 +                compavg(p);
424                  if (bright(p->v) < 1e-15) {
425                          error(COMMAND, "cannot normalize to zero");
426                          return;
# Line 422 | Line 438 | char  *s;
438   }
439  
440   typedef union {int i; double d; COLOR C;}       *MyUptr;
441 + #define  FEQ(x,y)     (fabs((x)-(y)) <= FTINY)
442  
443   int
444 < getparam(str, dsc, typ, p)              /* get variable from user */
445 < char  *str, *dsc;
446 < int  typ;
447 < void  *p;
444 > getparam(               /* get variable from user */
445 >        char  *str,
446 >        char  *dsc,
447 >        int  typ,
448 >        void  *p
449 > )
450   {
451 <        register MyUptr  ptr = (MyUptr)p;
451 >        MyUptr  ptr = (MyUptr)p;
452          int  i0;
453          double  d0, d1, d2;
454          char  buf[48];
# Line 444 | Line 463 | void  *p;
463                          if (sscanf(buf, "%d", &i0) != 1)
464                                  return(0);
465                  }
466 +                if (ptr->i == i0)
467 +                        return(0);
468                  ptr->i = i0;
469 <                return(1);
469 >                break;
470          case 'r':                       /* real */
471                  if (sscanf(str, "%lf", &d0) != 1) {
472                          (*dev->comout)(dsc);
# Line 455 | Line 476 | void  *p;
476                          if (sscanf(buf, "%lf", &d0) != 1)
477                                  return(0);
478                  }
479 +                if (FEQ(ptr->d, d0))
480 +                        return(0);
481                  ptr->d = d0;
482 <                return(1);
482 >                break;
483          case 'b':                       /* boolean */
484                  if (sscanf(str, "%1s", buf) != 1) {
485                          (*dev->comout)(dsc);
486                          sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
487                          (*dev->comout)(buf);
488                          (*dev->comin)(buf, NULL);
489 <                        if (buf[0] == '\0' ||
467 <                                        strchr("yY+1tTnN-0fF", buf[0]) == NULL)
489 >                        if (buf[0] == '\0')
490                                  return(0);
491                  }
492 <                ptr->i = strchr("yY+1tT", buf[0]) != NULL;
493 <                return(1);
492 >                if (strchr("yY+1tTnN-0fF", buf[0]) == NULL)
493 >                        return(0);
494 >                i0 = strchr("yY+1tT", buf[0]) != NULL;
495 >                if (ptr->i == i0)
496 >                        return(0);
497 >                ptr->i = i0;
498 >                break;
499          case 'C':                       /* color */
500                  if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
501                          (*dev->comout)(dsc);
# Line 481 | Line 508 | void  *p;
508                          if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
509                                  return(0);
510                  }
511 +                if (FEQ(colval(ptr->C,RED), d0) &&
512 +                                FEQ(colval(ptr->C,GRN), d1) &&
513 +                                FEQ(colval(ptr->C,BLU), d2))
514 +                        return(0);
515                  setcolor(ptr->C, d0, d1, d2);
516 <                return(1);
516 >                break;
517 >        default:
518 >                return(0);              /* shouldn't happen */
519          }
520 +        newparam++;
521 +        return(1);
522   }
523  
524  
525   void
526 < setparam(s)                             /* get/set program parameter */
527 < register char  *s;
526 > setparam(                               /* get/set program parameter */
527 >        char  *s
528 > )
529   {
530 +        int  prev_newp = newparam;
531          char  buf[128];
532          
533          if (s[0] == '\0') {
534                  (*dev->comout)(
535 <                "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: ");
535 >                "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: ");
536                  (*dev->comin)(buf, NULL);
537                  s = buf;
538          }
539          switch (s[0]) {
540 +        case 'u':                       /* uncorrelated sampling */
541 +                getparam(s+1, "uncorrelated sampling", 'b',
542 +                                (void *)&rand_samp);
543 +                break;
544          case 'l':                       /* limit */
545                  switch (s[1]) {
546                  case 'w':                       /* weight */
# Line 552 | Line 593 | register char  *s;
593                  case 'n': case 'N': case 'f': case 'F': case '0': case '-':
594                          getparam(s+1, "black and white", 'b',
595                                          (void *)&greyscale);
596 +                        newparam = prev_newp;
597                          break;
598                  default:
599                          goto badparam;
# Line 634 | Line 676 | register char  *s;
676                  default:
677                          goto badparam;
678                  }
679 +                newparam = prev_newp;
680                  break;
681          case 's':                       /* specular */
682                  switch (s[1]) {
683 <                case 'j':                       /* jitter */
684 <                        getparam(s+2, "specular jitter", 'r',
683 >                case 's':                       /* sampling */
684 >                        getparam(s+2, "specular sampling", 'r',
685                                          (void *)&specjitter);
686                          break;
687                  case 't':                       /* threshold */
# Line 662 | Line 705 | badparam:
705  
706  
707   void
708 < traceray(s)                             /* trace a single ray */
709 < char  *s;
708 > traceray(                               /* trace a single ray */
709 >        char  *s
710 > )
711   {
712 <        char  buf[128];
713 <        int  x, y;
670 <        OBJREC  *ino;
671 <        RAY  thisray;
712 >        RAY     thisray;
713 >        char    buf[512];
714  
715          thisray.rmax = 0.0;
716  
717          if (!sscanvec(s, thisray.rorg) ||
718                          !sscanvec(sskip2(s,3), thisray.rdir)) {
719 +                int  x, y;
720  
721                  if (dev->getcur == NULL)
722                          return;
# Line 692 | Line 735 | char  *s;
735                  return;
736          }
737  
738 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
696 <        
697 <        rayvalue(&thisray);
738 >        ray_trace(&thisray);
739  
740          if (thisray.ro == NULL)
741                  (*dev->comout)("ray hit nothing");
742          else {
743 <                sprintf(buf, "ray hit %s%s %s \"%s\"",
744 <                                thisray.rod < 0.0 ? "back of " : "",
745 <                                thisray.ro->omod == OVOID ? VOIDID :
746 <                                        objptr(thisray.ro->omod)->oname,
743 >                OBJREC  *mat = NULL;
744 >                OBJREC  *mod = NULL;
745 >                char    matspec[256];
746 >                OBJREC  *ino;
747 >
748 >                matspec[0] = '\0';
749 >                if (thisray.ro->omod != OVOID) {
750 >                        mod = objptr(thisray.ro->omod);
751 >                        mat = findmaterial(mod);
752 >                }
753 >                if (thisray.rod < 0.0)
754 >                        strcpy(matspec, "back of ");
755 >                if (mod != NULL) {
756 >                        strcat(matspec, mod->oname);
757 >                        if (mat != mod && mat != NULL)
758 >                                sprintf(matspec+strlen(matspec),
759 >                                        " (%s)", mat->oname);
760 >                } else
761 >                        strcat(matspec, VOIDID);
762 >                sprintf(buf, "ray hit %s %s \"%s\"", matspec,
763                                  ofun[thisray.ro->otype].funame,
764                                  thisray.ro->oname);
765                  if ((ino = objptr(thisray.robj)) != thisray.ro)
# Line 731 | Line 788 | char  *s;
788  
789  
790   void
791 < writepict(s)                            /* write the picture to a file */
792 < char  *s;
791 > writepict(                              /* write the picture to a file */
792 >        char  *s
793 > )
794   {
795          static char  buf[128];
796          char  *fname;
797          FILE  *fp;
798          COLR  *scanline;
799          int  y;
800 <
801 <        while (isspace(*s))
744 <                s++;
745 <        if (*s)
746 <                atos(buf, sizeof(buf), s);
747 <        else if (buf[0] == '\0') {
800 >                                /* XXX relies on words.c 2.11 behavior */
801 >        if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) {
802                  error(COMMAND, "no file");
803                  return;
804          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines