ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/vwrays.c
(Generate patch)

Comparing ray/src/util/vwrays.c (file contents):
Revision 3.3 by gregl, Fri Oct 17 10:42:45 1997 UTC vs.
Revision 3.12 by greg, Mon Sep 19 04:26:09 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Compute rays corresponding to a given picture or view.
6   */
7  
8 <
8 > #include "platform.h"
9   #include "standard.h"
10 <
10 > #include "random.h"
11   #include "view.h"
12  
13 < #include "resolu.h"
13 > typedef void putfunc(FVECT ro, FVECT rd);
14 > static putfunc puta;
15 > static putfunc putf;
16 > static putfunc putd;
17 > static void pix2rays(FILE *fp);
18 > static void putrays(void);
19  
20 < extern int      putf(), putd(), puta();
20 > static putfunc *putr = puta;
21  
20 int     (*putr)() = puta;
21
22   VIEW    vw = STDVIEW;
23  
24   RESOLU  rs = {PIXSTANDARD, 512, 512};
25  
26   double  pa = 1.;
27  
28 + double  pj = 0.;
29 +
30   int     zfd = -1;
31  
32 + int     fromstdin = 0;
33 +
34   char    *progname;
35  
36  
37 < main(argc, argv)
38 < int     argc;
39 < char    *argv[];
37 > int
38 > main(
39 >        int     argc,
40 >        char    *argv[]
41 > )
42   {
43          char    *err;
44          int     rval, getdim = 0;
# Line 93 | Line 99 | char   *argv[];
99                                  exit(1);
100                          }
101                          break;
102 <                case 'p':                       /* pixel aspect ratio */
103 <                        pa = atof(argv[++i]);
102 >                case 'p':                       /* pixel aspect or jitter */
103 >                        if (argv[i][2] == 'a')
104 >                                pa = atof(argv[++i]);
105 >                        else if (argv[i][2] == 'j')
106 >                                pj= atof(argv[++i]);
107 >                        else
108 >                                goto userr;
109                          break;
110 +                case 'i':                       /* get pixels from stdin */
111 +                        fromstdin = 1;
112 +                        break;
113                  default:
114                          goto userr;
115                  }
116 <        if (i > argc | i+2 < argc)
116 >        if ((i > argc) | (i+2 < argc))
117                  goto userr;
118          if (i < argc) {
119                  rval = viewfile(argv[i], &vw, &rs);
# Line 128 | Line 142 | char   *argv[];
142                                  vw.vaft > FTINY ? '+' : '-');
143                  exit(0);
144          }
145 <        putrays();
145 >        if (fromstdin)
146 >                pix2rays(stdin);
147 >        else
148 >                putrays();
149          exit(0);
150   userr:
151          fprintf(stderr,
152 <        "Usage: %s [ -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
152 >        "Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
153                          progname);
154          exit(1);
155   }
156  
157  
158 < putrays()
158 > static void
159 > jitterloc(
160 >        RREAL   loc[2]
161 > )
162   {
163 <        static FLOAT    loc[2];
163 >        if (pj > FTINY) {
164 >                loc[0] += pj*(.5 - frandom())/rs.xr;
165 >                loc[1] += pj*(.5 - frandom())/rs.yr;
166 >        }
167 > }
168 >
169 >
170 > static void
171 > pix2rays(
172 >        FILE *fp
173 > )
174 > {
175          static FVECT    rorg, rdir;
176 <        float   *zbuf;
176 >        float   zval;
177 >        double  px, py;
178 >        RREAL   loc[2];
179 >        int     pp[2];
180 >        double  d;
181 >        register int    i;
182 >
183 >        while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
184 >                px += .5; py += .5;
185 >                if (px < 0 || px >= rs.xr ||
186 >                                py < 0 || py >= rs.yr) {
187 >                        fprintf(stderr,
188 >                                "%s: (x,y) pair (%.0f,%.0f) out of range\n",
189 >                                        progname, px, py);
190 >                        exit(1);
191 >                }
192 >                loc[0] = px/rs.xr; loc[1] = py/rs.yr;
193 >                if (zfd >= 0) {
194 >                        loc2pix(pp, &rs, loc[0], loc[1]);
195 >                        if (lseek(zfd,
196 >                                (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
197 >                                                SEEK_SET) < 0 ||
198 >                                        read(zfd, &zval, sizeof(float))
199 >                                                < sizeof(float)) {
200 >                                fprintf(stderr, "%s: depth buffer read error\n",
201 >                                                progname);
202 >                                exit(1);
203 >                        }
204 >                }
205 >                jitterloc(loc);
206 >                d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
207 >                if (d < -FTINY)
208 >                        rorg[0] = rorg[1] = rorg[2] =
209 >                        rdir[0] = rdir[1] = rdir[2] = 0.;
210 >                else if (zfd >= 0)
211 >                        for (i = 0; i < 3; i++) {
212 >                                rorg[i] += rdir[i]*zval;
213 >                                rdir[i] = -rdir[i];
214 >                        }
215 >                else if (d > FTINY) {
216 >                        rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
217 >                }
218 >                (*putr)(rorg, rdir);
219 >        }
220 >        if (!feof(fp)) {
221 >                fprintf(stderr, "%s: expected px py on input\n", progname);
222 >                exit(1);
223 >        }
224 > }
225 >
226 >
227 > static void
228 > putrays(void)
229 > {
230 >        RREAL   loc[2];
231 >        FVECT   rorg, rdir;
232 >        float   *zbuf = NULL;
233          int     sc;
234          double  d;
235          register int    si, i;
# Line 165 | Line 252 | putrays()
252                  }
253                  for (si = 0; si < scanlen(&rs); si++) {
254                          pix2loc(loc, &rs, si, sc);
255 +                        jitterloc(loc);
256                          d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
257                          if (d < -FTINY)
258                                  rorg[0] = rorg[1] = rorg[2] =
# Line 181 | Line 269 | putrays()
269                  }
270          }
271          if (zfd >= 0)
272 <                free((char *)zbuf);
272 >                free((void *)zbuf);
273   }
274  
275  
276 < puta(ro, rd)            /* put out ray in ASCII format */
277 < FVECT   ro, rd;
276 > static void
277 > puta(           /* put out ray in ASCII format */
278 >        FVECT   ro,
279 >        FVECT   rd
280 > )
281   {
282          printf("%.5e %.5e %.5e %.5e %.5e %.5e\n",
283                          ro[0], ro[1], ro[2],
# Line 194 | Line 285 | FVECT  ro, rd;
285   }
286  
287  
288 < putf(ro, rd)            /* put out ray in float format */
289 < FVECT   ro, rd;
288 > static void
289 > putf(           /* put out ray in float format */
290 >        FVECT   ro,
291 >        FVECT   rd
292 > )
293   {
294          float v[6];
295  
# Line 205 | Line 299 | FVECT  ro, rd;
299   }
300  
301  
302 < putd(ro, rd)            /* put out ray in double format */
303 < FVECT   ro, rd;
302 > static void
303 > putd(           /* put out ray in double format */
304 >        FVECT   ro,
305 >        FVECT   rd
306 > )
307   {
308          double v[6];
309  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines