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.33 by gwlarson, Mon Mar 8 17:31:49 1999 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines