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.13 by greg, Thu Apr 18 12:57:40 1991 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 101 | Line 103 | breakopt:
103          }
104  
105          printargs(argc, argv, stdout);  /* info. header */
106 +        fputformat(OCTFMT, stdout);
107          printf("\n");
108  
109          startobj = nobjects;            /* previous objects already converted */
# Line 191 | Line 194 | register char  *s;
194   }
195  
196  
197 + #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
198 + #define  tstbit(f,i)            bitop(f,i,&)
199 + #define  setbit(f,i)            bitop(f,i,|=)
200 + #define  clrbit(f,i)            bitop(f,i,&=~)
201 + #define  tglbit(f,i)            bitop(f,i,^=)
202 +
203 +
204   addobject(cu, obj)                      /* add an object to a cube */
205   register CUBE  *cu;
206   OBJECT  obj;
207   {
198 #define nexti(n)  ((ndx += cnt*cnt++)%(n))
199        static unsigned long  ndx;
200        static unsigned int  cnt;
208          CUBE  cukid;
209          OCTREE  ot;
210          OBJECT  oset[MAXSET+1];
211 <        int  in, k;
211 >        unsigned char  inflg[MAXSET/8], volflg[MAXSET/8];
212 >        int  in;
213          register int  i, j;
214  
215          in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
# Line 222 | Line 230 | OBJECT  obj;
230                          addobject(&cukid, obj);
231                          octkid(cu->cutree, i) = cukid.cutree;
232                  }
233 <                
234 <        } else if (isempty(cu->cutree)) {
233 >                return;
234 >        }
235 >        if (isempty(cu->cutree)) {
236                                                  /* singular set */
237                  oset[0] = 1; oset[1] = obj;
238                  cu->cutree = fullnode(oset);
239 <                
240 <        } else {
241 <                                                /* add to full node */
242 <                objset(oset, cu->cutree);
243 <                cukid.cusize = cu->cusize * 0.5;
244 <                
245 <                if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
246 <                                                        /* add to set */
247 <                        if (oset[0] >= MAXSET) {
248 <                                sprintf(errmsg,
249 <                                        "set overflow in addobject (%s)",
250 <                                                objptr(obj)->oname);
251 <                                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;
239 >                return;
240 >        }
241 >                                        /* add to full node */
242 >        objset(oset, cu->cutree);
243 >        cukid.cusize = cu->cusize * 0.5;
244 >        
245 >        if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
246 >                                                /* add to set */
247 >                if (oset[0] >= MAXSET) {
248 >                        sprintf(errmsg,
249 >                                "set overflow in addobject (%s)",
250 >                                        objptr(obj)->oname);
251 >                        error(INTERNAL, errmsg);
252                  }
253 +                insertelem(oset, obj);
254 +                cu->cutree = fullnode(oset);
255 +                return;
256          }
257 < #undef nexti
257 >                                        /* subdivide cube */
258 >        if ((ot = octalloc()) == EMPTY)
259 >                error(SYSTEM, "out of octree space");
260 >                                        /* mark volumes */
261 >        j = (oset[0]+7)>>3;
262 >        while (j--)
263 >                volflg[j] = inflg[j] = 0;
264 >        for (j = 1; j <= oset[0]; j++)
265 >                if (isvolume(objptr(oset[j])->otype)) {
266 >                        setbit(volflg,j-1);
267 >                        if ((*ofun[objptr(oset[j])->otype].funp)
268 >                                        (objptr(oset[j]),cu) == O_IN)
269 >                                setbit(inflg,j-1);
270 >                }
271 >                                        /* assign subcubes */
272 >        for (i = 0; i < 8; i++) {
273 >                cukid.cutree = EMPTY;
274 >                for (j = 0; j < 3; j++) {
275 >                        cukid.cuorg[j] = cu->cuorg[j];
276 >                        if ((1<<j) & i)
277 >                                cukid.cuorg[j] += cukid.cusize;
278 >                }
279 >                                        /* surfaces first */
280 >                for (j = 1; j <= oset[0]; j++)
281 >                        if (!tstbit(volflg,j-1))
282 >                                addobject(&cukid, oset[j]);
283 >                                        /* then this object */
284 >                addobject(&cukid, obj);
285 >                                        /* partial volumes */
286 >                for (j = 1; j <= oset[0]; j++)
287 >                        if (tstbit(volflg,j-1) &&
288 >                                        !tstbit(inflg,j-1))
289 >                                addobject(&cukid, oset[j]);
290 >                                        /* full volumes */
291 >                for (j = 1; j <= oset[0]; j++)
292 >                        if (tstbit(inflg,j-1))
293 >                                addobject(&cukid, oset[j]);
294 >                                        /* returned node */
295 >                octkid(ot, i) = cukid.cutree;
296 >        }
297 >        cu->cutree = ot;
298   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines