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

Comparing ray/src/common/objset.c (file contents):
Revision 1.2 by greg, Thu Sep 6 23:32:41 1990 UTC vs.
Revision 2.4 by greg, Fri Mar 7 15:45:28 1997 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "object.h"
18  
19 < #include  "otypes.h"
19 > #ifndef  OSTSIZ
20 > #ifdef  BIGMEM
21 > #define  OSTSIZ         56437           /* object table size (a prime!) */
22 > #else
23 > #define  OSTSIZ         12329           /* object table size (a prime!) */
24 > #endif
25 > #endif
26  
21 #define  OSTSIZ         3037            /* object table size (a prime!) */
22
27   static OBJECT  *ostable[OSTSIZ];        /* the object set table */
28  
29  
# Line 44 | Line 48 | OBJECT  obj;
48   {
49          register int  i;
50  
51 <        for (i = (*os++)--; i > 0 && *os < obj; i--, os++)
52 <                ;
51 >        i = (*os)--;
52 >        os++;
53 >        while (i > 0 && *os < obj) {
54 >                i--;
55 >                os++;
56 >        }
57          while (--i > 0) {
58                  os[0] = os[1];
59                  os++;
# Line 62 | Line 70 | OBJECT  obj;
70  
71          lower = 1;
72          upper = cm = os[0] + 1;
73 <
73 >                                        /* binary search algorithm */
74          while ((i = (lower + upper) >> 1) != cm) {
75                  cm = obj - os[i];
76                  if (cm > 0)
# Line 99 | Line 107 | register OBJECT  *os1, *os2;
107   }
108  
109  
110 + OBJECT *
111 + setsave(os)                     /* allocate space and save set */
112 + register OBJECT  *os;
113 + {
114 +        OBJECT  *osnew;
115 +        register OBJECT  *oset;
116 +        register int  i;
117 +
118 +        if ((osnew = oset = (OBJECT *)malloc((*os+1)*sizeof(OBJECT))) == NULL)
119 +                error(SYSTEM, "out of memory in setsave\n");
120 +        for (i = *os; i-- >= 0; )       /* inline setcopy */
121 +                *oset++ = *os++;
122 +        return(osnew);
123 + }
124 +
125 +
126 + setunion(osr, os1, os2)         /* osr = os1 Union os2 */
127 + register OBJECT  *osr, *os1, *os2;
128 + {
129 +        register int    i1, i2;
130 +
131 +        osr[0] = 0;
132 +        for (i1 = i2 = 1; i1 <= os1[0] || i2 <= os2[0]; ) {
133 +                while (i1 <= os1[0] && (i2 > os2[0] || os1[i1] <= os2[i2])) {
134 +                        osr[++osr[0]] = os1[i1];
135 +                        if (i2 <= os2[0] && os2[i2] == os1[i1])
136 +                                i2++;
137 +                        i1++;
138 +                }
139 +                while (i2 <= os2[0] && (i1 > os1[0] || os2[i2] < os1[i1]))
140 +                        osr[++osr[0]] = os2[i2++];
141 +        }
142 + }
143 +
144 +
145 + setintersect(osr, os1, os2)     /* osr = os1 Intersect os2 */
146 + register OBJECT  *osr, *os1, *os2;
147 + {
148 +        register int    i1, i2;
149 +
150 +        osr[0] = 0;
151 +        if (os1[0] <= 0)
152 +                return;
153 +        for (i1 = i2 = 1; i2 <= os2[0]; ) {
154 +                while (os1[i1] < os2[i2])
155 +                        if (++i1 > os1[0])
156 +                                return;
157 +                while (os2[i2] < os1[i1])
158 +                        if (++i2 > os2[0])
159 +                                return;
160 +                if (os1[i1] == os2[i2])
161 +                        osr[++osr[0]] = os2[i2++];
162 +        }
163 + }
164 +
165 +
166   OCTREE
167   fullnode(oset)                  /* return octree for object set */
168   OBJECT  *oset;
# Line 178 | Line 242 | noderr:
242   }
243  
244  
245 < nonsurfinset(orig, nobjs)               /* check sets for non-surfaces */
246 < int  orig, nobjs;
245 > int
246 > dosets(f)                               /* loop through all sets */
247 > int     (*f)();
248   {
249 +        int  res = 0;
250          int  n;
185        OBJECT  *nonset;
251          register OBJECT  *os;
252 <        register OBJECT  i;
188 <                                                /* count non-surfaces */
189 <        n = 0;
190 <        for (i = orig; i < orig+nobjs; i++)
191 <                if (!issurface(objptr(i)->otype))
192 <                        n++;
193 <        if (n <= 0)
194 <                return(0);
195 <                                                /* allocate set */
196 <        if ((nonset = (OBJECT *)malloc((n+1)*sizeof(OBJECT))) == NULL)
197 <                return(0);              /* give up if we haven't enough mem */
198 <                                                /* fill set */
199 <        os = nonset;
200 <        *os = n;
201 <        for (i = orig; i < orig+nobjs; i++)
202 <                if (!issurface(objptr(i)->otype))
203 <                        *++os = i;
204 <                                                /* now check all sets */
252 >
253          for (n = 0; n < OSTSIZ; n++) {
254                  if ((os = ostable[n]) == NULL)
255                          continue;
256 <                while ((i = *os++) > 0)
257 <                        while (i--) {
258 <                                if (*os >= nonset[1]
259 <                                                && *os <= nonset[nonset[0]]
212 <                                                && inset(nonset, *os))
213 <                                        goto done;
214 <                                os++;
215 <                        }
256 >                while (*os > 0) {
257 >                        res += (*f)(os);
258 >                        os += *os + 1;
259 >                }
260          }
261 < done:
262 <        free((char *)nonset);
263 <        return(n < OSTSIZ);
261 >        return(res);
262 > }
263 >
264 >
265 > donesets()                      /* free ALL SETS in our table */
266 > {
267 >        register int  n;
268 >
269 >        for (n = 0; n < OSTSIZ; n++)
270 >                if (ostable[n] != NULL) {
271 >                        free((char *)ostable[n]);
272 >                        ostable[n] = NULL;
273 >                }
274   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines