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 2.2 by greg, Thu Dec 19 15:06:31 1991 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "otypes.h"
20  
21 + #ifndef  DEFPATH
22 + #define  DEFPATH        ":/usr/local/lib/ray"
23 + #endif
24 +
25   #define  OMARGIN        (10*FTINY)      /* margin around global cube */
26  
27   #define  MAXOBJFIL      63              /* maximum number of scene files */
# Line 46 | Line 50 | main(argc, argv)               /* convert object files to an octree
50   int  argc;
51   char  **argv;
52   {
53 <        char  *getenv();
50 <        double  atof();
53 >        extern char  *getenv();
54          FVECT  bbmin, bbmax;
55          char  *infile = NULL;
56          int  outflags = IO_ALL;
# Line 57 | Line 60 | char  **argv;
60          progname = argv[0];
61  
62          if ((libpath = getenv("RAYPATH")) == NULL)
63 <                libpath = ":/usr/local/lib/ray";
63 >                libpath = DEFPATH;
64  
65 +        initotypes();
66 +
67          for (i = 1; i < argc && argv[i][0] == '-'; i++)
68                  switch (argv[i][1]) {
69                  case '\0':                              /* scene from stdin */
# Line 101 | Line 106 | breakopt:
106          }
107  
108          printargs(argc, argv, stdout);  /* info. header */
109 +        fputformat(OCTFMT, stdout);
110          printf("\n");
111  
112          startobj = nobjects;            /* previous objects already converted */
# Line 191 | Line 197 | register char  *s;
197   }
198  
199  
200 + #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
201 + #define  tstbit(f,i)            bitop(f,i,&)
202 + #define  setbit(f,i)            bitop(f,i,|=)
203 + #define  clrbit(f,i)            bitop(f,i,&=~)
204 + #define  tglbit(f,i)            bitop(f,i,^=)
205 +
206 +
207   addobject(cu, obj)                      /* add an object to a cube */
208   register CUBE  *cu;
209   OBJECT  obj;
# Line 198 | Line 211 | OBJECT  obj;
211          CUBE  cukid;
212          OCTREE  ot;
213          OBJECT  oset[MAXSET+1];
214 +        unsigned char  inflg[MAXSET/8], volflg[MAXSET/8];
215          int  in;
216          register int  i, j;
217  
# Line 219 | Line 233 | OBJECT  obj;
233                          addobject(&cukid, obj);
234                          octkid(cu->cutree, i) = cukid.cutree;
235                  }
236 <                
237 <        } else if (isempty(cu->cutree)) {
236 >                return;
237 >        }
238 >        if (isempty(cu->cutree)) {
239                                                  /* singular set */
240                  oset[0] = 1; oset[1] = obj;
241                  cu->cutree = fullnode(oset);
242 <                
243 <        } else {
244 <                                                /* add to full node */
245 <                objset(oset, cu->cutree);
246 <                cukid.cusize = cu->cusize * 0.5;
247 <                
248 <                if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
249 <                                                        /* add to set */
250 <                        if (oset[0] >= MAXSET) {
251 <                                sprintf(errmsg,
252 <                                        "set overflow in addobject (%s)",
253 <                                                objptr(obj)->oname);
254 <                                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;
242 >                return;
243 >        }
244 >                                        /* add to full node */
245 >        objset(oset, cu->cutree);
246 >        cukid.cusize = cu->cusize * 0.5;
247 >        
248 >        if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
249 >                                                /* add to set */
250 >                if (oset[0] >= MAXSET) {
251 >                        sprintf(errmsg,
252 >                                "set overflow in addobject (%s)",
253 >                                        objptr(obj)->oname);
254 >                        error(INTERNAL, errmsg);
255                  }
256 +                insertelem(oset, obj);
257 +                cu->cutree = fullnode(oset);
258 +                return;
259          }
260 +                                        /* subdivide cube */
261 +        if ((ot = octalloc()) == EMPTY)
262 +                error(SYSTEM, "out of octree space");
263 +                                        /* mark volumes */
264 +        j = (oset[0]+7)>>3;
265 +        while (j--)
266 +                volflg[j] = inflg[j] = 0;
267 +        for (j = 1; j <= oset[0]; j++)
268 +                if (isvolume(objptr(oset[j])->otype)) {
269 +                        setbit(volflg,j-1);
270 +                        if ((*ofun[objptr(oset[j])->otype].funp)
271 +                                        (objptr(oset[j]),cu) == O_IN)
272 +                                setbit(inflg,j-1);
273 +                }
274 +                                        /* assign subcubes */
275 +        for (i = 0; i < 8; i++) {
276 +                cukid.cutree = EMPTY;
277 +                for (j = 0; j < 3; j++) {
278 +                        cukid.cuorg[j] = cu->cuorg[j];
279 +                        if ((1<<j) & i)
280 +                                cukid.cuorg[j] += cukid.cusize;
281 +                }
282 +                                        /* surfaces first */
283 +                for (j = 1; j <= oset[0]; j++)
284 +                        if (!tstbit(volflg,j-1))
285 +                                addobject(&cukid, oset[j]);
286 +                                        /* then this object */
287 +                addobject(&cukid, obj);
288 +                                        /* partial volumes */
289 +                for (j = 1; j <= oset[0]; j++)
290 +                        if (tstbit(volflg,j-1) &&
291 +                                        !tstbit(inflg,j-1))
292 +                                addobject(&cukid, oset[j]);
293 +                                        /* full volumes */
294 +                for (j = 1; j <= oset[0]; j++)
295 +                        if (tstbit(inflg,j-1))
296 +                                addobject(&cukid, oset[j]);
297 +                                        /* returned node */
298 +                octkid(ot, i) = cukid.cutree;
299 +        }
300 +        cu->cutree = ot;
301   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines