--- ray/src/common/readoct.c 1994/08/29 14:20:37 2.11 +++ ray/src/common/readoct.c 2003/02/22 02:07:22 2.13 @@ -1,13 +1,65 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: readoct.c,v 2.13 2003/02/22 02:07:22 greg Exp $"; #endif - /* * readoct.c - routines to read octree information. + */ + +/* ==================================================================== + * The Radiance Software License, Version 1.0 * - * 7/30/85 + * Copyright (c) 1990 - 2002 The Regents of the University of California, + * through Lawrence Berkeley National Laboratory. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes Radiance software + * (http://radsite.lbl.gov/) + * developed by the Lawrence Berkeley National Laboratory + * (http://www.lbl.gov/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory" + * and "The Regents of the University of California" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact radiance@radsite.lbl.gov. + * + * 5. Products derived from this software may not be called "Radiance", + * nor may "Radiance" appear in their name, without prior written + * permission of Lawrence Berkeley National Laboratory. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of Lawrence Berkeley National Laboratory. For more + * information on Lawrence Berkeley National Laboratory, please see + * . */ #include "standard.h" @@ -21,37 +73,44 @@ static char SCCSid[] = "$SunId$ LBL"; static double ogetflt(); static long ogetint(); static char *ogetstr(); +static int nonsurfinset(); static int getobj(), octerror(), skiptree(); static OCTREE getfullnode(), gettree(); -static char *infn; /* input file name */ +static char *infn; /* input file specification */ static FILE *infp; /* input file stream */ static int objsize; /* size of stored OBJECT's */ static OBJECT objorig; /* zeroeth object */ +static OBJECT fnobjects; /* number of objects in this file */ static short otypmap[NUMOTYPE+8]; /* object type map */ int -readoct(fname, load, scene, ofn) /* read in octree from file */ -char *fname; +readoct(inpspec, load, scene, ofn) /* read in octree file or stream */ +char *inpspec; int load; CUBE *scene; char *ofn[]; { char sbuf[512]; int nf; - OBJECT fnobjects; register int i; long m; - if (fname == NULL) { + if (inpspec == NULL) { infn = "standard input"; infp = stdin; + } else if (inpspec[0] == '!') { + infn = inpspec; + if ((infp = popen(inpspec+1, "r")) == NULL) { + sprintf(errmsg, "cannot execute \"%s\"", inpspec); + error(SYSTEM, errmsg); + } } else { - infn = fname; - if ((infp = fopen(fname, "r")) == NULL) { + infn = inpspec; + if ((infp = fopen(inpspec, "r")) == NULL) { sprintf(errmsg, "cannot open octree file \"%s\"", - fname); + inpspec); error(SYSTEM, errmsg); } } @@ -90,7 +149,7 @@ char *ofn[]; if (fnobjects != m) octerror(USER, "too many objects"); - if (load & IO_TREE) /* get the octree */ + if (load & IO_TREE) /* get the octree */ scene->cutree = gettree(); else if (load & IO_SCENE && nf == 0) skiptree(); @@ -109,10 +168,14 @@ char *ofn[]; if (nobjects != objorig+fnobjects) octerror(USER, "bad object count; octree stale?"); /* check for non-surfaces */ - if (nonsurfinset(objorig, fnobjects)) + if (dosets(nonsurfinset)) octerror(USER, "modifier in tree; octree stale?"); } - fclose(infp); + /* close the input */ + if (infn[0] == '!') + pclose(infp); + else + fclose(infp); return(nf); } @@ -199,6 +262,21 @@ gettree() /* get a pre-ordered octree */ } +static int +nonsurfinset(os) /* check set for modifier */ +register OBJECT *os; +{ + register OBJECT s; + register int i; + + for (i = *os; i-- > 0; ) + if ((s = *++os) >= objorig && s < objorig+fnobjects && + ismodifier(objptr(s)->otype)) + return(1); + return(0); +} + + static skiptree() /* skip octree on input */ { @@ -249,7 +327,7 @@ getobj() /* get next object */ objp->omod = m; objp->oname = savqstr(ogetstr(sbuf)); if (objp->oargs.nsargs = ogetint(2)) { - objp->oargs.sarg = (char **)bmalloc + objp->oargs.sarg = (char **)malloc (objp->oargs.nsargs*sizeof(char *)); if (objp->oargs.sarg == NULL) goto memerr; @@ -259,7 +337,7 @@ getobj() /* get next object */ objp->oargs.sarg = NULL; #ifdef IARGS if (objp->oargs.niargs = ogetint(2)) { - objp->oargs.iarg = (long *)bmalloc + objp->oargs.iarg = (long *)malloc (objp->oargs.niargs*sizeof(long)); if (objp->oargs.iarg == NULL) goto memerr; @@ -269,7 +347,7 @@ getobj() /* get next object */ objp->oargs.iarg = NULL; #endif if (objp->oargs.nfargs = ogetint(2)) { - objp->oargs.farg = (FLOAT *)bmalloc + objp->oargs.farg = (FLOAT *)malloc (objp->oargs.nfargs*sizeof(FLOAT)); if (objp->oargs.farg == NULL) goto memerr;