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.4 by greg, Thu Jun 1 19:23:13 1989 UTC vs.
Revision 1.11 by greg, Wed Aug 29 21:56:17 1990 UTC

# Line 39 | Line 39 | int  nfiles = 0;                       /* number of object files */
39  
40   double  mincusize;                      /* minimum cube size from resolu */
41  
42 + int  (*addobjnotify[])() = {NULL};      /* new object notifier functions */
43  
44 +
45   main(argc, argv)                /* convert object files to an octree */
46   int  argc;
47   char  **argv;
# Line 57 | Line 59 | char  **argv;
59          if ((libpath = getenv("RAYPATH")) == NULL)
60                  libpath = ":/usr/local/lib/ray";
61  
62 <        for (i = 1; i < argc && argv[i][0] == '-' && argv[i][1]; i++)
62 >        for (i = 1; i < argc && argv[i][0] == '-'; i++)
63                  switch (argv[i][1]) {
64 +                case '\0':                              /* scene from stdin */
65 +                        goto breakopt;
66                  case 'i':                               /* input octree */
67                          infile = argv[++i];
68                          break;
# Line 85 | Line 89 | char  **argv;
89                          error(USER, errmsg);
90                          break;
91                  }
92 <
92 > breakopt:
93          if (infile != NULL) {           /* get old octree & objects */
94                  if (thescene.cusize > FTINY)
95                          error(USER, "only one of '-b' or '-i'");
# Line 175 | 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 194 | 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  
212          in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
213  
214 <        if (!in)
214 >        if (in == O_MISS)
215                  return;                         /* no intersection */
216          
217          if (istree(cu->cutree)) {
# Line 215 | 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 == 2 || 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);
236 <                        }
237 <                        insertelem(oset, obj);
238 <                        cu->cutree = fullnode(oset);
239 <
240 <                } else {
241 <                                                        /* subdivide cube */
242 <                        if ((ot = octalloc()) == EMPTY)
243 <                                error(SYSTEM, "out of octree space");
244 <                        for (i = 0; i < 8; i++) {
245 <                                cukid.cutree = EMPTY;
246 <                                for (j = 0; j < 3; j++) {
247 <                                        cukid.cuorg[j] = cu->cuorg[j];
248 <                                        if ((1<<j) & i)
249 <                                                cukid.cuorg[j] += cukid.cusize;
250 <                                }
251 <                                for (j = 1; j <= oset[0]; j++)
252 <                                        addobject(&cukid, oset[j]);
253 <                                addobject(&cukid, obj);
254 <                                octkid(ot, i) = cukid.cutree;
255 <                        }
256 <                        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