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.10 by greg, Wed Aug 29 13:01:16 1990 UTC vs.
Revision 1.12 by greg, Thu Dec 13 10:52:51 1990 UTC

# Line 59 | Line 59 | char  **argv;
59          if ((libpath = getenv("RAYPATH")) == NULL)
60                  libpath = ":/usr/local/lib/ray";
61  
62 +        initotypes();
63 +
64          for (i = 1; i < argc && argv[i][0] == '-'; i++)
65                  switch (argv[i][1]) {
66                  case '\0':                              /* scene from stdin */
# Line 191 | Line 193 | register char  *s;
193   }
194  
195  
196 + #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
197 + #define  tstbit(f,i)            bitop(f,i,&)
198 + #define  setbit(f,i)            bitop(f,i,|=)
199 + #define  clrbit(f,i)            bitop(f,i,&=~)
200 + #define  tglbit(f,i)            bitop(f,i,^=)
201 +
202 +
203   addobject(cu, obj)                      /* add an object to a cube */
204   register CUBE  *cu;
205   OBJECT  obj;
206   {
198 #define nexti(n)  ((ndx += cnt*cnt++)%(n))
199        static unsigned long  ndx;
200        static unsigned int  cnt;
207          CUBE  cukid;
208          OCTREE  ot;
209          OBJECT  oset[MAXSET+1];
210 <        int  in, k;
210 >        unsigned char  inflg[MAXSET/8], volflg[MAXSET/8];
211 >        int  in;
212          register int  i, j;
213  
214          in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
# Line 222 | Line 229 | OBJECT  obj;
229                          addobject(&cukid, obj);
230                          octkid(cu->cutree, i) = cukid.cutree;
231                  }
232 <                
233 <        } else if (isempty(cu->cutree)) {
232 >                return;
233 >        }
234 >        if (isempty(cu->cutree)) {
235                                                  /* singular set */
236                  oset[0] = 1; oset[1] = obj;
237                  cu->cutree = fullnode(oset);
238 <                
239 <        } else {
240 <                                                /* add to full node */
241 <                objset(oset, cu->cutree);
242 <                cukid.cusize = cu->cusize * 0.5;
243 <                
244 <                if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
245 <                                                        /* add to set */
246 <                        if (oset[0] >= MAXSET) {
247 <                                sprintf(errmsg,
248 <                                        "set overflow in addobject (%s)",
249 <                                                objptr(obj)->oname);
250 <                                error(INTERNAL, errmsg);
243 <                        }
244 <                        insertelem(oset, obj);
245 <                        cu->cutree = fullnode(oset);
246 <
247 <                } else {
248 <                                                        /* subdivide cube */
249 <                        if ((ot = octalloc()) == EMPTY)
250 <                                error(SYSTEM, "out of octree space");
251 <                        for (i = 0; i < 8; i++) {
252 <                                cukid.cutree = EMPTY;
253 <                                for (j = 0; j < 3; j++) {
254 <                                        cukid.cuorg[j] = cu->cuorg[j];
255 <                                        if ((1<<j) & i)
256 <                                                cukid.cuorg[j] += cukid.cusize;
257 <                                }
258 <                                                        /* surfaces first */
259 <                                for (j = 1; j <= oset[0]; j++)
260 <                                        if (!isvolume(objptr(oset[j])->otype))
261 <                                                addobject(&cukid, oset[j]);
262 <                                                        /* then this object */
263 <                                addobject(&cukid, obj);
264 <                                                        /* volumes last */
265 <                                k = nexti(oset[0]);     /* random start */
266 <                                for (j = k+1; j <= oset[0]; j++)
267 <                                        if (isvolume(objptr(oset[j])->otype))
268 <                                                addobject(&cukid, oset[j]);
269 <                                for (j = 1; j <= k; j++)
270 <                                        if (isvolume(objptr(oset[j])->otype))
271 <                                                addobject(&cukid, oset[j]);
272 <                                octkid(ot, i) = cukid.cutree;
273 <                        }
274 <                        cu->cutree = ot;
238 >                return;
239 >        }
240 >                                        /* add to full node */
241 >        objset(oset, cu->cutree);
242 >        cukid.cusize = cu->cusize * 0.5;
243 >        
244 >        if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
245 >                                                /* add to set */
246 >                if (oset[0] >= MAXSET) {
247 >                        sprintf(errmsg,
248 >                                "set overflow in addobject (%s)",
249 >                                        objptr(obj)->oname);
250 >                        error(INTERNAL, errmsg);
251                  }
252 +                insertelem(oset, obj);
253 +                cu->cutree = fullnode(oset);
254 +                return;
255          }
256 < #undef nexti
256 >                                        /* subdivide cube */
257 >        if ((ot = octalloc()) == EMPTY)
258 >                error(SYSTEM, "out of octree space");
259 >                                        /* mark volumes */
260 >        j = (oset[0]+7)>>3;
261 >        while (j--)
262 >                volflg[j] = inflg[j] = 0;
263 >        for (j = 1; j <= oset[0]; j++)
264 >                if (isvolume(objptr(oset[j])->otype)) {
265 >                        setbit(volflg,j-1);
266 >                        if ((*ofun[objptr(oset[j])->otype].funp)
267 >                                        (objptr(oset[j]),cu) == O_IN)
268 >                                setbit(inflg,j-1);
269 >                }
270 >                                        /* assign subcubes */
271 >        for (i = 0; i < 8; i++) {
272 >                cukid.cutree = EMPTY;
273 >                for (j = 0; j < 3; j++) {
274 >                        cukid.cuorg[j] = cu->cuorg[j];
275 >                        if ((1<<j) & i)
276 >                                cukid.cuorg[j] += cukid.cusize;
277 >                }
278 >                                        /* surfaces first */
279 >                for (j = 1; j <= oset[0]; j++)
280 >                        if (!tstbit(volflg,j-1))
281 >                                addobject(&cukid, oset[j]);
282 >                                        /* then this object */
283 >                addobject(&cukid, obj);
284 >                                        /* partial volumes */
285 >                for (j = 1; j <= oset[0]; j++)
286 >                        if (tstbit(volflg,j-1) &&
287 >                                        !tstbit(inflg,j-1))
288 >                                addobject(&cukid, oset[j]);
289 >                                        /* full volumes */
290 >                for (j = 1; j <= oset[0]; j++)
291 >                        if (tstbit(inflg,j-1))
292 >                                addobject(&cukid, oset[j]);
293 >                                        /* returned node */
294 >                octkid(ot, i) = cukid.cutree;
295 >        }
296 >        cu->cutree = ot;
297   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines