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.18 by gregl, Mon Jan 5 16:46:34 1998 UTC vs.
Revision 3.23 by gwlarson, Wed Aug 12 17:56:06 1998 UTC

# Line 20 | Line 20 | static int     lastin= -1;     /* last ordered position in lis
20  
21  
22   int
23 < beamcmp(b0, b1)                 /* comparison for descending compute order */
23 > beamcmp(b0, b1)                         /* comparison for compute order */
24   register PACKHEAD       *b0, *b1;
25   {
26          return( b1->nr*(b0->nc+1) - b0->nr*(b1->nc+1) );
# Line 28 | Line 28 | register PACKHEAD      *b0, *b1;
28  
29  
30   int
31 < dispbeam(b, hp, bi)                     /* display a holodeck beam */
31 > beamidcmp(b0, b1)                       /* comparison for beam searching */
32 > register PACKHEAD       *b0, *b1;
33 > {
34 >        register int    c = b0->hd - b1->hd;
35 >
36 >        if (c) return(c);
37 >        return(b0->bi - b1->bi);
38 > }
39 >
40 >
41 > int
42 > dispbeam(b, hb)                         /* display a holodeck beam */
43   register BEAM   *b;
44 < HOLO    *hp;
34 < int     bi;
44 > register HDBEAMI        *hb;
45   {
46          static int      n = 0;
47          static PACKHEAD *p = NULL;
# Line 48 | Line 58 | int    bi;
58                                          /* assign packet fields */
59          bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL));
60          p->nr = p->nc = b->nrm;
61 <        for (p->hd = 0; hdlist[p->hd] != hp; p->hd++)
61 >        for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++)
62                  if (hdlist[p->hd] == NULL)
63                          error(CONSISTENCY, "unregistered holodeck in dispbeam");
64 <        p->bi = bi;
64 >        p->bi = hb->b;
65          disp_packet(p);                 /* display it */
66   }
67  
68  
69   bundle_set(op, clist, nents)    /* bundle set operation */
70   int     op;
71 < register PACKHEAD       *clist;
71 > PACKHEAD        *clist;
72   int     nents;
73   {
74 <        register int    i, n;
75 <
74 >        int     oldnr, n;
75 >        HDBEAMI *hbarr;
76 >        register PACKHEAD       *csm;
77 >        register int    i;
78 >                                        /* search for common members */
79 >        qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp);
80 >        for (csm = clist+nents; csm-- > clist; )
81 >                csm->nc = -1;
82 >        for (i = 0; i < complen; i++) {
83 >                csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist,
84 >                                nents, sizeof(PACKHEAD), beamidcmp);
85 >                if (csm == NULL)
86 >                        continue;
87 >                oldnr = complist[i].nr;
88 >                csm->nc = complist[i].nc;
89 >                switch (op) {
90 >                case BS_ADD:            /* add to count */
91 >                        complist[i].nr += csm->nr;
92 >                        csm->nr = 0;
93 >                        break;
94 >                case BS_ADJ:            /* reset count */
95 >                        complist[i].nr = csm->nr;
96 >                        csm->nr = 0;
97 >                        break;
98 >                case BS_DEL:            /* delete count */
99 >                        if (csm->nr == 0 || csm->nr >= complist[i].nr)
100 >                                complist[i].nr = 0;
101 >                        else
102 >                                complist[i].nr -= csm->nr;
103 >                        break;
104 >                }
105 >                if (complist[i].nr != oldnr)
106 >                        lastin = -1;    /* flag sort */
107 >        }
108 >                                /* computed rays for each uncommon beams */
109 >        for (csm = clist+nents; csm-- > clist; )
110 >                if (csm->nc < 0)
111 >                        csm->nc = bnrays(hdlist[csm->hd], csm->bi);
112 >                                /* complete list operations */
113          switch (op) {
114          case BS_NEW:                    /* new computation set */
115 <                if (complen)
115 >                listpos = 0; lastin = -1;
116 >                if (complen)            /* free old list */
117                          free((char *)complist);
118 <                if (nents <= 0) {
119 <                        complist = NULL;
72 <                        listpos = complen = 0;
73 <                        lastin = -1;
118 >                complist = NULL;
119 >                if (!(complen = nents))
120                          return;
75                }
121                  complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD));
122                  if (complist == NULL)
123                          goto memerr;
124                  bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD));
80                complen = nents;        /* finish initialization below */
125                  break;
126          case BS_ADD:                    /* add to computation set */
127          case BS_ADJ:                    /* adjust set quantities */
128                  if (nents <= 0)
129                          return;
130 <                                        /* merge any common members */
87 <                for (n = 0; n < nents; n++) {
88 <                        for (i = 0; i < complen; i++)
89 <                                if (clist[n].bi == complist[i].bi &&
90 <                                                clist[n].hd == complist[i].hd) {
91 <                                        int     oldnr = complist[i].nr;
92 <                                        if (op == BS_ADD)
93 <                                                complist[i].nr += clist[n].nr;
94 <                                        else /* op == BS_ADJ */
95 <                                                complist[i].nr = clist[n].nr;
96 <                                        clist[n].nr = 0;
97 <                                        clist[n].nc = complist[i].nc;
98 <                                        if (complist[i].nr != oldnr)
99 <                                                lastin = -1;    /* flag sort */
100 <                                        break;
101 <                                }
102 <                        if (i >= complen)
103 <                                clist[n].nc = bnrays(hdlist[clist[n].hd],
104 <                                                clist[n].bi);
105 <                }
106 <                                        /* sort updated list */
107 <                sortcomplist();
108 <                                        /* sort new entries */
130 >                sortcomplist();         /* sort updated list & new entries */
131                  qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp);
132                                          /* what can't we satisfy? */
133 <                for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++)
133 >                for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++)
134                          ;
135 <                if (op == BS_ADJ)
136 <                        nents = n;
135 >                n = csm - clist;
136 >                if (op == BS_ADJ) {     /* don't regenerate adjusted beams */
137 >                        for (i = n; i < nents && clist[i].nr > 0; i++)
138 >                                ;
139 >                        nents = i;
140 >                }
141                  if (n) {                /* allocate space for merged list */
142                          PACKHEAD        *newlist;
143                          newlist = (PACKHEAD *)malloc(
# Line 129 | Line 155 | int    nents;
155                  lastin = complen-1;     /* list is now sorted */
156                  break;
157          case BS_DEL:                    /* delete from computation set */
158 <                if (nents <= 0)
133 <                        return;
134 <                                        /* find each member */
135 <                for (i = 0; i < complen; i++)
136 <                        for (n = 0; n < nents; n++)
137 <                                if (clist[n].bi == complist[i].bi &&
138 <                                                clist[n].hd == complist[i].hd) {
139 <                                        if (clist[n].nr == 0 ||
140 <                                                clist[n].nr >= complist[i].nr)
141 <                                                complist[i].nr = 0;
142 <                                        else
143 <                                                complist[i].nr -= clist[n].nr;
144 <                                        lastin = -1;    /* flag full sort */
145 <                                        break;
146 <                                }
147 <                return;                 /* no display */
158 >                return;                 /* already done */
159          default:
160                  error(CONSISTENCY, "bundle_set called with unknown operation");
161          }
162 <        if (outdev != NULL) {           /* load and display beams we have */
163 <                register HDBEAMI        *hb;
164 <
165 <                hb = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI));
166 <                for (i = 0; i < nents; i++) {
167 <                        hb[i].h = hdlist[clist[i].hd];
168 <                        hb[i].b = clist[i].bi;
158 <                }
159 <                hdloadbeams(hb, nents, dispbeam);
160 <                free((char *)hb);
162 >        if (outdev == NULL)             /* nothing to display? */
163 >                return;
164 >                                        /* load and display beams we have */
165 >        hbarr = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI));
166 >        for (i = nents; i--; ) {
167 >                hbarr[i].h = hdlist[clist[i].hd];
168 >                hbarr[i].b = clist[i].bi;
169          }
170 <        if (op == BS_NEW) {
171 <                done_packets(flush_queue());    /* empty queue, so we can... */
164 <                for (i = 0; i < complen; i++)   /* ...get number computed */
165 <                        complist[i].nc = bnrays(hdlist[complist[i].hd],
166 <                                                complist[i].bi);
167 <                listpos = 0;
168 <                lastin = -1;            /* flag for initial sort */
169 <        }
170 >        hdloadbeams(hbarr, nents, dispbeam);
171 >        free((char *)hbarr);
172          return;
173   memerr:
174          error(SYSTEM, "out of memory in bundle_set");
# Line 227 | Line 229 | init_global()                  /* initialize global ray computation *
229                                          /* compute beam weights */
230          k = 0;
231          for (j = 0; hdlist[j] != NULL; j++) {
232 <                frac = 512. * hdlist[j]->wg[0] *
233 <                                hdlist[j]->wg[1] * hdlist[j]->wg[2];
234 <                if (frac < 0.) frac = -frac;
232 >                frac = 512. * VLEN(hdlist[j]->wg[0]) *
233 >                                VLEN(hdlist[j]->wg[1]) *
234 >                                VLEN(hdlist[j]->wg[2]);
235                  for (i = nbeams(hdlist[j]); i > 0; i--) {
236                          complist[k].hd = j;
237                          complist[k].bi = i;
# Line 245 | Line 247 | init_global()                  /* initialize global ray computation *
247                  frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL));
248          while (k--)
249                  complist[k].nr = frac * complist[k].nr;
250 <        listpos = 0; lastin = -1;       /* flag initial sort */
250 >        listpos = 0; lastin = -1;       /* perform initial sort */
251 >        sortcomplist();
252   }
253  
254  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines