--- ray/src/util/ranimove.c 2003/02/22 02:07:30 3.1
+++ ray/src/util/ranimove.c 2011/10/05 17:20:55 3.15
@@ -1,5 +1,5 @@
#ifndef lint
-static const char RCSid[] = "$Id: ranimove.c,v 3.1 2003/02/22 02:07:30 greg Exp $";
+static const char RCSid[] = "$Id: ranimove.c,v 3.15 2011/10/05 17:20:55 greg Exp $";
#endif
/*
* Radiance object animation program
@@ -9,67 +9,20 @@ static const char RCSid[] = "$Id: ranimove.c,v 3.1 200
* See ranimove.h and the ranimove(1) man page for details.
*/
-/* ====================================================================
- * 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 "ranimove.h"
-#include
+#include
+#ifdef _WIN32
+ #include /* struct timeval. XXX find a replacement? */
+#else
+ #include
+#endif
#include
+#include
+#include "paths.h"
+#include "ranimove.h"
+
int NVARS = NV_INIT; /* total number of variables */
VARIABLE vv[] = VV_INIT; /* variable-value pairs */
@@ -109,11 +62,21 @@ int haveprio = 0; /* high-level saliency specified */
int gargc; /* global argc for printargs */
char **gargv; /* global argv for printargs */
+static void setdefaults(void);
+static void setmove(struct ObjMove *om, char *ms);
+static void setrendparams(char *optf, char *qval);
+static void getradfile(char *rfargs);
+static void animate(void);
+static int countviews(void); /* XXX duplicated function */
+static char * getobjname(struct ObjMove *om);
+static char * getxf(struct ObjMove *om, int n);
+
int
-main(argc, argv)
-int argc;
-char *argv[];
+main(
+ int argc,
+ char *argv[]
+)
{
int explicate = 0;
char *cfname;
@@ -146,7 +109,7 @@ char *argv[];
case 'f': /* frame range */
switch (sscanf(argv[++i], "%d,%d", &fbeg, &fend)) {
case 2:
- if ((fbeg <= 0 | fend < fbeg))
+ if ((fbeg <= 0) | (fend < fbeg))
goto userr;
break;
case 1:
@@ -190,7 +153,7 @@ char *argv[];
/* all done */
if (lorendoptf[0])
unlink(lorendoptf);
- if (hirendoptf[0])
+ if (hirendoptf[0] && strcmp(hirendoptf, lorendoptf))
unlink(hirendoptf);
if (objtmpf[0])
unlink(objtmpf);
@@ -200,12 +163,14 @@ userr:
"Usage: %s [-n nprocs][-f beg,end][-t sec][-d jnd][-s][-w][-e] anim_file\n",
progname);
quit(1);
+ return 1; /* pro forma return */
}
void
-eputs(s) /* put string to stderr */
-register char *s;
+eputs( /* put string to stderr */
+ register char *s
+)
{
static int midline = 0;
@@ -224,8 +189,18 @@ register char *s;
void
-setdefaults() /* set default values */
+quit(ec) /* make sure exit is called */
+int ec;
{
+ if (ray_pnprocs > 0) /* close children if any */
+ ray_pclose(0);
+ exit(ec);
+}
+
+
+static void
+setdefaults(void) /* set default values */
+{
int nviews;
int decades;
char buf[256];
@@ -296,14 +271,15 @@ setdefaults() /* set default values */
setrendparams(lorendoptf, vval(LOWQ));
ray_save(&lorendparams);
curparams = &lorendparams;
- twolevels = bcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS));
+ twolevels = memcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS));
}
-void
-setmove(om, ms) /* assign a move object from spec. */
-struct ObjMove *om;
-char *ms;
+static void
+setmove( /* assign a move object from spec. */
+ struct ObjMove *om,
+ char *ms
+)
{
char parname[128];
char *cp;
@@ -348,7 +324,7 @@ char *ms;
if (isflt(om->prio_file)) {
om->prio = atof(om->prio_file);
om->prio_file[0] = '\0';
- haveprio |= (om->prio < 0.95 | om->prio > 1.05);
+ haveprio |= ((om->prio < 0.95) | (om->prio > 1.05));
} else
haveprio = 1;
} else
@@ -360,10 +336,11 @@ badspec:
}
-void
-setrendparams(optf, qval) /* set global rendering parameters */
-char *optf;
-char *qval;
+static void
+setrendparams( /* set global rendering parameters */
+ char *optf,
+ char *qval
+)
{
char *argv[1024];
char **av = argv;
@@ -383,8 +360,8 @@ char *qval;
if (qval != NULL && qval[0] == '-')
ac += wordstring(av+ac, qval);
- /* start with default parameters */
- ray_defaults(NULL);
+ /* restore default parameters */
+ ray_restore(NULL);
/* set what we have */
for (i = 0; i < ac; i++) {
while ((rval = expandarg(&ac, &av, i)) > 0)
@@ -398,25 +375,25 @@ char *qval;
continue;
}
rval = getrenderopt(ac-i, av+i);
- if (rval >= 0) {
- i += rval;
- continue;
+ if (rval < 0) {
+ sprintf(errmsg, "bad render option at '%s'", av[i]);
+ error(USER, errmsg);
}
- sprintf(errmsg, "bad render option at '%s'", av[i]);
- error(USER, errmsg);
+ i += rval;
}
}
-void
-getradfile(rfargs) /* run rad and get needed variables */
-char *rfargs;
+static void
+getradfile( /* run rad and get needed variables */
+ char *rfargs
+)
{
static short mvar[] = {OCONV,OCTREEF,RESOLUTION,EXPOSURE,-1};
char combuf[256];
register int i;
register char *cp;
- char *pippt;
+ char *pippt = NULL;
/* create rad command */
strcpy(lorendoptf, "ranim0.opt");
sprintf(combuf,
@@ -437,7 +414,7 @@ char *rfargs;
pippt = NULL;
}
if (pippt != NULL)
- strcpy(pippt, "> /dev/null"); /* nothing to match */
+ strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */
else {
strcpy(cp, ")[ \t]*=' > ranimove.var");
cp += 11; /* point to file name */
@@ -459,8 +436,8 @@ char *rfargs;
}
-void
-animate() /* run through animation */
+static void
+animate(void) /* run through animation */
{
int rpass;
@@ -491,9 +468,10 @@ animate() /* run through animation */
}
-VIEW *
-getview(n) /* get view number n */
-int n;
+extern VIEW *
+getview( /* get view number n */
+ int n
+)
{
static FILE *viewfp = NULL; /* view file pointer */
static int viewnum = 0; /* current view number */
@@ -505,7 +483,7 @@ int n;
fclose(viewfp);
viewfp = NULL;
viewnum = 0;
- copystruct(&curview, &stdview);
+ curview = stdview;
}
return(NULL);
}
@@ -521,7 +499,7 @@ int n;
perror(vval(VIEWFILE));
quit(1);
}
- copystruct(&curview, &stdview);
+ curview = stdview;
viewnum = 0;
}
if (n < 0) { /* get next view */
@@ -541,8 +519,8 @@ int n;
}
-int
-countviews() /* count views in view file */
+static int
+countviews(void) /* count views in view file */
{
int n;
@@ -554,9 +532,10 @@ countviews() /* count views in view file */
}
-char *
-getexp(n) /* get exposure for nth frame */
-int n;
+extern char *
+getexp( /* get exposure for nth frame */
+ int n
+)
{
extern char *fskip();
static char expval[32];
@@ -608,12 +587,14 @@ formerr:
sprintf(errmsg, "%s: exposure format error on line %d",
vval(EXPOSURE), curfrm);
error(USER, errmsg);
+ return NULL; /* pro forma return */
}
-double
-expspec_val(s) /* get exposure value from spec. */
-char *s;
+extern double
+expspec_val( /* get exposure value from spec. */
+ char *s
+)
{
double expval;
@@ -621,30 +602,30 @@ char *s;
return(1.0);
expval = atof(s);
- if ((s[0] == '+' | s[0] == '-'))
+ if ((s[0] == '+') | (s[0] == '-'))
return(pow(2.0, expval));
return(expval);
}
-char *
-getoctspec(n) /* get octree for the given frame */
-int n;
+extern char *
+getoctspec( /* get octree for the given frame */
+ int n
+)
{
static char combuf[1024];
- int cfm = 0;
+ static int cfm = 0;
int uses_inline;
FILE *fp;
int i;
/* is octree static? */
if (!vdef(MOVE))
return(vval(OCTREEF));
- /* done already */
+ /* done already? */
if (n == cfm)
return(combuf);
/* else create object file */
- strcpy(objtmpf, "movinobj.rad");
- fp = fopen(objtmpf, "w");
+ fp = fopen(mktemp(strcpy(objtmpf, TEMPLATE)), "w");
if (fp == NULL) {
sprintf(errmsg, "cannot write to moving objects file '%s'",
objtmpf);
@@ -675,15 +656,17 @@ int n;
vdef(OCONV) ? vval(OCONV) : "",
vval(OCTREEF), objtmpf);
else
- sprintf(combuf, "!xform -f %s | oconv -f -i '%s' -",
- objtmpf, vval(OCTREEF));
+ sprintf(combuf, "!xform -f %s | oconv %s -f -i '%s' -",
+ objtmpf, vdef(OCONV) ? vval(OCONV) : "",
+ vval(OCTREEF));
return(combuf);
}
-char *
-getobjname(om) /* get fully qualified object name */
-register struct ObjMove *om;
+static char *
+getobjname( /* get fully qualified object name */
+ register struct ObjMove *om
+)
{
static char objName[512];
register char *cp = objName;
@@ -699,10 +682,11 @@ register struct ObjMove *om;
}
-char *
-getxf(om, n) /* get total transform for object */
-register struct ObjMove *om;
-int n;
+static char *
+getxf( /* get total transform for object */
+ register struct ObjMove *om,
+ int n
+)
{
static char xfsbuf[4096];
char *xfp;
@@ -810,19 +794,21 @@ int n;
om->cprio = om->prio;
}
/* XXX bxfm relies on call order */
- if (framestep)
+ if (framestep) {
if (invmat4(om->bxfm, om->cxfm))
multmat4(om->bxfm, om->bxfm, oxf.xfm);
else
setident4(om->bxfm);
+ }
/* all done */
return(xfp);
}
-int
-getmove(obj) /* find matching move object */
-OBJECT obj;
+extern int
+getmove( /* find matching move object */
+ OBJECT obj
+)
{
static int lasti;
static OBJECT lasto = OVOID;
@@ -840,7 +826,7 @@ OBJECT obj;
objnm = obj_move[i].name;
len = strlen(objnm);
if (!strncmp(onm, objnm, len)) {
- if ((obj_move[i].parent < 0 & onm[len] == '.'))
+ if ((obj_move[i].parent < 0) & (onm[len] == '.'))
break;
objnm = getobjname(&obj_move[i]) + len;
len2 = strlen(objnm);
@@ -853,9 +839,10 @@ OBJECT obj;
}
-double
-obj_prio(obj) /* return priority for object */
-OBJECT obj;
+extern double
+obj_prio( /* return priority for object */
+ OBJECT obj
+)
{
int moi;
@@ -865,8 +852,46 @@ OBJECT obj;
}
-double
-getTime() /* get current time (CPU or real) */
+#ifdef _WIN32
+ /* replacement function for Windoze */
+static int
+gettimeofday(struct timeval *tp, void *dummy)
+{
+ FILETIME ft;
+ LARGE_INTEGER li;
+ __int64 t;
+
+ SYSTEMTIME st;
+ FILETIME ft2;
+ LARGE_INTEGER li2;
+ __int64 t2;
+
+ st.wYear = 1970;
+ st.wHour = 0;
+ st.wMinute = 0;
+ st.wSecond = 0;
+ st.wMilliseconds = 1;
+
+ SystemTimeToFileTime(&st, &ft2);
+ li2.LowPart = ft2.dwLowDateTime;
+ li2.HighPart = ft2.dwHighDateTime;
+ t2 = li2.QuadPart;
+
+ GetSystemTimeAsFileTime(&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ t = li.QuadPart;
+ t -= t2; // From 1970
+ t /= 10; // In microseconds
+ tp->tv_sec = (long)(t / 1000000);
+ tp->tv_usec = (long)(t % 1000000);
+ return 0;
+}
+
+#endif
+
+extern double
+getTime(void) /* get current time (CPU or real) */
{
struct timeval time_now;
/* return CPU time if one process */