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.9 by greg, Tue Jun 26 09:02:03 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;
# Line 198 | Line 207 | OBJECT  obj;
207          CUBE  cukid;
208          OCTREE  ot;
209          OBJECT  oset[MAXSET+1];
210 +        unsigned char  inflg[MAXSET/8], volflg[MAXSET/8];
211          int  in;
212          register int  i, j;
213  
# Line 219 | 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);
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 <                                                        /* surfaces first */
256 <                                for (j = 1; j <= oset[0]; j++)
257 <                                        if (!isvolume(objptr(oset[j])->otype))
258 <                                                addobject(&cukid, oset[j]);
259 <                                                        /* then this object */
260 <                                addobject(&cukid, obj);
261 <                                                        /* volumes last */
262 <                                for (j = 1; j <= oset[0]; j++)
263 <                                        if (isvolume(objptr(oset[j])->otype))
264 <                                                addobject(&cukid, oset[j]);
265 <                                octkid(ot, i) = cukid.cutree;
266 <                        }
267 <                        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 +                                        /* 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