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.8 by greg, Mon Apr 2 15:19:46 1990 UTC vs.
Revision 2.16 by schorsch, Sun Jun 8 12:03:10 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  oconv.c - main program for object to octree conversion.
6   *
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   */
9  
10   #include  "standard.h"
11 <
11 > #include  "platform.h"
12   #include  "octree.h"
16
13   #include  "object.h"
18
14   #include  "otypes.h"
15 + #include  "paths.h"
16  
17 < #define  OMARGIN        (10*FTINY)      /* margin around global cube */
17 > #define  OMARGIN        (10*FTINY)      /* margin around global cube */
18  
19 < #define  MAXOBJFIL      63              /* maximum number of scene files */
19 > #define  MAXOBJFIL      127             /* maximum number of scene files */
20  
21   char  *progname;                        /* argv[0] */
22  
27 char  *libpath;                         /* library search path */
28
23   int  nowarn = 0;                        /* supress warnings? */
24  
25 < int  objlim = 5;                        /* # of objects before split */
25 > int  objlim = 6;                        /* # of objects before split */
26  
27 < int  resolu = 1024;                     /* octree resolution limit */
27 > int  resolu = 16384;                    /* octree resolution limit */
28  
29   CUBE  thescene = {EMPTY, {0.0, 0.0, 0.0}, 0.0};         /* our scene */
30  
31   char  *ofname[MAXOBJFIL+1];             /* object file names */
32   int  nfiles = 0;                        /* number of object files */
33  
34 < double  mincusize;                      /* minimum cube size from resolu */
34 > double  mincusize;                      /* minimum cube size from resolu */
35  
36 < int  (*addobjnotify[])() = {NULL};      /* new object notifier functions */
36 > void  (*addobjnotify[])() = {NULL};     /* new object notifier functions */
37  
38  
39   main(argc, argv)                /* convert object files to an octree */
40   int  argc;
41 < char  **argv;
41 > char  *argv[];
42   {
49        char  *getenv();
50        double  atof();
43          FVECT  bbmin, bbmax;
44          char  *infile = NULL;
45 +        int  inpfrozen = 0;
46          int  outflags = IO_ALL;
47 <        OBJECT  startobj;
47 >        OBJECT  startobj;
48          int  i;
49  
50 <        progname = argv[0];
50 >        progname = argv[0] = fixargv0(argv[0]);
51  
52 <        if ((libpath = getenv("RAYPATH")) == NULL)
60 <                libpath = ":/usr/local/lib/ray";
52 >        initotypes();
53  
54          for (i = 1; i < argc && argv[i][0] == '-'; i++)
55                  switch (argv[i][1]) {
# Line 90 | Line 82 | char  **argv;
82                          break;
83                  }
84   breakopt:
85 +        SET_FILE_BINARY(stdout);
86          if (infile != NULL) {           /* get old octree & objects */
87                  if (thescene.cusize > FTINY)
88                          error(USER, "only one of '-b' or '-i'");
89                  nfiles = readoct(infile, IO_ALL, &thescene, ofname);
90 <                if (nfiles == 0 && outflags & IO_FILES) {
91 <                        error(WARNING, "frozen octree");
92 <                        outflags &= ~IO_FILES;
93 <                }
94 <        }
95 <
103 <        printargs(argc, argv, stdout);  /* info. header */
90 >                if (nfiles == 0)
91 >                        inpfrozen++;
92 >        } else
93 >                newheader("RADIANCE", stdout);  /* new binary file header */
94 >        printargs(argc, argv, stdout);
95 >        fputformat(OCTFMT, stdout);
96          printf("\n");
97  
98          startobj = nobjects;            /* previous objects already converted */
99 <        
99 >
100          for ( ; i < argc; i++)          /* read new scene descriptions */
101                  if (!strcmp(argv[i], "-")) {    /* from stdin */
102                          readobj(NULL);
# Line 116 | Line 108 | breakopt:
108                  }
109  
110          ofname[nfiles] = NULL;
111 +
112 +        if (inpfrozen && outflags & IO_FILES) {
113 +                error(WARNING, "frozen octree");
114 +                outflags &= ~IO_FILES;
115 +        }
116                                                  /* find bounding box */
117          bbmin[0] = bbmin[1] = bbmin[2] = FHUGE;
118          bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE;
# Line 143 | Line 140 | breakopt:
140          }
141  
142          mincusize = thescene.cusize / resolu - FTINY;
143 <                
143 >
144          for (i = startobj; i < nobjects; i++)           /* add new objects */
145                  addobject(&thescene, i);
146 <        
146 >
147          thescene.cutree = combine(thescene.cutree);     /* optimize */
148  
149          writeoct(outflags, &thescene, ofname);  /* write structures to stdout */
# Line 155 | Line 152 | breakopt:
152   }
153  
154  
155 + void
156   quit(code)                              /* exit program */
157   int  code;
158   {
# Line 162 | Line 160 | int  code;
160   }
161  
162  
163 + void
164   cputs()                                 /* interactive error */
165   {
166          /* referenced, but not used */
167   }
168  
169  
170 + void
171   wputs(s)                                /* warning message */
172   char  *s;
173   {
# Line 176 | Line 176 | char  *s;
176   }
177  
178  
179 + void
180   eputs(s)                                /* put string to stderr */
181   register char  *s;
182   {
183 <        static int  inline = 0;
183 >        static int  inln = 0;
184  
185 <        if (!inline++) {
185 >        if (!inln++) {
186                  fputs(progname, stderr);
187                  fputs(": ", stderr);
188          }
189          fputs(s, stderr);
190          if (*s && s[strlen(s)-1] == '\n')
191 <                inline = 0;
191 >                inln = 0;
192   }
193  
194  
195 + #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
196 + #define  tstbit(f,i)            bitop(f,i,&)
197 + #define  setbit(f,i)            bitop(f,i,|=)
198 + #define  clrbit(f,i)            bitop(f,i,&=~)
199 + #define  tglbit(f,i)            bitop(f,i,^=)
200 +
201 +
202   addobject(cu, obj)                      /* add an object to a cube */
203   register CUBE  *cu;
204 < OBJECT  obj;
204 > OBJECT  obj;
205   {
206 <        CUBE  cukid;
199 <        OCTREE  ot;
200 <        OBJECT  oset[MAXSET+1];
201 <        int  in;
202 <        register int  i, j;
206 >        int  inc;
207  
208 <        in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
208 >        inc = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
209  
210 <        if (in == O_MISS)
210 >        if (inc == O_MISS)
211                  return;                         /* no intersection */
212 <        
212 >
213          if (istree(cu->cutree)) {
214 <                                                /* do children */
214 >                CUBE  cukid;                    /* do children */
215 >                int  i, j;
216                  cukid.cusize = cu->cusize * 0.5;
217                  for (i = 0; i < 8; i++) {
218                          cukid.cutree = octkid(cu->cutree, i);
# Line 219 | Line 224 | OBJECT  obj;
224                          addobject(&cukid, obj);
225                          octkid(cu->cutree, i) = cukid.cutree;
226                  }
227 <                
228 <        } else if (isempty(cu->cutree)) {
229 <                                                /* singular set */
227 >                return;
228 >        }
229 >        if (isempty(cu->cutree)) {
230 >                OBJECT  oset[2];                /* singular set */
231                  oset[0] = 1; oset[1] = obj;
232                  cu->cutree = fullnode(oset);
233 <                
234 <        } else {
235 <                                                /* add to full node */
236 <                objset(oset, cu->cutree);
237 <                cukid.cusize = cu->cusize * 0.5;
232 <                
233 <                if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
234 <                                                        /* add to set */
235 <                        if (oset[0] >= MAXSET) {
236 <                                sprintf(errmsg,
237 <                                        "set overflow in addobject (%s)",
238 <                                                objptr(obj)->oname);
239 <                                error(INTERNAL, errmsg);
240 <                        }
241 <                        insertelem(oset, obj);
242 <                        cu->cutree = fullnode(oset);
233 >                return;
234 >        }
235 >                                        /* add to full node */
236 >        add2full(cu, obj, inc);
237 > }
238  
239 <                } else {
240 <                                                        /* subdivide cube */
241 <                        if ((ot = octalloc()) == EMPTY)
242 <                                error(SYSTEM, "out of octree space");
243 <                        for (i = 0; i < 8; i++) {
244 <                                cukid.cutree = EMPTY;
245 <                                for (j = 0; j < 3; j++) {
246 <                                        cukid.cuorg[j] = cu->cuorg[j];
247 <                                        if ((1<<j) & i)
248 <                                                cukid.cuorg[j] += cukid.cusize;
249 <                                }
250 <                                                        /* surfaces first */
251 <                                for (j = 1; j <= oset[0]; j++)
252 <                                        if (!isvolume(objptr(oset[j])->otype))
253 <                                                addobject(&cukid, oset[j]);
254 <                                                        /* then this object */
255 <                                addobject(&cukid, obj);
256 <                                                        /* volumes last */
257 <                                for (j = 1; j <= oset[0]; j++)
258 <                                        if (isvolume(objptr(oset[j])->otype))
259 <                                                addobject(&cukid, oset[j]);
265 <                                octkid(ot, i) = cukid.cutree;
266 <                        }
267 <                        cu->cutree = ot;
239 >
240 > add2full(cu, obj, inc)                  /* add object to full node */
241 > register CUBE  *cu;
242 > OBJECT  obj;
243 > int  inc;
244 > {
245 >        OCTREE  ot;
246 >        OBJECT  oset[MAXSET+1];
247 >        CUBE  cukid;
248 >        unsigned char  inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8];
249 >        register int  i, j;
250 >
251 >        objset(oset, cu->cutree);
252 >        cukid.cusize = cu->cusize * 0.5;
253 >
254 >        if (inc==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