20 |
|
#define vfork fork |
21 |
|
#endif |
22 |
|
|
23 |
< |
#define NSCANS 32 /* number of scanlines to buffer */ |
23 |
> |
#define NSCANS 64 /* number of scanlines to buffer */ |
24 |
|
|
25 |
|
int rt_pid = -1; /* process id for rtrace */ |
26 |
|
int fd_tort, fd_fromrt; /* pipe descriptors */ |
149 |
|
float *vb; |
150 |
|
{ |
151 |
|
float rt_buf[6*MAXPIX]; /* rtrace send/receive buffer */ |
152 |
< |
int npix_tort; /* number of pixels in buffer */ |
152 |
> |
register int n; /* number of pixels in buffer */ |
153 |
|
short buf_vh[MAXPIX]; /* pixel positions */ |
154 |
|
FVECT dir; |
155 |
|
register int vh; |
156 |
– |
register int i; |
156 |
|
|
157 |
+ |
#ifdef DEBUG |
158 |
|
if (verbose) |
159 |
|
fprintf(stderr, "%s: computing view span at %d...\n", |
160 |
|
progname, vv); |
161 |
< |
npix_tort = 0; |
161 |
> |
#endif |
162 |
> |
n = 0; |
163 |
|
for (vh = -hsize; vh <= hsize; vh++) { |
164 |
|
if (compdir(dir, vh, vv) < 0) { /* off viewable region */ |
165 |
|
vb[vh+hsize] = -1.0; |
170 |
|
if (rt_pid == -1) /* missing information */ |
171 |
|
continue; |
172 |
|
/* send to rtrace */ |
173 |
< |
if (npix_tort >= MAXPIX) { /* flush */ |
174 |
< |
rt_compute(rt_buf, npix_tort); |
175 |
< |
for (i = 0; i < npix_tort; i++) |
176 |
< |
vb[buf_vh[i]+hsize] = luminance(rt_buf+3*i); |
176 |
< |
npix_tort = 0; |
173 |
> |
if (n >= MAXPIX) { /* flush */ |
174 |
> |
rt_compute(rt_buf, n); |
175 |
> |
while (n-- > 0) |
176 |
> |
vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n); |
177 |
|
} |
178 |
< |
rt_buf[6*npix_tort] = ourview.vp[0]; |
179 |
< |
rt_buf[6*npix_tort+1] = ourview.vp[1]; |
180 |
< |
rt_buf[6*npix_tort+2] = ourview.vp[2]; |
181 |
< |
rt_buf[6*npix_tort+3] = dir[0]; |
182 |
< |
rt_buf[6*npix_tort+4] = dir[1]; |
183 |
< |
rt_buf[6*npix_tort+5] = dir[2]; |
184 |
< |
buf_vh[npix_tort++] = vh; |
178 |
> |
rt_buf[6*n] = ourview.vp[0]; |
179 |
> |
rt_buf[6*n+1] = ourview.vp[1]; |
180 |
> |
rt_buf[6*n+2] = ourview.vp[2]; |
181 |
> |
rt_buf[6*n+3] = dir[0]; |
182 |
> |
rt_buf[6*n+4] = dir[1]; |
183 |
> |
rt_buf[6*n+5] = dir[2]; |
184 |
> |
buf_vh[n++] = vh; |
185 |
|
} |
186 |
< |
if (npix_tort > 0) { /* process pending buffer */ |
187 |
< |
rt_compute(rt_buf, npix_tort); |
188 |
< |
for (i = 0; i < npix_tort; i++) |
189 |
< |
vb[buf_vh[i]+hsize] = luminance(rt_buf+3*i); |
190 |
< |
} |
186 |
> |
#ifdef DEBUG |
187 |
|
if (verbose) |
188 |
|
pict_stats(); |
189 |
+ |
#endif |
190 |
+ |
if (n > 0) { /* process pending buffer */ |
191 |
+ |
rt_compute(rt_buf, n); |
192 |
+ |
while (n-- > 0) |
193 |
+ |
vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n); |
194 |
+ |
} |
195 |
|
} |
196 |
|
|
197 |
|
|
201 |
|
{ |
202 |
|
static float nbuf[6] = {0.,0.,0.,0.,0.,0.}; |
203 |
|
|
204 |
+ |
#ifdef DEBUG |
205 |
|
if (verbose && np > 1) |
206 |
|
fprintf(stderr, "%s: sending %d samples to rtrace...\n", |
207 |
|
progname, np); |
208 |
+ |
#endif |
209 |
|
if (writebuf(fd_tort,(char *)pb,6*sizeof(float)*np) < 6*sizeof(float)*np |
210 |
|
|| writebuf(fd_tort,(char *)nbuf,sizeof(nbuf)) < sizeof(nbuf)) { |
211 |
|
fprintf(stderr, "%s: error writing to rtrace process\n", |
302 |
|
perror(progname); |
303 |
|
exit(1); |
304 |
|
} |
305 |
+ |
close(p0[0]); |
306 |
+ |
close(p1[1]); |
307 |
|
fd_tort = p0[1]; |
308 |
|
fd_fromrt = p1[0]; |
309 |
|
} |