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.16 by greg, Sat Aug 20 20:57:52 2011 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 + int     unbuffered = 0;
35 +
36   char    *progname;
37  
38  
39 < main(argc, argv)
40 < int     argc;
41 < char    *argv[];
39 > int
40 > main(
41 >        int     argc,
42 >        char    *argv[]
43 > )
44   {
45          char    *err;
46          int     rval, getdim = 0;
# Line 50 | Line 58 | char   *argv[];
58                                  break;
59                          case 'f':                       /* float */
60                                  putr = putf;
61 +                                SET_FILE_BINARY(stdout);
62                                  break;
63                          case 'd':                       /* double */
64                                  putr = putd;
65 +                                SET_FILE_BINARY(stdout);
66                                  break;
67                          default:
68                                  goto userr;
# Line 93 | Line 103 | char   *argv[];
103                                  exit(1);
104                          }
105                          break;
106 <                case 'p':                       /* pixel aspect ratio */
107 <                        pa = atof(argv[++i]);
106 >                case 'p':                       /* pixel aspect or jitter */
107 >                        if (argv[i][2] == 'a')
108 >                                pa = atof(argv[++i]);
109 >                        else if (argv[i][2] == 'j')
110 >                                pj = atof(argv[++i]);
111 >                        else
112 >                                goto userr;
113                          break;
114 +                case 'i':                       /* get pixels from stdin */
115 +                        fromstdin = 1;
116 +                        break;
117 +                case 'u':                       /* unbuffered output */
118 +                        unbuffered = 1;
119 +                        break;
120                  default:
121                          goto userr;
122                  }
123 <        if (i > argc | i+2 < argc)
123 >        if ((i > argc) | (i+2 < argc))
124                  goto userr;
125          if (i < argc) {
126                  rval = viewfile(argv[i], &vw, &rs);
# Line 128 | Line 149 | char   *argv[];
149                                  vw.vaft > FTINY ? '+' : '-');
150                  exit(0);
151          }
152 <        putrays();
152 >        if (fromstdin)
153 >                pix2rays(stdin);
154 >        else
155 >                putrays();
156          exit(0);
157   userr:
158          fprintf(stderr,
159 <        "Usage: %s [ -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
159 >        "Usage: %s [ -i -u -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
160                          progname);
161          exit(1);
162   }
163  
164  
165 < putrays()
165 > static void
166 > jitterloc(
167 >        RREAL   loc[2]
168 > )
169   {
170 <        static FLOAT    loc[2];
170 >        if (pj > FTINY) {
171 >                loc[0] += pj*(.5 - frandom())/rs.xr;
172 >                loc[1] += pj*(.5 - frandom())/rs.yr;
173 >        }
174 > }
175 >
176 >
177 > static void
178 > pix2rays(
179 >        FILE *fp
180 > )
181 > {
182          static FVECT    rorg, rdir;
183 <        float   *zbuf;
183 >        float   zval;
184 >        double  px, py;
185 >        RREAL   loc[2];
186 >        int     pp[2];
187 >        double  d;
188 >        register int    i;
189 >
190 >        while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
191 >                px += .5; py += .5;
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 >                if (unbuffered)
220 >                        fflush(stdout);
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