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 2.2 by greg, Thu Mar 12 11:41:18 1992 UTC vs.
Revision 2.7 by gwlarson, Fri Sep 11 15:26:43 1998 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "object.h"
18  
19 #include  "otypes.h"
20
19   #ifndef  OSTSIZ
20   #ifdef  BIGMEM
21 < #define  OSTSIZ         56437           /* object table size (a prime!) */
21 > #define  OSTSIZ         262139          /* object table size (a prime!) */
22   #else
23 < #define  OSTSIZ         12329           /* object table size (a prime!) */
23 > #define  OSTSIZ         32749           /* object table size (a prime!) */
24   #endif
25   #endif
26  
# Line 70 | Line 68 | OBJECT  obj;
68          int  upper, lower;
69          register int  cm, i;
70  
71 +        if ((i = os[0]) <= 6) {         /* linear search algorithm */
72 +                cm = obj;
73 +                while (i-- > 0)
74 +                        if (*++os == cm)
75 +                                return(1);
76 +                return(0);
77 +        }
78          lower = 1;
79 <        upper = cm = os[0] + 1;
80 <
79 >        upper = cm = i + 1;
80 >                                        /* binary search algorithm */
81          while ((i = (lower + upper) >> 1) != cm) {
82                  cm = obj - os[i];
83                  if (cm > 0)
# Line 109 | Line 114 | register OBJECT  *os1, *os2;
114   }
115  
116  
117 + OBJECT *
118 + setsave(os)                     /* allocate space and save set */
119 + register OBJECT  *os;
120 + {
121 +        OBJECT  *osnew;
122 +        register OBJECT  *oset;
123 +        register int  i;
124 +
125 +        if ((osnew = oset = (OBJECT *)malloc((*os+1)*sizeof(OBJECT))) == NULL)
126 +                error(SYSTEM, "out of memory in setsave\n");
127 +        for (i = *os; i-- >= 0; )       /* inline setcopy */
128 +                *oset++ = *os++;
129 +        return(osnew);
130 + }
131 +
132 +
133 + setunion(osr, os1, os2)         /* osr = os1 Union os2 */
134 + register OBJECT  *osr, *os1, *os2;
135 + {
136 +        register int    i1, i2;
137 +
138 +        osr[0] = 0;
139 +        for (i1 = i2 = 1; i1 <= os1[0] || i2 <= os2[0]; ) {
140 +                while (i1 <= os1[0] && (i2 > os2[0] || os1[i1] <= os2[i2])) {
141 +                        osr[++osr[0]] = os1[i1];
142 +                        if (i2 <= os2[0] && os2[i2] == os1[i1])
143 +                                i2++;
144 +                        i1++;
145 +                }
146 +                while (i2 <= os2[0] && (i1 > os1[0] || os2[i2] < os1[i1]))
147 +                        osr[++osr[0]] = os2[i2++];
148 +        }
149 + }
150 +
151 +
152 + setintersect(osr, os1, os2)     /* osr = os1 Intersect os2 */
153 + register OBJECT  *osr, *os1, *os2;
154 + {
155 +        register int    i1, i2;
156 +
157 +        osr[0] = 0;
158 +        if (os1[0] <= 0)
159 +                return;
160 +        for (i1 = i2 = 1; i2 <= os2[0]; ) {
161 +                while (os1[i1] < os2[i2])
162 +                        if (++i1 > os1[0])
163 +                                return;
164 +                while (os2[i2] < os1[i1])
165 +                        if (++i2 > os2[0])
166 +                                return;
167 +                if (os1[i1] == os2[i2])
168 +                        osr[++osr[0]] = os2[i2++];
169 +        }
170 + }
171 +
172 +
173   OCTREE
174   fullnode(oset)                  /* return octree for object set */
175   OBJECT  *oset;
# Line 174 | Line 235 | OCTREE  ot;
235  
236          if (!isfull(ot))
237                  goto noderr;
238 <        i = oseti(ot);
239 <        if ((os = ostable[i%OSTSIZ]) == NULL)
238 >        ot = oseti(ot);
239 >        if ((os = ostable[ot%OSTSIZ]) == NULL)
240                  goto noderr;
241 <        for (i /= OSTSIZ; i--; os += *os + 1)
241 >        for (i = ot/OSTSIZ; i--; os += *os + 1)
242                  if (*os <= 0)
243                          goto noderr;
244          for (i = *os; i-- >= 0; )               /* copy set here */
# Line 188 | Line 249 | noderr:
249   }
250  
251  
252 < nonsurfinset(orig, nobjs)               /* check sets for non-surfaces */
253 < int  orig, nobjs;
252 > int
253 > dosets(f)                               /* loop through all sets */
254 > int     (*f)();
255   {
256 +        int  res = 0;
257          int  n;
258          register OBJECT  *os;
196        register OBJECT  i, s;
259  
260          for (n = 0; n < OSTSIZ; n++) {
261                  if ((os = ostable[n]) == NULL)
262                          continue;
263 <                while ((i = *os++) > 0)
264 <                        while (i--) {
265 <                                s = *os;
266 <                                if (s >= orig && s < orig+nobjs &&
205 <                                                ismodifier(objptr(s)->otype))
206 <                                        return(1);
207 <                                os++;
208 <                        }
263 >                while (*os > 0) {
264 >                        res += (*f)(os);
265 >                        os += *os + 1;
266 >                }
267          }
268 <        return(0);
268 >        return(res);
269 > }
270 >
271 >
272 > donesets()                      /* free ALL SETS in our table */
273 > {
274 >        register int  n;
275 >
276 >        for (n = 0; n < OSTSIZ; n++)
277 >                if (ostable[n] != NULL) {
278 >                        free((char *)ostable[n]);
279 >                        ostable[n] = NULL;
280 >                }
281   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines