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.14 by greg, Wed Nov 3 05:05:21 2010 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 > #ifdef _WIN32
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 "paths.h"
24 + #include "ranimove.h"
25 +
26   int             NVARS = NV_INIT; /* total number of variables */
27  
28   VARIABLE        vv[] = VV_INIT; /* variable-value pairs */
# Line 109 | Line 62 | int            haveprio = 0;   /* high-level saliency specified */
62   int             gargc;          /* global argc for printargs */
63   char            **gargv;        /* global argv for printargs */
64  
65 + static void setdefaults(void);
66 + static void setmove(struct ObjMove      *om, char       *ms);
67 + static void setrendparams(char          *optf, char             *qval);
68 + static void getradfile(char     *rfargs);
69 + static void animate(void);
70 + static int countviews(void); /* XXX duplicated function */
71 + static char * getobjname(struct ObjMove *om);
72 + static char * getxf(struct ObjMove      *om, int        n);
73  
74 +
75   int
76 < main(argc, argv)
77 < int     argc;
78 < char    *argv[];
76 > main(
77 >        int     argc,
78 >        char    *argv[]
79 > )
80   {
81          int     explicate = 0;
82          char    *cfname;
# Line 146 | Line 109 | char   *argv[];
109                  case 'f':                       /* frame range */
110                          switch (sscanf(argv[++i], "%d,%d", &fbeg, &fend)) {
111                          case 2:
112 <                                if ((fbeg <= 0 | fend < fbeg))
112 >                                if ((fbeg <= 0) | (fend < fbeg))
113                                          goto userr;
114                                  break;
115                          case 1:
# Line 190 | Line 153 | char   *argv[];
153                                                  /* all done */
154          if (lorendoptf[0])
155                  unlink(lorendoptf);
156 <        if (hirendoptf[0])
156 >        if (hirendoptf[0] && strcmp(hirendoptf, lorendoptf))
157                  unlink(hirendoptf);
158          if (objtmpf[0])
159                  unlink(objtmpf);
# Line 200 | Line 163 | userr:
163   "Usage: %s [-n nprocs][-f beg,end][-t sec][-d jnd][-s][-w][-e] anim_file\n",
164                          progname);
165          quit(1);
166 +        return 1; /* pro forma return */
167   }
168  
169  
170   void
171 < eputs(s)                                /* put string to stderr */
172 < register char  *s;
171 > eputs(                          /* put string to stderr */
172 >        register char  *s
173 > )
174   {
175          static int  midline = 0;
176  
# Line 224 | Line 189 | register char  *s;
189  
190  
191   void
192 < setdefaults()                   /* set default values */
192 > quit(ec)                        /* make sure exit is called */
193 > int     ec;
194   {
195 +        if (ray_pnprocs > 0)    /* close children if any */
196 +                ray_pclose(0);          
197 +        exit(ec);
198 + }
199 +
200 +
201 + static void
202 + setdefaults(void)                       /* set default values */
203 + {
204          int     nviews;
205          int     decades;
206          char    buf[256];
# Line 296 | Line 271 | setdefaults()                  /* set default values */
271          setrendparams(lorendoptf, vval(LOWQ));
272          ray_save(&lorendparams);
273          curparams = &lorendparams;
274 <        twolevels = bcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS));
274 >        twolevels = memcmp(&lorendparams, &hirendparams, sizeof(RAYPARAMS));
275   }
276  
277  
278 < void
279 < setmove(om, ms)                 /* assign a move object from spec. */
280 < struct ObjMove  *om;
281 < char    *ms;
278 > static void
279 > setmove(                        /* assign a move object from spec. */
280 >        struct ObjMove  *om,
281 >        char    *ms
282 > )
283   {
284          char    parname[128];
285          char    *cp;
# Line 348 | Line 324 | char   *ms;
324                  if (isflt(om->prio_file)) {
325                          om->prio = atof(om->prio_file);
326                          om->prio_file[0] = '\0';
327 <                        haveprio |= (om->prio < 0.95 | om->prio > 1.05);
327 >                        haveprio |= ((om->prio < 0.95) | (om->prio > 1.05));
328                  } else
329                          haveprio = 1;
330          } else
# Line 360 | Line 336 | badspec:
336   }
337  
338  
339 < void
340 < setrendparams(optf, qval)       /* set global rendering parameters */
341 < char            *optf;
342 < char            *qval;
339 > static void
340 > setrendparams(  /* set global rendering parameters */
341 >        char            *optf,
342 >        char            *qval
343 > )
344   {
345          char    *argv[1024];
346          char    **av = argv;
# Line 383 | Line 360 | char           *qval;
360          if (qval != NULL && qval[0] == '-')
361                  ac += wordstring(av+ac, qval);
362  
363 <                                /* start with default parameters */
364 <        ray_defaults(NULL);
363 >                                /* restore default parameters */
364 >        ray_restore(NULL);
365                                  /* set what we have */
366          for (i = 0; i < ac; i++) {
367                  while ((rval = expandarg(&ac, &av, i)) > 0)
# Line 398 | Line 375 | char           *qval;
375                          continue;
376                  }
377                  rval = getrenderopt(ac-i, av+i);
378 <                if (rval >= 0) {
379 <                        i += rval;
380 <                        continue;
378 >                if (rval < 0) {
379 >                        sprintf(errmsg, "bad render option at '%s'", av[i]);
380 >                        error(USER, errmsg);
381                  }
382 <                sprintf(errmsg, "bad render option at '%s'", av[i]);
406 <                error(USER, errmsg);
382 >                i += rval;
383          }
384   }
385  
386  
387 < void
388 < getradfile(rfargs)              /* run rad and get needed variables */
389 < char    *rfargs;
387 > static void
388 > getradfile(             /* run rad and get needed variables */
389 >        char    *rfargs
390 > )
391   {
392          static short    mvar[] = {OCONV,OCTREEF,RESOLUTION,EXPOSURE,-1};
393          char    combuf[256];
394          register int    i;
395          register char   *cp;
396 <        char    *pippt;
396 >        char    *pippt = NULL;
397                                          /* create rad command */
398          strcpy(lorendoptf, "ranim0.opt");
399          sprintf(combuf,
# Line 437 | Line 414 | char   *rfargs;
414                          pippt = NULL;
415                  }
416          if (pippt != NULL)
417 <                strcpy(pippt, "> /dev/null");   /* nothing to match */
417 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
418          else {
419                  strcpy(cp, ")[ \t]*=' > ranimove.var");
420                  cp += 11;               /* point to file name */
# Line 459 | Line 436 | char   *rfargs;
436   }
437  
438  
439 < void
440 < animate()                       /* run through animation */
439 > static void
440 > animate(void)                   /* run through animation */
441   {
442          int     rpass;
443  
# Line 491 | Line 468 | animate()                      /* run through animation */
468   }
469  
470  
471 < VIEW *
472 < getview(n)                      /* get view number n */
473 < int     n;
471 > extern VIEW *
472 > getview(                        /* get view number n */
473 >        int     n
474 > )
475   {
476          static FILE     *viewfp = NULL;         /* view file pointer */
477          static int      viewnum = 0;            /* current view number */
# Line 505 | Line 483 | int    n;
483                          fclose(viewfp);
484                          viewfp = NULL;
485                          viewnum = 0;
486 <                        copystruct(&curview, &stdview);
486 >                        curview = stdview;
487                  }
488                  return(NULL);
489          }
# Line 521 | Line 499 | int    n;
499                          perror(vval(VIEWFILE));
500                          quit(1);
501                  }
502 <                copystruct(&curview, &stdview);
502 >                curview = stdview;
503                  viewnum = 0;
504          }
505          if (n < 0) {                            /* get next view */
# Line 541 | Line 519 | int    n;
519   }
520  
521  
522 < int
523 < countviews()                    /* count views in view file */
522 > static int
523 > countviews(void)                        /* count views in view file */
524   {
525          int     n;
526  
# Line 554 | Line 532 | countviews()                   /* count views in view file */
532   }
533  
534  
535 < char *
536 < getexp(n)                       /* get exposure for nth frame */
537 < int     n;
535 > extern char *
536 > getexp(                 /* get exposure for nth frame */
537 >        int     n
538 > )
539   {
540          extern char     *fskip();
541          static char     expval[32];
# Line 608 | Line 587 | formerr:
587          sprintf(errmsg, "%s: exposure format error on line %d",
588                          vval(EXPOSURE), curfrm);
589          error(USER, errmsg);
590 +        return NULL; /* pro forma return */
591   }
592  
593  
594 < double
595 < expspec_val(s)                  /* get exposure value from spec. */
596 < char    *s;
594 > extern double
595 > expspec_val(                    /* get exposure value from spec. */
596 >        char    *s
597 > )
598   {
599          double  expval;
600  
# Line 621 | Line 602 | char   *s;
602                  return(1.0);
603  
604          expval = atof(s);
605 <        if ((s[0] == '+' | s[0] == '-'))
605 >        if ((s[0] == '+') | (s[0] == '-'))
606                  return(pow(2.0, expval));
607          return(expval);
608   }
609  
610  
611 < char *
612 < getoctspec(n)                   /* get octree for the given frame */
613 < int     n;
611 > extern char *
612 > getoctspec(                     /* get octree for the given frame */
613 >        int     n
614 > )
615   {
616          static char     combuf[1024];
617 <        int             cfm = 0;
617 >        static int      cfm = 0;
618          int     uses_inline;
619          FILE    *fp;
620          int     i;
621                                          /* is octree static? */
622          if (!vdef(MOVE))
623                  return(vval(OCTREEF));
624 <                                        /* done already */
624 >                                        /* done already? */
625          if (n == cfm)
626                  return(combuf);
627                                          /* else create object file */
628 <        strcpy(objtmpf, "movinobj.rad");
647 <        fp = fopen(objtmpf, "w");
628 >        fp = fopen(mktemp(strcpy(objtmpf, TEMPLATE)), "w");
629          if (fp == NULL) {
630                  sprintf(errmsg, "cannot write to moving objects file '%s'",
631                                  objtmpf);
# Line 675 | Line 656 | int    n;
656                                  vdef(OCONV) ? vval(OCONV) : "",
657                                  vval(OCTREEF), objtmpf);
658          else
659 <                sprintf(combuf, "!xform -f %s | oconv -f -i '%s' -",
660 <                                objtmpf, vval(OCTREEF));
659 >                sprintf(combuf, "!xform -f %s | oconv %s -f -i '%s' -",
660 >                                objtmpf, vdef(OCONV) ? vval(OCONV) : "",
661 >                                vval(OCTREEF));
662          return(combuf);
663   }
664  
665  
666 < char *
667 < getobjname(om)                  /* get fully qualified object name */
668 < register struct ObjMove *om;
666 > static char *
667 > getobjname(                     /* get fully qualified object name */
668 >        register struct ObjMove *om
669 > )
670   {
671          static char     objName[512];
672          register char   *cp = objName;
# Line 699 | Line 682 | register struct ObjMove        *om;
682   }
683  
684  
685 < char *
686 < getxf(om, n)                    /* get total transform for object */
687 < register struct ObjMove *om;
688 < int     n;
685 > static char *
686 > getxf(                  /* get total transform for object */
687 >        register struct ObjMove *om,
688 >        int     n
689 > )
690   {
691          static char     xfsbuf[4096];
692          char            *xfp;
# Line 810 | Line 794 | int    n;
794                  om->cprio = om->prio;
795          }
796                                          /* XXX bxfm relies on call order */
797 <        if (framestep)
797 >        if (framestep) {
798                  if (invmat4(om->bxfm, om->cxfm))
799                          multmat4(om->bxfm, om->bxfm, oxf.xfm);
800                  else
801                          setident4(om->bxfm);
802 +        }
803                                          /* all done */
804          return(xfp);
805   }
806  
807  
808 < int
809 < getmove(obj)                            /* find matching move object */
810 < OBJECT  obj;
808 > extern int
809 > getmove(                                /* find matching move object */
810 >        OBJECT  obj
811 > )
812   {
813          static int      lasti;
814          static OBJECT   lasto = OVOID;
# Line 840 | Line 826 | OBJECT obj;
826                  objnm = obj_move[i].name;
827                  len = strlen(objnm);
828                  if (!strncmp(onm, objnm, len)) {
829 <                        if ((obj_move[i].parent < 0 & onm[len] == '.'))
829 >                        if ((obj_move[i].parent < 0) & (onm[len] == '.'))
830                                  break;
831                          objnm = getobjname(&obj_move[i]) + len;
832                          len2 = strlen(objnm);
# Line 853 | Line 839 | OBJECT obj;
839   }
840  
841  
842 < double
843 < obj_prio(obj)                   /* return priority for object */
844 < OBJECT  obj;
842 > extern double
843 > obj_prio(                       /* return priority for object */
844 >        OBJECT  obj
845 > )
846   {
847          int     moi;
848          
# Line 865 | Line 852 | OBJECT obj;
852   }
853  
854  
855 < double
856 < getTime()                       /* get current time (CPU or real) */
855 > extern double
856 > getTime(void)                   /* get current time (CPU or real) */
857   {
858          struct timeval  time_now;
859                                          /* return CPU time if one process */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines