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

Comparing ray/src/util/rad.c (file contents):
Revision 2.93 by greg, Tue May 18 00:01:02 2010 UTC vs.
Revision 2.112 by greg, Tue May 26 10:00:47 2015 UTC

# Line 24 | Line 24 | static const char      RCSid[] = "$Id$";
24    #define RENAMECMD "mv"
25    #include <sys/types.h>
26    #include <sys/wait.h>
27 +  #include <signal.h>
28   #endif
29  
30                                  /* variables (alphabetical by name) */
# Line 35 | Line 36 | static const char      RCSid[] = "$Id$";
36   #define INDIRECT        5               /* indirection in lighting */
37   #define MATERIAL        6               /* material files */
38   #define MKILLUM         7               /* mkillum options */
39 < #define OBJECT          8               /* object files */
40 < #define OCONV           9               /* oconv options */
41 < #define OCTREE          10              /* octree file name */
42 < #define OPTFILE         11              /* rendering options file */
43 < #define PENUMBRAS       12              /* shadow penumbras are desired */
44 < #define PFILT           13              /* pfilt options */
45 < #define PICTURE         14              /* picture file root name */
46 < #define QUALITY         15              /* desired rendering quality */
47 < #define RAWFILE         16              /* raw picture file root name */
48 < #define RENDER          17              /* rendering options */
49 < #define REPORT          18              /* report frequency and errfile */
50 < #define RESOLUTION      19              /* maximum picture resolution */
51 < #define RPICT           20              /* rpict parameters */
52 < #define RVU             21              /* rvu parameters */
53 < #define SCENE           22              /* scene files */
54 < #define UP              23              /* view up (X, Y or Z) */
55 < #define VARIABILITY     24              /* level of light variability */
56 < #define VIEWS           25              /* view(s) for picture(s) */
57 < #define ZFILE           26              /* distance file root name */
58 < #define ZONE            27              /* simulation zone */
39 > #define MKPMAP          8               /* mkpmap options */
40 > #define OBJECT          9               /* object files */
41 > #define OCONV           10              /* oconv options */
42 > #define OCTREE          11              /* octree file name */
43 > #define OPTFILE         12              /* rendering options file */
44 > #define PCMAP           13              /* caustic photon map */
45 > #define PENUMBRAS       14              /* shadow penumbras are desired */
46 > #define PFILT           15              /* pfilt options */
47 > #define PGMAP           16              /* global photon map */
48 > #define PICTURE         17              /* picture file root name */
49 > #define QUALITY         18              /* desired rendering quality */
50 > #define RAWFILE         19              /* raw picture file root name */
51 > #define RENDER          20              /* rendering options */
52 > #define REPORT          21              /* report frequency and errfile */
53 > #define RESOLUTION      22              /* maximum picture resolution */
54 > #define RPICT           23              /* rpict parameters */
55 > #define RVU             24              /* rvu parameters */
56 > #define SCENE           25              /* scene files */
57 > #define UP              26              /* view up (X, Y or Z) */
58 > #define VARIABILITY     27              /* level of light variability */
59 > #define VIEWS           28              /* view(s) for picture(s) */
60 > #define ZFILE           29              /* distance file root name */
61 > #define ZONE            30              /* simulation zone */
62                                  /* total number of variables */
63 < int NVARS = 28;
63 > int NVARS = 31;
64  
65   VARIABLE        vv[] = {                /* variable-value pairs */
66          {"AMBFILE",     3,      0,      NULL,   onevalue},
# Line 67 | Line 71 | VARIABLE       vv[] = {                /* variable-value pairs */
71          {"INDIRECT",    3,      0,      NULL,   intvalue},
72          {"materials",   3,      0,      NULL,   catvalues},
73          {"mkillum",     3,      0,      NULL,   catvalues},
74 +        {"mkpmap",      3,      0,      NULL,   catvalues},
75          {"objects",     3,      0,      NULL,   catvalues},
76          {"oconv",       3,      0,      NULL,   catvalues},
77          {"OCTREE",      3,      0,      NULL,   onevalue},
78          {"OPTFILE",     3,      0,      NULL,   onevalue},
79 +        {"PCMAP",       2,      0,      NULL,   onevalue},
80          {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
81          {"pfilt",       2,      0,      NULL,   catvalues},
82 +        {"PGMAP",       2,      0,      NULL,   onevalue},
83          {"PICTURE",     3,      0,      NULL,   onevalue},
84          {"QUALITY",     3,      0,      NULL,   qualvalue},
85          {"RAWFILE",     3,      0,      NULL,   onevalue},
# Line 107 | Line 114 | time_t oct0date;               /* date of pre-mkillum octree */
114   char    *oct1name;              /* name of post-mkillum octree */
115   time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
116  
117 + char    *pgmapname;             /* name of global photon map */
118 + time_t  pgmapdate;              /* date of global photon map (>= oct1date) */
119 + char    *pcmapname;             /* name of caustic photon map */
120 + time_t  pcmapdate;              /* date of caustic photon map (>= oct1date) */
121 +
122   int     nowarn = 0;             /* no warnings */
123   int     explicate = 0;          /* explicate variables */
124   int     silent = 0;             /* do work silently */
# Line 121 | Line 133 | char   *viewselect = NULL;     /* specific view only */
133                                  /* command paths */
134   char    c_oconv[256] = "oconv";
135   char    c_mkillum[256] = "mkillum";
136 + char    c_mkpmap[256] = "mkpmap";
137   char    c_rvu[256] = "rvu";
138   char    c_rpict[256] = DEF_RPICT_PATH;
139   char    c_rpiece[] = "rpiece";
# Line 144 | Line 157 | static void checkfiles(void);
157   static void getoctcube(double   org[3], double  *sizp);
158   static void setdefaults(void);
159   static void oconv(void);
160 + static void mkpmap(void);
161   static char * addarg(char       *op, char       *arg);
162   static void oconvopts(char      *oo);
163   static void mkillumopts(char    *mo);
164 + static void mkpmapopts(char     *mo);
165   static void checkambfile(void);
166   static double ambval(void);
167   static void renderopts(char     *op, char       *po);
# Line 165 | Line 180 | static int touch(char  *fn);
180   static int runcom(char  *cs);
181   static int rmfile(char  *fn);
182   static int mvfile(char  *fold, char     *fnew);
183 < static int next_process(void);
183 > static int next_process(int     reserve);
184   static void wait_process(int    all);
185   static void finish_process(void);
186   static void badvalue(int        vc);
# Line 243 | Line 258 | main(
258                  printvars(stdout);
259                                  /* build octree (and run mkillum) */
260          oconv();
261 +                                /* run mkpmap if indicated */
262 +        mkpmap();
263                                  /* check date on ambient file */
264          checkambfile();
265                                  /* run simulation */
# Line 264 | Line 281 | userr:
281  
282   static void
283   rootname(               /* remove tail from end of fn */
284 <        register char   *rn,
285 <        register char   *fn
284 >        char    *rn,
285 >        char    *fn
286   )
287   {
288          char    *tp, *dp;
# Line 282 | Line 299 | rootname(              /* remove tail from end of fn */
299  
300   static time_t
301   checklast(                      /* check files and find most recent */
302 <        register char   *fnames
302 >        char    *fnames
303   )
304   {
305          char    thisfile[PATH_MAX];
# Line 312 | Line 329 | newfname(              /* create modified file name */
329          int     pred
330   )
331   {
332 <        register char   *cp;
333 <        register int    n;
332 >        char    *cp;
333 >        int     n;
334          int     suffix;
335  
336          n = 0; cp = orig; suffix = -1;          /* suffix position, length */
# Line 335 | Line 352 | newfname(              /* create modified file name */
352   static void
353   checkfiles(void)                        /* check for existence and modified times */
354   {
355 +        char    fntemp[256];
356          time_t  objdate;
357  
358          if (!vdef(OCTREE)) {
# Line 364 | Line 382 | checkfiles(void)                       /* check for existence and modified
382                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
383                  quit(1);
384          }
385 +        if (vdef(PGMAP)) {
386 +                if (!*sskip2(vval(PGMAP),1)) {
387 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
388 +                                        progname, vnam(PGMAP));
389 +                        quit(1);
390 +                }
391 +                atos(fntemp, sizeof(fntemp), vval(PGMAP));
392 +                pgmapname = savqstr(fntemp);
393 +                pgmapdate = fdate(pgmapname);
394 +        }
395 +        if (vdef(PCMAP)) {
396 +                if (!*sskip2(vval(PCMAP),1)) {
397 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
398 +                                        progname, vnam(PCMAP));
399 +                        quit(1);
400 +                }
401 +                atos(fntemp, sizeof(fntemp), vval(PCMAP));
402 +                pcmapname = savqstr(fntemp);
403 +                pcmapdate = fdate(pcmapname);
404 +                if (pgmapname == NULL && !nowarn)
405 +                        fprintf(stderr, "%s: '%s' assigned without '%s'\n",
406 +                                        progname, vnam(PCMAP), vnam(PGMAP));
407 +        }
408          matdate = checklast(vval(MATERIAL));
409   }      
410  
# Line 378 | Line 419 | getoctcube(            /* get octree bounding cube */
419          double  min[3], max[3];
420          char    buf[1024];
421          FILE    *fp;
422 <        register int    i;
422 >        int     i;
423  
424          if (osiz <= FTINY) {
425                  if (!nprocs && fdate(oct1name) <
# Line 558 | Line 599 | oconv(void)                            /* run oconv and mkillum if necessary *
599                          unlink(illumtmp);
600                          quit(1);
601                  }
602 +                rmfile(oct0name);
603                                                  /* make octree1 (frozen) */
604                  if (octreedate)
605                          sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
# Line 584 | Line 626 | oconv(void)                            /* run oconv and mkillum if necessary *
626   }
627  
628  
629 + static void
630 + mkpmap(void)                    /* run mkpmap if indicated */
631 + {
632 +        char    combuf[2048], *cp;
633 +        time_t  tnow;
634 +                                /* nothing to do? */
635 +        if ((pgmapname == NULL) | (pgmapdate >= oct1date) &&
636 +                        (pcmapname == NULL) | (pcmapdate >= oct1date))
637 +                return;
638 +                                /* just update existing file dates? */
639 +        if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) &&
640 +                        (pcmapname == NULL) | (pcmapdate > 0)) {
641 +                if (pgmapname != NULL)
642 +                        touch(pgmapname);
643 +                if (pcmapname != NULL)
644 +                        touch(pcmapname);
645 +        } else {                /* else need to (re)run pkpmap */
646 +                strcpy(combuf, c_mkpmap);
647 +                for (cp = combuf; *cp; cp++)
648 +                        ;
649 +                mkpmapopts(cp);
650 +                if (vdef(REPORT)) {
651 +                        char    errfile[256];
652 +                        int     n;
653 +                        double  minutes;
654 +                        n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile);
655 +                        if (n == 2)
656 +                                sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile);
657 +                        else if (n == 1)
658 +                                sprintf(cp, " -t %d", (int)(minutes*60));
659 +                        else
660 +                                badvalue(REPORT);
661 +                }
662 +                if (vdef(PGMAP)) {
663 +                        cp = addarg(cp, "-apg");
664 +                        addarg(cp, vval(PGMAP));
665 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
666 +                        *cp = '\0';
667 +                }
668 +                if (vdef(PCMAP)) {
669 +                        cp = addarg(cp, "-apc");
670 +                        addarg(cp, vval(PCMAP));
671 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
672 +                        *cp = '\0';
673 +                }
674 +                cp = addarg(cp, oct1name);
675 +                if (runcom(combuf)) {
676 +                        fprintf(stderr, "%s: error running %s\n",
677 +                                        progname, c_mkpmap);
678 +                        if (pgmapname != NULL)
679 +                                unlink(pgmapname);
680 +                        if (pcmapname != NULL)
681 +                                unlink(pcmapname);
682 +                        quit(1);
683 +                }
684 +        }
685 +        tnow = time((time_t *)NULL);
686 +        if (pgmapname != NULL)
687 +                pgmapdate = tnow;
688 +        if (pcmapname != NULL)
689 +                pcmapdate = tnow;
690 +        oct1date = tnow;        /* trigger ambient file removal if needed */
691 + }
692 +
693 +
694   static char *
695   addarg(                         /* append argument and advance pointer */
696 < register char   *op,
697 < register char   *arg
696 > char    *op,
697 > char    *arg
698   )
699   {
700          while (*op)
# Line 601 | Line 708 | register char  *arg
708  
709   static void
710   oconvopts(                              /* get oconv options */
711 <        register char   *oo
711 >        char    *oo
712   )
713   {
714          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
715  
716          *oo = '\0';
717 <        if (vdef(OCONV))
718 <                if (vval(OCONV)[0] != '-') {
719 <                        atos(c_oconv, sizeof(c_oconv), vval(OCONV));
720 <                        oo = addarg(oo, sskip2(vval(OCONV), 1));
721 <                } else
722 <                        oo = addarg(oo, vval(OCONV));
717 >        if (!vdef(OCONV))
718 >                return;
719 >        if (vval(OCONV)[0] != '-') {
720 >                atos(c_oconv, sizeof(c_oconv), vval(OCONV));
721 >                oo = addarg(oo, sskip2(vval(OCONV), 1));
722 >        } else
723 >                oo = addarg(oo, vval(OCONV));
724   }
725  
726  
# Line 627 | Line 735 | mkillumopts(                           /* get mkillum options */
735                  sprintf(mo, " -n %d", nprocs);
736          else
737                  *mo = '\0';
738 <        if (vdef(MKILLUM))
739 <                if (vval(MKILLUM)[0] != '-') {
740 <                        atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
741 <                        mo = addarg(mo, sskip2(vval(MKILLUM), 1));
742 <                } else
743 <                        mo = addarg(mo, vval(MKILLUM));
738 >        if (!vdef(MKILLUM))
739 >                return;
740 >        if (vval(MKILLUM)[0] != '-') {
741 >                atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
742 >                mo = addarg(mo, sskip2(vval(MKILLUM), 1));
743 >        } else
744 >                mo = addarg(mo, vval(MKILLUM));
745   }
746  
747  
748   static void
749 + mkpmapopts(                             /* get mkpmap options */
750 +        char    *mo
751 + )
752 + {
753 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
754 +
755 +        *mo = '\0';
756 +        if (!vdef(MKPMAP))
757 +                return;
758 +        if (vval(MKPMAP)[0] != '-') {
759 +                atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP));
760 +                mo = addarg(mo, sskip2(vval(MKPMAP), 1));
761 +        } else
762 +                mo = addarg(mo, vval(MKPMAP));
763 + }
764 +
765 +
766 + static void
767   checkambfile(void)                      /* check date on ambient file */
768   {
769          time_t  afdate;
# Line 677 | Line 804 | renderopts(                    /* set rendering options */
804          char    *po
805   )
806   {
807 +        char    pmapf[256], *bw;
808 +
809          switch(vscale(QUALITY)) {
810          case LOW:
811                  lowqopts(op, po);
# Line 688 | Line 817 | renderopts(                    /* set rendering options */
817                  hiqopts(op, po);
818                  break;
819          }
820 +        if (vdef(PGMAP)) {
821 +                bw = sskip2(vval(PGMAP), 2);
822 +                atos(pmapf, sizeof(pmapf), vval(PGMAP));
823 +                op = addarg(addarg(op, "-ap"), pmapf);
824 +                if (atoi(bw) > 0) op = addarg(op, bw);
825 +        }
826 +        if (vdef(PCMAP)) {
827 +                bw = sskip2(vval(PCMAP), 2);
828 +                atos(pmapf, sizeof(pmapf), vval(PCMAP));
829 +                op = addarg(addarg(op, "-ap"), pmapf);
830 +                if (atoi(bw) > 0) op = addarg(op, bw);
831 +        }
832          if (vdef(RENDER))
833                  op = addarg(op, vval(RENDER));
834          if (rvdevice != NULL) {
# Line 710 | Line 851 | renderopts(                    /* set rendering options */
851  
852   static void
853   lowqopts(                       /* low quality rendering options */
854 <        register char   *op,
854 >        char    *op,
855          char    *po
856   )
857   {
# Line 751 | Line 892 | lowqopts(                      /* low quality rendering options */
892                  op = addarg(op, "-ds .4");
893          else
894                  op = addarg(op, "-ds 0");
895 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
895 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5");
896          if (vdef(AMBFILE)) {
897                  sprintf(op, " -af %s", vval(AMBFILE));
898                  op += strlen(op);
# Line 772 | Line 913 | lowqopts(                      /* low quality rendering options */
913          d = ambval();
914          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
915          op += strlen(op);
916 <        op = addarg(op, "-lr 6 -lw .01");
916 >        op = addarg(op, "-lr 6 -lw .003");
917   }
918  
919  
920   static void
921   medqopts(                       /* medium quality rendering options */
922 <        register char   *op,
922 >        char    *op,
923          char    *po
924   )
925   {
# Line 826 | Line 967 | medqopts(                      /* medium quality rendering options */
967                  op = addarg(op, "-ds .2 -dj .9");
968          else
969                  op = addarg(op, "-ds .3");
970 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
970 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
971          if ( (overture = vint(INDIRECT)) ) {
972                  sprintf(op, " -ab %d", overture);
973                  op += strlen(op);
# Line 850 | Line 991 | medqopts(                      /* medium quality rendering options */
991          d = ambval();
992          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
993          op += strlen(op);
994 <        op = addarg(op, "-lr 8 -lw .002");
994 >        op = addarg(op, "-lr 8 -lw 1e-4");
995   }
996  
997  
998   static void
999   hiqopts(                                /* high quality rendering options */
1000 <        register char   *op,
1000 >        char    *op,
1001          char    *po
1002   )
1003   {
# Line 904 | Line 1045 | hiqopts(                               /* high quality rendering options */
1045                  op = addarg(op, "-ds .1 -dj .9");
1046          else
1047                  op = addarg(op, "-ds .2");
1048 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1048 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
1049          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1050          op += strlen(op);
1051          if (vdef(AMBFILE)) {
# Line 926 | Line 1067 | hiqopts(                               /* high quality rendering options */
1067          d = ambval();
1068          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1069          op += strlen(op);
1070 <        op = addarg(op, "-lr 12 -lw .0005");
1070 >        op = addarg(op, "-lr 12 -lw 1e-5");
1071   }
1072  
1073  
1074 + #ifdef _WIN32
1075   static void
1076 + setenv(                 /* set an environment variable */
1077 +        char    *vname,
1078 +        char    *value
1079 + )
1080 + {
1081 +        char    *evp;
1082 +
1083 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1084 +        if (evp == NULL)
1085 +                syserr(progname);
1086 +        sprintf(evp, "%s=%s", vname, value);
1087 +        if (putenv(evp) != 0) {
1088 +                fprintf(stderr, "%s: out of environment space\n", progname);
1089 +                quit(1);
1090 +        }
1091 +        if (!silent)
1092 +                printf("set %s\n", evp);
1093 + }
1094 + #endif
1095 +
1096 +
1097 + static void
1098   xferopts(                               /* transfer options if indicated */
1099          char    *ro
1100   )
1101   {
1102          int     fd, n;
1103 <        register char   *cp;
1103 >        char    *cp;
1104          
1105          n = strlen(ro);
1106          if (n < 2)
# Line 965 | Line 1129 | xferopts(                              /* transfer options if indicated */
1129  
1130   static void
1131   pfiltopts(                              /* get pfilt options */
1132 <        register char   *po
1132 >        char    *po
1133   )
1134   {
1135          *po = '\0';
# Line 992 | Line 1156 | pfiltopts(                             /* get pfilt options */
1156  
1157   static int
1158   matchword(                      /* match white-delimited words */
1159 <        register char   *s1,
1160 <        register char   *s2
1159 >        char    *s1,
1160 >        char    *s2
1161   )
1162   {
1163          while (isspace(*s1)) s1++;
# Line 1007 | Line 1171 | matchword(                     /* match white-delimited words */
1171  
1172   static char *
1173   specview(                               /* get proper view spec from vs */
1174 <        register char   *vs
1174 >        char    *vs
1175   )
1176   {
1177          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1178                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1179          static char     viewopts[128];
1180 <        register char   *cp;
1180 >        char    *cp;
1181          int     xpos, ypos, zpos, viewtype, upax;
1182 <        register int    i;
1182 >        int     i;
1183          double  cent[3], dim[3], mult, d;
1184  
1185          if (vs == NULL || *vs == '-')
# Line 1075 | Line 1239 | specview(                              /* get proper view spec from vs */
1239                          cent[i] += .5*dim[i];
1240                  }
1241                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
1242 <                sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1242 >                sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g",
1243                                  cent[0]+xpos*mult*dim[0],
1244                                  cent[1]+ypos*mult*dim[1],
1245                                  cent[2]+zpos*mult*dim[2],
# Line 1107 | Line 1271 | specview(                              /* get proper view spec from vs */
1271                          break;
1272                  case VT_PAR:
1273                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1274 <                        sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1274 >                        sprintf(cp, " -vh %.3g -vv %.3g", d, d);
1275                          cp += strlen(cp);
1276                          break;
1277                  case VT_ANG:
# Line 1147 | Line 1311 | getview(                               /* get view n, or NULL if none */
1311          char    *vn             /* returned view name */
1312   )
1313   {
1314 <        register char   *mv;
1314 >        char    *mv;
1315  
1316          if (viewselect != NULL) {               /* command-line selected */
1317                  if (n)                          /* only do one */
# Line 1179 | Line 1343 | numview:
1343          mv = nvalue(VIEWS, n);          /* use view n */
1344          if ((vn != NULL) & (mv != NULL))
1345                  if (*mv != '-') {
1346 <                        register char   *mv2 = mv;
1346 >                        char    *mv2 = mv;
1347                          while (*mv2 && !isspace(*mv2))
1348                                  *vn++ = *mv2++;
1349                          *vn = '\0';
# Line 1192 | Line 1356 | numview:
1356  
1357   static int
1358   myprintview(                    /* print out selected view */
1359 <        register char   *vopts,
1359 >        char    *vopts,
1360          FILE    *fp
1361   )
1362   {
1363          VIEW    vwr;
1364          char    buf[128];
1365 <        register char   *cp;
1365 >        char    *cp;
1366   #ifdef _WIN32
1367   /* XXX Should we allow something like this for all platforms? */
1368   /* XXX Or is it still required at all? */
# Line 1254 | Line 1418 | rvu(                           /* run rvu with first view */
1418   }
1419  
1420  
1421 + static int
1422 + syncf_done(                     /* check if an rpiece sync file is complete */
1423 +        char *sfname
1424 + )
1425 + {
1426 +        FILE    *fp = fopen(sfname, "r");
1427 +        int     todo = 1;
1428 +        int     x, y;
1429 +
1430 +        if (fp == NULL)
1431 +                return(0);
1432 +        if (fscanf(fp, "%d %d", &x, &y) != 2)
1433 +                goto checked;
1434 +        todo = x*y;             /* total number of tiles */
1435 +        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1436 +                goto checked;
1437 +                                /* XXX assume no redundant tiles */
1438 +        while (fscanf(fp, "%d %d", &x, &y) == 2)
1439 +                if (!--todo)
1440 +                        break;
1441 + checked:
1442 +        fclose(fp);
1443 +        return(!todo);
1444 + }
1445 +
1446 +
1447   static void
1448   rpict(                          /* run rpict and pfilt for each view */
1449          char    *opts,
# Line 1261 | Line 1451 | rpict(                         /* run rpict and pfilt for each view */
1451   )
1452   {
1453   #define do_rpiece       (sfile[0]!='\0')
1454 <        char    combuf[4*PATH_MAX+512];
1454 >        char    combuf[5*PATH_MAX+512];
1455          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1456          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1457 <        char    rppopt[128], sfile[64], *pfile = NULL;
1457 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1458          char    pfopts[128];
1459          char    vs[32], *vw;
1460          int     vn, mult;
1461          FILE    *fp;
1462          time_t  rfdt, pfdt;
1463 +        int     xres, yres;
1464 +        double  aspect;
1465 +        int     n;
1466                                          /* get pfilt options */
1467          pfiltopts(pfopts);
1468                                          /* get resolution, reporting */
# Line 1284 | Line 1477 | rpict(                         /* run rpict and pfilt for each view */
1477                  mult = 3;
1478                  break;
1479          }
1480 <        {
1481 <                int     xres, yres;
1482 <                double  aspect;
1483 <                int     n;
1484 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1485 <                if (n == 3)
1486 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1487 <                                        mult*xres, mult*yres, aspect);
1488 <                else if (n) {
1489 <                        if (n == 1) yres = xres;
1297 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1298 <                } else
1299 <                        badvalue(RESOLUTION);
1300 <        }
1480 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1481 >        if (n == 3)
1482 >                sprintf(res, "-x %d -y %d -pa %.3f",
1483 >                                mult*xres, mult*yres, aspect);
1484 >        else if (n) {
1485 >                aspect = 1.;
1486 >                if (n == 1) yres = xres;
1487 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1488 >        } else
1489 >                badvalue(RESOLUTION);
1490          rep[0] = '\0';
1491          if (vdef(REPORT)) {
1492                  double  minutes;
1304                int     n;
1493                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1494                  if (n == 2)
1495                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1316 | Line 1504 | rpict(                         /* run rpict and pfilt for each view */
1504                                          getview(0, vs) != NULL) {
1505                  if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1506                                  getview(1, NULL) == NULL) {
1507 <                        sprintf(sfile, "rpiece_%s.txt", vs);
1507 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1508 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1509 >                                        vs);
1510                          strcpy(rppopt, "-PP pfXXXXXX");
1511                  } else {
1512                          strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1513                  }
1514                  pfile = rppopt + strlen(rppopt) - 8;
1515 <                if (mktemp(pfile) == NULL)
1515 >                if (mktemp(pfile) == NULL) {
1516                          if (do_rpiece) {
1517                                  fprintf(stderr, "%s: cannot create\n", pfile);
1518                                  quit(1);
1519 <                        } else
1520 <                                pfile = NULL;
1519 >                        }
1520 >                        pfile = NULL;
1521 >                }
1522          }
1523          vn = 0;                                 /* do each view */
1524          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1356 | Line 1547 | rpict(                         /* run rpict and pfilt for each view */
1547                  }
1548                                                  /* parallel running? */
1549                  if (do_rpiece) {
1550 <                        if (rfdt < oct1date || fdate(sfile) < oct1date) {
1551 <                                rfdt = 0;               /* start fresh */
1550 >                        if (rfdt < oct1date || !fdate(sfile)) {
1551 >                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1552 >                                if (rfdt >= oct1date) {
1553 >                                        fprintf(stderr,
1554 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1555 >                                        quit(1);
1556 >                                }
1557 >                                if (rfdt) {     /* start fresh */
1558 >                                        rmfile(rawfile);
1559 >                                        rfdt = 0;
1560 >                                }
1561 >                                if (!silent)
1562 >                                        printf("\techo %d %d > %s\n",
1563 >                                                        xdiv, ydiv, sfile);
1564                                  if ((fp = fopen(sfile, "w")) == NULL) {
1565                                          fprintf(stderr, "%s: cannot create\n",
1566                                                          sfile);
1567                                          quit(1);
1568                                  }
1569 <                                fprintf(fp, "%d %d\n", 8+nprocs/3, 8+nprocs/3);
1569 >                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1570                                  fclose(fp);
1571                          }
1572 <                } else if (next_process()) {
1572 >                } else if (next_process(0)) {
1573                          if (pfile != NULL)
1574                                  sleep(10);
1575                          continue;
# Line 1379 | Line 1582 | rpict(                         /* run rpict and pfilt for each view */
1582                                  sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1583                                                  c_rpiece, sfile, rppopt, rep, vw,
1584                                                  res, opts, po, rawfile, oct1name);
1585 <                                while (children_running < nprocs-1 &&
1383 <                                                        next_process()) {
1585 >                                while (next_process(1)) {
1586                                          sleep(10);
1587                                          combuf[strlen(c_rpiece)+2] = 'F';
1588                                  }
# Line 1392 | Line 1594 | rpict(                         /* run rpict and pfilt for each view */
1594                  } else {
1595                          if (overture) {         /* run overture calculation */
1596                                  sprintf(combuf,
1597 <                                "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1597 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1598                                                  c_rpict, rep, vw, opts,
1599                                                  oct1name, overfile);
1600 <                                if (runcom(combuf)) {
1601 <                                        fprintf(stderr,
1600 >                                if (!do_rpiece || !next_process(0)) {
1601 >                                        if (runcom(combuf)) {
1602 >                                                fprintf(stderr,
1603                                          "%s: error in overture for view %s\n",
1604 <                                                progname, vs);
1605 <                                        quit(1);
1606 <                                }
1604 >                                                        progname, vs);
1605 >                                                quit(1);
1606 >                                        }
1607   #ifndef NULL_DEVICE
1608 <                                rmfile(overfile);
1608 >                                        rmfile(overfile);
1609   #endif
1610 +                                } else if (do_rpiece)
1611 +                                        sleep(20);
1612                          }
1613                          if (do_rpiece) {
1614                                  sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1615                                                  c_rpiece, sfile, rppopt, rep, vw,
1616                                                  res, opts, po, rawfile, oct1name);
1617 <                                while (children_running < nprocs-1 &&
1413 <                                                        next_process())
1617 >                                while (next_process(1))
1618                                          sleep(10);
1619                          } else {
1620                                  sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
# Line 1436 | Line 1640 | rpict(                         /* run rpict and pfilt for each view */
1640                  if (do_rpiece) {                /* need to finish raw, first */
1641                          finish_process();
1642                          wait_process(1);
1643 <                        /* XXX should check sync file to see if really done? */
1643 >                        if (!syncf_done(sfile)) {
1644 >                                fprintf(stderr,
1645 >                        "%s: %s did not complete rendering of view %s\n",
1646 >                                                progname, c_rpiece, vs);
1647 >                                quit(1);
1648 >                        }
1649                  }
1650                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1651                                                  /* build pfilt command */
1652 <                        if (mult > 1)
1652 >                        if (do_rpiece)
1653 >                                sprintf(combuf,
1654 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1655 >                                        c_pfilt, pfopts, xres, yres, aspect,
1656 >                                        rawfile, picfile);
1657 >                        else if (mult > 1)
1658                                  sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1659                                          c_pfilt, pfopts, mult, mult,
1660                                          rawfile, picfile);
# Line 1467 | Line 1681 | rpict(                         /* run rpict and pfilt for each view */
1681                          finish_process();       /* exit if child */
1682          }
1683          wait_process(1);                /* wait for children to finish */
1684 <        if (pfile != NULL) {            /* clean up rpict persistent mode */
1684 >        if (pfile != NULL) {            /* clean up persistent rpict */
1685                  RT_PID  pid;
1686                  fp = fopen(pfile, "r");
1687                  if (fp != NULL) {
# Line 1494 | Line 1708 | touch(                 /* update a file */
1708                  printf("\ttouch %s\n", fn);
1709          if (!nprocs)
1710                  return(0);
1497 #ifdef notused
1498        if (access(fn, F_OK) == -1)             /* create it */
1499                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1500                        return(-1);
1501 #endif
1711          return(setfdate(fn, time((time_t *)NULL)));
1712   }
1713  
# Line 1546 | Line 1755 | mvfile(                /* move a file */
1755  
1756   #ifdef RHAS_FORK_EXEC
1757   static int
1758 < next_process(void)                      /* fork the next process (max. nprocs) */
1758 > next_process(int reserve)               /* fork the next process */
1759   {
1760          RT_PID  child_pid;
1761  
# Line 1557 | Line 1766 | next_process(void)                     /* fork the next process (max. np
1766                                  progname);
1767                  quit(1);
1768          }
1769 +        if (reserve > 0 && children_running >= nprocs-reserve)
1770 +                return(0);              /* caller holding back process(es) */
1771          if (children_running >= nprocs)
1772                  wait_process(0);        /* wait for someone to finish */
1773          fflush(NULL);                   /* flush output */
1774          child_pid = fork();             /* split process */
1775          if (child_pid == 0) {           /* we're the child */
1776                  children_running = -1;
1777 +                nprocs = 1;
1778                  return(0);
1779          }
1780          if (child_pid > 0) {            /* we're the parent */
# Line 1604 | Line 1816 | wait_process(                  /* wait for process(es) to finish */
1816   }
1817   #else   /* ! RHAS_FORK_EXEC */
1818   static int
1819 < next_process(void)
1819 > next_process(int reserve)
1820   {
1821          return(0);                      /* cannot start new process */
1822   }
# Line 1630 | Line 1842 | finish_process(void)                   /* exit a child process */
1842                  return;                 /* in parent -- noop */
1843          exit(0);
1844   }
1633
1634 #ifdef _WIN32
1635 setenv(vname, value)            /* set an environment variable */
1636 char    *vname, *value;
1637 {
1638        register char   *evp;
1639
1640        evp = bmalloc(strlen(vname)+strlen(value)+2);
1641        if (evp == NULL)
1642                syserr(progname);
1643        sprintf(evp, "%s=%s", vname, value);
1644        if (putenv(evp) != 0) {
1645                fprintf(stderr, "%s: out of environment space\n", progname);
1646                quit(1);
1647        }
1648        if (!silent)
1649                printf("set %s\n", evp);
1650 }
1651 #endif
1845  
1846  
1847   static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines