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.10 by schorsch, Fri Mar 26 23:34:23 2004 UTC vs.
Revision 3.25 by greg, Fri Jan 12 17:29:10 2024 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7  
8   #include "platform.h"
9   #include "standard.h"
10 + #include "random.h"
11   #include "view.h"
12  
13   typedef void putfunc(FVECT ro, FVECT rd);
# Line 24 | Line 25 | RESOLU rs = {PIXSTANDARD, 512, 512};
25  
26   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 + int     unbuffered = 0;
37 +
38 + int     repeatcnt = 1;
39 +
40   char    *progname;
41  
42  
# Line 39 | Line 48 | main(
48   {
49          char    *err;
50          int     rval, getdim = 0;
51 <        register int    i;
51 >        int     i;
52  
53          progname = argv[0];
54          if (argc < 2)
# Line 53 | Line 62 | main(
62                                  break;
63                          case 'f':                       /* float */
64                                  putr = putf;
65 +                                SET_FILE_BINARY(stdout);
66                                  break;
67                          case 'd':                       /* double */
68                                  putr = putd;
69 +                                SET_FILE_BINARY(stdout);
70                                  break;
71                          default:
72                                  goto userr;
# Line 68 | Line 79 | main(
79                                          fprintf(stderr,
80                                                  "%s: no view in file\n",
81                                                          argv[i]);
82 <                                        exit(1);
82 >                                        return(1);
83                                  }
84                                  break;
85                          }
# Line 85 | Line 96 | main(
96                          if (rs.xr <= 0) {
97                                  fprintf(stderr, "%s: bad x resolution\n",
98                                                  progname);
99 <                                exit(1);
99 >                                return(1);
100                          }
101                          break;
102                  case 'y':                       /* y resolution */
# Line 93 | Line 104 | main(
104                          if (rs.yr <= 0) {
105                                  fprintf(stderr, "%s: bad y resolution\n",
106                                                  progname);
107 <                                exit(1);
107 >                                return(1);
108                          }
109                          break;
110 <                case 'p':                       /* pixel aspect ratio */
111 <                        pa = atof(argv[++i]);
110 >                case 'c':                       /* repeat count */
111 >                        repeatcnt = atoi(argv[++i]);
112 >                        if (repeatcnt < 1) repeatcnt = 1;
113                          break;
114 +                case 'p':                       /* pixel aspect or jitter */
115 +                        if (argv[i][2] == 'a')
116 +                                pa = atof(argv[++i]);
117 +                        else if (argv[i][2] == 'j')
118 +                                pj = atof(argv[++i]);
119 +                        else if (argv[i][2] == 'd')
120 +                                pd = atof(argv[++i]);
121 +                        else
122 +                                goto userr;
123 +                        break;
124                  case 'i':                       /* get pixels from stdin */
125                          fromstdin = 1;
126                          break;
127 +                case 'u':                       /* unbuffered output */
128 +                        unbuffered = 1;
129 +                        break;
130                  default:
131                          goto userr;
132                  }
# Line 111 | Line 136 | main(
136                  rval = viewfile(argv[i], &vw, &rs);
137                  if (rval <= 0) {
138                          fprintf(stderr, "%s: no view in picture\n", argv[i]);
139 <                        exit(1);
139 >                        return(1);
140                  }
141 <                if (i+1 < argc) {
142 <                        zfd = open(argv[i+1], O_RDONLY);
143 <                        if (zfd < 0) {
144 <                                fprintf(stderr,
120 <                                        "%s: cannot open depth buffer\n",
121 <                                                argv[i+1]);
122 <                                exit(1);
123 <                        }
141 >                if (!getdim & (i+1 < argc)) {
142 >                        zfd = open_float_depth(argv[i+1], (long)rs.xr*rs.yr);
143 >                        if (zfd < 0)
144 >                                return(1);
145                  }
146          }
147          if ((err = setview(&vw)) != NULL) {
148                  fprintf(stderr, "%s: %s\n", progname, err);
149 <                exit(1);
149 >                return(1);
150          }
151          if (i == argc)
152                  normaspect(viewaspect(&vw), &pa, &rs.xr, &rs.yr);
153          if (getdim) {
154 <                printf("-x %d -y %d -ld%c\n", rs.xr, rs.yr,
155 <                                vw.vaft > FTINY ? '+' : '-');
156 <                exit(0);
154 >                printf("-x %d -y %d%s\n", rs.xr, rs.yr,
155 >                                (vw.vaft > FTINY) ? " -ld+" : "");
156 >                return(0);
157          }
158 +        if ((repeatcnt > 1) & (pj > FTINY))
159 +                initurand(1024);
160          if (fromstdin)
161                  pix2rays(stdin);
162          else
163                  putrays();
164 <        exit(0);
164 >        return(0);
165   userr:
166          fprintf(stderr,
167 <        "Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
167 >        "Usage: %s [ -i -u -f{a|f|d} -c rept | -d ] { view opts .. | picture [zbuf] }\n",
168                          progname);
169 <        exit(1);
169 >        return(1);
170   }
171  
172  
173   static void
174 + jitterloc(
175 +        RREAL   loc[2]
176 + )
177 + {
178 +        static int      nsamp;
179 +        double          xyr[2];
180 +
181 +        if (pj <= FTINY)
182 +                return;
183 +
184 +        if (repeatcnt == 1) {
185 +                xyr[0] = frandom();
186 +                xyr[1] = frandom();
187 +        } else                          /* stratify samples */
188 +                multisamp(xyr, 2, urand(nsamp++));
189 +
190 +        loc[0] += pj*(.5 - xyr[0])/rs.xr;
191 +        loc[1] += pj*(.5 - xyr[1])/rs.yr;
192 + }
193 +
194 +
195 + static void
196   pix2rays(
197          FILE *fp
198   )
# Line 155 | Line 200 | pix2rays(
200          static FVECT    rorg, rdir;
201          float   zval;
202          double  px, py;
203 +        RREAL   loc[2];
204          int     pp[2];
205          double  d;
206 <        register int    i;
206 >        int     i, c;
207  
208          while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
209 <                if (px < 0 || px >= rs.xr ||
210 <                                py < 0 || py >= rs.yr) {
165 <                        fprintf(stderr,
166 <                                "%s: (x,y) pair (%.0f,%.0f) out of range\n",
167 <                                        progname, px, py);
168 <                        exit(1);
169 <                }
209 >                px += .5; py += .5;
210 >                loc[0] = px/rs.xr; loc[1] = py/rs.yr;
211                  if (zfd >= 0) {
212 <                        loc2pix(pp, &rs, px/rs.xr, py/rs.yr);
212 >                        if ((loc[0] < 0) | (loc[0] >= 1) |
213 >                                        (loc[1] < 0) | (loc[1] >= 1)) {
214 >                                fprintf(stderr, "%s: input pixel outside image\n",
215 >                                                progname);
216 >                                exit(1);
217 >                        }
218 >                        loc2pix(pp, &rs, loc[0], loc[1]);
219                          if (lseek(zfd,
220                                  (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
221                                                  SEEK_SET) < 0 ||
# Line 179 | Line 226 | pix2rays(
226                                  exit(1);
227                          }
228                  }
229 <                d = viewray(rorg, rdir, &vw, px/rs.xr, py/rs.yr);
230 <                if (d < -FTINY)
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];
229 >                for (c = repeatcnt; c-- > 0; ) {
230 >                        jitterloc(loc);
231 >                        d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
232 >                        if (d < -FTINY || !jitteraperture(rorg, rdir, &vw, pd))
233 >                                rorg[0] = rorg[1] = rorg[2] =
234 >                                rdir[0] = rdir[1] = rdir[2] = 0.;
235 >                        else if (zfd >= 0)
236 >                                for (i = 0; i < 3; i++) {
237 >                                        rorg[i] += rdir[i]*zval;
238 >                                        rdir[i] = -rdir[i];
239 >                                }
240 >                        else if (d > FTINY) {
241 >                                rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
242                          }
243 <                else if (d > FTINY) {
244 <                        rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
243 >                        (*putr)(rorg, rdir);
244 >                        if (c) {
245 >                                loc[0] = px/rs.xr; loc[1] = py/rs.yr;
246 >                        }
247                  }
248 <                (*putr)(rorg, rdir);
248 >                if (unbuffered)
249 >                        fflush(stdout);
250          }
251          if (!feof(fp)) {
252                  fprintf(stderr, "%s: expected px py on input\n", progname);
# Line 203 | Line 258 | pix2rays(
258   static void
259   putrays(void)
260   {
261 <        static RREAL    loc[2];
262 <        static FVECT    rorg, rdir;
261 >        RREAL   loc[2];
262 >        FVECT   rorg, rdir;
263          float   *zbuf = NULL;
264          int     sc;
265          double  d;
266 <        register int    si, i;
266 >        int     si, i, c;
267  
268          if (zfd >= 0) {
269                  zbuf = (float *)malloc(scanlen(&rs)*sizeof(float));
# Line 227 | Line 282 | putrays(void)
282                          }
283                  }
284                  for (si = 0; si < scanlen(&rs); si++) {
285 +                    for (c = repeatcnt; c-- > 0; ) {
286                          pix2loc(loc, &rs, si, sc);
287 +                        jitterloc(loc);
288                          d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
289 <                        if (d < -FTINY)
289 >                        if (d < -FTINY || !jitteraperture(rorg, rdir, &vw, pd))
290                                  rorg[0] = rorg[1] = rorg[2] =
291                                  rdir[0] = rdir[1] = rdir[2] = 0.;
292                          else if (zfd >= 0)
293                                  for (i = 0; i < 3; i++) {
294 <                                        rorg[i] += rdir[i]*zbuf[si];
295 <                                        rdir[i] = -rdir[i];
294 >                                        rdir[i] = -rdir[i]*zbuf[si];
295 >                                        rorg[i] -= rdir[i];
296                                  }
297                          else if (d > FTINY) {
298                                  rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
299                          }
300                          (*putr)(rorg, rdir);
301 +                    }
302                  }
303          }
304          if (zfd >= 0)
# Line 270 | Line 328 | putf(          /* put out ray in float format */
328  
329          v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2];
330          v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2];
331 <        fwrite(v, sizeof(float), 6, stdout);
331 >        putbinary(v, sizeof(float), 6, stdout);
332   }
333  
334  
# Line 284 | Line 342 | putd(          /* put out ray in double format */
342  
343          v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2];
344          v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2];
345 <        fwrite(v, sizeof(double), 6, stdout);
345 >        putbinary(v, sizeof(double), 6, stdout);
346   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines