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

Comparing ray/src/util/ranimate.c (file contents):
Revision 2.29 by greg, Sat Feb 22 02:07:30 2003 UTC vs.
Revision 2.47 by greg, Tue Jun 8 19:48:31 2004 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 animation control program
# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
13   * See the ranimate(1) man page for further details.
14   */
15  
16 < /* ====================================================================
17 < * The Radiance Software License, Version 1.0
18 < *
19 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
20 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
21 < *
22 < * Redistribution and use in source and binary forms, with or without
23 < * modification, are permitted provided that the following conditions
24 < * are met:
25 < *
26 < * 1. Redistributions of source code must retain the above copyright
27 < *         notice, this list of conditions and the following disclaimer.
28 < *
29 < * 2. Redistributions in binary form must reproduce the above copyright
30 < *       notice, this list of conditions and the following disclaimer in
31 < *       the documentation and/or other materials provided with the
32 < *       distribution.
33 < *
34 < * 3. The end-user documentation included with the redistribution,
35 < *           if any, must include the following acknowledgment:
36 < *             "This product includes Radiance software
37 < *                 (http://radsite.lbl.gov/)
38 < *                 developed by the Lawrence Berkeley National Laboratory
39 < *               (http://www.lbl.gov/)."
40 < *       Alternately, this acknowledgment may appear in the software itself,
41 < *       if and wherever such third-party acknowledgments normally appear.
42 < *
43 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
44 < *       and "The Regents of the University of California" must
45 < *       not be used to endorse or promote products derived from this
46 < *       software without prior written permission. For written
47 < *       permission, please contact [email protected].
48 < *
49 < * 5. Products derived from this software may not be called "Radiance",
50 < *       nor may "Radiance" appear in their name, without prior written
51 < *       permission of Lawrence Berkeley National Laboratory.
52 < *
53 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
54 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
56 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
57 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
60 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
62 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
63 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 < * SUCH DAMAGE.
65 < * ====================================================================
66 < *
67 < * This software consists of voluntary contributions made by many
68 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
69 < * information on Lawrence Berkeley National Laboratory, please see
70 < * <http://www.lbl.gov/>.
71 < */
16 > #include "copyright.h"
17  
18 < #include "standard.h"
18 > #include <stdio.h>
19   #include <ctype.h>
20   #include <sys/stat.h>
21 + #include <time.h>
22 + #include <signal.h>
23 +
24 + #include "platform.h"
25 + #include "paths.h"
26 + #include "standard.h"
27   #include "view.h"
28   #include "vars.h"
29   #include "netproc.h"
# Line 81 | Line 32 | static const char      RCSid[] = "$Id$";
32   #define DEF_NBLUR       5
33   #endif
34                                  /* default remote shell */
84 #ifdef _AUX_SOURCE
85 #define REMSH           "remsh"
86 #else
35   #define REMSH           "rsh"
88 #endif
36                                  /* input variables (alphabetical by name) */
37   #define ANIMATE         0               /* animation command */
38   #define ARCHIVE         1               /* archiving command */
# Line 174 | Line 121 | struct pslot {
121   int     npslots;                /* number of process slots */
122  
123   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
177
178 struct pslot    *findpslot();
179
124   PSERVER *lastpserver;           /* last process server with error */
125  
126 < VIEW    *getview();
127 < char    *getexp(), *dirfile();
128 < int     getblur();
126 > static struct pslot * findpslot(int pid);
127 > static void checkdir(void);
128 > static VIEW * getview(int n);
129  
130 < extern time_t   time();
130 > static char * dirfile(char *df, register char *path);
131 > static char * getexp(int n);
132 > static int getblur(double *bf);
133 > static int getastat(void);
134 > static void getradfile(char *rfargs);
135 > static void badvalue(int vc);
136 > static int rmfile(char *fn);
137 > static int runcom(char *cs);
138 > static int pruncom(char *com, char *ppins, int maxcopies);
139 > static void bwait(int ncoms);
140 > static int bruncom(char *com, int fout, int (*rf)());
141 > static int serverdown(void);
142 > static pscompfunc donecom;
143 > static int countviews(void);
144 > static int dofilt(int frame, int rvr);
145 > static void archive(void);
146 > static int frecover(int frame);
147 > static int recover(int frame);
148 > static void sethosts(void);
149 > static void walkwait(int first, int last, char *vfn);
150 > static void animrend(int frame, VIEW *vp);
151 > static void transferframes(void);
152 > static void filterframes(void);
153 > static void renderframes(int nframes);
154 > static void animate(void);
155 > static void setdefaults(void);
156 > static void putastat(void);
157  
158  
159 < main(argc, argv)
160 < int     argc;
161 < char    *argv[];
159 > int
160 > main(
161 >        int     argc,
162 >        char    *argv[]
163 > )
164   {
165          int     explicate = 0;
166          int     i;
# Line 251 | Line 223 | char   *argv[];
223                  quit(1);
224          }
225          quit(0);
226 +        return 0; /* pro forma return */
227   userr:
228          fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname);
229          quit(1);
230 +        return 1; /* pro forma return */
231   }
232  
233  
234 < getastat()                      /* check/set animation status */
234 > static int
235 > getastat(void)                  /* check/set animation status */
236   {
237          char    sfname[256];
238          FILE    *fp;
# Line 321 | Line 296 | fmterr:
296   }
297  
298  
299 < putastat()                      /* put out current status */
299 > static void
300 > putastat(void)                  /* put out current status */
301   {
302          char    buf[256];
303          FILE    *fp;
# Line 343 | Line 319 | putastat()                     /* put out current status */
319   }
320  
321  
322 < checkdir()                      /* make sure we have our directory */
322 > static void
323 > checkdir(void)                  /* make sure we have our directory */
324   {
325          struct stat     stb;
326  
# Line 365 | Line 342 | checkdir()                     /* make sure we have our directory */
342   }
343  
344  
345 < setdefaults()                   /* set default values */
345 > static void
346 > setdefaults(void)                       /* set default values */
347   {
348          extern char     *atos();
349          int     decades;
# Line 453 | Line 431 | setdefaults()                  /* set default values */
431   }
432  
433  
434 < sethosts()                      /* set up process servers */
434 > static void
435 > sethosts(void)                  /* set up process servers */
436   {
437          extern char     *iskip();
438          char    buf[256], *dir, *uname;
# Line 508 | Line 487 | sethosts()                     /* set up process servers */
487          }
488   }
489  
490 <
491 < getradfile(rfargs)              /* run rad and get needed variables */
513 < char    *rfargs;
490 > static void
491 > getradfile(char *rfargs)                /* run rad and get needed variables */
492   {
493          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
494          char    combuf[256];
495          register int    i;
496          register char   *cp;
497 <        char    *pippt;
497 >        char    *pippt = NULL;
498                                          /* create rad command */
499          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
500          sprintf(combuf,
# Line 535 | Line 513 | char   *rfargs;
513                          pippt = NULL;
514                  }
515          if (pippt != NULL)
516 <                strcpy(pippt, "> /dev/null");   /* nothing to match */
516 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
517          else {
518                  sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
519                  cp += 11;               /* point to file name */
# Line 548 | Line 526 | char   *rfargs;
526   }
527  
528  
529 < animate()                       /* run animation */
529 > static void
530 > animate(void)                   /* run animation */
531   {
532          int     xres, yres;
533          float   pa, mult;
# Line 619 | Line 598 | animate()                      /* run animation */
598   }
599  
600  
601 < renderframes(nframes)           /* render next nframes frames */
602 < int     nframes;
601 > static void
602 > renderframes(int nframes)               /* render next nframes frames */
603   {
604          static char     vendbuf[16];
605          VIEW    *vp;
# Line 676 | Line 655 | int    nframes;
655   }
656  
657  
658 < filterframes()                          /* catch up with filtering */
658 > static void
659 > filterframes(void)                              /* catch up with filtering */
660   {
681        VIEW    *vp;
661          register int    i;
662  
663          if (astat.tnext < astat.fnext)  /* other work to do first */
664                  return;
665                                          /* filter each view */
666 <        for (i = astat.fnext; i < astat.rnext; i++) {
667 <                if ((vp = getview(i)) == NULL) {        /* get view i */
668 <                        fprintf(stderr,
690 <                        "%s: unexpected error reading view for frame %d\n",
691 <                                        progname, i);
692 <                        quit(1);
693 <                }
694 <                dofilt(i, vp, getexp(i), 0);            /* filter frame */
695 <        }
666 >        for (i = astat.fnext; i < astat.rnext; i++)
667 >                dofilt(i, 0);
668 >
669          bwait(0);                       /* wait for filter processes */
670          archive();                      /* archive originals */
671          astat.fnext = i;                /* update status */
# Line 700 | Line 673 | filterframes()                         /* catch up with filtering */
673   }
674  
675  
676 < transferframes()                        /* catch up with picture transfers */
676 > static void
677 > transferframes(void)                    /* catch up with picture transfers */
678   {
679          char    combuf[10240], *fbase;
680          register char   *cp;
# Line 740 | Line 714 | transferframes()                       /* catch up with picture transfers
714   }
715  
716  
717 < animrend(frame, vp)                     /* start animation frame */
718 < int     frame;
719 < VIEW    *vp;
717 > static void
718 > animrend(                       /* start animation frame */
719 > int     frame,
720 > VIEW    *vp
721 > )
722   {
747        extern int      recover();
723          char    combuf[2048];
724          char    fname[128];
725  
# Line 758 | Line 733 | VIEW   *vp;
733   }
734  
735  
736 < walkwait(first, last, vfn)              /* walk-through frames */
737 < int     first, last;
738 < char    *vfn;
736 > static void
737 > walkwait(               /* walk-through frames */
738 > int     first,
739 > int last,
740 > char    *vfn
741 > )
742   {
743          double  blurf;
744          int     nblur = getblur(&blurf);
# Line 810 | Line 788 | char   *vfn;
788   }
789  
790  
791 < int
792 < recover(frame)                          /* recover the specified frame */
815 < int     frame;
791 > static int
792 > recover(int frame)                      /* recover the specified frame */
793   {
794          static int      *rfrm;          /* list of recovered frames */
795          static int      nrfrms = 0;
# Line 853 | Line 830 | int    frame;
830                  return(1);
831                                          /* add frame to recovered list */
832          if (nrfrms)
833 <                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
833 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
834          else
835                  rfrm = (int *)malloc(sizeof(int));
836          if (rfrm == NULL) {
# Line 865 | Line 842 | int    frame;
842   }
843  
844  
845 < int
846 < frecover(frame)                         /* recover filtered frame */
870 < int     frame;
845 > static int
846 > frecover(int frame)                             /* recover filtered frame */
847   {
848 <        VIEW    *vp;
873 <        char    *ex;
874 <
875 <        vp = getview(frame);
876 <        ex = getexp(frame);
877 <        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1))
848 >        if (dofilt(frame, 2) && dofilt(frame, 1))
849                  return(1);
850          return(0);
851   }
852  
853  
854 < archive()                       /* archive and remove renderings */
854 > static void
855 > archive(void)                   /* archive and remove renderings */
856   {
857   #define RMCOML  (sizeof(rmcom)-1)
858          static char     rmcom[] = "rm -f";
# Line 923 | Line 895 | archive()                      /* archive and remove renderings */
895   }
896  
897  
898 < int
899 < dofilt(frame, vp, ep, rvr)                      /* filter frame */
900 < int     frame;
901 < VIEW    *vp;
902 < char    *ep;
931 < int     rvr;
898 > static int
899 > dofilt(                         /* filter frame */
900 > int     frame,
901 > int     rvr
902 > )
903   {
933        extern int      frecover();
904          static int      iter = 0;
905          double  blurf;
906          int     nblur = getblur(&blurf);
907 +        VIEW    *vp = getview(frame);
908 +        char    *ep = getexp(frame);
909          char    fnbefore[128], fnafter[128], *fbase;
910          char    combuf[1024], fname0[128], fname1[128];
911          int     usepinterp, usepfilt, nora_rgbe;
912          int     frseq[2];
913                                                  /* check what is needed */
914 +        if (vp == NULL) {
915 +                 fprintf(stderr,
916 +                        "%s: unexpected error reading view for frame %d\n",
917 +                                          progname, frame);
918 +                quit(1);
919 +        }
920          usepinterp = (nblur > 1);
921 <        usepfilt = pfiltalways | ep==NULL;
921 >        usepfilt = pfiltalways | (ep==NULL);
922          if (ep != NULL && !strcmp(ep, "1"))
923                  ep = "+0";
924          nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
# Line 1011 | Line 989 | int    rvr;
989                                  putc('\n', fp); fclose(fp);
990                          }
991                          sprintf(combuf,
992 <                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B",
992 >                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
993                                          blurf, nblur,
994                                          fname0, fname1, fname0, fname1);
995                          iter++;
# Line 1026 | Line 1004 | int    rvr;
1004                  if (usepfilt)
1005                          sprintf(combuf+strlen(combuf), " %s", rresopt);
1006                  else
1007 <                        sprintf(combuf+strlen(combuf), " %s -e %s",
1007 >                        sprintf(combuf+strlen(combuf), " -a %s -e %s",
1008                                          fresopt, ep);
1009                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1010                                  fnbefore, fnbefore);
# Line 1073 | Line 1051 | int    rvr;
1051   }
1052  
1053  
1054 < VIEW *
1055 < getview(n)                      /* get view number n */
1078 < int     n;
1054 > static VIEW *
1055 > getview(int n)                  /* get view number n */
1056   {
1057          static FILE     *viewfp = NULL;         /* view file pointer */
1058          static int      viewnum = 0;            /* current view number */
# Line 1087 | Line 1064 | int    n;
1064                          fclose(viewfp);
1065                          viewfp = NULL;
1066                          viewnum = 0;
1067 <                        copystruct(&curview, &stdview);
1067 >                        curview = stdview;
1068                  }
1069                  return(NULL);
1070          }
# Line 1103 | Line 1080 | int    n;
1080                          perror(vval(VIEWFILE));
1081                          quit(1);
1082                  }
1083 <                copystruct(&curview, &stdview);
1083 >                curview = stdview;
1084                  viewnum = 0;
1085          }
1086          if (n < 0) {                            /* get next view */
# Line 1123 | Line 1100 | int    n;
1100   }
1101  
1102  
1103 < int
1104 < countviews()                    /* count views in view file */
1103 > static int
1104 > countviews(void)                        /* count views in view file */
1105   {
1106          int     n;
1107  
# Line 1136 | Line 1113 | countviews()                   /* count views in view file */
1113   }
1114  
1115  
1116 < char *
1117 < getexp(n)                       /* get exposure for nth frame */
1141 < int     n;
1116 > static char *
1117 > getexp(int n)                   /* get exposure for nth frame */
1118   {
1119          extern char     *fskip();
1120          static char     expval[32];
# Line 1207 | Line 1183 | int    n;
1183   }
1184  
1185  
1186 < struct pslot *
1187 < findpslot(pid)                  /* find or allocate a process slot */
1212 < int     pid;
1186 > static struct pslot *
1187 > findpslot(int pid)                      /* find or allocate a process slot */
1188   {
1189          register struct pslot   *psempty = NULL;
1190          register int    i;
# Line 1224 | Line 1199 | int    pid;
1199   }
1200  
1201  
1202 < int
1203 < donecom(ps, pn, status)         /* clean up after finished process */
1204 < PSERVER *ps;
1205 < int     pn;
1206 < int     status;
1202 > static int
1203 > donecom(                /* clean up after finished process */
1204 >        PSERVER *ps,
1205 >        int     pn,
1206 >        int     status
1207 > )
1208   {
1209 <        register PROC   *pp;
1209 >        register NETPROC        *pp;
1210          register struct pslot   *psl;
1211  
1212          pp = ps->proc + pn;
# Line 1265 | Line 1241 | int    status;
1241   }
1242  
1243  
1244 < int
1245 < serverdown()                    /* check status of last process server */
1244 > static int
1245 > serverdown(void)                        /* check status of last process server */
1246   {
1247          if (lastpserver == NULL || !lastpserver->hostname[0])
1248                  return(0);
# Line 1282 | Line 1258 | serverdown()                   /* check status of last process server
1258   }
1259  
1260  
1261 < int
1262 < bruncom(com, fout, rf)          /* run a command in the background */
1263 < char    *com;
1264 < int     fout;
1265 < int     (*rf)();
1261 > static int
1262 > bruncom(                /* run a command in the background */
1263 > char    *com,
1264 > int     fout,
1265 > int     (*rf)()
1266 > )
1267   {
1268          int     pid;
1269          register struct pslot   *psl;
# Line 1315 | Line 1292 | int    (*rf)();
1292   }
1293  
1294  
1295 < bwait(ncoms)                            /* wait for batch job(s) to finish */
1296 < int     ncoms;
1295 > static void
1296 > bwait(int ncoms)                                /* wait for batch job(s) to finish */
1297   {
1298          int     status;
1299  
# Line 1330 | Line 1307 | int    ncoms;
1307   }
1308  
1309  
1310 < int
1311 < pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1312 < char    *com, *ppins;
1313 < int     maxcopies;
1310 > static int
1311 > pruncom(        /* run a command in parallel over network */
1312 > char    *com,
1313 > char    *ppins,
1314 > int     maxcopies
1315 > )
1316   {
1317          int     retstatus = 0;
1318          int     hostcopies;
# Line 1355 | Line 1334 | int    maxcopies;
1334                          strcpy(com1=buf, com);  /* build -PP command */
1335                          sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1336                                          vval(DIRECTORY), phostname(ps));
1337 +                        unlink(com1+(ppins-com)+5);
1338                          strcat(com1, ppins);
1339                  } else
1340                          com1 = com;
# Line 1399 | Line 1379 | int    maxcopies;
1379   }
1380  
1381  
1382 < runcom(cs)                      /* run a command locally and wait for it */
1383 < char    *cs;
1382 > static int
1383 > runcom(char *cs)                        /* run a command locally and wait for it */
1384   {
1385          if (!silent)            /* echo it */
1386                  printf("\t%s\n", cs);
# Line 1411 | Line 1391 | char   *cs;
1391   }
1392  
1393  
1394 < rmfile(fn)                      /* remove a file */
1395 < char    *fn;
1394 > static int
1395 > rmfile(char *fn)                        /* remove a file */
1396   {
1397          if (!silent)
1398 < #ifdef MSDOS
1398 > #ifdef _WIN32
1399                  printf("\tdel %s\n", fn);
1400   #else
1401                  printf("\trm -f %s\n", fn);
# Line 1426 | Line 1406 | char   *fn;
1406   }
1407  
1408  
1409 < badvalue(vc)                    /* report bad variable value and exit */
1410 < int     vc;
1409 > static void
1410 > badvalue(int vc)                        /* report bad variable value and exit */
1411   {
1412          fprintf(stderr, "%s: bad value for variable '%s'\n",
1413                          progname, vnam(vc));
# Line 1435 | Line 1415 | int    vc;
1415   }
1416  
1417  
1418 < char *
1419 < dirfile(df, path)               /* separate path into directory and file */
1420 < char    *df;
1421 < register char   *path;
1418 > static char *
1419 > dirfile(                /* separate path into directory and file */
1420 > char    *df,
1421 > register char   *path
1422 > )
1423   {
1424          register int    i;
1425          int     psep;
# Line 1446 | Line 1427 | register char  *path;
1427          for (i = 0, psep = -1; path[i]; i++)
1428                  if (path[i] == '/')
1429                          psep = i;
1430 <        if (df != NULL)
1430 >        if (df != NULL) {
1431                  if (psep == 0) {
1432                          df[0] = '/';
1433                          df[1] = '\0';
# Line 1455 | Line 1436 | register char  *path;
1436                          df[psep] = '\0';
1437                  } else
1438                          df[0] = '\0';
1439 +        }
1440          return(path+psep+1);
1441   }
1442  
1443  
1444 < int
1444 > static int
1445   getblur(double *bf)             /* get # blur samples (and fraction) */
1446   {
1447          double  blurf;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines