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.9 by greg, Mon Jun 7 09:42:16 1993 UTC vs.
Revision 2.14 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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   *  readoct.c - routines to read octree information.
9 *
10 *     7/30/85
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "standard.h"
11  
12   #include  "octree.h"
# Line 21 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18   static double  ogetflt();
19   static long  ogetint();
20   static char  *ogetstr();
21 < static int  getobj(), octerror();
21 > static int  nonsurfinset();
22 > static int  getobj(), octerror(), skiptree();
23   static OCTREE  getfullnode(), gettree();
24  
25 < static char  *infn;                     /* input file name */
25 > static char  *infn;                     /* input file specification */
26   static FILE  *infp;                     /* input file stream */
27   static int  objsize;                    /* size of stored OBJECT's */
28   static OBJECT  objorig;                 /* zeroeth object */
29 + static OBJECT  fnobjects;               /* number of objects in this file */
30   static short  otypmap[NUMOTYPE+8];      /* object type map */
31  
32  
33   int
34 < readoct(fname, load, scene, ofn)        /* read in octree from file */
35 < char  *fname;
34 > readoct(inpspec, load, scene, ofn)      /* read in octree file or stream */
35 > char  *inpspec;
36   int  load;
37   CUBE  *scene;
38   char  *ofn[];
39   {
40          char  sbuf[512];
41          int  nf;
43        OBJECT  fnobjects;
42          register int  i;
43          long  m;
44          
45 <        if (fname == NULL) {
45 >        if (inpspec == NULL) {
46                  infn = "standard input";
47                  infp = stdin;
48 +        } else if (inpspec[0] == '!') {
49 +                infn = inpspec;
50 +                if ((infp = popen(inpspec+1, "r")) == NULL) {
51 +                        sprintf(errmsg, "cannot execute \"%s\"", inpspec);
52 +                        error(SYSTEM, errmsg);
53 +                }
54          } else {
55 <                infn = fname;
56 <                if ((infp = fopen(fname, "r")) == NULL) {
55 >                infn = inpspec;
56 >                if ((infp = fopen(inpspec, "r")) == NULL) {
57                          sprintf(errmsg, "cannot open octree file \"%s\"",
58 <                                        fname);
58 >                                        inpspec);
59                          error(SYSTEM, errmsg);
60                  }
61          }
# Line 59 | Line 63 | char  *ofn[];
63          setmode(fileno(infp), O_BINARY);
64   #endif
65                                          /* get header */
66 <        if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0)
66 >        if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : (FILE *)NULL) < 0)
67                  octerror(USER, "not an octree");
68                                          /* check format */
69          if ((objsize = ogetint(2)-OCTMAGIC) <= 0 ||
# Line 90 | Line 94 | char  *ofn[];
94          if (fnobjects != m)
95                  octerror(USER, "too many objects");
96  
97 <        if (load & IO_TREE)                     /* get the octree */
97 >        if (load & IO_TREE)             /* get the octree */
98                  scene->cutree = gettree();
99          else if (load & IO_SCENE && nf == 0)
100                  skiptree();
# Line 109 | Line 113 | char  *ofn[];
113                  if (nobjects != objorig+fnobjects)
114                          octerror(USER, "bad object count; octree stale?");
115                                  /* check for non-surfaces */
116 <                if (nonsurfinset(objorig, fnobjects))
116 >                if (dosets(nonsurfinset))
117                          octerror(USER, "modifier in tree; octree stale?");
118              }
119 <        fclose(infp);
119 >                                /* close the input */
120 >        if (infn[0] == '!')
121 >                pclose(infp);
122 >        else
123 >                fclose(infp);
124          return(nf);
125   }
126  
# Line 199 | Line 207 | gettree()                      /* get a pre-ordered octree */
207   }
208  
209  
210 + static int
211 + nonsurfinset(os)                        /* check set for modifier */
212 + register OBJECT  *os;
213 + {
214 +        register OBJECT  s;
215 +        register int  i;
216 +
217 +        for (i = *os; i-- > 0; )
218 +                if ((s = *++os) >= objorig && s < objorig+fnobjects &&
219 +                                ismodifier(objptr(s)->otype))
220 +                        return(1);
221 +        return(0);
222 + }
223 +
224 +
225   static
226   skiptree()                              /* skip octree on input */
227   {
# Line 249 | Line 272 | getobj()                               /* get next object */
272          objp->omod = m;
273          objp->oname = savqstr(ogetstr(sbuf));
274          if (objp->oargs.nsargs = ogetint(2)) {
275 <                objp->oargs.sarg = (char **)bmalloc
275 >                objp->oargs.sarg = (char **)malloc
276                                  (objp->oargs.nsargs*sizeof(char *));
277                  if (objp->oargs.sarg == NULL)
278                          goto memerr;
# Line 259 | Line 282 | getobj()                               /* get next object */
282                  objp->oargs.sarg = NULL;
283   #ifdef  IARGS
284          if (objp->oargs.niargs = ogetint(2)) {
285 <                objp->oargs.iarg = (long *)bmalloc
285 >                objp->oargs.iarg = (long *)malloc
286                                  (objp->oargs.niargs*sizeof(long));
287                  if (objp->oargs.iarg == NULL)
288                          goto memerr;
# Line 269 | Line 292 | getobj()                               /* get next object */
292                  objp->oargs.iarg = NULL;
293   #endif
294          if (objp->oargs.nfargs = ogetint(2)) {
295 <                objp->oargs.farg = (FLOAT *)bmalloc
295 >                objp->oargs.farg = (FLOAT *)malloc
296                                  (objp->oargs.nfargs*sizeof(FLOAT));
297                  if (objp->oargs.farg == NULL)
298                          goto memerr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines