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.14 by greg, Mon Jun 22 00:12:04 2009 UTC vs.
Revision 3.26 by greg, Tue Jun 3 21:31:51 2025 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;
35  
36 < char    *progname;
36 > int     unbuffered = 0;
37  
38 + int     repeatcnt = 1;
39  
40 +
41   int
42   main(
43          int     argc,
# Line 42 | Line 46 | main(
46   {
47          char    *err;
48          int     rval, getdim = 0;
49 <        register int    i;
49 >        int     i;
50  
51 <        progname = argv[0];
51 >        fixargv0(argv[0]);              /* sets global progname */
52          if (argc < 2)
53                  goto userr;
54          for (i = 1; i < argc && argv[i][0] == '-'; i++)
# Line 73 | Line 77 | main(
77                                          fprintf(stderr,
78                                                  "%s: no view in file\n",
79                                                          argv[i]);
80 <                                        exit(1);
80 >                                        return(1);
81                                  }
82                                  break;
83                          }
# Line 90 | Line 94 | main(
94                          if (rs.xr <= 0) {
95                                  fprintf(stderr, "%s: bad x resolution\n",
96                                                  progname);
97 <                                exit(1);
97 >                                return(1);
98                          }
99                          break;
100                  case 'y':                       /* y resolution */
# Line 98 | Line 102 | main(
102                          if (rs.yr <= 0) {
103                                  fprintf(stderr, "%s: bad y resolution\n",
104                                                  progname);
105 <                                exit(1);
105 >                                return(1);
106                          }
107                          break;
108 +                case 'c':                       /* repeat count */
109 +                        repeatcnt = atoi(argv[++i]);
110 +                        if (repeatcnt < 1) repeatcnt = 1;
111 +                        break;
112                  case 'p':                       /* pixel aspect or jitter */
113                          if (argv[i][2] == 'a')
114                                  pa = atof(argv[++i]);
115                          else if (argv[i][2] == 'j')
116 <                                pj= atof(argv[++i]);
116 >                                pj = atof(argv[++i]);
117 >                        else if (argv[i][2] == 'd')
118 >                                pd = atof(argv[++i]);
119                          else
120                                  goto userr;
121                          break;
122                  case 'i':                       /* get pixels from stdin */
123                          fromstdin = 1;
124                          break;
125 +                case 'u':                       /* unbuffered output */
126 +                        unbuffered = 1;
127 +                        break;
128                  default:
129                          goto userr;
130                  }
# Line 121 | Line 134 | main(
134                  rval = viewfile(argv[i], &vw, &rs);
135                  if (rval <= 0) {
136                          fprintf(stderr, "%s: no view in picture\n", argv[i]);
137 <                        exit(1);
137 >                        return(1);
138                  }
139 <                if (i+1 < argc) {
140 <                        zfd = open(argv[i+1], O_RDONLY);
141 <                        if (zfd < 0) {
142 <                                fprintf(stderr,
130 <                                        "%s: cannot open depth buffer\n",
131 <                                                argv[i+1]);
132 <                                exit(1);
133 <                        }
139 >                if (!getdim & (i+1 < argc)) {
140 >                        zfd = open_float_depth(argv[i+1], (long)rs.xr*rs.yr);
141 >                        if (zfd < 0)
142 >                                return(1);
143                  }
144          }
145          if ((err = setview(&vw)) != NULL) {
146                  fprintf(stderr, "%s: %s\n", progname, err);
147 <                exit(1);
147 >                return(1);
148          }
149          if (i == argc)
150                  normaspect(viewaspect(&vw), &pa, &rs.xr, &rs.yr);
151          if (getdim) {
152 <                printf("-x %d -y %d -ld%c\n", rs.xr, rs.yr,
153 <                                vw.vaft > FTINY ? '+' : '-');
154 <                exit(0);
152 >                printf("-x %d -y %d%s\n", rs.xr, rs.yr,
153 >                                (vw.vaft > FTINY) ? " -ld+" : "");
154 >                return(0);
155          }
156 +        if ((repeatcnt > 1) & (pj > FTINY))
157 +                initurand(1024);
158          if (fromstdin)
159                  pix2rays(stdin);
160          else
161                  putrays();
162 <        exit(0);
162 >        return(0);
163   userr:
164          fprintf(stderr,
165 <        "Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
165 >        "Usage: %s [ -i -u -f{a|f|d} -c rept | -d ] { view opts .. | picture [zbuf] }\n",
166                          progname);
167 <        exit(1);
167 >        return(1);
168   }
169  
170  
# Line 162 | Line 173 | jitterloc(
173          RREAL   loc[2]
174   )
175   {
176 <        if (pj > FTINY) {
177 <                loc[0] += pj*(.5 - frandom())/rs.xr;
178 <                loc[1] += pj*(.5 - frandom())/rs.yr;
179 <        }
176 >        static int      nsamp;
177 >        double          xyr[2];
178 >
179 >        if (pj <= FTINY)
180 >                return;
181 >
182 >        if (repeatcnt == 1) {
183 >                xyr[0] = frandom();
184 >                xyr[1] = frandom();
185 >        } else                          /* stratify samples */
186 >                multisamp(xyr, 2, urand(nsamp++));
187 >
188 >        loc[0] += pj*(.5 - xyr[0])/rs.xr;
189 >        loc[1] += pj*(.5 - xyr[1])/rs.yr;
190   }
191  
192  
# Line 180 | Line 201 | pix2rays(
201          RREAL   loc[2];
202          int     pp[2];
203          double  d;
204 <        register int    i;
204 >        int     i, c;
205  
206          while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
207                  px += .5; py += .5;
208                  loc[0] = px/rs.xr; loc[1] = py/rs.yr;
209                  if (zfd >= 0) {
210 +                        if ((loc[0] < 0) | (loc[0] >= 1) |
211 +                                        (loc[1] < 0) | (loc[1] >= 1)) {
212 +                                fprintf(stderr, "%s: input pixel outside image\n",
213 +                                                progname);
214 +                                exit(1);
215 +                        }
216                          loc2pix(pp, &rs, loc[0], loc[1]);
217                          if (lseek(zfd,
218                                  (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
# Line 197 | Line 224 | pix2rays(
224                                  exit(1);
225                          }
226                  }
227 <                jitterloc(loc);
228 <                d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
229 <                if (d < -FTINY)
230 <                        rorg[0] = rorg[1] = rorg[2] =
231 <                        rdir[0] = rdir[1] = rdir[2] = 0.;
232 <                else if (zfd >= 0)
233 <                        for (i = 0; i < 3; i++) {
234 <                                rorg[i] += rdir[i]*zval;
235 <                                rdir[i] = -rdir[i];
227 >                for (c = repeatcnt; c-- > 0; ) {
228 >                        jitterloc(loc);
229 >                        d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
230 >                        if (d < -FTINY || !jitteraperture(rorg, rdir, &vw, pd))
231 >                                rorg[0] = rorg[1] = rorg[2] =
232 >                                rdir[0] = rdir[1] = rdir[2] = 0.;
233 >                        else if (zfd >= 0)
234 >                                for (i = 0; i < 3; i++) {
235 >                                        rorg[i] += rdir[i]*zval;
236 >                                        rdir[i] = -rdir[i];
237 >                                }
238 >                        else if (d > FTINY) {
239 >                                rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
240                          }
241 <                else if (d > FTINY) {
242 <                        rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
241 >                        (*putr)(rorg, rdir);
242 >                        if (c) {
243 >                                loc[0] = px/rs.xr; loc[1] = py/rs.yr;
244 >                        }
245                  }
246 <                (*putr)(rorg, rdir);
246 >                if (unbuffered)
247 >                        fflush(stdout);
248          }
249          if (!feof(fp)) {
250                  fprintf(stderr, "%s: expected px py on input\n", progname);
# Line 227 | Line 261 | putrays(void)
261          float   *zbuf = NULL;
262          int     sc;
263          double  d;
264 <        register int    si, i;
264 >        int     si, i, c;
265  
266          if (zfd >= 0) {
267                  zbuf = (float *)malloc(scanlen(&rs)*sizeof(float));
# Line 246 | Line 280 | putrays(void)
280                          }
281                  }
282                  for (si = 0; si < scanlen(&rs); si++) {
283 +                    for (c = repeatcnt; c-- > 0; ) {
284                          pix2loc(loc, &rs, si, sc);
285                          jitterloc(loc);
286                          d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
287 <                        if (d < -FTINY)
287 >                        if (d < -FTINY || !jitteraperture(rorg, rdir, &vw, pd))
288                                  rorg[0] = rorg[1] = rorg[2] =
289                                  rdir[0] = rdir[1] = rdir[2] = 0.;
290                          else if (zfd >= 0)
291                                  for (i = 0; i < 3; i++) {
292 <                                        rorg[i] += rdir[i]*zbuf[si];
293 <                                        rdir[i] = -rdir[i];
292 >                                        rdir[i] = -rdir[i]*zbuf[si];
293 >                                        rorg[i] -= rdir[i];
294                                  }
295                          else if (d > FTINY) {
296                                  rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
297                          }
298                          (*putr)(rorg, rdir);
299 +                    }
300                  }
301          }
302          if (zfd >= 0)
# Line 290 | Line 326 | putf(          /* put out ray in float format */
326  
327          v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2];
328          v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2];
329 <        fwrite(v, sizeof(float), 6, stdout);
329 >        putbinary(v, sizeof(float), 6, stdout);
330   }
331  
332  
# Line 304 | Line 340 | putd(          /* put out ray in double format */
340  
341          v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2];
342          v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2];
343 <        fwrite(v, sizeof(double), 6, stdout);
343 >        putbinary(v, sizeof(double), 6, stdout);
344   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines