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.17 by greg, Thu Jun 14 05:19:05 2012 UTC vs.
Revision 3.23 by greg, Sat Dec 4 16:29:29 2021 UTC

# Line 27 | Line 27 | double pa = 1.;
27  
28   double  pj = 0.;
29  
30 + double  pd = 0.;
31 +
32   int     zfd = -1;
33  
34   int     fromstdin = 0;
# Line 113 | Line 115 | main(
115                                  pa = atof(argv[++i]);
116                          else if (argv[i][2] == 'j')
117                                  pj = atof(argv[++i]);
118 +                        else if (argv[i][2] == 'd')
119 +                                pd = atof(argv[++i]);
120                          else
121                                  goto userr;
122                          break;
# Line 133 | Line 137 | main(
137                          fprintf(stderr, "%s: no view in picture\n", argv[i]);
138                          exit(1);
139                  }
140 <                if (i+1 < argc) {
141 <                        zfd = open(argv[i+1], O_RDONLY);
142 <                        if (zfd < 0) {
139 <                                fprintf(stderr,
140 <                                        "%s: cannot open depth buffer\n",
141 <                                                argv[i+1]);
140 >                if (!getdim & (i+1 < argc)) {
141 >                        zfd = open_float_depth(argv[i+1], (long)rs.xr*rs.yr);
142 >                        if (zfd < 0)
143                                  exit(1);
143                        }
144                  }
145          }
146          if ((err = setview(&vw)) != NULL) {
# Line 151 | Line 151 | main(
151                  normaspect(viewaspect(&vw), &pa, &rs.xr, &rs.yr);
152          if (getdim) {
153                  printf("-x %d -y %d -ld%c\n", rs.xr, rs.yr,
154 <                                vw.vaft > FTINY ? '+' : '-');
154 >                                (i+1 == argc) & (vw.vaft > FTINY) ? '+' : '-');
155                  exit(0);
156          }
157          if (fromstdin)
# Line 190 | Line 190 | pix2rays(
190          RREAL   loc[2];
191          int     pp[2];
192          double  d;
193 <        int     i;
193 >        int     i, c;
194  
195          while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
196                  px += .5; py += .5;
197                  loc[0] = px/rs.xr; loc[1] = py/rs.yr;
198                  if (zfd >= 0) {
199 +                        if ((loc[0] < 0) | (loc[0] >= 1) |
200 +                                        (loc[1] < 0) | (loc[1] >= 1)) {
201 +                                fprintf(stderr, "%s: input pixel outside image\n",
202 +                                                progname);
203 +                                exit(1);
204 +                        }
205                          loc2pix(pp, &rs, loc[0], loc[1]);
206                          if (lseek(zfd,
207                                  (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
# Line 207 | Line 213 | pix2rays(
213                                  exit(1);
214                          }
215                  }
216 <                jitterloc(loc);
217 <                d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
218 <                if (d < -FTINY)
219 <                        rorg[0] = rorg[1] = rorg[2] =
220 <                        rdir[0] = rdir[1] = rdir[2] = 0.;
221 <                else if (zfd >= 0)
222 <                        for (i = 0; i < 3; i++) {
223 <                                rorg[i] += rdir[i]*zval;
224 <                                rdir[i] = -rdir[i];
216 >                for (c = repeatcnt; c-- > 0; ) {
217 >                        jitterloc(loc);
218 >                        d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
219 >                        if (d < -FTINY || !jitteraperture(rorg, rdir, &vw, pd))
220 >                                rorg[0] = rorg[1] = rorg[2] =
221 >                                rdir[0] = rdir[1] = rdir[2] = 0.;
222 >                        else if (zfd >= 0)
223 >                                for (i = 0; i < 3; i++) {
224 >                                        rorg[i] += rdir[i]*zval;
225 >                                        rdir[i] = -rdir[i];
226 >                                }
227 >                        else if (d > FTINY) {
228 >                                rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
229                          }
230 <                else if (d > FTINY) {
231 <                        rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
230 >                        (*putr)(rorg, rdir);
231 >                        if (c) {
232 >                                loc[0] = px/rs.xr; loc[1] = py/rs.yr;
233 >                        }
234                  }
223                (*putr)(rorg, rdir);
235                  if (unbuffered)
236                          fflush(stdout);
237          }
# Line 262 | Line 273 | putrays(void)
273                          pix2loc(loc, &rs, si, sc);
274                          jitterloc(loc);
275                          d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
276 <                        if (d < -FTINY)
276 >                        if (d < -FTINY || !jitteraperture(rorg, rdir, &vw, pd))
277                                  rorg[0] = rorg[1] = rorg[2] =
278                                  rdir[0] = rdir[1] = rdir[2] = 0.;
279                          else if (zfd >= 0)
280                                  for (i = 0; i < 3; i++) {
281 <                                        rorg[i] += rdir[i]*zbuf[si];
282 <                                        rdir[i] = -rdir[i];
281 >                                        rdir[i] = -rdir[i]*zbuf[si];
282 >                                        rorg[i] -= rdir[i];
283                                  }
284                          else if (d > FTINY) {
285                                  rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
# Line 304 | Line 315 | putf(          /* put out ray in float format */
315  
316          v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2];
317          v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2];
318 <        fwrite(v, sizeof(float), 6, stdout);
318 >        putbinary(v, sizeof(float), 6, stdout);
319   }
320  
321  
# Line 318 | Line 329 | putd(          /* put out ray in double format */
329  
330          v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2];
331          v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2];
332 <        fwrite(v, sizeof(double), 6, stdout);
332 >        putbinary(v, sizeof(double), 6, stdout);
333   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines