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 2.2 by greg, Thu Dec 19 15:06:31 1991 UTC vs.
Revision 2.25 by greg, Sat Jun 7 05:09:46 2025 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   *
7   *     7/29/85
8   */
9  
10 + #include  "platform.h"
11   #include  "standard.h"
14
12   #include  "octree.h"
16
13   #include  "object.h"
18
14   #include  "otypes.h"
15 + #include  "resolu.h"
16 + #include  "oconv.h"
17  
18 < #ifndef  DEFPATH
22 < #define  DEFPATH        ":/usr/local/lib/ray"
23 < #endif
18 > #define  OMARGIN        (10*FTINY)      /* margin around global cube */
19  
20 < #define  OMARGIN        (10*FTINY)      /* margin around global cube */
20 > #define  MAXOBJFIL      255             /* maximum number of scene files */
21  
27 #define  MAXOBJFIL      63              /* maximum number of scene files */
28
29 char  *progname;                        /* argv[0] */
30
31 char  *libpath;                         /* library search path */
32
22   int  nowarn = 0;                        /* supress warnings? */
23  
24 < int  objlim = 5;                        /* # of objects before split */
24 > int  objlim = 6;                        /* # of objects before split */
25  
26 < int  resolu = 1024;                     /* octree resolution limit */
26 > int  resolu = 16384;                    /* octree resolution limit */
27  
28 < CUBE  thescene = {EMPTY, {0.0, 0.0, 0.0}, 0.0};         /* our scene */
28 > CUBE  thescene = {{0.0, 0.0, 0.0}, 0.0, EMPTY};         /* our scene */
29  
30   char  *ofname[MAXOBJFIL+1];             /* object file names */
31   int  nfiles = 0;                        /* number of object files */
32  
33 < double  mincusize;                      /* minimum cube size from resolu */
33 > double  mincusize;                      /* minimum cube size from resolu */
34  
35 < int  (*addobjnotify[])() = {NULL};      /* new object notifier functions */
35 > void  (*addobjnotify[])() = {NULL};     /* new object notifier functions */
36  
37 + static void addobject(CUBE  *cu, OBJECT obj);
38 + static void add2full(CUBE  *cu, OBJECT  obj, int  inc);
39  
40 < main(argc, argv)                /* convert object files to an octree */
41 < int  argc;
42 < char  **argv;
40 >
41 > int
42 > main(           /* convert object files to an octree */
43 >        int  argc,
44 >        char  *argv[]
45 > )
46   {
53        extern char  *getenv();
47          FVECT  bbmin, bbmax;
48          char  *infile = NULL;
49 +        int  inpfrozen = 0;
50          int  outflags = IO_ALL;
51 <        OBJECT  startobj;
51 >        OBJECT  startobj;
52          int  i;
53  
54 <        progname = argv[0];
54 >        fixargv0(argv[0]);              /* sets global progname */
55  
56 <        if ((libpath = getenv("RAYPATH")) == NULL)
63 <                libpath = DEFPATH;
56 >        ot_initotypes();
57  
65        initotypes();
66
58          for (i = 1; i < argc && argv[i][0] == '-'; i++)
59                  switch (argv[i][1]) {
60                  case '\0':                              /* scene from stdin */
# Line 95 | Line 86 | char  **argv;
86                          break;
87                  }
88   breakopt:
89 +        SET_FILE_BINARY(stdout);
90          if (infile != NULL) {           /* get old octree & objects */
91                  if (thescene.cusize > FTINY)
92                          error(USER, "only one of '-b' or '-i'");
93                  nfiles = readoct(infile, IO_ALL, &thescene, ofname);
94 <                if (nfiles == 0 && outflags & IO_FILES) {
95 <                        error(WARNING, "frozen octree");
96 <                        outflags &= ~IO_FILES;
97 <                }
98 <        }
107 <
108 <        printargs(argc, argv, stdout);  /* info. header */
94 >                if (nfiles == 0)
95 >                        inpfrozen++;
96 >        } else
97 >                newheader("RADIANCE", stdout);  /* new binary file header */
98 >        printargs(argc, argv, stdout);
99          fputformat(OCTFMT, stdout);
100          printf("\n");
101  
102          startobj = nobjects;            /* previous objects already converted */
103 <        
103 >
104          for ( ; i < argc; i++)          /* read new scene descriptions */
105                  if (!strcmp(argv[i], "-")) {    /* from stdin */
106                          readobj(NULL);
# Line 122 | Line 112 | breakopt:
112                  }
113  
114          ofname[nfiles] = NULL;
115 +
116 +        if (inpfrozen && outflags & IO_FILES) {
117 +                error(WARNING, "frozen octree");
118 +                outflags &= ~IO_FILES;
119 +        }
120                                                  /* find bounding box */
121          bbmin[0] = bbmin[1] = bbmin[2] = FHUGE;
122          bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE;
# Line 149 | Line 144 | breakopt:
144          }
145  
146          mincusize = thescene.cusize / resolu - FTINY;
147 <                
147 >
148          for (i = startobj; i < nobjects; i++)           /* add new objects */
149                  addobject(&thescene, i);
150 <        
150 >
151          thescene.cutree = combine(thescene.cutree);     /* optimize */
152  
153          writeoct(outflags, &thescene, ofname);  /* write structures to stdout */
154  
155          quit(0);
156 +        return 0; /* pro forma return */
157   }
158  
159  
160 < quit(code)                              /* exit program */
161 < int  code;
160 > void
161 > quit(                           /* exit program */
162 >        int  code
163 > )
164   {
165          exit(code);
166   }
167  
168  
169 < cputs()                                 /* interactive error */
169 > void
170 > cputs(void)                                     /* interactive error */
171   {
172          /* referenced, but not used */
173   }
174  
175  
176 < wputs(s)                                /* warning message */
177 < char  *s;
176 > void
177 > wputs(                          /* warning message */
178 >        const char  *s
179 > )
180   {
181          if (!nowarn)
182                  eputs(s);
183   }
184  
185  
186 < eputs(s)                                /* put string to stderr */
187 < register char  *s;
186 > void
187 > eputs(                          /* put string to stderr */
188 >        const char  *s
189 > )
190   {
191          static int  inln = 0;
192  
# Line 196 | Line 199 | register char  *s;
199                  inln = 0;
200   }
201  
202 +                                /* conflicting def's in param.h */
203 + #undef  tstbit
204 + #undef  setbit
205 + #undef  clrbit
206 + #undef  tglbit
207  
208 < #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
209 < #define  tstbit(f,i)            bitop(f,i,&)
210 < #define  setbit(f,i)            bitop(f,i,|=)
211 < #define  clrbit(f,i)            bitop(f,i,&=~)
212 < #define  tglbit(f,i)            bitop(f,i,^=)
208 > #define  bitop(f,i,op)          (f[((i)>>3)] op (1<<((i)&7)))
209 > #define  tstbit(f,i)            bitop(f,i,&)
210 > #define  setbit(f,i)            bitop(f,i,|=)
211 > #define  clrbit(f,i)            bitop(f,i,&=~)
212 > #define  tglbit(f,i)            bitop(f,i,^=)
213  
214  
215 < addobject(cu, obj)                      /* add an object to a cube */
216 < register CUBE  *cu;
217 < OBJECT  obj;
215 > static void
216 > addobject(                      /* add an object to a cube */
217 >        CUBE  *cu,
218 >        OBJECT  obj
219 > )
220   {
221 <        CUBE  cukid;
212 <        OCTREE  ot;
213 <        OBJECT  oset[MAXSET+1];
214 <        unsigned char  inflg[MAXSET/8], volflg[MAXSET/8];
215 <        int  in;
216 <        register int  i, j;
221 >        int  inc;
222  
223 <        in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
223 >        inc = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);
224  
225 <        if (in == O_MISS)
225 >        if (inc == O_MISS)
226                  return;                         /* no intersection */
227 <        
227 >
228          if (istree(cu->cutree)) {
229 <                                                /* do children */
229 >                CUBE  cukid;                    /* do children */
230 >                int  i, j;
231                  cukid.cusize = cu->cusize * 0.5;
232                  for (i = 0; i < 8; i++) {
233                          cukid.cutree = octkid(cu->cutree, i);
# Line 236 | Line 242 | OBJECT  obj;
242                  return;
243          }
244          if (isempty(cu->cutree)) {
245 <                                                /* singular set */
245 >                OBJECT  oset[2];                /* singular set */
246                  oset[0] = 1; oset[1] = obj;
247                  cu->cutree = fullnode(oset);
248                  return;
249          }
250                                          /* add to full node */
251 +        add2full(cu, obj, inc);
252 + }
253 +
254 +
255 + static void
256 + add2full(                       /* add object to full node */
257 +        CUBE  *cu,
258 +        OBJECT  obj,
259 +        int  inc
260 + )
261 + {
262 +        OCTREE  ot;
263 +        OBJECT  oset[MAXSET+1];
264 +        CUBE  cukid;
265 +        unsigned char  inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8];
266 +        int  i, j;
267 +
268          objset(oset, cu->cutree);
269          cukid.cusize = cu->cusize * 0.5;
270 <        
271 <        if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
270 >
271 >        if (inc==O_IN || oset[0] < objlim || cukid.cusize <
272 >                        (oset[0] < MAXSET ? mincusize : mincusize/256.0)) {
273                                                  /* add to set */
274                  if (oset[0] >= MAXSET) {
275 <                        sprintf(errmsg,
252 <                                "set overflow in addobject (%s)",
275 >                        sprintf(errmsg, "set overflow in addobject (%s)",
276                                          objptr(obj)->oname);
277                          error(INTERNAL, errmsg);
278                  }
# Line 268 | Line 291 | OBJECT  obj;
291                  if (isvolume(objptr(oset[j])->otype)) {
292                          setbit(volflg,j-1);
293                          if ((*ofun[objptr(oset[j])->otype].funp)
294 <                                        (objptr(oset[j]),cu) == O_IN)
294 >                                        (objptr(oset[j]), cu) == O_IN)
295                                  setbit(inflg,j-1);
296                  }
297                                          /* assign subcubes */
# Line 285 | Line 308 | OBJECT  obj;
308                                  addobject(&cukid, oset[j]);
309                                          /* then this object */
310                  addobject(&cukid, obj);
311 <                                        /* partial volumes */
311 >                                        /* then partial volumes */
312                  for (j = 1; j <= oset[0]; j++)
313                          if (tstbit(volflg,j-1) &&
314                                          !tstbit(inflg,j-1))
315                                  addobject(&cukid, oset[j]);
316 <                                        /* full volumes */
316 >                                        /* full volumes last */
317                  for (j = 1; j <= oset[0]; j++)
318                          if (tstbit(inflg,j-1))
319                                  addobject(&cukid, oset[j]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines