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.11 by greg, Wed Aug 29 21:56:17 1990 UTC vs.
Revision 2.6 by greg, Fri Feb 12 18:43:24 1993 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");
99 <                        outflags &= ~IO_FILES;
100 <                }
105 >                if (nfiles == 0)
106 >                        inpfrozen++;
107          }
108  
109          printargs(argc, argv, stdout);  /* info. header */
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,^=)
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];
220 <        unsigned char  inflg[MAXSET/8], volflg[MAXSET/8];
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  
# Line 213 | Line 225 | OBJECT  obj;
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 238 | Line 250 | OBJECT  obj;
250                                          /* add to full node */
251          objset(oset, cu->cutree);
252          cukid.cusize = cu->cusize * 0.5;
253 <        
253 >
254          if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) {
255                                                  /* add to set */
256                  if (oset[0] >= MAXSET) {
257 <                        sprintf(errmsg,
246 <                                "set overflow in addobject (%s)",
257 >                        sprintf(errmsg, "set overflow in addobject (%s)",
258                                          objptr(obj)->oname);
259                          error(INTERNAL, errmsg);
260                  }
# Line 262 | Line 273 | OBJECT  obj;
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)
276 >                                        (objptr(oset[j]), cu) == O_IN)
277                                  setbit(inflg,j-1);
278                  }
279                                          /* assign subcubes */
# Line 279 | Line 290 | OBJECT  obj;
290                                  addobject(&cukid, oset[j]);
291                                          /* then this object */
292                  addobject(&cukid, obj);
293 <                                        /* partial volumes */
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 */
298 >                                        /* full volumes last */
299                  for (j = 1; j <= oset[0]; j++)
300                          if (tstbit(inflg,j-1))
301                                  addobject(&cukid, oset[j]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines