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.3 by greg, Mon Apr 10 17:00:27 1989 UTC vs.
Revision 1.13 by greg, Thu Apr 18 12:57:40 1991 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 +        initotypes();
63 +
64          for (i = 1; i < argc && argv[i][0] == '-'; i++)
65                  switch (argv[i][1]) {
66 +                case '\0':                              /* scene from stdin */
67 +                        goto breakopt;
68                  case 'i':                               /* input octree */
69                          infile = argv[++i];
70                          break;
# Line 85 | Line 91 | char  **argv;
91                          error(USER, errmsg);
92                          break;
93                  }
94 <        
94 > breakopt:
95          if (infile != NULL) {           /* get old octree & objects */
96                  if (thescene.cusize > FTINY)
97                          error(USER, "only one of '-b' or '-i'");
# Line 97 | Line 103 | char  **argv;
103          }
104  
105          printargs(argc, argv, stdout);  /* info. header */
106 +        fputformat(OCTFMT, stdout);
107          printf("\n");
108  
109          startobj = nobjects;            /* previous objects already converted */
110          
111 <        for ( ; i < argc; i++) {                /* read new files */
112 <                if (nfiles >= MAXOBJFIL)
113 <                        error(INTERNAL, "too many scene files");
114 <                readobj(ofname[nfiles++] = argv[i]);
115 <        }
111 >        for ( ; i < argc; i++)          /* read new scene descriptions */
112 >                if (!strcmp(argv[i], "-")) {    /* from stdin */
113 >                        readobj(NULL);
114 >                        outflags &= ~IO_FILES;
115 >                } else {                        /* from file */
116 >                        if (nfiles >= MAXOBJFIL)
117 >                                error(INTERNAL, "too many scene files");
118 >                        readobj(ofname[nfiles++] = argv[i]);
119 >                }
120 >
121          ofname[nfiles] = NULL;
122                                                  /* find bounding box */
123          bbmin[0] = bbmin[1] = bbmin[2] = FHUGE;
# Line 170 | Line 182 | char  *s;
182   eputs(s)                                /* put string to stderr */
183   register char  *s;
184   {
185 <        static int  inline = 0;
185 >        static int  inln = 0;
186  
187 <        if (!inline++) {
187 >        if (!inln++) {
188                  fputs(progname, stderr);
189                  fputs(": ", stderr);
190          }
191          fputs(s, stderr);
192          if (*s && s[strlen(s)-1] == '\n')
193 <                inline = 0;
193 >                inln = 0;
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;
# Line 189 | Line 208 | OBJECT  obj;
208          CUBE  cukid;
209          OCTREE  ot;
210          OBJECT  oset[MAXSET+1];
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);
216  
217 <        if (!in)
217 >        if (in == O_MISS)
218                  return;                         /* no intersection */
219          
220          if (istree(cu->cutree)) {
# Line 210 | 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 == 2 || 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);
231 <                        }
232 <                        insertelem(oset, obj);
233 <                        cu->cutree = fullnode(oset);
234 <
235 <                } else {
236 <                                                        /* subdivide cube */
237 <                        if ((ot = octalloc()) == EMPTY)
238 <                                error(SYSTEM, "out of octree space");
239 <                        for (i = 0; i < 8; i++) {
240 <                                cukid.cutree = EMPTY;
241 <                                for (j = 0; j < 3; j++) {
242 <                                        cukid.cuorg[j] = cu->cuorg[j];
243 <                                        if ((1<<j) & i)
244 <                                                cukid.cuorg[j] += cukid.cusize;
245 <                                }
246 <                                for (j = 1; j <= oset[0]; j++)
247 <                                        addobject(&cukid, oset[j]);
248 <                                addobject(&cukid, obj);
249 <                                octkid(ot, i) = cukid.cutree;
250 <                        }
251 <                        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 +                                        /* 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