1 |
|
#ifndef lint |
2 |
< |
static const char RCSid[] = "$Id$"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
|
* Radiance object animation program |
11 |
|
|
12 |
|
#include "copyright.h" |
13 |
|
|
14 |
< |
#include "ranimove.h" |
15 |
< |
#include <sys/time.h> |
14 |
> |
#include <time.h> |
15 |
> |
#if defined(_WIN32) || defined(_WIN64) |
16 |
> |
#include <winsock.h> /* struct timeval. XXX find a replacement? */ |
17 |
> |
#else |
18 |
> |
#include <sys/time.h> |
19 |
> |
#endif |
20 |
|
#include <ctype.h> |
21 |
+ |
#include <string.h> |
22 |
|
|
23 |
+ |
#include "platform.h" |
24 |
+ |
#include "paths.h" |
25 |
+ |
#include "ranimove.h" |
26 |
+ |
#include "func.h" |
27 |
+ |
|
28 |
|
int NVARS = NV_INIT; /* total number of variables */ |
29 |
|
|
30 |
|
VARIABLE vv[] = VV_INIT; /* variable-value pairs */ |
64 |
|
int gargc; /* global argc for printargs */ |
65 |
|
char **gargv; /* global argv for printargs */ |
66 |
|
|
67 |
+ |
static void setdefaults(void); |
68 |
+ |
static void setmove(struct ObjMove *om, char *ms); |
69 |
+ |
static void setrendparams(char *optf, char *qval); |
70 |
+ |
static void getradfile(char *rfargs); |
71 |
+ |
static void animate(void); |
72 |
+ |
static int countviews(void); /* XXX duplicated function */ |
73 |
+ |
static char * getobjname(struct ObjMove *om); |
74 |
+ |
static char * getxf(struct ObjMove *om, int n); |
75 |
|
|
76 |
+ |
|
77 |
|
int |
78 |
< |
main(argc, argv) |
79 |
< |
int argc; |
80 |
< |
char *argv[]; |
78 |
> |
main( |
79 |
> |
int argc, |
80 |
> |
char *argv[] |
81 |
> |
) |
82 |
|
{ |
83 |
|
int explicate = 0; |
84 |
|
char *cfname; |
85 |
|
int i; |
86 |
|
|
87 |
|
progname = argv[0]; /* get arguments */ |
88 |
+ |
/* initialize calcomp */ |
89 |
+ |
initfunc(); |
90 |
|
gargc = argc; |
91 |
|
gargv = argv; |
92 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
113 |
|
case 'f': /* frame range */ |
114 |
|
switch (sscanf(argv[++i], "%d,%d", &fbeg, &fend)) { |
115 |
|
case 2: |
116 |
< |
if ((fbeg <= 0 | fend < fbeg)) |
116 |
> |
if ((fbeg <= 0) | (fend < fbeg)) |
117 |
|
goto userr; |
118 |
|
break; |
119 |
|
case 1: |
157 |
|
/* all done */ |
158 |
|
if (lorendoptf[0]) |
159 |
|
unlink(lorendoptf); |
160 |
< |
if (hirendoptf[0]) |
160 |
> |
if (hirendoptf[0] && strcmp(hirendoptf, lorendoptf)) |
161 |
|
unlink(hirendoptf); |
162 |
|
if (objtmpf[0]) |
163 |
|
unlink(objtmpf); |
167 |
|
"Usage: %s [-n nprocs][-f beg,end][-t sec][-d jnd][-s][-w][-e] anim_file\n", |
168 |
|
progname); |
169 |
|
quit(1); |
170 |
+ |
return 1; /* pro forma return */ |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
void |
175 |
< |
eputs(s) /* put string to stderr */ |
176 |
< |
register char *s; |
175 |
> |
eputs( /* put string to stderr */ |
176 |
> |
const char *s |
177 |
> |
) |
178 |
|
{ |
179 |
|
static int midline = 0; |
180 |
|
|
193 |
|
|
194 |
|
|
195 |
|
void |
196 |
< |
setdefaults() /* set default values */ |
196 |
> |
quit(int ec) /* make sure exit is called */ |
197 |
|
{ |
198 |
+ |
if (ray_pnprocs > 0) /* close children if any */ |
199 |
+ |
ray_pclose(0); |
200 |
+ |
else if (ray_pnprocs < 0) |
201 |
+ |
_exit(ec); /* avoid flush in child */ |
202 |
+ |
exit(ec); |
203 |
+ |
} |
204 |
+ |
|
205 |
+ |
|
206 |
+ |
static void |
207 |
+ |
setdefaults(void) /* set default values */ |
208 |
+ |
{ |
209 |
|
int nviews; |
210 |
|
int decades; |
211 |
|
char buf[256]; |
276 |
|
setrendparams(lorendoptf, vval(LOWQ)); |
277 |
|
ray_save(&lorendparams); |
278 |
|
curparams = &lorendparams; |
279 |
< |
twolevels = bcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS)); |
279 |
> |
twolevels = memcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS)); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
void |
284 |
< |
setmove(om, ms) /* assign a move object from spec. */ |
285 |
< |
struct ObjMove *om; |
286 |
< |
char *ms; |
283 |
> |
static void |
284 |
> |
setmove( /* assign a move object from spec. */ |
285 |
> |
struct ObjMove *om, |
286 |
> |
char *ms |
287 |
> |
) |
288 |
|
{ |
289 |
|
char parname[128]; |
290 |
|
char *cp; |
329 |
|
if (isflt(om->prio_file)) { |
330 |
|
om->prio = atof(om->prio_file); |
331 |
|
om->prio_file[0] = '\0'; |
332 |
< |
haveprio |= (om->prio < 0.95 | om->prio > 1.05); |
332 |
> |
haveprio |= ((om->prio < 0.95) | (om->prio > 1.05)); |
333 |
|
} else |
334 |
|
haveprio = 1; |
335 |
|
} else |
341 |
|
} |
342 |
|
|
343 |
|
|
344 |
< |
void |
345 |
< |
setrendparams(optf, qval) /* set global rendering parameters */ |
346 |
< |
char *optf; |
347 |
< |
char *qval; |
344 |
> |
static void |
345 |
> |
setrendparams( /* set global rendering parameters */ |
346 |
> |
char *optf, |
347 |
> |
char *qval |
348 |
> |
) |
349 |
|
{ |
350 |
|
char *argv[1024]; |
351 |
|
char **av = argv; |
354 |
|
av[ac=0] = NULL; |
355 |
|
/* load options from file, first */ |
356 |
|
if (optf != NULL && *optf) { |
357 |
< |
ac = wordfile(av, optf); |
357 |
> |
ac = wordfile(av, 1024, optf); |
358 |
|
if (ac < 0) { |
359 |
|
sprintf(errmsg, "cannot load options file \"%s\"", |
360 |
|
optf); |
363 |
|
} |
364 |
|
/* then from options string */ |
365 |
|
if (qval != NULL && qval[0] == '-') |
366 |
< |
ac += wordstring(av+ac, qval); |
366 |
> |
ac += wordstring(av+ac, 1024-ac, qval); |
367 |
|
|
368 |
< |
/* start with default parameters */ |
369 |
< |
ray_defaults(NULL); |
368 |
> |
/* restore default parameters */ |
369 |
> |
ray_restore(NULL); |
370 |
|
/* set what we have */ |
371 |
|
for (i = 0; i < ac; i++) { |
372 |
|
while ((rval = expandarg(&ac, &av, i)) > 0) |
380 |
|
continue; |
381 |
|
} |
382 |
|
rval = getrenderopt(ac-i, av+i); |
383 |
< |
if (rval >= 0) { |
384 |
< |
i += rval; |
385 |
< |
continue; |
383 |
> |
if (rval < 0) { |
384 |
> |
sprintf(errmsg, "bad render option at '%s'", av[i]); |
385 |
> |
error(USER, errmsg); |
386 |
|
} |
387 |
< |
sprintf(errmsg, "bad render option at '%s'", av[i]); |
351 |
< |
error(USER, errmsg); |
387 |
> |
i += rval; |
388 |
|
} |
389 |
|
} |
390 |
|
|
391 |
|
|
392 |
< |
void |
393 |
< |
getradfile(rfargs) /* run rad and get needed variables */ |
394 |
< |
char *rfargs; |
392 |
> |
static void |
393 |
> |
getradfile( /* run rad and get needed variables */ |
394 |
> |
char *rfargs |
395 |
> |
) |
396 |
|
{ |
397 |
|
static short mvar[] = {OCONV,OCTREEF,RESOLUTION,EXPOSURE,-1}; |
398 |
|
char combuf[256]; |
399 |
< |
register int i; |
400 |
< |
register char *cp; |
401 |
< |
char *pippt; |
399 |
> |
int i; |
400 |
> |
char *cp; |
401 |
> |
char *pippt = NULL; |
402 |
|
/* create rad command */ |
403 |
|
strcpy(lorendoptf, "ranim0.opt"); |
404 |
|
sprintf(combuf, |
419 |
|
pippt = NULL; |
420 |
|
} |
421 |
|
if (pippt != NULL) |
422 |
< |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
422 |
> |
strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */ |
423 |
|
else { |
424 |
|
strcpy(cp, ")[ \t]*=' > ranimove.var"); |
425 |
|
cp += 11; /* point to file name */ |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
< |
void |
445 |
< |
animate() /* run through animation */ |
444 |
> |
static void |
445 |
> |
animate(void) /* run through animation */ |
446 |
|
{ |
447 |
|
int rpass; |
448 |
|
|
474 |
|
|
475 |
|
|
476 |
|
VIEW * |
477 |
< |
getview(n) /* get view number n */ |
478 |
< |
int n; |
477 |
> |
getview( /* get view number n */ |
478 |
> |
int n |
479 |
> |
) |
480 |
|
{ |
481 |
|
static FILE *viewfp = NULL; /* view file pointer */ |
482 |
|
static int viewnum = 0; /* current view number */ |
488 |
|
fclose(viewfp); |
489 |
|
viewfp = NULL; |
490 |
|
viewnum = 0; |
491 |
< |
copystruct(&curview, &stdview); |
491 |
> |
curview = stdview; |
492 |
|
} |
493 |
|
return(NULL); |
494 |
|
} |
504 |
|
perror(vval(VIEWFILE)); |
505 |
|
quit(1); |
506 |
|
} |
507 |
< |
copystruct(&curview, &stdview); |
507 |
> |
curview = stdview; |
508 |
|
viewnum = 0; |
509 |
|
} |
510 |
|
if (n < 0) { /* get next view */ |
511 |
< |
register int c = getc(viewfp); |
511 |
> |
int c = getc(viewfp); |
512 |
|
if (c == EOF) |
513 |
|
return(NULL); /* that's it */ |
514 |
|
ungetc(c, viewfp); |
524 |
|
} |
525 |
|
|
526 |
|
|
527 |
< |
int |
528 |
< |
countviews() /* count views in view file */ |
527 |
> |
static int |
528 |
> |
countviews(void) /* count views in view file */ |
529 |
|
{ |
530 |
|
int n; |
531 |
|
|
538 |
|
|
539 |
|
|
540 |
|
char * |
541 |
< |
getexp(n) /* get exposure for nth frame */ |
542 |
< |
int n; |
541 |
> |
getexp( /* get exposure for nth frame */ |
542 |
> |
int n |
543 |
> |
) |
544 |
|
{ |
506 |
– |
extern char *fskip(); |
545 |
|
static char expval[32]; |
546 |
|
static FILE *expfp = NULL; |
547 |
|
static int curfrm = 0; |
548 |
< |
register char *cp; |
548 |
> |
char *cp; |
549 |
|
|
550 |
|
if (n == 0) { /* signal to close file */ |
551 |
|
if (expfp != NULL) { |
591 |
|
sprintf(errmsg, "%s: exposure format error on line %d", |
592 |
|
vval(EXPOSURE), curfrm); |
593 |
|
error(USER, errmsg); |
594 |
+ |
return NULL; /* pro forma return */ |
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
|
double |
599 |
< |
expspec_val(s) /* get exposure value from spec. */ |
600 |
< |
char *s; |
599 |
> |
expspec_val( /* get exposure value from spec. */ |
600 |
> |
char *s |
601 |
> |
) |
602 |
|
{ |
603 |
|
double expval; |
604 |
|
|
606 |
|
return(1.0); |
607 |
|
|
608 |
|
expval = atof(s); |
609 |
< |
if ((s[0] == '+' | s[0] == '-')) |
609 |
> |
if ((s[0] == '+') | (s[0] == '-')) |
610 |
|
return(pow(2.0, expval)); |
611 |
|
return(expval); |
612 |
|
} |
613 |
|
|
614 |
|
|
615 |
|
char * |
616 |
< |
getoctspec(n) /* get octree for the given frame */ |
617 |
< |
int n; |
616 |
> |
getoctspec( /* get octree for the given frame */ |
617 |
> |
int n |
618 |
> |
) |
619 |
|
{ |
620 |
|
static char combuf[1024]; |
621 |
< |
int cfm = 0; |
621 |
> |
static int cfm = 0; |
622 |
|
int uses_inline; |
623 |
|
FILE *fp; |
624 |
|
int i; |
625 |
|
/* is octree static? */ |
626 |
|
if (!vdef(MOVE)) |
627 |
|
return(vval(OCTREEF)); |
628 |
< |
/* done already */ |
628 |
> |
/* done already? */ |
629 |
|
if (n == cfm) |
630 |
|
return(combuf); |
631 |
|
/* else create object file */ |
632 |
< |
strcpy(objtmpf, "movinobj.rad"); |
592 |
< |
fp = fopen(objtmpf, "w"); |
632 |
> |
fp = fopen(mktemp(strcpy(objtmpf, TEMPLATE)), "w"); |
633 |
|
if (fp == NULL) { |
634 |
|
sprintf(errmsg, "cannot write to moving objects file '%s'", |
635 |
|
objtmpf); |
660 |
|
vdef(OCONV) ? vval(OCONV) : "", |
661 |
|
vval(OCTREEF), objtmpf); |
662 |
|
else |
663 |
< |
sprintf(combuf, "!xform -f %s | oconv -f -i '%s' -", |
664 |
< |
objtmpf, vval(OCTREEF)); |
663 |
> |
sprintf(combuf, "!xform -f %s | oconv %s -f -i '%s' -", |
664 |
> |
objtmpf, vdef(OCONV) ? vval(OCONV) : "", |
665 |
> |
vval(OCTREEF)); |
666 |
|
return(combuf); |
667 |
|
} |
668 |
|
|
669 |
|
|
670 |
< |
char * |
671 |
< |
getobjname(om) /* get fully qualified object name */ |
672 |
< |
register struct ObjMove *om; |
670 |
> |
static char * |
671 |
> |
getobjname( /* get fully qualified object name */ |
672 |
> |
struct ObjMove *om |
673 |
> |
) |
674 |
|
{ |
675 |
|
static char objName[512]; |
676 |
< |
register char *cp = objName; |
676 |
> |
char *cp = objName; |
677 |
|
|
678 |
|
strcpy(cp, om->name); |
679 |
|
while (om->parent >= 0) { |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
< |
char * |
690 |
< |
getxf(om, n) /* get total transform for object */ |
691 |
< |
register struct ObjMove *om; |
692 |
< |
int n; |
689 |
> |
static char * |
690 |
> |
getxf( /* get total transform for object */ |
691 |
> |
struct ObjMove *om, |
692 |
> |
int n |
693 |
> |
) |
694 |
|
{ |
695 |
|
static char xfsbuf[4096]; |
696 |
|
char *xfp; |
701 |
|
char *av[64]; |
702 |
|
int ac; |
703 |
|
int i; |
704 |
< |
register char *cp; |
704 |
> |
char *cp; |
705 |
|
/* get parent transform, first */ |
706 |
|
if (om->parent >= 0) |
707 |
|
xfp = getxf(&obj_move[om->parent], n); |
798 |
|
om->cprio = om->prio; |
799 |
|
} |
800 |
|
/* XXX bxfm relies on call order */ |
801 |
< |
if (framestep) |
801 |
> |
if (framestep) { |
802 |
|
if (invmat4(om->bxfm, om->cxfm)) |
803 |
|
multmat4(om->bxfm, om->bxfm, oxf.xfm); |
804 |
|
else |
805 |
|
setident4(om->bxfm); |
806 |
+ |
} |
807 |
|
/* all done */ |
808 |
|
return(xfp); |
809 |
|
} |
810 |
|
|
811 |
|
|
812 |
|
int |
813 |
< |
getmove(obj) /* find matching move object */ |
814 |
< |
OBJECT obj; |
813 |
> |
getmove( /* find matching move object */ |
814 |
> |
OBJECT obj |
815 |
> |
) |
816 |
|
{ |
817 |
|
static int lasti; |
818 |
|
static OBJECT lasto = OVOID; |
819 |
|
char *onm, *objnm; |
820 |
|
int len, len2; |
821 |
< |
register int i; |
821 |
> |
int i; |
822 |
|
|
823 |
|
if (obj == OVOID) |
824 |
|
return(-1); |
830 |
|
objnm = obj_move[i].name; |
831 |
|
len = strlen(objnm); |
832 |
|
if (!strncmp(onm, objnm, len)) { |
833 |
< |
if ((obj_move[i].parent < 0 & onm[len] == '.')) |
833 |
> |
if ((obj_move[i].parent < 0) & (onm[len] == '.')) |
834 |
|
break; |
835 |
|
objnm = getobjname(&obj_move[i]) + len; |
836 |
|
len2 = strlen(objnm); |
844 |
|
|
845 |
|
|
846 |
|
double |
847 |
< |
obj_prio(obj) /* return priority for object */ |
848 |
< |
OBJECT obj; |
847 |
> |
obj_prio( /* return priority for object */ |
848 |
> |
OBJECT obj |
849 |
> |
) |
850 |
|
{ |
851 |
|
int moi; |
852 |
|
|
856 |
|
} |
857 |
|
|
858 |
|
|
859 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
860 |
+ |
/* replacement function for Windoze */ |
861 |
+ |
static int |
862 |
+ |
gettimeofday(struct timeval *tp, void *dummy) |
863 |
+ |
{ |
864 |
+ |
FILETIME ft; |
865 |
+ |
LARGE_INTEGER li; |
866 |
+ |
__int64 t; |
867 |
+ |
|
868 |
+ |
SYSTEMTIME st; |
869 |
+ |
FILETIME ft2; |
870 |
+ |
LARGE_INTEGER li2; |
871 |
+ |
__int64 t2; |
872 |
+ |
|
873 |
+ |
st.wYear = 1970; |
874 |
+ |
st.wHour = 0; |
875 |
+ |
st.wMinute = 0; |
876 |
+ |
st.wSecond = 0; |
877 |
+ |
st.wMilliseconds = 1; |
878 |
+ |
|
879 |
+ |
SystemTimeToFileTime(&st, &ft2); |
880 |
+ |
li2.LowPart = ft2.dwLowDateTime; |
881 |
+ |
li2.HighPart = ft2.dwHighDateTime; |
882 |
+ |
t2 = li2.QuadPart; |
883 |
+ |
|
884 |
+ |
GetSystemTimeAsFileTime(&ft); |
885 |
+ |
li.LowPart = ft.dwLowDateTime; |
886 |
+ |
li.HighPart = ft.dwHighDateTime; |
887 |
+ |
t = li.QuadPart; |
888 |
+ |
t -= t2; // From 1970 |
889 |
+ |
t /= 10; // In microseconds |
890 |
+ |
tp->tv_sec = (long)(t / 1000000); |
891 |
+ |
tp->tv_usec = (long)(t % 1000000); |
892 |
+ |
return 0; |
893 |
+ |
} |
894 |
+ |
|
895 |
+ |
#endif |
896 |
+ |
|
897 |
|
double |
898 |
< |
getTime() /* get current time (CPU or real) */ |
898 |
> |
getTime(void) /* get current time (CPU or real) */ |
899 |
|
{ |
900 |
|
struct timeval time_now; |
901 |
|
/* return CPU time if one process */ |