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.11 by greg, Thu Jan 20 23:52:02 2005 UTC vs.
Revision 3.17 by greg, Thu Jun 14 05:19:05 2012 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   int     zfd = -1;
31  
32   int     fromstdin = 0;
33  
34 + int     unbuffered = 0;
35 +
36 + int     repeatcnt = 1;
37 +
38   char    *progname;
39  
40  
# Line 39 | Line 46 | main(
46   {
47          char    *err;
48          int     rval, getdim = 0;
49 <        register int    i;
49 >        int     i;
50  
51          progname = argv[0];
52          if (argc < 2)
# Line 53 | Line 60 | main(
60                                  break;
61                          case 'f':                       /* float */
62                                  putr = putf;
63 +                                SET_FILE_BINARY(stdout);
64                                  break;
65                          case 'd':                       /* double */
66                                  putr = putd;
67 +                                SET_FILE_BINARY(stdout);
68                                  break;
69                          default:
70                                  goto userr;
# Line 96 | Line 105 | main(
105                                  exit(1);
106                          }
107                          break;
108 <                case 'p':                       /* pixel aspect ratio */
109 <                        pa = atof(argv[++i]);
108 >                case 'c':                       /* repeat count */
109 >                        repeatcnt = atoi(argv[++i]);
110                          break;
111 +                case 'p':                       /* pixel aspect or jitter */
112 +                        if (argv[i][2] == 'a')
113 +                                pa = atof(argv[++i]);
114 +                        else if (argv[i][2] == 'j')
115 +                                pj = atof(argv[++i]);
116 +                        else
117 +                                goto userr;
118 +                        break;
119                  case 'i':                       /* get pixels from stdin */
120                          fromstdin = 1;
121                          break;
122 +                case 'u':                       /* unbuffered output */
123 +                        unbuffered = 1;
124 +                        break;
125                  default:
126                          goto userr;
127                  }
# Line 141 | Line 161 | main(
161          exit(0);
162   userr:
163          fprintf(stderr,
164 <        "Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
164 >        "Usage: %s [ -i -u -f{a|f|d} -c rept | -d ] { view opts .. | picture [zbuf] }\n",
165                          progname);
166          exit(1);
167   }
168  
169  
170   static void
171 + jitterloc(
172 +        RREAL   loc[2]
173 + )
174 + {
175 +        if (pj > FTINY) {
176 +                loc[0] += pj*(.5 - frandom())/rs.xr;
177 +                loc[1] += pj*(.5 - frandom())/rs.yr;
178 +        }
179 + }
180 +
181 +
182 + static void
183   pix2rays(
184          FILE *fp
185   )
# Line 155 | Line 187 | pix2rays(
187          static FVECT    rorg, rdir;
188          float   zval;
189          double  px, py;
190 +        RREAL   loc[2];
191          int     pp[2];
192          double  d;
193 <        register int    i;
193 >        int     i;
194  
195          while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
196                  px += .5; py += .5;
197 <                if (px < 0 || px >= rs.xr ||
165 <                                py < 0 || py >= rs.yr) {
166 <                        fprintf(stderr,
167 <                                "%s: (x,y) pair (%.0f,%.0f) out of range\n",
168 <                                        progname, px, py);
169 <                        exit(1);
170 <                }
197 >                loc[0] = px/rs.xr; loc[1] = py/rs.yr;
198                  if (zfd >= 0) {
199 <                        loc2pix(pp, &rs, px/rs.xr, py/rs.yr);
199 >                        loc2pix(pp, &rs, loc[0], loc[1]);
200                          if (lseek(zfd,
201                                  (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
202                                                  SEEK_SET) < 0 ||
# Line 180 | Line 207 | pix2rays(
207                                  exit(1);
208                          }
209                  }
210 <                d = viewray(rorg, rdir, &vw, px/rs.xr, py/rs.yr);
210 >                jitterloc(loc);
211 >                d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
212                  if (d < -FTINY)
213                          rorg[0] = rorg[1] = rorg[2] =
214                          rdir[0] = rdir[1] = rdir[2] = 0.;
# Line 193 | Line 221 | pix2rays(
221                          rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
222                  }
223                  (*putr)(rorg, rdir);
224 +                if (unbuffered)
225 +                        fflush(stdout);
226          }
227          if (!feof(fp)) {
228                  fprintf(stderr, "%s: expected px py on input\n", progname);
# Line 204 | Line 234 | pix2rays(
234   static void
235   putrays(void)
236   {
237 <        static RREAL    loc[2];
238 <        static FVECT    rorg, rdir;
237 >        RREAL   loc[2];
238 >        FVECT   rorg, rdir;
239          float   *zbuf = NULL;
240          int     sc;
241          double  d;
242 <        register int    si, i;
242 >        int     si, i, c;
243  
244          if (zfd >= 0) {
245                  zbuf = (float *)malloc(scanlen(&rs)*sizeof(float));
# Line 228 | Line 258 | putrays(void)
258                          }
259                  }
260                  for (si = 0; si < scanlen(&rs); si++) {
261 +                    for (c = repeatcnt; c-- > 0; ) {
262                          pix2loc(loc, &rs, si, sc);
263 +                        jitterloc(loc);
264                          d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
265                          if (d < -FTINY)
266                                  rorg[0] = rorg[1] = rorg[2] =
# Line 242 | Line 274 | putrays(void)
274                                  rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
275                          }
276                          (*putr)(rorg, rdir);
277 +                    }
278                  }
279          }
280          if (zfd >= 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines