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.13 by greg, Sun May 7 15:44:28 2006 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 50 | Line 56 | char   *argv[];
56                                  break;
57                          case 'f':                       /* float */
58                                  putr = putf;
59 +                                SET_FILE_BINARY(stdout);
60                                  break;
61                          case 'd':                       /* double */
62                                  putr = putd;
63 +                                SET_FILE_BINARY(stdout);
64                                  break;
65                          default:
66                                  goto userr;
# Line 93 | Line 101 | char   *argv[];
101                                  exit(1);
102                          }
103                          break;
104 <                case 'p':                       /* pixel aspect ratio */
105 <                        pa = atof(argv[++i]);
104 >                case 'p':                       /* pixel aspect or jitter */
105 >                        if (argv[i][2] == 'a')
106 >                                pa = atof(argv[++i]);
107 >                        else if (argv[i][2] == 'j')
108 >                                pj= atof(argv[++i]);
109 >                        else
110 >                                goto userr;
111                          break;
112 +                case 'i':                       /* get pixels from stdin */
113 +                        fromstdin = 1;
114 +                        break;
115                  default:
116                          goto userr;
117                  }
118 <        if (i > argc | i+2 < argc)
118 >        if ((i > argc) | (i+2 < argc))
119                  goto userr;
120          if (i < argc) {
121                  rval = viewfile(argv[i], &vw, &rs);
# Line 128 | Line 144 | char   *argv[];
144                                  vw.vaft > FTINY ? '+' : '-');
145                  exit(0);
146          }
147 <        putrays();
147 >        if (fromstdin)
148 >                pix2rays(stdin);
149 >        else
150 >                putrays();
151          exit(0);
152   userr:
153          fprintf(stderr,
154 <        "Usage: %s [ -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
154 >        "Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
155                          progname);
156          exit(1);
157   }
158  
159  
160 < putrays()
160 > static void
161 > jitterloc(
162 >        RREAL   loc[2]
163 > )
164   {
165 <        static FLOAT    loc[2];
165 >        if (pj > FTINY) {
166 >                loc[0] += pj*(.5 - frandom())/rs.xr;
167 >                loc[1] += pj*(.5 - frandom())/rs.yr;
168 >        }
169 > }
170 >
171 >
172 > static void
173 > pix2rays(
174 >        FILE *fp
175 > )
176 > {
177          static FVECT    rorg, rdir;
178 <        float   *zbuf;
178 >        float   zval;
179 >        double  px, py;
180 >        RREAL   loc[2];
181 >        int     pp[2];
182 >        double  d;
183 >        register int    i;
184 >
185 >        while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
186 >                px += .5; py += .5;
187 >                if (px < 0 || px >= rs.xr ||
188 >                                py < 0 || py >= rs.yr) {
189 >                        fprintf(stderr,
190 >                                "%s: (x,y) pair (%.0f,%.0f) out of range\n",
191 >                                        progname, px, py);
192 >                        exit(1);
193 >                }
194 >                loc[0] = px/rs.xr; loc[1] = py/rs.yr;
195 >                if (zfd >= 0) {
196 >                        loc2pix(pp, &rs, loc[0], loc[1]);
197 >                        if (lseek(zfd,
198 >                                (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
199 >                                                SEEK_SET) < 0 ||
200 >                                        read(zfd, &zval, sizeof(float))
201 >                                                < sizeof(float)) {
202 >                                fprintf(stderr, "%s: depth buffer read error\n",
203 >                                                progname);
204 >                                exit(1);
205 >                        }
206 >                }
207 >                jitterloc(loc);
208 >                d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
209 >                if (d < -FTINY)
210 >                        rorg[0] = rorg[1] = rorg[2] =
211 >                        rdir[0] = rdir[1] = rdir[2] = 0.;
212 >                else if (zfd >= 0)
213 >                        for (i = 0; i < 3; i++) {
214 >                                rorg[i] += rdir[i]*zval;
215 >                                rdir[i] = -rdir[i];
216 >                        }
217 >                else if (d > FTINY) {
218 >                        rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
219 >                }
220 >                (*putr)(rorg, rdir);
221 >        }
222 >        if (!feof(fp)) {
223 >                fprintf(stderr, "%s: expected px py on input\n", progname);
224 >                exit(1);
225 >        }
226 > }
227 >
228 >
229 > static void
230 > putrays(void)
231 > {
232 >        RREAL   loc[2];
233 >        FVECT   rorg, rdir;
234 >        float   *zbuf = NULL;
235          int     sc;
236          double  d;
237          register int    si, i;
# Line 165 | Line 254 | putrays()
254                  }
255                  for (si = 0; si < scanlen(&rs); si++) {
256                          pix2loc(loc, &rs, si, sc);
257 +                        jitterloc(loc);
258                          d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
259                          if (d < -FTINY)
260                                  rorg[0] = rorg[1] = rorg[2] =
# Line 181 | Line 271 | putrays()
271                  }
272          }
273          if (zfd >= 0)
274 <                free((char *)zbuf);
274 >                free((void *)zbuf);
275   }
276  
277  
278 < puta(ro, rd)            /* put out ray in ASCII format */
279 < FVECT   ro, rd;
278 > static void
279 > puta(           /* put out ray in ASCII format */
280 >        FVECT   ro,
281 >        FVECT   rd
282 > )
283   {
284          printf("%.5e %.5e %.5e %.5e %.5e %.5e\n",
285                          ro[0], ro[1], ro[2],
# Line 194 | Line 287 | FVECT  ro, rd;
287   }
288  
289  
290 < putf(ro, rd)            /* put out ray in float format */
291 < FVECT   ro, rd;
290 > static void
291 > putf(           /* put out ray in float format */
292 >        FVECT   ro,
293 >        FVECT   rd
294 > )
295   {
296          float v[6];
297  
# Line 205 | Line 301 | FVECT  ro, rd;
301   }
302  
303  
304 < putd(ro, rd)            /* put out ray in double format */
305 < FVECT   ro, rd;
304 > static void
305 > putd(           /* put out ray in double format */
306 >        FVECT   ro,
307 >        FVECT   rd
308 > )
309   {
310          double v[6];
311  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines