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

Comparing ray/src/hd/rholo3.c (file contents):
Revision 3.28 by gwlarson, Sat Jan 9 09:17:10 1999 UTC vs.
Revision 3.32 by gwlarson, Thu Mar 4 15:44:10 1999 UTC

# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ SGI";
9   */
10  
11   #include "rholo.h"
12 + #include "view.h"
13   #include <sys/types.h>
14  
15   #ifndef NFRAG2CHUNK
# Line 26 | Line 27 | static char SCCSid[] = "$SunId$ SGI";
27  
28   extern time_t   time();
29  
30 + int     chunkycmp = 0;          /* clump beams together on disk */
31 +
32   static PACKHEAD *complist=NULL; /* list of beams to compute */
33   static int      complen=0;      /* length of complist */
34   static int      listpos=0;      /* current list position for next_packet */
35   static int      lastin= -1;     /* last ordered position in list */
33 static int      chunky=0;       /* clump beams together on disk */
36  
37  
38   int
# Line 40 | Line 42 | register PACKHEAD      *b0, *b1;
42          BEAMI   *bip0, *bip1;
43          register long   c;
44                                          /* first check desired quantities */
45 <        if (chunky)
45 >        if (chunkycmp)
46                  c = rchunk(b1->nr)*(rchunk(b0->nc)+1L) -
47                                  rchunk(b0->nr)*(rchunk(b1->nc)+1L);
48          else
# Line 91 | Line 93 | register HDBEAMI       *hb;
93                  n = b->nrm;
94                  if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n));
95                  else p = (PACKHEAD *)realloc((char *)p, packsiz(n));
96 <                if (p == NULL)
95 <                        error(SYSTEM, "out of memory in dispbeam");
96 >                CHECK(p==NULL, SYSTEM, "out of memory in dispbeam");
97          }
98                                          /* assign packet fields */
99          bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL));
# Line 102 | Line 103 | register HDBEAMI       *hb;
103                          error(CONSISTENCY, "unregistered holodeck in dispbeam");
104          p->bi = hb->b;
105          disp_packet(p);                 /* display it */
106 +        if (n >= 1024) {                /* free ridiculous packets */
107 +                free((char *)p);
108 +                p = NULL; n = 0;
109 +        }
110   }
111  
112  
# Line 130 | Line 135 | int    nents;
135                          complist[i].nr += csm->nr;
136                          csm->nr = 0;
137                          break;
138 +                case BS_MAX:            /* maximum of counts */
139 +                        if (csm->nr > complist[i].nr)
140 +                                complist[i].nr = csm->nr;
141 +                        csm->nr = 0;
142 +                        break;
143                  case BS_ADJ:            /* reset count */
144                          complist[i].nr = csm->nr;
145                          csm->nr = 0;
# Line 163 | Line 173 | int    nents;
173                  bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD));
174                  break;
175          case BS_ADD:                    /* add to computation set */
176 +        case BS_MAX:                    /* maximum of quantities */
177          case BS_ADJ:                    /* adjust set quantities */
178                  if (nents <= 0)
179                          return;
# Line 172 | Line 183 | int    nents;
183                  for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++)
184                          ;
185                  n = csm - clist;
186 <                if (op == BS_ADJ) {     /* don't regenerate adjusted beams */
186 >                if (op != BS_ADD) {     /* don't regenerate adjusted beams */
187                          for (++i; i-- && csm->nr > 0; csm++)
188                                  ;
189                          nents = csm - clist;
# Line 251 | Line 262 | int    bi;
262   }
263  
264  
265 < init_global()                   /* initialize global ray computation */
265 > ambient_list()                  /* compute ambient beam list */
266   {
267 <        long    wtotal = 0;
267 >        int4    wtotal, minrt;
268          double  frac;
269          int     i;
270          register int    j, k;
271 <                                        /* free old list and empty queue */
261 <        if (complen > 0) {
262 <                free((char *)complist);
263 <                done_packets(flush_queue());
264 <        }
265 <                                        /* reseed random number generator */
266 <        srandom(time(NULL));
267 <                                        /* allocate beam list */
271 >
272          complen = 0;
273          for (j = 0; hdlist[j] != NULL; j++)
274                  complen += nbeams(hdlist[j]);
275          complist = (PACKHEAD *)malloc(complen*sizeof(PACKHEAD));
276 <        if (complist == NULL)
273 <                error(SYSTEM, "out of memory in init_global");
276 >        CHECK(complist==NULL, SYSTEM, "out of memory in ambient_list");
277                                          /* compute beam weights */
278 <        k = 0;
278 >        k = 0; wtotal = 0;
279          for (j = 0; hdlist[j] != NULL; j++) {
280                  frac = 512. * VLEN(hdlist[j]->wg[0]) *
281                                  VLEN(hdlist[j]->wg[1]) *
# Line 285 | Line 288 | init_global()                  /* initialize global ray computation *
288                          wtotal += complist[k++].nr;
289                  }
290          }
291 <                                        /* adjust weights */
291 >                                        /* adjust sample weights */
292          if (vdef(DISKSPACE))
293                  frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL));
294          else
295 <                frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL));
296 <        while (k--)
297 <                complist[k].nr = frac*complist[k].nr + 0.5;
298 <        listpos = 0; lastin = -1;       /* perform initial sort */
299 <        sortcomplist();
295 >                frac = 1024.*1024.*2048. / (wtotal*sizeof(RAYVAL));
296 >        minrt = .02*frac*wtotal/complen + .5;   /* heuristic mimimum */
297 >        if (minrt > RPACKSIZ)
298 >                minrt = RPACKSIZ;
299 >        for (k = complen; k--; )
300 >                if ((complist[k].nr = frac*complist[k].nr + 0.5) < minrt)
301 >                        complist[k].nr = minrt;
302 >        listpos = 0; lastin = -1;       /* flag initial sort */
303 > }
304 >
305 >
306 > view_list(fp)                   /* assign beam priority from view list */
307 > FILE    *fp;
308 > {
309 >        double  pa = 1.;
310 >        VIEW    curview;
311 >        int     xr, yr;
312 >        char    *err;
313 >        BEAMLIST        blist;
314 >
315 >        copystruct(&curview, &stdview);
316 >        while (nextview(&curview, fp) != EOF) {
317 >                if ((err = setview(&curview)) != NULL) {
318 >                        error(WARNING, err);
319 >                        continue;
320 >                }
321 >                xr = yr = 1024;
322 >                normaspect(viewaspect(&curview), &pa, &xr, &yr);
323 >                viewbeams(&curview, xr, yr, &blist);
324 >                bundle_set(BS_MAX, blist.bl, blist.nb);
325 >                free((char *)blist.bl);
326 >        }
327 > }
328 >
329 >
330 > init_global()                   /* initialize global ray computation */
331 > {
332 >        register int    k;
333 >                                        /* free old list and empty queue */
334 >        if (complen > 0) {
335 >                free((char *)complist);
336 >                done_packets(flush_queue());
337 >        }
338 >                                        /* reseed random number generator */
339 >        srandom(time(NULL));
340 >                                        /* allocate beam list */
341 >        if (readinp)
342 >                view_list(stdin);
343 >        else
344 >                ambient_list();
345                                          /* no view vicinity */
346          myeye.rng = 0;
347   }
# Line 330 | Line 378 | sortcomplist()                 /* fix our list order */
378  
379          if (complen <= 0)       /* check to see if there is even a list */
380                  return;
381 <        if (!chunky)            /* check to see if fragment list is full */
381 >        if (!chunkycmp)         /* check to see if fragment list is full */
382                  if (!hdfragOK(hdlist[0]->fd, &listlen, NULL)
383   #if NFRAG2CHUNK
384                                  || listlen >= NFRAG2CHUNK
385   #endif
386                                  ) {
387 +                        chunkycmp++;    /* use "chunky" comparison */
388 +                        lastin = -1;    /* need to re-sort list */
389   #ifdef DEBUG
390                          error(WARNING, "using chunky comparison mode");
391   #endif
342                        chunky++;       /* use "chunky" comparison */
343                        lastin = -1;    /* need to re-sort list */
392                  }
345 #ifdef DEBUG
346                        else
347                                fprintf(stderr, "sortcomplist: %d fragments\n",
348                                                listlen);
349 #endif
393          if (lastin < 0 || listpos*4 >= complen*3)
394                  qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp);
395          else if (listpos) {     /* else sort and merge sublist */
396                  list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD));
397 <                if (list2 == NULL)
355 <                        error(SYSTEM, "out of memory in sortcomplist");
397 >                CHECK(list2==NULL, SYSTEM, "out of memory in sortcomplist");
398                  bcopy((char *)complist,(char *)list2,listpos*sizeof(PACKHEAD));
399                  qsort((char *)list2, listpos, sizeof(PACKHEAD), beamcmp);
400                  mergeclists(complist, list2, listpos,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines