ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readoct.c
(Generate patch)

Comparing ray/src/common/readoct.c (file contents):
Revision 2.4 by greg, Mon Jul 13 15:36:29 1992 UTC vs.
Revision 2.10 by greg, Thu Nov 18 09:27:01 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 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 21 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21   static double  ogetflt();
22   static long  ogetint();
23   static char  *ogetstr();
24 < static int  getobj(), octerror();
24 > static int  getobj(), octerror(), skiptree();
25   static OCTREE  getfullnode(), gettree();
26  
27   static char  *infn;                     /* input file name */
# Line 38 | Line 38 | int  load;
38   CUBE  *scene;
39   char  *ofn[];
40   {
41        extern int  fputs();
41          char  sbuf[512];
42          int  nf;
43 <        OBJECT  fnobjects;
43 >        OBJECT  fnobjects;
44          register int  i;
45          long  m;
46          
# Line 56 | Line 55 | char  *ofn[];
55                          error(SYSTEM, errmsg);
56                  }
57          }
58 + #ifdef MSDOS
59 +        setmode(fileno(infp), O_BINARY);
60 + #endif
61                                          /* get header */
62          if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0)
63                  octerror(USER, "not an octree");
# Line 88 | Line 90 | char  *ofn[];
90          if (fnobjects != m)
91                  octerror(USER, "too many objects");
92  
93 <        if (load & IO_TREE) {
92 <                                                /* get the octree */
93 >        if (load & IO_TREE)                     /* get the octree */
94                  scene->cutree = gettree();
95 <                if (load & IO_SCENE)            /* get the scene */
96 <                    if (nf == 0) {
97 <                        for (i = 0; *ogetstr(sbuf); i++)
98 <                                if ((otypmap[i] = otype(sbuf)) < 0) {
99 <                                        sprintf(errmsg, "unknown type \"%s\"",
100 <                                                        sbuf);
101 <                                        octerror(WARNING, errmsg);
102 <                                }
103 <                        while (getobj() != OVOID)
104 <                                ;
105 <                    } else {                    /* consistency checks */
106 <                                        /* check object count */
107 <                        if (nobjects != objorig+fnobjects)
108 <                                octerror(USER, "bad object count; octree stale?");
109 <                                        /* check for non-surfaces */
110 <                        if (nonsurfinset(objorig, fnobjects))
111 <                                octerror(USER, "modifier in tree; octree stale?");
112 <                    }
113 <        }
95 >        else if (load & IO_SCENE && nf == 0)
96 >                skiptree();
97 >                
98 >        if (load & IO_SCENE)            /* get the scene */
99 >            if (nf == 0) {
100 >                for (i = 0; *ogetstr(sbuf); i++)
101 >                        if ((otypmap[i] = otype(sbuf)) < 0) {
102 >                                sprintf(errmsg, "unknown type \"%s\"", sbuf);
103 >                                octerror(WARNING, errmsg);
104 >                        }
105 >                while (getobj() != OVOID)
106 >                        ;
107 >            } else {                    /* consistency checks */
108 >                                /* check object count */
109 >                if (nobjects != objorig+fnobjects)
110 >                        octerror(USER, "bad object count; octree stale?");
111 >                                /* check for non-surfaces */
112 >                if (nonsurfinset(objorig, fnobjects))
113 >                        octerror(USER, "modifier in tree; octree stale?");
114 >            }
115          fclose(infp);
116          return(nf);
117   }
# Line 130 | Line 132 | char  *s;
132   static OCTREE
133   getfullnode()                   /* get a set, return fullnode */
134   {
135 <        OBJECT  set[MAXSET+1];
135 >        OBJECT  set[MAXSET+1];
136          register int  i;
137          register long  m;
138  
# Line 163 | Line 165 | static double
165   ogetflt()                       /* get a floating point number */
166   {
167          extern double  getflt();
168 <        double  r;
168 >        double  r;
169  
170          r = getflt(infp);
171          if (feof(infp))
# Line 175 | Line 177 | ogetflt()                      /* get a floating point number */
177   static OCTREE
178   gettree()                       /* get a pre-ordered octree */
179   {
180 <        register OCTREE  ot;
180 >        register OCTREE  ot;
181          register int  i;
182          
183          switch (getc(infp)) {
# Line 198 | Line 200 | gettree()                      /* get a pre-ordered octree */
200  
201  
202   static
203 + skiptree()                              /* skip octree on input */
204 + {
205 +        register int  i;
206 +        
207 +        switch (getc(infp)) {
208 +        case OT_EMPTY:
209 +                return;
210 +        case OT_FULL:
211 +                for (i = ogetint(objsize)*objsize; i-- > 0; )
212 +                        if (getc(infp) == EOF)
213 +                                octerror(USER, "truncated octree");
214 +                return;
215 +        case OT_TREE:
216 +                for (i = 0; i < 8; i++)
217 +                        skiptree();
218 +                return;
219 +        case EOF:
220 +                octerror(USER, "truncated octree");
221 +        default:
222 +                octerror(USER, "damaged octree");
223 +        }
224 + }
225 +
226 +
227 + static
228   getobj()                                /* get next object */
229   {
230          char  sbuf[MAXSTR];
231          int  obj;
232          register int  i;
233          register long  m;
234 <        register OBJREC  *objp;
234 >        register OBJREC  *objp;
235  
236          i = ogetint(1);
237          if (i == -1)
# Line 230 | Line 257 | getobj()                               /* get next object */
257                          objp->oargs.sarg[i] = savestr(ogetstr(sbuf));
258          } else
259                  objp->oargs.sarg = NULL;
260 < #ifdef  IARGS
260 > #ifdef  IARGS
261          if (objp->oargs.niargs = ogetint(2)) {
262                  objp->oargs.iarg = (long *)bmalloc
263                                  (objp->oargs.niargs*sizeof(long));
# Line 252 | Line 279 | getobj()                               /* get next object */
279                  objp->oargs.farg = NULL;
280                                                  /* initialize */
281          objp->os = NULL;
255        objp->lastrno = -1;
282                                                  /* insert */
283          insertobject(obj);
284          return(obj);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines