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 2.2 by greg, Sun Jun 21 17:52:58 1992 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  
44 + static long     scanbufsiz;             /* size of allocated scanline buffer */
45 +
46   static long     ncall = 0L;     /* number of calls to getpictscan */
47   static long     nread = 0L;     /* number of scanlines read */
48   static long     nrecl = 0L;     /* number of scanlines reclaimed */
# Line 160 | Line 156 | pict_val(vd)                   /* find picture value for view directio
156   FVECT   vd;
157   {
158          FVECT   pp;
159 <        double  vpx, vpy, vpz;
159 >        FVECT   ip;
160          COLOR   res;
161  
162          if (pictfp == NULL)
# Line 168 | Line 164 | FVECT  vd;
164          pp[0] = pictview.vp[0] + vd[0];
165          pp[1] = pictview.vp[1] + vd[1];
166          pp[2] = pictview.vp[2] + vd[2];
167 <        viewpixel(&vpx, &vpy, &vpz, &pictview, pp);
168 <        if (vpz <= FTINY || vpx < 0. || vpx >= 1. || vpy < 0. || vpy >= 1.)
167 >        viewloc(ip, &pictview, pp);
168 >        if (ip[2] <= FTINY || ip[0] < 0. || ip[0] >= 1. ||
169 >                        ip[1] < 0. || ip[1] >= 1.)
170                  return(-1.0);
171 <        colr_color(res, getpictscan((int)(vpy*pysiz))[(int)(vpx*pxsiz)]);
171 >        colr_color(res, getpictscan((int)(ip[1]*pysiz))[(int)(ip[0]*pxsiz)]);
172          return(luminance(res)/exposure);
173   }
174  
# Line 181 | Line 178 | getviewpix(vh, vv)             /* compute single view pixel */
178   int     vh, vv;
179   {
180          FVECT   dir;
181 <        float   rt_buf[6];
181 >        float   rt_buf[12];
182          double  res;
183  
184          if (compdir(dir, vh, vv) < 0)
# Line 189 | Line 186 | int    vh, vv;
186          npixinvw++;
187          if ((res = pict_val(dir)) >= 0.0)
188                  return(res);
189 <        if (rt_pid == -1) {
189 >        if (rt_pd[0] == -1) {
190                  npixmiss++;
191                  return(-1.0);
192          }
# Line 228 | Line 225 | float  *vb;
225                  npixinvw++;
226                  if ((vb[vh+hsize] = pict_val(dir)) >= 0.0)
227                          continue;
228 <                if (rt_pid == -1) {             /* missing information */
228 >                if (rt_pd[0] == -1) {           /* missing information */
229                          npixmiss++;
230                          continue;
231                  }
232                                                  /* send to rtrace */
233 <                if (n >= MAXPIX) {                      /* flush */
233 >                if (n >= maxpix) {                      /* flush */
234                          rt_compute(rt_buf, n);
235                          while (n-- > 0)
236                                  vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
# Line 262 | Line 259 | rt_compute(pb, np)             /* process buffer through rtrace *
259   float   *pb;
260   int     np;
261   {
265        static float    nbuf[6] = {0.,0.,0.,0.,0.,0.};
266
262   #ifdef DEBUG
263          if (verbose && np > 1)
264                  fprintf(stderr, "%s: sending %d samples to rtrace...\n",
265                                  progname, np);
266   #endif
267 <        if (writebuf(fd_tort,(char *)pb,6*sizeof(float)*np) < 6*sizeof(float)*np
268 <                || writebuf(fd_tort,(char *)nbuf,sizeof(nbuf)) < sizeof(nbuf)) {
269 <                fprintf(stderr, "%s: error writing to rtrace process\n",
267 >        bzero(pb+6*np, 6*sizeof(float));
268 >        if (process(rt_pd, pb, pb, 3*sizeof(float)*np,
269 >                        6*sizeof(float)*(np+1)) < 3*sizeof(float)*np) {
270 >                fprintf(stderr, "%s: rtrace communication error\n",
271                                  progname);
272                  exit(1);
273          }
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        }
274   }
275  
276  
# Line 307 | Line 297 | char   *fn;
297          }
298          exposure = 1.0;
299          getheader(pictfp, getexpos, NULL);
300 <        if (wrongformat ||
301 <                        fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) {
312 <                fprintf("%s: bad picture format\n", fn);
300 >        if (wrongformat || !fscnresolu(&pxsiz, &pysiz, pictfp)) {
301 >                fprintf(stderr, "%s: incompatible picture format\n", fn);
302                  exit(1);
303          }
304          initscans();
# Line 329 | Line 318 | close_pict()                   /* done with picture */
318   fork_rtrace(av)                 /* open pipe and start rtrace */
319   char    *av[];
320   {
321 <        int     p0[2], p1[2];
321 >        int     rval;
322  
323 <        if (pipe(p0) < 0 || pipe(p1) < 0) {
323 >        rval = open_process(rt_pd, av);
324 >        if (rval < 0) {
325                  perror(progname);
326                  exit(1);
327          }
328 <        if ((rt_pid = vfork()) == 0) {          /* if child */
329 <                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);
328 >        if (rval == 0) {
329 >                fprintf(stderr, "%s: command not found\n", av[0]);
330                  exit(1);
331          }
332 <        close(p0[0]);
333 <        close(p1[1]);
334 <        fd_tort = p0[1];
335 <        fd_fromrt = p1[0];
332 >        maxpix = rval/(6*sizeof(float));
333 >        if (maxpix > MAXPIX)
334 >                maxpix = MAXPIX;
335 >        maxpix--;
336   }
337  
338  
339   done_rtrace()                   /* wait for rtrace to finish */
340   {
341 <        int     pid, status;
341 >        int     status;
342  
343 <        if (rt_pid == -1)
344 <                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) {
343 >        status = close_process(rt_pd);
344 >        if (status > 0) {
345                  fprintf(stderr, "%s: bad status (%d) from rtrace\n",
346                                  progname, status);
347                  exit(1);
348          }
349 <        rt_pid = -1;
349 >        rt_pd[0] = -1;
350   }
351  
352  
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);
415 }
416
417
353   SCAN *
354   scanretire()                    /* retire old scanlines to free list */
355   {
# Line 465 | Line 400 | initscans()                            /* initialize scanline buffers */
400          register SCAN   *ptr;
401          register int    i;
402                                          /* initialize positions */
403 <        scanpos = (long *)malloc(pysiz*sizeof(long));
403 >        scanpos = (long *)bmalloc(pysiz*sizeof(long));
404          if (scanpos == NULL)
405                  memerr("scanline positions");
406          for (i = pysiz-1; i >= 0; i--)
# Line 482 | Line 417 | initscans()                            /* initialize scanline buffers */
417          i = MAXSBUF / scansize;         /* compute number to allocate */
418          if (i > HSIZE)
419                  i = HSIZE;
420 <        scan_buf = malloc(i*scansize);  /* get in one big chunk */
420 >        scanbufsiz = i*scansize;
421 >        scan_buf = bmalloc(scanbufsiz); /* get in one big chunk */
422          if (scan_buf == NULL)
423                  memerr("scanline buffers");
424          ptr = (SCAN *)scan_buf;
# Line 499 | Line 435 | initscans()                            /* initialize scanline buffers */
435  
436   donescans()                             /* free up scanlines */
437   {
438 <        free(scan_buf);
439 <        free((char *)scanpos);
438 >        bfree(scan_buf, scanbufsiz);
439 >        bfree((char *)scanpos, pysiz*sizeof(long));
440   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines