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 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  
46 +
47   main(argc, argv)                /* convert object files to an octree */
48   int  argc;
49   char  **argv;
50   {
51 <        char  *getenv();
48 <        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 <        for (i = 1; i < argc && argv[i][0] == '-' && argv[i][1]; i++)
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];
73                          break;
# Line 85 | Line 94 | char  **argv;
94                          error(USER, errmsg);
95                          break;
96                  }
97 <
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 <
99 <        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 112 | Line 123 | char  **argv;
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 139 | Line 155 | char  **argv;
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 175 | Line 191 | char  *s;
191   eputs(s)                                /* put string to stderr */
192   register char  *s;
193   {
194 <        static int  inline = 0;
194 >        static int  inln = 0;
195  
196 <        if (!inline++) {
196 >        if (!inln++) {
197                  fputs(progname, stderr);
198                  fputs(": ", stderr);
199          }
200          fputs(s, stderr);
201          if (*s && s[strlen(s)-1] == '\n')
202 <                inline = 0;
202 >                inln = 0;
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   {
217          CUBE  cukid;
218 <        OCTREE  ot;
219 <        OBJECT  oset[MAXSET+1];
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)
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 215 | 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;
228 <                
229 <                if (in == 2 || oset[0] < objlim || cukid.cusize < mincusize) {
230 <                                                        /* add to set */
231 <                        if (oset[0] >= MAXSET) {
232 <                                sprintf(errmsg,
233 <                                        "set overflow in addobject (%s)",
234 <                                                objptr(obj)->oname);
235 <                                error(INTERNAL, errmsg);
236 <                        }
237 <                        insertelem(oset, obj);
238 <                        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;
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;
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 +                                        /* 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