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.16 by greg, Sat Aug 20 20:57:52 2011 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   char    *progname;
37  
38  
# Line 53 | Line 58 | main(
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 96 | Line 103 | main(
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                  }
# Line 141 | Line 156 | main(
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   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   )
# Line 155 | Line 182 | pix2rays(
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) {
165 <                        fprintf(stderr,
166 <                                "%s: (x,y) pair (%.0f,%.0f) out of range\n",
167 <                                        progname, px, py);
168 <                        exit(1);
169 <                }
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),
197                                                  SEEK_SET) < 0 ||
# Line 179 | Line 202 | pix2rays(
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 192 | Line 216 | pix2rays(
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 203 | Line 229 | pix2rays(
229   static void
230   putrays(void)
231   {
232 <        static RREAL    loc[2];
233 <        static FVECT    rorg, rdir;
232 >        RREAL   loc[2];
233 >        FVECT   rorg, rdir;
234          float   *zbuf = NULL;
235          int     sc;
236          double  d;
# Line 228 | Line 254 | putrays(void)
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] =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines