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 2.7 by greg, Sun Feb 27 10:16:42 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 +        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");
95 <                        outflags &= ~IO_FILES;
96 <                }
105 >                if (nfiles == 0)
106 >                        inpfrozen++;
107          }
108  
109 <        printargs(argc, argv, stdout);  /* info. header */
109 >        newheader("RADIANCE", stdout);  /* new binary file header */
110 >        printargs(argc, argv, stdout);
111 >        fputformat(OCTFMT, stdout);
112          printf("\n");
113  
114          startobj = nobjects;            /* previous objects already converted */
115 <        
116 <        for ( ; i < argc; i++) {                /* read new files */
117 <                if (nfiles >= MAXOBJFIL)
118 <                        error(INTERNAL, "too many scene files");
119 <                readobj(ofname[nfiles++] = argv[i]);
120 <        }
115 >
116 >        for ( ; i < argc; i++)          /* read new scene descriptions */
117 >                if (!strcmp(argv[i], "-")) {    /* from stdin */
118 >                        readobj(NULL);
119 >                        outflags &= ~IO_FILES;
120 >                } else {                        /* from file */
121 >                        if (nfiles >= MAXOBJFIL)
122 >                                error(INTERNAL, "too many scene files");
123 >                        readobj(ofname[nfiles++] = argv[i]);
124 >                }
125 >
126          ofname[nfiles] = NULL;
127 +
128 +        if (inpfrozen && outflags & IO_FILES) {
129 +                error(WARNING, "frozen octree");
130 +                outflags &= ~IO_FILES;
131 +        }
132                                                  /* find bounding box */
133          bbmin[0] = bbmin[1] = bbmin[2] = FHUGE;
134          bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE;
# Line 134 | Line 156 | char  **argv;
156          }
157  
158          mincusize = thescene.cusize / resolu - FTINY;
159 <                
159 >
160          for (i = startobj; i < nobjects; i++)           /* add new objects */
161                  addobject(&thescene, i);
162 <        
162 >
163          thescene.cutree = combine(thescene.cutree);     /* optimize */
164  
165          writeoct(outflags, &thescene, ofname);  /* write structures to stdout */
# Line 170 | Line 192 | char  *s;
192   eputs(s)                                /* put string to stderr */
193   register char  *s;
194   {
195 <        static int  inline = 0;
195 >        static int  inln = 0;
196  
197 <        if (!inline++) {
197 >        if (!inln++) {
198                  fputs(progname, stderr);
199                  fputs(": ", stderr);
200          }
201          fputs(s, stderr);
202          if (*s && s[strlen(s)-1] == '\n')
203 <                inline = 0;
203 >                inln = 0;
204   }
205  
206  
207 + #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
208 + #define  tstbit(f,i)            bitop(f,i,&)
209 + #define  setbit(f,i)            bitop(f,i,|=)
210 + #define  clrbit(f,i)            bitop(f,i,&=~)
211 + #define  tglbit(f,i)            bitop(f,i,^=)
212 +
213 +
214   addobject(cu, obj)                      /* add an object to a cube */
215   register CUBE  *cu;
216 < OBJECT  obj;
216 > OBJECT  obj;
217   {
218          CUBE  cukid;
219 <        OCTREE  ot;
220 <        OBJECT  oset[MAXSET+1];
219 >        OCTREE  ot;
220 >        OBJECT  oset[MAXSET+1];
221 >        unsigned char  inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8];
222          int  in;
223          register int  i, j;
224  
225          in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
226  
227 <        if (!in)
227 >        if (in == O_MISS)
228                  return;                         /* no intersection */
229 <        
229 >
230          if (istree(cu->cutree)) {
231                                                  /* do children */
232                  cukid.cusize = cu->cusize * 0.5;
# Line 210 | Line 240 | OBJECT  obj;
240                          addobject(&cukid, obj);
241                          octkid(cu->cutree, i) = cukid.cutree;
242                  }
243 <                
244 <        } else if (isempty(cu->cutree)) {
243 >                return;
244 >        }
245 >        if (isempty(cu->cutree)) {
246                                                  /* singular set */
247                  oset[0] = 1; oset[1] = obj;
248                  cu->cutree = fullnode(oset);
249 <                
250 <        } else {
251 <                                                /* add to full node */
252 <                objset(oset, cu->cutree);
253 <                cukid.cusize = cu->cusize * 0.5;
223 <                
224 <                if (in == 2 || oset[0] < objlim || cukid.cusize < mincusize) {
225 <                                                        /* add to set */
226 <                        if (oset[0] >= MAXSET) {
227 <                                sprintf(errmsg,
228 <                                        "set overflow in addobject (%s)",
229 <                                                objptr(obj)->oname);
230 <                                error(INTERNAL, errmsg);
231 <                        }
232 <                        insertelem(oset, obj);
233 <                        cu->cutree = fullnode(oset);
249 >                return;
250 >        }
251 >                                        /* add to full node */
252 >        objset(oset, cu->cutree);
253 >        cukid.cusize = cu->cusize * 0.5;
254  
255 <                } else {
256 <                                                        /* subdivide cube */
257 <                        if ((ot = octalloc()) == EMPTY)
258 <                                error(SYSTEM, "out of octree space");
259 <                        for (i = 0; i < 8; i++) {
260 <                                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;
255 >        if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
256 >                                                /* add to set */
257 >                if (oset[0] >= MAXSET) {
258 >                        sprintf(errmsg, "set overflow in addobject (%s)",
259 >                                        objptr(obj)->oname);
260 >                        error(INTERNAL, errmsg);
261                  }
262 +                insertelem(oset, obj);
263 +                cu->cutree = fullnode(oset);
264 +                return;
265          }
266 +                                        /* subdivide cube */
267 +        if ((ot = octalloc()) == EMPTY)
268 +                error(SYSTEM, "out of octree space");
269 +                                        /* mark volumes */
270 +        j = (oset[0]+7)>>3;
271 +        while (j--)
272 +                volflg[j] = inflg[j] = 0;
273 +        for (j = 1; j <= oset[0]; j++)
274 +                if (isvolume(objptr(oset[j])->otype)) {
275 +                        setbit(volflg,j-1);
276 +                        if ((*ofun[objptr(oset[j])->otype].funp)
277 +                                        (objptr(oset[j]), cu) == O_IN)
278 +                                setbit(inflg,j-1);
279 +                }
280 +                                        /* assign subcubes */
281 +        for (i = 0; i < 8; i++) {
282 +                cukid.cutree = EMPTY;
283 +                for (j = 0; j < 3; j++) {
284 +                        cukid.cuorg[j] = cu->cuorg[j];
285 +                        if ((1<<j) & i)
286 +                                cukid.cuorg[j] += cukid.cusize;
287 +                }
288 +                                        /* surfaces first */
289 +                for (j = 1; j <= oset[0]; j++)
290 +                        if (!tstbit(volflg,j-1))
291 +                                addobject(&cukid, oset[j]);
292 +                                        /* then this object */
293 +                addobject(&cukid, obj);
294 +                                        /* then partial volumes */
295 +                for (j = 1; j <= oset[0]; j++)
296 +                        if (tstbit(volflg,j-1) &&
297 +                                        !tstbit(inflg,j-1))
298 +                                addobject(&cukid, oset[j]);
299 +                                        /* full volumes last */
300 +                for (j = 1; j <= oset[0]; j++)
301 +                        if (tstbit(inflg,j-1))
302 +                                addobject(&cukid, oset[j]);
303 +                                        /* returned node */
304 +                octkid(ot, i) = cukid.cutree;
305 +        }
306 +        cu->cutree = ot;
307   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines