ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/ranimove.c
(Generate patch)

Comparing ray/src/util/ranimove.c (file contents):
Revision 3.1 by greg, Sat Feb 22 02:07:30 2003 UTC vs.
Revision 3.24 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  Radiance object animation program
# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9   *  See ranimove.h and the ranimove(1) man page for details.
10   */
11  
12 < /* ====================================================================
13 < * The Radiance Software License, Version 1.0
14 < *
15 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
16 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
17 < *
18 < * Redistribution and use in source and binary forms, with or without
19 < * modification, are permitted provided that the following conditions
20 < * are met:
21 < *
22 < * 1. Redistributions of source code must retain the above copyright
23 < *         notice, this list of conditions and the following disclaimer.
24 < *
25 < * 2. Redistributions in binary form must reproduce the above copyright
26 < *       notice, this list of conditions and the following disclaimer in
27 < *       the documentation and/or other materials provided with the
28 < *       distribution.
29 < *
30 < * 3. The end-user documentation included with the redistribution,
31 < *           if any, must include the following acknowledgment:
32 < *             "This product includes Radiance software
33 < *                 (http://radsite.lbl.gov/)
34 < *                 developed by the Lawrence Berkeley National Laboratory
35 < *               (http://www.lbl.gov/)."
36 < *       Alternately, this acknowledgment may appear in the software itself,
37 < *       if and wherever such third-party acknowledgments normally appear.
38 < *
39 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
40 < *       and "The Regents of the University of California" must
41 < *       not be used to endorse or promote products derived from this
42 < *       software without prior written permission. For written
43 < *       permission, please contact [email protected].
44 < *
45 < * 5. Products derived from this software may not be called "Radiance",
46 < *       nor may "Radiance" appear in their name, without prior written
47 < *       permission of Lawrence Berkeley National Laboratory.
48 < *
49 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
50 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
53 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
56 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
57 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
59 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 < * SUCH DAMAGE.
61 < * ====================================================================
62 < *
63 < * This software consists of voluntary contributions made by many
64 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
65 < * information on Lawrence Berkeley National Laboratory, please see
66 < * <http://www.lbl.gov/>.
67 < */
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 "ranimove.h"
25 + #include "func.h"
26 +
27   int             NVARS = NV_INIT; /* total number of variables */
28  
29   VARIABLE        vv[] = VV_INIT; /* variable-value pairs */
# Line 109 | Line 63 | int            haveprio = 0;   /* high-level saliency specified */
63   int             gargc;          /* global argc for printargs */
64   char            **gargv;        /* global argv for printargs */
65  
66 + static void setdefaults(void);
67 + static void setmove(struct ObjMove      *om, char       *ms);
68 + static void setrendparams(char          *optf, char             *qval);
69 + static void getradfile(char     *rfargs);
70 + static void animate(void);
71 + static int countviews(void); /* XXX duplicated function */
72 + static char * getobjname(struct ObjMove *om);
73 + static char * getxf(struct ObjMove      *om, int        n);
74  
75 +
76   int
77 < main(argc, argv)
78 < int     argc;
79 < char    *argv[];
77 > main(
78 >        int     argc,
79 >        char    *argv[]
80 > )
81   {
82          int     explicate = 0;
83          char    *cfname;
84          int     i;
85 <
86 <        progname = argv[0];                     /* get arguments */
85 >                                                /* set global progname */
86 >        fixargv0(argv[0]);
87 >                                                /* initialize calcomp */
88 >        initfunc();
89          gargc = argc;
90          gargv = argv;
91          for (i = 1; i < argc && argv[i][0] == '-'; i++)
# Line 146 | Line 112 | char   *argv[];
112                  case 'f':                       /* frame range */
113                          switch (sscanf(argv[++i], "%d,%d", &fbeg, &fend)) {
114                          case 2:
115 <                                if ((fbeg <= 0 | fend < fbeg))
115 >                                if ((fbeg <= 0) | (fend < fbeg))
116                                          goto userr;
117                                  break;
118                          case 1:
# Line 190 | Line 156 | char   *argv[];
156                                                  /* all done */
157          if (lorendoptf[0])
158                  unlink(lorendoptf);
159 <        if (hirendoptf[0])
159 >        if (hirendoptf[0] && strcmp(hirendoptf, lorendoptf))
160                  unlink(hirendoptf);
161          if (objtmpf[0])
162                  unlink(objtmpf);
# Line 200 | Line 166 | userr:
166   "Usage: %s [-n nprocs][-f beg,end][-t sec][-d jnd][-s][-w][-e] anim_file\n",
167                          progname);
168          quit(1);
169 +        return 1; /* pro forma return */
170   }
171  
172  
173   void
174 < eputs(s)                                /* put string to stderr */
175 < register char  *s;
174 > eputs(                          /* put string to stderr */
175 >        const char  *s
176 > )
177   {
178          static int  midline = 0;
179  
# Line 224 | Line 192 | register char  *s;
192  
193  
194   void
195 < setdefaults()                   /* set default values */
195 > quit(int ec)                    /* make sure exit is called */
196   {
197 +        if (ray_pnprocs > 0)    /* close children if any */
198 +                ray_pclose(0);
199 +        else if (ray_pnprocs < 0)
200 +                _exit(ec);      /* avoid flush in child */
201 +        exit(ec);
202 + }
203 +
204 +
205 + static void
206 + setdefaults(void)                       /* set default values */
207 + {
208          int     nviews;
209          int     decades;
210          char    buf[256];
# Line 296 | Line 275 | setdefaults()                  /* set default values */
275          setrendparams(lorendoptf, vval(LOWQ));
276          ray_save(&lorendparams);
277          curparams = &lorendparams;
278 <        twolevels = bcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS));
278 >        twolevels = memcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS));
279   }
280  
281  
282 < void
283 < setmove(om, ms)                 /* assign a move object from spec. */
284 < struct ObjMove  *om;
285 < char    *ms;
282 > static void
283 > setmove(                        /* assign a move object from spec. */
284 >        struct ObjMove  *om,
285 >        char    *ms
286 > )
287   {
288          char    parname[128];
289          char    *cp;
# Line 348 | Line 328 | char   *ms;
328                  if (isflt(om->prio_file)) {
329                          om->prio = atof(om->prio_file);
330                          om->prio_file[0] = '\0';
331 <                        haveprio |= (om->prio < 0.95 | om->prio > 1.05);
331 >                        haveprio |= ((om->prio < 0.95) | (om->prio > 1.05));
332                  } else
333                          haveprio = 1;
334          } else
# Line 360 | Line 340 | badspec:
340   }
341  
342  
343 < void
344 < setrendparams(optf, qval)       /* set global rendering parameters */
345 < char            *optf;
346 < char            *qval;
343 > static void
344 > setrendparams(  /* set global rendering parameters */
345 >        char            *optf,
346 >        char            *qval
347 > )
348   {
349          char    *argv[1024];
350          char    **av = argv;
# Line 372 | Line 353 | char           *qval;
353          av[ac=0] = NULL;
354                                  /* load options from file, first */
355          if (optf != NULL && *optf) {
356 <                ac = wordfile(av, optf);
356 >                ac = wordfile(av, 1024, optf);
357                  if (ac < 0) {
358                          sprintf(errmsg, "cannot load options file \"%s\"",
359                                          optf);
# Line 381 | Line 362 | char           *qval;
362          }
363                                  /* then from options string */
364          if (qval != NULL && qval[0] == '-')
365 <                ac += wordstring(av+ac, qval);
365 >                ac += wordstring(av+ac, 1024-ac, qval);
366  
367 <                                /* start with default parameters */
368 <        ray_defaults(NULL);
367 >                                /* restore default parameters */
368 >        ray_restore(NULL);
369                                  /* set what we have */
370          for (i = 0; i < ac; i++) {
371                  while ((rval = expandarg(&ac, &av, i)) > 0)
# Line 398 | Line 379 | char           *qval;
379                          continue;
380                  }
381                  rval = getrenderopt(ac-i, av+i);
382 <                if (rval >= 0) {
383 <                        i += rval;
384 <                        continue;
382 >                if (rval < 0) {
383 >                        sprintf(errmsg, "bad render option at '%s'", av[i]);
384 >                        error(USER, errmsg);
385                  }
386 <                sprintf(errmsg, "bad render option at '%s'", av[i]);
406 <                error(USER, errmsg);
386 >                i += rval;
387          }
388   }
389  
390  
391 < void
392 < getradfile(rfargs)              /* run rad and get needed variables */
393 < char    *rfargs;
391 > static void
392 > getradfile(             /* run rad and get needed variables */
393 >        char    *rfargs
394 > )
395   {
396          static short    mvar[] = {OCONV,OCTREEF,RESOLUTION,EXPOSURE,-1};
397          char    combuf[256];
398 <        register int    i;
399 <        register char   *cp;
400 <        char    *pippt;
398 >        int     i;
399 >        char    *cp;
400 >        char    *pippt = NULL;
401                                          /* create rad command */
402          strcpy(lorendoptf, "ranim0.opt");
403          sprintf(combuf,
# Line 437 | Line 418 | char   *rfargs;
418                          pippt = NULL;
419                  }
420          if (pippt != NULL)
421 <                strcpy(pippt, "> /dev/null");   /* nothing to match */
421 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
422          else {
423                  strcpy(cp, ")[ \t]*=' > ranimove.var");
424                  cp += 11;               /* point to file name */
# Line 459 | Line 440 | char   *rfargs;
440   }
441  
442  
443 < void
444 < animate()                       /* run through animation */
443 > static void
444 > animate(void)                   /* run through animation */
445   {
446          int     rpass;
447  
# Line 492 | Line 473 | animate()                      /* run through animation */
473  
474  
475   VIEW *
476 < getview(n)                      /* get view number n */
477 < int     n;
476 > getview(                        /* get view number n */
477 >        int     n
478 > )
479   {
480          static FILE     *viewfp = NULL;         /* view file pointer */
481          static int      viewnum = 0;            /* current view number */
# Line 505 | Line 487 | int    n;
487                          fclose(viewfp);
488                          viewfp = NULL;
489                          viewnum = 0;
490 <                        copystruct(&curview, &stdview);
490 >                        curview = stdview;
491                  }
492                  return(NULL);
493          }
# Line 521 | Line 503 | int    n;
503                          perror(vval(VIEWFILE));
504                          quit(1);
505                  }
506 <                copystruct(&curview, &stdview);
506 >                curview = stdview;
507                  viewnum = 0;
508          }
509          if (n < 0) {                            /* get next view */
510 <                register int    c = getc(viewfp);
510 >                int     c = getc(viewfp);
511                  if (c == EOF)
512                          return(NULL);                   /* that's it */
513                  ungetc(c, viewfp);
# Line 541 | Line 523 | int    n;
523   }
524  
525  
526 < int
527 < countviews()                    /* count views in view file */
526 > static int
527 > countviews(void)                        /* count views in view file */
528   {
529          int     n;
530  
# Line 555 | Line 537 | countviews()                   /* count views in view file */
537  
538  
539   char *
540 < getexp(n)                       /* get exposure for nth frame */
541 < int     n;
540 > getexp(                 /* get exposure for nth frame */
541 >        int     n
542 > )
543   {
561        extern char     *fskip();
544          static char     expval[32];
545          static FILE     *expfp = NULL;
546          static int      curfrm = 0;
547 <        register char   *cp;
547 >        char    *cp;
548  
549          if (n == 0) {                           /* signal to close file */
550                  if (expfp != NULL) {
# Line 608 | Line 590 | formerr:
590          sprintf(errmsg, "%s: exposure format error on line %d",
591                          vval(EXPOSURE), curfrm);
592          error(USER, errmsg);
593 +        return NULL; /* pro forma return */
594   }
595  
596  
597   double
598 < expspec_val(s)                  /* get exposure value from spec. */
599 < char    *s;
598 > expspec_val(                    /* get exposure value from spec. */
599 >        char    *s
600 > )
601   {
602          double  expval;
603  
# Line 621 | Line 605 | char   *s;
605                  return(1.0);
606  
607          expval = atof(s);
608 <        if ((s[0] == '+' | s[0] == '-'))
608 >        if ((s[0] == '+') | (s[0] == '-'))
609                  return(pow(2.0, expval));
610          return(expval);
611   }
612  
613  
614   char *
615 < getoctspec(n)                   /* get octree for the given frame */
616 < int     n;
615 > getoctspec(                     /* get octree for the given frame */
616 >        int     n
617 > )
618   {
619          static char     combuf[1024];
620 <        int             cfm = 0;
620 >        static int      cfm = 0;
621          int     uses_inline;
622          FILE    *fp;
623          int     i;
624                                          /* is octree static? */
625          if (!vdef(MOVE))
626                  return(vval(OCTREEF));
627 <                                        /* done already */
627 >                                        /* done already? */
628          if (n == cfm)
629                  return(combuf);
630                                          /* else create object file */
631 <        strcpy(objtmpf, "movinobj.rad");
647 <        fp = fopen(objtmpf, "w");
631 >        fp = fopen(mktemp(strcpy(objtmpf, TEMPLATE)), "w");
632          if (fp == NULL) {
633                  sprintf(errmsg, "cannot write to moving objects file '%s'",
634                                  objtmpf);
# Line 675 | Line 659 | int    n;
659                                  vdef(OCONV) ? vval(OCONV) : "",
660                                  vval(OCTREEF), objtmpf);
661          else
662 <                sprintf(combuf, "!xform -f %s | oconv -f -i '%s' -",
663 <                                objtmpf, vval(OCTREEF));
662 >                sprintf(combuf, "!xform -f %s | oconv %s -f -i '%s' -",
663 >                                objtmpf, vdef(OCONV) ? vval(OCONV) : "",
664 >                                vval(OCTREEF));
665          return(combuf);
666   }
667  
668  
669 < char *
670 < getobjname(om)                  /* get fully qualified object name */
671 < register struct ObjMove *om;
669 > static char *
670 > getobjname(                     /* get fully qualified object name */
671 >        struct ObjMove  *om
672 > )
673   {
674          static char     objName[512];
675 <        register char   *cp = objName;
675 >        char    *cp = objName;
676          
677          strcpy(cp, om->name);
678          while (om->parent >= 0) {
# Line 699 | Line 685 | register struct ObjMove        *om;
685   }
686  
687  
688 < char *
689 < getxf(om, n)                    /* get total transform for object */
690 < register struct ObjMove *om;
691 < int     n;
688 > static char *
689 > getxf(                  /* get total transform for object */
690 >        struct ObjMove  *om,
691 >        int     n
692 > )
693   {
694          static char     xfsbuf[4096];
695          char            *xfp;
# Line 713 | Line 700 | int    n;
700          char            *av[64];
701          int             ac;
702          int             i;
703 <        register char   *cp;
703 >        char    *cp;
704                                          /* get parent transform, first */
705          if (om->parent >= 0)
706                  xfp = getxf(&obj_move[om->parent], n);
# Line 810 | Line 797 | int    n;
797                  om->cprio = om->prio;
798          }
799                                          /* XXX bxfm relies on call order */
800 <        if (framestep)
800 >        if (framestep) {
801                  if (invmat4(om->bxfm, om->cxfm))
802                          multmat4(om->bxfm, om->bxfm, oxf.xfm);
803                  else
804                          setident4(om->bxfm);
805 +        }
806                                          /* all done */
807          return(xfp);
808   }
809  
810  
811   int
812 < getmove(obj)                            /* find matching move object */
813 < OBJECT  obj;
812 > getmove(                                /* find matching move object */
813 >        OBJECT  obj
814 > )
815   {
816          static int      lasti;
817          static OBJECT   lasto = OVOID;
818          char    *onm, *objnm;
819          int     len, len2;
820 <        register int    i;
820 >        int     i;
821  
822          if (obj == OVOID)
823                  return(-1);
# Line 840 | Line 829 | OBJECT obj;
829                  objnm = obj_move[i].name;
830                  len = strlen(objnm);
831                  if (!strncmp(onm, objnm, len)) {
832 <                        if ((obj_move[i].parent < 0 & onm[len] == '.'))
832 >                        if ((obj_move[i].parent < 0) & (onm[len] == '.'))
833                                  break;
834                          objnm = getobjname(&obj_move[i]) + len;
835                          len2 = strlen(objnm);
# Line 854 | Line 843 | OBJECT obj;
843  
844  
845   double
846 < obj_prio(obj)                   /* return priority for object */
847 < OBJECT  obj;
846 > obj_prio(                       /* return priority for object */
847 >        OBJECT  obj
848 > )
849   {
850          int     moi;
851          
# Line 865 | Line 855 | OBJECT obj;
855   }
856  
857  
858 + #if defined(_WIN32) || defined(_WIN64)
859 +                                /* replacement function for Windoze */
860 + static int
861 + gettimeofday(struct timeval *tp, void *dummy)
862 + {
863 +    FILETIME        ft;
864 +    LARGE_INTEGER   li;
865 +    __int64         t;
866 +
867 +        SYSTEMTIME              st;
868 +        FILETIME                ft2;
869 +        LARGE_INTEGER   li2;
870 +        __int64                 t2;
871 +
872 +        st.wYear = 1970;
873 +        st.wHour = 0;
874 +        st.wMinute = 0;
875 +        st.wSecond = 0;
876 +        st.wMilliseconds = 1;
877 +
878 +        SystemTimeToFileTime(&st, &ft2);
879 +        li2.LowPart = ft2.dwLowDateTime;
880 +        li2.HighPart = ft2.dwHighDateTime;
881 +        t2 = li2.QuadPart;
882 +
883 +    GetSystemTimeAsFileTime(&ft);
884 +    li.LowPart  = ft.dwLowDateTime;
885 +    li.HighPart = ft.dwHighDateTime;
886 +    t  = li.QuadPart;      
887 +    t -= t2; // From 1970
888 +    t /= 10; // In microseconds
889 +    tp->tv_sec  = (long)(t / 1000000);
890 +    tp->tv_usec = (long)(t % 1000000);
891 +    return 0;
892 + }
893 +
894 + #endif
895 +
896   double
897 < getTime()                       /* get current time (CPU or real) */
897 > getTime(void)                   /* get current time (CPU or real) */
898   {
899          struct timeval  time_now;
900                                          /* return CPU time if one process */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines