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.5 by schorsch, Thu Jun 26 00:58:11 2003 UTC vs.
Revision 3.16 by greg, Sat Aug 20 20:57:52 2011 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
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 < extern int      putf(), putd(), puta();
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 < int     (*putr)() = puta;
20 > static putfunc *putr = puta;
21  
22   VIEW    vw = STDVIEW;
23  
# Line 20 | Line 25 | 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 47 | 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 90 | 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 135 | Line 156 | char   *argv[];
156          exit(0);
157   userr:
158          fprintf(stderr,
159 <        "Usage: %s [ -i -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 < pix2rays(FILE *fp)
165 > static void
166 > jitterloc(
167 >        RREAL   loc[2]
168 > )
169   {
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   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 <                if (px < 0 || px >= rs.xr ||
192 <                                py < 0 || py >= rs.yr) {
156 <                        fprintf(stderr,
157 <                                "%s: (x,y) pair (%.0f,%.0f) out of range\n",
158 <                                        progname, px, py);
159 <                        exit(1);
160 <                }
191 >                px += .5; py += .5;
192 >                loc[0] = px/rs.xr; loc[1] = py/rs.yr;
193                  if (zfd >= 0) {
194 <                        loc2pix(pp, &rs, px/rs.xr, py/rs.yr);
194 >                        loc2pix(pp, &rs, loc[0], loc[1]);
195                          if (lseek(zfd,
196 <                                (pp[1]*scanlen(&rs)+pp[0])*sizeof(float), 0)
197 <                                        < 0 ||
196 >                                (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
197 >                                                SEEK_SET) < 0 ||
198                                          read(zfd, &zval, sizeof(float))
199 <                                        < sizeof(float)) {
199 >                                                < sizeof(float)) {
200                                  fprintf(stderr, "%s: depth buffer read error\n",
201                                                  progname);
202                                  exit(1);
203                          }
204                  }
205 <                d = viewray(rorg, rdir, &vw, px/rs.xr, py/rs.yr);
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.;
# Line 183 | Line 216 | pix2rays(FILE *fp)
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);
# Line 191 | Line 226 | pix2rays(FILE *fp)
226   }
227  
228  
229 < putrays()
229 > static void
230 > putrays(void)
231   {
232 <        static RREAL    loc[2];
233 <        static FVECT    rorg, rdir;
234 <        float   *zbuf;
232 >        RREAL   loc[2];
233 >        FVECT   rorg, rdir;
234 >        float   *zbuf = NULL;
235          int     sc;
236          double  d;
237          register int    si, i;
# Line 218 | 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 238 | Line 275 | putrays()
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 247 | 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 258 | 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