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 2.8 by greg, Mon Mar 28 11:13:58 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "otypes.h"
20  
21 < #define  OMARGIN        (10*FTINY)      /* margin around global cube */
21 > #include  "paths.h"
22  
23 < #define  MAXOBJFIL      63              /* maximum number of scene files */
23 > #define  OMARGIN        (10*FTINY)      /* margin around global cube */
24  
25 + #define  MAXOBJFIL      63              /* maximum number of scene files */
26 +
27   char  *progname;                        /* argv[0] */
28  
29   char  *libpath;                         /* library search path */
# Line 37 | Line 39 | CUBE  thescene = {EMPTY, {0.0, 0.0, 0.0}, 0.0};                /* ou
39   char  *ofname[MAXOBJFIL+1];             /* object file names */
40   int  nfiles = 0;                        /* number of object files */
41  
42 < double  mincusize;                      /* minimum cube size from resolu */
42 > double  mincusize;                      /* minimum cube size from resolu */
43  
44   int  (*addobjnotify[])() = {NULL};      /* new object notifier functions */
45  
# Line 46 | Line 48 | main(argc, argv)               /* convert object files to an octree
48   int  argc;
49   char  **argv;
50   {
51 <        char  *getenv();
50 <        double  atof();
51 >        extern char  *getenv();
52          FVECT  bbmin, bbmax;
53          char  *infile = NULL;
54 +        int  inpfrozen = 0;
55          int  outflags = IO_ALL;
56 <        OBJECT  startobj;
56 >        OBJECT  startobj;
57          int  i;
58  
59 <        progname = argv[0];
59 >        progname = argv[0] = fixargv0(argv[0]);
60  
61 <        if ((libpath = getenv("RAYPATH")) == NULL)
62 <                libpath = ":/usr/local/lib/ray";
61 >        if ((libpath = getenv(ULIBVAR)) == NULL)
62 >                libpath = DEFPATH;
63  
64 +        initotypes();
65 +
66          for (i = 1; i < argc && argv[i][0] == '-'; i++)
67                  switch (argv[i][1]) {
68                  case '\0':                              /* scene from stdin */
69 +                        outflags &= ~IO_FILES;
70                          goto breakopt;
71                  case 'i':                               /* input octree */
72                          infile = argv[++i];
# Line 90 | Line 95 | char  **argv;
95                          break;
96                  }
97   breakopt:
98 + #ifdef MSDOS
99 +        setmode(fileno(stdout), O_BINARY);
100 + #endif
101          if (infile != NULL) {           /* get old octree & objects */
102                  if (thescene.cusize > FTINY)
103                          error(USER, "only one of '-b' or '-i'");
104                  nfiles = readoct(infile, IO_ALL, &thescene, ofname);
105 <                if (nfiles == 0 && outflags & IO_FILES) {
106 <                        error(WARNING, "frozen octree");
107 <                        outflags &= ~IO_FILES;
108 <                }
109 <        }
110 <
103 <        printargs(argc, argv, stdout);  /* info. header */
105 >                if (nfiles == 0)
106 >                        inpfrozen++;
107 >        } else
108 >                newheader("RADIANCE", stdout);  /* new binary file header */
109 >        printargs(argc, argv, stdout);
110 >        fputformat(OCTFMT, stdout);
111          printf("\n");
112  
113          startobj = nobjects;            /* previous objects already converted */
114 <        
114 >
115          for ( ; i < argc; i++)          /* read new scene descriptions */
116                  if (!strcmp(argv[i], "-")) {    /* from stdin */
117                          readobj(NULL);
# Line 116 | Line 123 | breakopt:
123                  }
124  
125          ofname[nfiles] = NULL;
126 +
127 +        if (inpfrozen && outflags & IO_FILES) {
128 +                error(WARNING, "frozen octree");
129 +                outflags &= ~IO_FILES;
130 +        }
131                                                  /* find bounding box */
132          bbmin[0] = bbmin[1] = bbmin[2] = FHUGE;
133          bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE;
# Line 143 | Line 155 | breakopt:
155          }
156  
157          mincusize = thescene.cusize / resolu - FTINY;
158 <                
158 >
159          for (i = startobj; i < nobjects; i++)           /* add new objects */
160                  addobject(&thescene, i);
161 <        
161 >
162          thescene.cutree = combine(thescene.cutree);     /* optimize */
163  
164          writeoct(outflags, &thescene, ofname);  /* write structures to stdout */
# Line 191 | Line 203 | register char  *s;
203   }
204  
205  
206 + #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
207 + #define  tstbit(f,i)            bitop(f,i,&)
208 + #define  setbit(f,i)            bitop(f,i,|=)
209 + #define  clrbit(f,i)            bitop(f,i,&=~)
210 + #define  tglbit(f,i)            bitop(f,i,^=)
211 +
212 +
213   addobject(cu, obj)                      /* add an object to a cube */
214   register CUBE  *cu;
215 < OBJECT  obj;
215 > OBJECT  obj;
216   {
198 #define nexti(n)  ((ndx += cnt*cnt++)%(n))
199        static unsigned long  ndx;
200        static unsigned int  cnt;
217          CUBE  cukid;
218 <        OCTREE  ot;
219 <        OBJECT  oset[MAXSET+1];
220 <        int  in, k;
218 >        OCTREE  ot;
219 >        OBJECT  oset[MAXSET+1];
220 >        unsigned char  inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8];
221 >        int  in;
222          register int  i, j;
223  
224          in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
225  
226          if (in == O_MISS)
227                  return;                         /* no intersection */
228 <        
228 >
229          if (istree(cu->cutree)) {
230                                                  /* do children */
231                  cukid.cusize = cu->cusize * 0.5;
# Line 222 | Line 239 | OBJECT  obj;
239                          addobject(&cukid, obj);
240                          octkid(cu->cutree, i) = cukid.cutree;
241                  }
242 <                
243 <        } else if (isempty(cu->cutree)) {
242 >                return;
243 >        }
244 >        if (isempty(cu->cutree)) {
245                                                  /* singular set */
246                  oset[0] = 1; oset[1] = obj;
247                  cu->cutree = fullnode(oset);
248 <                
249 <        } else {
250 <                                                /* add to full node */
251 <                objset(oset, cu->cutree);
252 <                cukid.cusize = cu->cusize * 0.5;
235 <                
236 <                if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
237 <                                                        /* add to set */
238 <                        if (oset[0] >= MAXSET) {
239 <                                sprintf(errmsg,
240 <                                        "set overflow in addobject (%s)",
241 <                                                objptr(obj)->oname);
242 <                                error(INTERNAL, errmsg);
243 <                        }
244 <                        insertelem(oset, obj);
245 <                        cu->cutree = fullnode(oset);
248 >                return;
249 >        }
250 >                                        /* add to full node */
251 >        objset(oset, cu->cutree);
252 >        cukid.cusize = cu->cusize * 0.5;
253  
254 <                } else {
255 <                                                        /* subdivide cube */
256 <                        if ((ot = octalloc()) == EMPTY)
257 <                                error(SYSTEM, "out of octree space");
258 <                        for (i = 0; i < 8; i++) {
259 <                                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;
254 >        if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
255 >                                                /* add to set */
256 >                if (oset[0] >= MAXSET) {
257 >                        sprintf(errmsg, "set overflow in addobject (%s)",
258 >                                        objptr(obj)->oname);
259 >                        error(INTERNAL, errmsg);
260                  }
261 +                insertelem(oset, obj);
262 +                cu->cutree = fullnode(oset);
263 +                return;
264          }
265 < #undef nexti
265 >                                        /* subdivide cube */
266 >        if ((ot = octalloc()) == EMPTY)
267 >                error(SYSTEM, "out of octree space");
268 >                                        /* mark volumes */
269 >        j = (oset[0]+7)>>3;
270 >        while (j--)
271 >                volflg[j] = inflg[j] = 0;
272 >        for (j = 1; j <= oset[0]; j++)
273 >                if (isvolume(objptr(oset[j])->otype)) {
274 >                        setbit(volflg,j-1);
275 >                        if ((*ofun[objptr(oset[j])->otype].funp)
276 >                                        (objptr(oset[j]), cu) == O_IN)
277 >                                setbit(inflg,j-1);
278 >                }
279 >                                        /* assign subcubes */
280 >        for (i = 0; i < 8; i++) {
281 >                cukid.cutree = EMPTY;
282 >                for (j = 0; j < 3; j++) {
283 >                        cukid.cuorg[j] = cu->cuorg[j];
284 >                        if ((1<<j) & i)
285 >                                cukid.cuorg[j] += cukid.cusize;
286 >                }
287 >                                        /* surfaces first */
288 >                for (j = 1; j <= oset[0]; j++)
289 >                        if (!tstbit(volflg,j-1))
290 >                                addobject(&cukid, oset[j]);
291 >                                        /* then this object */
292 >                addobject(&cukid, obj);
293 >                                        /* then partial volumes */
294 >                for (j = 1; j <= oset[0]; j++)
295 >                        if (tstbit(volflg,j-1) &&
296 >                                        !tstbit(inflg,j-1))
297 >                                addobject(&cukid, oset[j]);
298 >                                        /* full volumes last */
299 >                for (j = 1; j <= oset[0]; j++)
300 >                        if (tstbit(inflg,j-1))
301 >                                addobject(&cukid, oset[j]);
302 >                                        /* returned node */
303 >                octkid(ot, i) = cukid.cutree;
304 >        }
305 >        cu->cutree = ot;
306   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines