--- ray/src/common/readoct.c 2003/02/22 02:07:22 2.13
+++ ray/src/common/readoct.c 2025/06/07 05:09:45 2.37
@@ -1,100 +1,50 @@
#ifndef lint
-static const char RCSid[] = "$Id: readoct.c,v 2.13 2003/02/22 02:07:22 greg Exp $";
+static const char RCSid[] = "$Id: readoct.c,v 2.37 2025/06/07 05:09:45 greg Exp $";
#endif
/*
* readoct.c - routines to read octree information.
*/
-/* ====================================================================
- * The Radiance Software License, Version 1.0
- *
- * 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 "copyright.h"
-#include "standard.h"
+#include
+#include
+#include "platform.h"
+#include "standard.h"
#include "octree.h"
-
#include "object.h"
-
#include "otypes.h"
+#include "resolu.h"
-static double ogetflt();
-static long ogetint();
-static char *ogetstr();
-static int nonsurfinset();
-static int getobj(), octerror(), skiptree();
-static OCTREE getfullnode(), gettree();
+static double ogetflt(void);
+static long ogetint(int);
+static char *ogetstr(char *);
+static int nonsurfintree(OCTREE ot);
+static void octerror(int etyp, char *msg);
+static void skiptree(void);
+static OCTREE getfullnode(void), gettree(void);
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(inpspec, load, scene, ofn) /* read in octree file or stream */
-char *inpspec;
-int load;
-CUBE *scene;
-char *ofn[];
+readoct( /* read in octree file or stream */
+ char *inpspec,
+ int load,
+ CUBE *scene,
+ char *ofn[]
+)
{
+ time_t oct_t = 0;
+ time_t last_it = 0;
char sbuf[512];
int nf;
- register int i;
+ int i;
long m;
if (inpspec == NULL) {
@@ -113,10 +63,12 @@ char *ofn[];
inpspec);
error(SYSTEM, errmsg);
}
+ oct_t = fddate(fileno(infp));
}
-#ifdef MSDOS
- setmode(fileno(infp), O_BINARY);
+#ifdef getc_unlocked /* avoid stupid semaphores */
+ flockfile(infp);
#endif
+ SET_FILE_BINARY(infp);
/* get header */
if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : (FILE *)NULL) < 0)
octerror(USER, "not an octree");
@@ -140,6 +92,11 @@ char *ofn[];
readobj(sbuf);
if (load & IO_FILES)
ofn[nf] = savqstr(sbuf);
+ if (oct_t > last_it) {
+ time_t t = fdate(sbuf);
+ if (t > last_it)
+ last_it = t;
+ }
nf++;
}
if (load & IO_FILES)
@@ -154,38 +111,39 @@ char *ofn[];
else if (load & IO_SCENE && nf == 0)
skiptree();
- if (load & IO_SCENE) /* get the scene */
+ if (load & IO_SCENE) { /* get the scene */
if (nf == 0) {
- for (i = 0; *ogetstr(sbuf); i++)
- if ((otypmap[i] = otype(sbuf)) < 0) {
- sprintf(errmsg, "unknown type \"%s\"", sbuf);
- octerror(WARNING, errmsg);
- }
- while (getobj() != OVOID)
- ;
+ /* load binary scene data */
+ readscene(infp, objsize);
+
} else { /* consistency checks */
/* check object count */
if (nobjects != objorig+fnobjects)
octerror(USER, "bad object count; octree stale?");
/* check for non-surfaces */
- if (dosets(nonsurfinset))
+ if (oct_t <= last_it && nonsurfintree(scene->cutree))
octerror(USER, "modifier in tree; octree stale?");
}
+ }
/* close the input */
- if (infn[0] == '!')
- pclose(infp);
- else
+ if (inpspec[0] == '!') {
+ if (pclose(infp) != 0) {
+ sprintf(errmsg, "bad status from \"%s\"", inpspec);
+ error(WARNING, errmsg);
+ }
+ } else if (infp != stdin)
fclose(infp);
+#ifdef getc_unlocked
+ else
+ funlockfile(infp);
+#endif
return(nf);
}
static char *
-ogetstr(s) /* get null-terminated string */
-char *s;
+ogetstr(char *s) /* get null-terminated string */
{
- extern char *getstr();
-
if (getstr(s, infp) == NULL)
octerror(USER, "truncated octree");
return(s);
@@ -196,8 +154,8 @@ static OCTREE
getfullnode() /* get a set, return fullnode */
{
OBJECT set[MAXSET+1];
- register int i;
- register long m;
+ int i;
+ long m;
if ((set[0] = ogetint(objsize)) > MAXSET)
octerror(USER, "bad set in getfullnode");
@@ -211,11 +169,9 @@ getfullnode() /* get a set, return fullnode */
static long
-ogetint(siz) /* get a siz-byte integer */
-int siz;
+ogetint(int siz) /* get a siz-byte integer */
{
- extern long getint();
- register long r;
+ long r;
r = getint(siz, infp);
if (feof(infp))
@@ -227,7 +183,6 @@ int siz;
static double
ogetflt() /* get a floating point number */
{
- extern double getflt();
double r;
r = getflt(infp);
@@ -240,8 +195,8 @@ ogetflt() /* get a floating point number */
static OCTREE
gettree() /* get a pre-ordered octree */
{
- register OCTREE ot;
- register int i;
+ OCTREE ot;
+ int i;
switch (getc(infp)) {
case OT_EMPTY:
@@ -259,28 +214,36 @@ gettree() /* get a pre-ordered octree */
default:
octerror(USER, "damaged octree");
}
+ return EMPTY; /* pro forma return */
}
static int
-nonsurfinset(os) /* check set for modifier */
-register OBJECT *os;
+nonsurfintree(OCTREE ot) /* check tree for modifiers */
{
- register OBJECT s;
- register int i;
+ OBJECT set[MAXSET+1];
+ int i;
- for (i = *os; i-- > 0; )
- if ((s = *++os) >= objorig && s < objorig+fnobjects &&
- ismodifier(objptr(s)->otype))
+ if (isempty(ot))
+ return(0);
+ if (istree(ot)) {
+ for (i = 0; i < 8; i++)
+ if (nonsurfintree(octkid(ot, i)))
+ return(1);
+ return(0);
+ }
+ objset(set, ot);
+ for (i = set[0]; i > 0; i-- )
+ if (ismodifier(objptr(set[i])->otype))
return(1);
return(0);
}
-static
-skiptree() /* skip octree on input */
+static void
+skiptree(void) /* skip octree on input */
{
- register int i;
+ int i;
switch (getc(infp)) {
case OT_EMPTY:
@@ -302,73 +265,8 @@ skiptree() /* skip octree on input */
}
-static
-getobj() /* get next object */
-{
- char sbuf[MAXSTR];
- int obj;
- register int i;
- register long m;
- register OBJREC *objp;
-
- i = ogetint(1);
- if (i == -1)
- return(OVOID); /* terminator */
- if ((obj = newobject()) == OVOID)
- error(SYSTEM, "out of object space");
- objp = objptr(obj);
- if ((objp->otype = otypmap[i]) < 0)
- octerror(USER, "reference to unknown type");
- if ((m = ogetint(objsize)) != OVOID) {
- m += objorig;
- if ((OBJECT)m != m)
- octerror(USER, "too many objects");
- }
- objp->omod = m;
- objp->oname = savqstr(ogetstr(sbuf));
- if (objp->oargs.nsargs = ogetint(2)) {
- objp->oargs.sarg = (char **)malloc
- (objp->oargs.nsargs*sizeof(char *));
- if (objp->oargs.sarg == NULL)
- goto memerr;
- for (i = 0; i < objp->oargs.nsargs; i++)
- objp->oargs.sarg[i] = savestr(ogetstr(sbuf));
- } else
- objp->oargs.sarg = NULL;
-#ifdef IARGS
- if (objp->oargs.niargs = ogetint(2)) {
- objp->oargs.iarg = (long *)malloc
- (objp->oargs.niargs*sizeof(long));
- if (objp->oargs.iarg == NULL)
- goto memerr;
- for (i = 0; i < objp->oargs.niargs; i++)
- objp->oargs.iarg[i] = ogetint(4);
- } else
- objp->oargs.iarg = NULL;
-#endif
- if (objp->oargs.nfargs = ogetint(2)) {
- objp->oargs.farg = (FLOAT *)malloc
- (objp->oargs.nfargs*sizeof(FLOAT));
- if (objp->oargs.farg == NULL)
- goto memerr;
- for (i = 0; i < objp->oargs.nfargs; i++)
- objp->oargs.farg[i] = ogetflt();
- } else
- objp->oargs.farg = NULL;
- /* initialize */
- objp->os = NULL;
- /* insert */
- insertobject(obj);
- return(obj);
-memerr:
- error(SYSTEM, "out of memory in getobj");
-}
-
-
-static
-octerror(etyp, msg) /* octree error */
-int etyp;
-char *msg;
+static void
+octerror(int etyp, char *msg) /* octree error */
{
char msgbuf[128];