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

Comparing ray/src/ot/oconv.c (file contents):
Revision 1.7 by greg, Fri Jan 12 10:50:59 1990 UTC vs.
Revision 1.11 by greg, Wed Aug 29 21:56:17 1990 UTC

# Line 179 | Line 179 | char  *s;
179   eputs(s)                                /* put string to stderr */
180   register char  *s;
181   {
182 <        static int  inline = 0;
182 >        static int  inln = 0;
183  
184 <        if (!inline++) {
184 >        if (!inln++) {
185                  fputs(progname, stderr);
186                  fputs(": ", stderr);
187          }
188          fputs(s, stderr);
189          if (*s && s[strlen(s)-1] == '\n')
190 <                inline = 0;
190 >                inln = 0;
191   }
192  
193  
194 + #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
195 + #define  tstbit(f,i)            bitop(f,i,&)
196 + #define  setbit(f,i)            bitop(f,i,|=)
197 + #define  clrbit(f,i)            bitop(f,i,&=~)
198 + #define  tglbit(f,i)            bitop(f,i,^=)
199 +
200 +
201   addobject(cu, obj)                      /* add an object to a cube */
202   register CUBE  *cu;
203   OBJECT  obj;
# Line 198 | Line 205 | OBJECT  obj;
205          CUBE  cukid;
206          OCTREE  ot;
207          OBJECT  oset[MAXSET+1];
208 +        unsigned char  inflg[MAXSET/8], volflg[MAXSET/8];
209          int  in;
210          register int  i, j;
211  
# Line 219 | Line 227 | OBJECT  obj;
227                          addobject(&cukid, obj);
228                          octkid(cu->cutree, i) = cukid.cutree;
229                  }
230 <                
231 <        } else if (isempty(cu->cutree)) {
230 >                return;
231 >        }
232 >        if (isempty(cu->cutree)) {
233                                                  /* singular set */
234                  oset[0] = 1; oset[1] = obj;
235                  cu->cutree = fullnode(oset);
236 <                
237 <        } else {
238 <                                                /* add to full node */
239 <                objset(oset, cu->cutree);
240 <                cukid.cusize = cu->cusize * 0.5;
241 <                
242 <                if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
243 <                                                        /* add to set */
244 <                        if (oset[0] >= MAXSET) {
245 <                                sprintf(errmsg,
246 <                                        "set overflow in addobject (%s)",
247 <                                                objptr(obj)->oname);
248 <                                error(INTERNAL, errmsg);
240 <                        }
241 <                        insertelem(oset, obj);
242 <                        cu->cutree = fullnode(oset);
243 <
244 <                } else {
245 <                                                        /* subdivide cube */
246 <                        if ((ot = octalloc()) == EMPTY)
247 <                                error(SYSTEM, "out of octree space");
248 <                        for (i = 0; i < 8; i++) {
249 <                                cukid.cutree = EMPTY;
250 <                                for (j = 0; j < 3; j++) {
251 <                                        cukid.cuorg[j] = cu->cuorg[j];
252 <                                        if ((1<<j) & i)
253 <                                                cukid.cuorg[j] += cukid.cusize;
254 <                                }
255 <                                addobject(&cukid, obj);
256 <                                for (j = 1; j <= oset[0]; j++)
257 <                                        addobject(&cukid, oset[j]);
258 <                                octkid(ot, i) = cukid.cutree;
259 <                        }
260 <                        cu->cutree = ot;
236 >                return;
237 >        }
238 >                                        /* add to full node */
239 >        objset(oset, cu->cutree);
240 >        cukid.cusize = cu->cusize * 0.5;
241 >        
242 >        if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
243 >                                                /* add to set */
244 >                if (oset[0] >= MAXSET) {
245 >                        sprintf(errmsg,
246 >                                "set overflow in addobject (%s)",
247 >                                        objptr(obj)->oname);
248 >                        error(INTERNAL, errmsg);
249                  }
250 +                insertelem(oset, obj);
251 +                cu->cutree = fullnode(oset);
252 +                return;
253          }
254 +                                        /* subdivide cube */
255 +        if ((ot = octalloc()) == EMPTY)
256 +                error(SYSTEM, "out of octree space");
257 +                                        /* mark volumes */
258 +        j = (oset[0]+7)>>3;
259 +        while (j--)
260 +                volflg[j] = inflg[j] = 0;
261 +        for (j = 1; j <= oset[0]; j++)
262 +                if (isvolume(objptr(oset[j])->otype)) {
263 +                        setbit(volflg,j-1);
264 +                        if ((*ofun[objptr(oset[j])->otype].funp)
265 +                                        (objptr(oset[j]),cu) == O_IN)
266 +                                setbit(inflg,j-1);
267 +                }
268 +                                        /* assign subcubes */
269 +        for (i = 0; i < 8; i++) {
270 +                cukid.cutree = EMPTY;
271 +                for (j = 0; j < 3; j++) {
272 +                        cukid.cuorg[j] = cu->cuorg[j];
273 +                        if ((1<<j) & i)
274 +                                cukid.cuorg[j] += cukid.cusize;
275 +                }
276 +                                        /* surfaces first */
277 +                for (j = 1; j <= oset[0]; j++)
278 +                        if (!tstbit(volflg,j-1))
279 +                                addobject(&cukid, oset[j]);
280 +                                        /* then this object */
281 +                addobject(&cukid, obj);
282 +                                        /* partial volumes */
283 +                for (j = 1; j <= oset[0]; j++)
284 +                        if (tstbit(volflg,j-1) &&
285 +                                        !tstbit(inflg,j-1))
286 +                                addobject(&cukid, oset[j]);
287 +                                        /* full volumes */
288 +                for (j = 1; j <= oset[0]; j++)
289 +                        if (tstbit(inflg,j-1))
290 +                                addobject(&cukid, oset[j]);
291 +                                        /* returned node */
292 +                octkid(ot, i) = cukid.cutree;
293 +        }
294 +        cu->cutree = ot;
295   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines