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.1 by greg, Mon Mar 18 12:15:41 1991 UTC vs.
Revision 1.7 by greg, Tue Apr 2 14:29:17 1991 UTC

# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20   #define vfork           fork
21   #endif
22  
23 < #define NSCANS          16              /* 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 */
# Line 36 | Line 36 | struct {
36          COLR    *sl;            /* scanline contents */
37   } scan[NSCANS];         /* buffered scanlines */
38  
39 + static long     ncall = 0L;     /* number of calls to getpictscan */
40 + static long     nread = 0L;     /* number of scanlines read */
41  
42 + extern long     ftell();
43 +
44 +
45   COLR *
46   getpictscan(y)                  /* get picture scanline */
47   int     y;
48   {
44        extern long     ftell();
45        static long     ncall = 0;
49          int     minused;
50          register int    i;
51                                          /* first check our buffers */
# Line 57 | Line 60 | int    y;
60                          minused = i;
61          }
62                                          /* not there, read it in */
63 <        if (scanpos[y] == -1) {                 /* need to search */
64 <                if (verbose)
65 <                        fprintf(stderr, "%s: reading picture...\n",
66 <                                        progname);
67 <                while (curpos > y) {
63 >        if (scanpos[y] < 0) {                   /* need to search */
64 >                for (i = y+1; i < curpos; i++)
65 >                        if (scanpos[i] >= 0) {
66 >                                if (fseek(pictfp, scanpos[i], 0) < 0)
67 >                                        goto seekerr;
68 >                                curpos = i;
69 >                                break;
70 >                        }
71 >                while (curpos >= y) {
72                          scanpos[curpos] = ftell(pictfp);
73                          if (freadcolrs(scan[minused].sl, pxsiz, pictfp) < 0)
74                                  goto readerr;
75 +                        nread++;
76                          curpos--;
77                  }
78 <        } else if (fseek(pictfp, scanpos[y], 0) < 0) {
79 <                fprintf(stderr, "%s: picture seek error\n", progname);
80 <                exit(1);
78 >        } else {
79 >                if (curpos != y && fseek(pictfp, scanpos[y], 0) < 0)
80 >                        goto seekerr;
81 >                if (freadcolrs(scan[minused].sl, pxsiz, pictfp) < 0)
82 >                        goto readerr;
83 >                nread++;
84 >                curpos = y-1;
85          }
74        if (verbose)
75                fprintf(stderr, "%s: reading scanline %d...\n", progname, y);
76        if (freadcolrs(scan[minused].sl, pxsiz, pictfp) < 0)
77                goto readerr;
78        curpos = y-1;
86          scan[minused].lused = ncall;
87          scan[minused].y = y;
88          return(scan[minused].sl);
89   readerr:
90          fprintf(stderr, "%s: picture read error\n", progname);
91          exit(1);
92 + seekerr:
93 +        fprintf(stderr, "%s: picture seek error\n", progname);
94 +        exit(1);
95   }
96  
97  
98 + #ifdef DEBUG
99 + pict_stats()                    /* print out picture read statistics */
100 + {
101 +        static long     lastcall = 0L;  /* ncall at last report */
102 +        static long     lastread = 0L;  /* nread at last report */
103 +
104 +        if (ncall == lastcall)
105 +                return;
106 +        fprintf(stderr, "%s: %ld scanlines read in %ld calls\n",
107 +                        progname, nread-lastread, ncall-lastcall);
108 +        lastcall = ncall;
109 +        lastread = nread;
110 + }
111 + #endif
112 +
113 +
114   double
115   pict_val(vd)                    /* find picture value for view direction */
116   FVECT   vd;
# Line 116 | Line 142 | int    vh, vv;
142  
143          if (compdir(dir, vh, vv) < 0)
144                  return(-1.0);
145 +        npixinvw++;
146          if ((res = pict_val(dir)) >= 0.0)
147                  return(res);
148 <        if (rt_pid == -1)
148 >        if (rt_pid == -1) {
149 >                npixmiss++;
150                  return(-1.0);
151 +        }
152          rt_buf[0] = ourview.vp[0];
153          rt_buf[1] = ourview.vp[1];
154          rt_buf[2] = ourview.vp[2];
# Line 136 | Line 165 | int    vv;
165   float   *vb;
166   {
167          float   rt_buf[6*MAXPIX];       /* rtrace send/receive buffer */
168 <        int     npix_tort;              /* number of pixels in buffer */
168 >        register int    n;              /* number of pixels in buffer */
169          short   buf_vh[MAXPIX];         /* pixel positions */
170          FVECT   dir;
171          register int    vh;
143        register int    i;
172  
173 + #ifdef DEBUG
174          if (verbose)
175                  fprintf(stderr, "%s: computing view span at %d...\n",
176                                  progname, vv);
177 <        npix_tort = 0;
177 > #endif
178 >        n = 0;
179          for (vh = -hsize; vh <= hsize; vh++) {
180                  if (compdir(dir, vh, vv) < 0) { /* off viewable region */
181                          vb[vh+hsize] = -1.0;
182                          continue;
183                  }
184 +                npixinvw++;
185                  if ((vb[vh+hsize] = pict_val(dir)) >= 0.0)
186                          continue;
187 <                if (rt_pid == -1)               /* missing information */
187 >                if (rt_pid == -1) {             /* missing information */
188 >                        npixmiss++;
189                          continue;
190 +                }
191                                                  /* send to rtrace */
192 <                if (npix_tort >= MAXPIX) {              /* flush */
193 <                        rt_compute(rt_buf, npix_tort);
194 <                        for (i = 0; i < npix_tort; i++)
195 <                                vb[buf_vh[i]+hsize] = luminance(rt_buf+3*i);
163 <                        npix_tort = 0;
192 >                if (n >= MAXPIX) {                      /* flush */
193 >                        rt_compute(rt_buf, n);
194 >                        while (n-- > 0)
195 >                                vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
196                  }
197 <                rt_buf[npix_tort] = ourview.vp[0];
198 <                rt_buf[npix_tort+1] = ourview.vp[1];
199 <                rt_buf[npix_tort+2] = ourview.vp[2];
200 <                rt_buf[npix_tort+3] = dir[0];
201 <                rt_buf[npix_tort+4] = dir[1];
202 <                rt_buf[npix_tort+5] = dir[2];
203 <                buf_vh[npix_tort++] = vh;
197 >                rt_buf[6*n] = ourview.vp[0];
198 >                rt_buf[6*n+1] = ourview.vp[1];
199 >                rt_buf[6*n+2] = ourview.vp[2];
200 >                rt_buf[6*n+3] = dir[0];
201 >                rt_buf[6*n+4] = dir[1];
202 >                rt_buf[6*n+5] = dir[2];
203 >                buf_vh[n++] = vh;
204          }
205 <        if (npix_tort > 0) {                    /* process pending buffer */
206 <                rt_compute(rt_buf, npix_tort);
207 <                for (i = 0; i < npix_tort; i++)
208 <                        vb[buf_vh[i]+hsize] = luminance(rt_buf+3*i);
205 > #ifdef DEBUG
206 >        if (verbose)
207 >                pict_stats();
208 > #endif
209 >        if (n > 0) {                            /* process pending buffer */
210 >                rt_compute(rt_buf, n);
211 >                while (n-- > 0)
212 >                        vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
213          }
214   }
215  
# Line 184 | Line 220 | int    np;
220   {
221          static float    nbuf[6] = {0.,0.,0.,0.,0.,0.};
222  
223 + #ifdef DEBUG
224          if (verbose && np > 1)
225                  fprintf(stderr, "%s: sending %d samples to rtrace...\n",
226                                  progname, np);
227 + #endif
228          if (writebuf(fd_tort,(char *)pb,6*sizeof(float)*np) < 6*sizeof(float)*np
229                  || writebuf(fd_tort,(char *)nbuf,sizeof(nbuf)) < sizeof(nbuf)) {
230                  fprintf(stderr, "%s: error writing to rtrace process\n",
# Line 228 | Line 266 | char   *fn;
266          scanpos = (long *)malloc(pysiz*sizeof(long));
267          if (scanpos == NULL)
268                  memerr("scanline positions");
269 <        for (i = 0; i < pysiz; i++)
269 >        for (i = pysiz-1; i >= 0; i--)
270                  scanpos[i] = -1L;
271 +        curpos = pysiz-1;
272          for (i = 0; i < NSCANS; i++) {
273                  scan[i].lused = -1;
274                  scan[i].y = -1;
# Line 237 | Line 276 | char   *fn;
276                  if (scan[i].sl == NULL)
277                          memerr("scanline buffers");
278          }
240        curpos = pysiz-1;
279   }
280  
281  
# Line 283 | Line 321 | char   *av[];
321                  perror(progname);
322                  exit(1);
323          }
324 +        close(p0[0]);
325 +        close(p1[1]);
326          fd_tort = p0[1];
327          fd_fromrt = p1[0];
328   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines