ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/glareval.c
(Generate patch)

Comparing ray/src/util/glareval.c (file contents):
Revision 1.18 by greg, Wed Jun 26 13:35:16 1991 UTC vs.
Revision 1.21 by greg, Mon Nov 11 15:09:42 1991 UTC

# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include "glare.h"
12 < #include <sys/param.h>
13 <                                        /* compute rtrace buffer size */
14 < #ifndef PIPE_BUF
15 < #define PIPE_BUF        512             /* hyperconservative */
16 < #endif
17 < #define MAXPIX          (PIPE_BUF/(6*sizeof(float)) - 1)
12 > #include "resolu.h"
13 >                                        /* maximum rtrace buffer size */
14 > #define MAXPIX          (4096/(6*sizeof(float)))
15  
19 #ifndef BSD
20 #define vfork           fork
21 #endif
22
16   #define MAXSBUF         786432  /* maximum total size of scanline buffer */
17   #define HSIZE           317     /* size of scanline hash table */
18   #define NRETIRE         16      /* number of scanlines to retire at once */
19  
20 < int     rt_pid = -1;            /* process id for rtrace */
28 < int     fd_tort, fd_fromrt;     /* pipe descriptors */
20 > int     rt_pd[3] = {-1,-1,-1};  /* process id & descriptors for rtrace */
21  
22   FILE    *pictfp = NULL;         /* picture file pointer */
23   double  exposure;               /* picture exposure */
# Line 44 | Line 36 | typedef struct scan {
36   #define scandata(sl)    ((COLR *)((sl)+1))
37   #define shash(y)        ((y)%HSIZE)
38  
39 + static int      maxpix;         /* maximum number of pixels to buffer */
40 +
41   static SCAN     *freelist;              /* scanline free list */
42   static SCAN     *hashtab[HSIZE];        /* scanline hash table */
43  
# Line 160 | Line 154 | pict_val(vd)                   /* find picture value for view directio
154   FVECT   vd;
155   {
156          FVECT   pp;
157 <        double  vpx, vpy, vpz;
157 >        FVECT   ip;
158          COLOR   res;
159  
160          if (pictfp == NULL)
# Line 168 | Line 162 | FVECT  vd;
162          pp[0] = pictview.vp[0] + vd[0];
163          pp[1] = pictview.vp[1] + vd[1];
164          pp[2] = pictview.vp[2] + vd[2];
165 <        viewpixel(&vpx, &vpy, &vpz, &pictview, pp);
166 <        if (vpz <= FTINY || vpx < 0. || vpx >= 1. || vpy < 0. || vpy >= 1.)
165 >        viewloc(ip, &pictview, pp);
166 >        if (ip[2] <= FTINY || ip[0] < 0. || ip[0] >= 1. ||
167 >                        ip[1] < 0. || ip[1] >= 1.)
168                  return(-1.0);
169 <        colr_color(res, getpictscan((int)(vpy*pysiz))[(int)(vpx*pxsiz)]);
169 >        colr_color(res, getpictscan((int)(ip[1]*pysiz))[(int)(ip[0]*pxsiz)]);
170          return(luminance(res)/exposure);
171   }
172  
# Line 181 | Line 176 | getviewpix(vh, vv)             /* compute single view pixel */
176   int     vh, vv;
177   {
178          FVECT   dir;
179 <        float   rt_buf[6];
179 >        float   rt_buf[12];
180          double  res;
181  
182          if (compdir(dir, vh, vv) < 0)
# Line 189 | Line 184 | int    vh, vv;
184          npixinvw++;
185          if ((res = pict_val(dir)) >= 0.0)
186                  return(res);
187 <        if (rt_pid == -1) {
187 >        if (rt_pd[0] == -1) {
188                  npixmiss++;
189                  return(-1.0);
190          }
# Line 228 | Line 223 | float  *vb;
223                  npixinvw++;
224                  if ((vb[vh+hsize] = pict_val(dir)) >= 0.0)
225                          continue;
226 <                if (rt_pid == -1) {             /* missing information */
226 >                if (rt_pd[0] == -1) {           /* missing information */
227                          npixmiss++;
228                          continue;
229                  }
230                                                  /* send to rtrace */
231 <                if (n >= MAXPIX) {                      /* flush */
231 >                if (n >= maxpix) {                      /* flush */
232                          rt_compute(rt_buf, n);
233                          while (n-- > 0)
234                                  vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
# Line 262 | Line 257 | rt_compute(pb, np)             /* process buffer through rtrace *
257   float   *pb;
258   int     np;
259   {
265        static float    nbuf[6] = {0.,0.,0.,0.,0.,0.};
266
260   #ifdef DEBUG
261          if (verbose && np > 1)
262                  fprintf(stderr, "%s: sending %d samples to rtrace...\n",
263                                  progname, np);
264   #endif
265 <        if (writebuf(fd_tort,(char *)pb,6*sizeof(float)*np) < 6*sizeof(float)*np
266 <                || writebuf(fd_tort,(char *)nbuf,sizeof(nbuf)) < sizeof(nbuf)) {
267 <                fprintf(stderr, "%s: error writing to rtrace process\n",
265 >        bzero(pb+6*np, 6*sizeof(float));
266 >        if (process(rt_pd, pb, pb, 3*sizeof(float)*np,
267 >                        6*sizeof(float)*(np+1)) < 3*sizeof(float)*np) {
268 >                fprintf(stderr, "%s: rtrace communication error\n",
269                                  progname);
270                  exit(1);
271          }
278        if (readbuf(fd_fromrt, (char *)pb, 3*sizeof(float)*np)
279                        < 3*sizeof(float)*np) {
280                fprintf(stderr, "%s: error reading from rtrace process\n",
281                                progname);
282                exit(1);
283        }
272   }
273  
274  
# Line 307 | Line 295 | char   *fn;
295          }
296          exposure = 1.0;
297          getheader(pictfp, getexpos, NULL);
298 <        if (wrongformat ||
299 <                        fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) {
312 <                fprintf("%s: bad picture format\n", fn);
298 >        if (wrongformat || !fscnresolu(&pxsiz, &pysiz, pictfp)) {
299 >                fprintf(stderr, "%s: incompatible picture format\n", fn);
300                  exit(1);
301          }
302          initscans();
# Line 329 | Line 316 | close_pict()                   /* done with picture */
316   fork_rtrace(av)                 /* open pipe and start rtrace */
317   char    *av[];
318   {
319 <        int     p0[2], p1[2];
319 >        int     rval;
320  
321 <        if (pipe(p0) < 0 || pipe(p1) < 0) {
321 >        rval = open_process(rt_pd, av);
322 >        if (rval < 0) {
323                  perror(progname);
324                  exit(1);
325          }
326 <        if ((rt_pid = vfork()) == 0) {          /* if child */
327 <                close(p0[1]);
340 <                close(p1[0]);
341 <                if (p0[0] != 0) {       /* connect p0 to stdin */
342 <                        dup2(p0[0], 0);
343 <                        close(p0[0]);
344 <                }
345 <                if (p1[1] != 1) {       /* connect p1 to stdout */
346 <                        dup2(p1[1], 1);
347 <                        close(p1[1]);
348 <                }
349 <                execvp(av[0], av);
350 <                perror(av[0]);
351 <                _exit(127);
352 <        }
353 <        if (rt_pid == -1) {
354 <                perror(progname);
326 >        if (rval == 0) {
327 >                fprintf(stderr, "%s: command not found\n", av[0]);
328                  exit(1);
329          }
330 <        close(p0[0]);
331 <        close(p1[1]);
332 <        fd_tort = p0[1];
333 <        fd_fromrt = p1[0];
330 >        maxpix = rval/(6*sizeof(float));
331 >        if (maxpix > MAXPIX)
332 >                maxpix = MAXPIX;
333 >        maxpix--;
334   }
335  
336  
337   done_rtrace()                   /* wait for rtrace to finish */
338   {
339 <        int     pid, status;
339 >        int     status;
340  
341 <        if (rt_pid == -1)
342 <                return;
370 <        close(fd_tort);
371 <        close(fd_fromrt);
372 <        while ((pid = wait(&status)) != -1 && pid != rt_pid)
373 <                ;
374 <        if (pid == rt_pid && status != 0) {
341 >        status = close_process(rt_pd);
342 >        if (status > 0) {
343                  fprintf(stderr, "%s: bad status (%d) from rtrace\n",
344                                  progname, status);
345                  exit(1);
346          }
347 <        rt_pid = -1;
380 < }
381 <
382 <
383 < int
384 < readbuf(fd, bpos, siz)
385 < int     fd;
386 < char    *bpos;
387 < int     siz;
388 < {
389 <        register int    cc, nrem = siz;
390 <
391 <        while (nrem > 0 && (cc = read(fd, bpos, nrem)) > 0) {
392 <                bpos += cc;
393 <                nrem -= cc;
394 <        }
395 <        if (cc < 0)
396 <                return(cc);
397 <        return(siz-nrem);
398 < }
399 <
400 <
401 < int
402 < writebuf(fd, bpos, siz)
403 < char    *bpos;
404 < int     siz;
405 < {
406 <        register int    cc, nrem = siz;
407 <
408 <        while (nrem > 0 && (cc = write(fd, bpos, nrem)) > 0) {
409 <                bpos += cc;
410 <                nrem -= cc;
411 <        }
412 <        if (cc < 0)
413 <                return(cc);
414 <        return(siz-nrem);
347 >        rt_pd[0] = -1;
348   }
349  
350  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines