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.33 by gwlarson, Mon Mar 8 17:31:49 1999 UTC vs.
Revision 3.45 by greg, Tue Jan 21 22:30:01 2025 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1999 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines for tracking beam compuatations
6   */
7  
8   #include "rholo.h"
12 #include "view.h"
9  
10   #ifndef NFRAG2CHUNK
11   #define NFRAG2CHUNK     4096    /* number of fragments to start chunking */
12   #endif
13  
14 + #ifndef MAXADISK
15 + #define MAXADISK        10240.  /* maximum holodeck size (Megs) for ambient */
16 + #endif
17 +
18   #ifndef abs
19   #define abs(x)          ((x) > 0 ? (x) : -(x))
20   #endif
# Line 24 | Line 24 | static char SCCSid[] = "$SunId$ SGI";
24  
25   #define rchunk(n)       (((n)+(RPACKSIZ/2))/RPACKSIZ)
26  
27 extern time_t   time();
28
27   int     chunkycmp = 0;          /* clump beams together on disk */
28  
29   static PACKHEAD *complist=NULL; /* list of beams to compute */
# Line 33 | Line 31 | static int     complen=0;      /* length of complist */
31   static int      listpos=0;      /* current list position for next_packet */
32   static int      lastin= -1;     /* last ordered position in list */
33  
34 + static void sortcomplist(void);
35 + static void mergeclists(PACKHEAD *cdest, PACKHEAD *cl1, int n1, PACKHEAD *cl2, int n2);
36 + static void view_list(FILE      *fp);
37 + static void ambient_list(void);
38 + static double beamvolume(HOLO   *hp, int        bi);
39 + static void dispbeam(BEAM       *b, HDBEAMI     *hb);
40  
41 < int
41 >
42 >
43 > static int
44   beamcmp(b0, b1)                         /* comparison for compute order */
45 < register PACKHEAD       *b0, *b1;
45 > PACKHEAD        *b0, *b1;
46   {
47          BEAMI   *bip0, *bip1;
48 <        register long   c;
48 >        long    c;
49                                          /* first check desired quantities */
50          if (chunkycmp)
51                  c = rchunk(b1->nr)*(rchunk(b0->nc)+1L) -
# Line 69 | Line 75 | register PACKHEAD      *b0, *b1;
75  
76   int
77   beamidcmp(b0, b1)                       /* comparison for beam searching */
78 < register PACKHEAD       *b0, *b1;
78 > PACKHEAD        *b0, *b1;
79   {
80 <        register int    c = b0->hd - b1->hd;
80 >        int     c = b0->hd - b1->hd;
81  
82          if (c) return(c);
83          return(b0->bi - b1->bi);
84   }
85  
86  
87 < int
88 < dispbeam(b, hb)                         /* display a holodeck beam */
89 < register BEAM   *b;
90 < register HDBEAMI        *hb;
87 > static void
88 > dispbeam(                               /* display a holodeck beam */
89 >        BEAM    *b,
90 >        HDBEAMI *hb
91 > )
92   {
93          static int      n = 0;
94          static PACKHEAD *p = NULL;
# Line 91 | Line 98 | register HDBEAMI       *hb;
98          if (b->nrm > n) {               /* (re)allocate packet holder */
99                  n = b->nrm;
100                  if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n));
101 <                else p = (PACKHEAD *)realloc((char *)p, packsiz(n));
101 >                else p = (PACKHEAD *)realloc((void *)p, packsiz(n));
102                  CHECK(p==NULL, SYSTEM, "out of memory in dispbeam");
103          }
104                                          /* assign packet fields */
105 <        bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL));
105 >        memcpy((void *)packra(p), (void *)hdbray(b), b->nrm*sizeof(RAYVAL));
106          p->nr = p->nc = b->nrm;
107          for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++)
108                  if (hdlist[p->hd] == NULL)
# Line 103 | Line 110 | register HDBEAMI       *hb;
110          p->bi = hb->b;
111          disp_packet(p);                 /* display it */
112          if (n >= 1024) {                /* free ridiculous packets */
113 <                free((char *)p);
113 >                free((void *)p);
114                  p = NULL; n = 0;
115          }
116   }
117  
118  
119 < bundle_set(op, clist, nents)    /* bundle set operation */
120 < int     op;
121 < PACKHEAD        *clist;
122 < int     nents;
119 > void
120 > bundle_set(     /* bundle set operation */
121 >        int     op,
122 >        PACKHEAD        *clist,
123 >        int     nents
124 > )
125   {
126          int     oldnr, n;
127          HDBEAMI *hbarr;
128 <        register PACKHEAD       *csm;
129 <        register int    i;
128 >        PACKHEAD        *csm;
129 >        int     i;
130                                          /* search for common members */
131          for (csm = clist+nents; csm-- > clist; )
132                  csm->nc = -1;
133 <        qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp);
133 >        qsort((void *)clist, nents, sizeof(PACKHEAD), beamidcmp);
134          for (i = 0; i < complen; i++) {
135 <                csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist,
135 >                csm = (PACKHEAD *)bsearch((void *)(complist+i), (void *)clist,
136                                  nents, sizeof(PACKHEAD), beamidcmp);
137                  if (csm == NULL)
138                          continue;
# Line 162 | Line 171 | int    nents;
171          case BS_NEW:                    /* new computation set */
172                  listpos = 0; lastin = -1;
173                  if (complen)            /* free old list */
174 <                        free((char *)complist);
174 >                        free((void *)complist);
175                  complist = NULL;
176                  if (!(complen = nents))
177                          return;
178                  complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD));
179                  if (complist == NULL)
180                          goto memerr;
181 <                bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD));
181 >                memcpy((void *)complist, (void *)clist, nents*sizeof(PACKHEAD));
182                  break;
183          case BS_ADD:                    /* add to computation set */
184          case BS_MAX:                    /* maximum of quantities */
# Line 177 | Line 186 | int    nents;
186                  if (nents <= 0)
187                          return;
188                  sortcomplist();         /* sort updated list & new entries */
189 <                qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp);
189 >                qsort((void *)clist, nents, sizeof(PACKHEAD), beamcmp);
190                                          /* what can't we satisfy? */
191                  for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++)
192                          ;
# Line 196 | Line 205 | int    nents;
205                                                  /* merge lists */
206                          mergeclists(newlist, clist, n, complist, complen);
207                          if (complen)
208 <                                free((char *)complist);
208 >                                free((void *)complist);
209                          complist = newlist;
210                          complen += n;
211                  }
# Line 217 | Line 226 | int    nents;
226                  hbarr[i].b = clist[i].bi;
227          }
228          hdloadbeams(hbarr, nents, dispbeam);
229 <        free((char *)hbarr);
229 >        free((void *)hbarr);
230          if (hdfragflags&FF_READ) {
231                  listpos = 0;
232                  lastin = -1;            /* need to re-sort list */
# Line 228 | Line 237 | memerr:
237   }
238  
239  
240 < double
241 < beamvolume(hp, bi)      /* compute approximate volume of a beam */
242 < HOLO    *hp;
243 < int     bi;
240 > static double
241 > beamvolume(     /* compute approximate volume of a beam */
242 >        HOLO    *hp,
243 >        int     bi
244 > )
245   {
246          GCOORD  gc[2];
247          FVECT   cp[4], edgeA, edgeB, cent[2];
248 <        FVECT   v, crossp[2], diffv;
248 >        FVECT   crossp[2], diffv;
249          double  vol[2];
250 <        register int    i;
250 >        int     i;
251                                          /* get grid coordinates */
252          if (!hdbcoord(gc, hp, bi))
253                  error(CONSISTENCY, "bad beam index in beamvolume");
# Line 261 | Line 271 | int    bi;
271   }
272  
273  
274 < ambient_list()                  /* compute ambient beam list */
274 > static void
275 > ambient_list(void)                      /* compute ambient beam list */
276   {
277 <        int4    wtotal, minrt;
277 >        unsigned long   wtotal;
278 >        int32   minrt;
279          double  frac;
280          int     i;
281 <        register int    j, k;
281 >        int     j, k;
282  
283          complen = 0;
284          for (j = 0; hdlist[j] != NULL; j++)
# Line 276 | Line 288 | ambient_list()                 /* compute ambient beam list */
288                                          /* compute beam weights */
289          k = 0; wtotal = 0;
290          for (j = 0; hdlist[j] != NULL; j++) {
291 +                                        /* 512. arbitrary -- adjusted below */
292                  frac = 512. * VLEN(hdlist[j]->wg[0]) *
293                                  VLEN(hdlist[j]->wg[1]) *
294                                  VLEN(hdlist[j]->wg[2]);
# Line 291 | Line 304 | ambient_list()                 /* compute ambient beam list */
304          if (vdef(DISKSPACE))
305                  frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL));
306          else
307 <                frac = 1024.*1024.*2048. / (wtotal*sizeof(RAYVAL));
308 <        minrt = .02*frac*wtotal/complen + .5;   /* heuristic mimimum */
307 >                frac = 1024.*1024.*MAXADISK / (wtotal*sizeof(RAYVAL));
308 >        minrt = .02*frac*wtotal/complen + 1.1;  /* heuristic mimimum */
309          if (minrt > RPACKSIZ)
310                  minrt = RPACKSIZ;
311          for (k = complen; k--; )
# Line 302 | Line 315 | ambient_list()                 /* compute ambient beam list */
315   }
316  
317  
318 < view_list(fp)                   /* assign beam priority from view list */
319 < FILE    *fp;
318 > static void
319 > view_list(                      /* assign beam priority from view list */
320 >        FILE    *fp
321 > )
322   {
323          double  pa = 1.;
324          VIEW    curview;
# Line 311 | Line 326 | FILE   *fp;
326          char    *err;
327          BEAMLIST        blist;
328  
329 <        copystruct(&curview, &stdview);
329 >        curview = stdview;
330          while (nextview(&curview, fp) != EOF) {
331                  if ((err = setview(&curview)) != NULL) {
332                          error(WARNING, err);
# Line 321 | Line 336 | FILE   *fp;
336                  normaspect(viewaspect(&curview), &pa, &xr, &yr);
337                  viewbeams(&curview, xr, yr, &blist);
338                  bundle_set(BS_MAX, blist.bl, blist.nb);
339 <                free((char *)blist.bl);
339 >                free((void *)blist.bl);
340          }
341   }
342  
343  
344 < init_global()                   /* initialize global ray computation */
344 > void
345 > init_global(void)                       /* initialize global ray computation */
346   {
331        register int    k;
347                                          /* free old list and empty queue */
348          if (complen > 0) {
349 <                free((char *)complist);
349 >                free((void *)complist);
350                  done_packets(flush_queue());
351          }
352                                          /* reseed random number generator */
# Line 346 | Line 361 | init_global()                  /* initialize global ray computation *
361   }
362  
363  
364 < mergeclists(cdest, cl1, n1, cl2, n2)    /* merge two sorted lists */
365 < register PACKHEAD       *cdest;
366 < register PACKHEAD       *cl1, *cl2;
367 < int     n1, n2;
364 > static void
365 > mergeclists(    /* merge two sorted lists */
366 >        PACKHEAD        *cdest,
367 >        PACKHEAD        *cl1,
368 >        int     n1,
369 >        PACKHEAD        *cl2,
370 >        int     n2
371 > )
372   {
373 <        register int    cmp;
373 >        int     cmp;
374  
375          while (n1 | n2) {
376                  if (!n1) cmp = 1;
377                  else if (!n2) cmp = -1;
378                  else cmp = beamcmp(cl1, cl2);
379                  if (cmp > 0) {
380 <                        copystruct(cdest, cl2);
380 >                        *cdest = *cl2;
381                          cl2++; n2--;
382                  } else {
383 <                        copystruct(cdest, cl1);
383 >                        *cdest = *cl1;
384                          cl1++; n1--;
385                  }
386                  cdest++;
# Line 369 | Line 388 | int    n1, n2;
388   }
389  
390  
391 < sortcomplist()                  /* fix our list order */
391 > static void
392 > sortcomplist(void)                      /* fix our list order */
393   {
394          PACKHEAD        *list2;
395          int     listlen;
396 <        register int    i;
396 >        int     i;
397  
398          if (complen <= 0)       /* check to see if there is even a list */
399                  return;
# Line 390 | Line 410 | sortcomplist()                 /* fix our list order */
410   #endif
411                  }
412          if (lastin < 0 || listpos*4 >= complen*3)
413 <                qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp);
413 >                qsort((void *)complist, complen, sizeof(PACKHEAD), beamcmp);
414          else if (listpos) {     /* else sort and merge sublist */
415                  list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD));
416                  CHECK(list2==NULL, SYSTEM, "out of memory in sortcomplist");
417 <                bcopy((char *)complist,(char *)list2,listpos*sizeof(PACKHEAD));
418 <                qsort((char *)list2, listpos, sizeof(PACKHEAD), beamcmp);
417 >                memcpy((void *)list2,(void *)complist,listpos*sizeof(PACKHEAD));
418 >                qsort((void *)list2, listpos, sizeof(PACKHEAD), beamcmp);
419                  mergeclists(complist, list2, listpos,
420                                  complist+listpos, complen-listpos);
421 <                free((char *)list2);
421 >                free((void *)list2);
422          }
423                                          /* drop satisfied requests */
424          for (i = complen; i-- && complist[i].nr <= complist[i].nc; )
425                  ;
426          if (i < 0) {
427 <                free((char *)complist);
427 >                free((void *)complist);
428                  complist = NULL;
429                  complen = 0;
430          } else if (i < complen-1) {
431 <                list2 = (PACKHEAD *)realloc((char *)complist,
431 >                list2 = (PACKHEAD *)realloc((void *)complist,
432                                  (i+1)*sizeof(PACKHEAD));
433                  if (list2 != NULL)
434                          complist = list2;
# Line 427 | Line 447 | sortcomplist()                 /* fix our list order */
447   * list and start again from the beginning.  Since
448   * a merge sort is used, the sorting costs are minimal.
449   */
450 < next_packet(p, n)               /* prepare packet for computation */
451 < register PACKET *p;
452 < int     n;
450 > int
451 > next_packet(            /* prepare packet for computation */
452 >        PACKET  *p,
453 >        int     n
454 > )
455   {
434        register int    i;
435
456          if (listpos > lastin)           /* time to sort the list */
457                  sortcomplist();
458          if (complen <= 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines