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.81 by schorsch, Mon Sep 12 14:40:13 2005 UTC vs.
Revision 2.108 by greg, Mon Aug 12 21:01:00 2013 UTC

# Line 47 | Line 47 | static const char      RCSid[] = "$Id$";
47   #define RENDER          17              /* rendering options */
48   #define REPORT          18              /* report frequency and errfile */
49   #define RESOLUTION      19              /* maximum picture resolution */
50 < #define SCENE           20              /* scene files */
51 < #define UP              21              /* view up (X, Y or Z) */
52 < #define VARIABILITY     22              /* level of light variability */
53 < #define VIEWS           23              /* view(s) for picture(s) */
54 < #define ZFILE           24              /* distance file root name */
55 < #define ZONE            25              /* simulation zone */
50 > #define RPICT           20              /* rpict parameters */
51 > #define RVU             21              /* rvu parameters */
52 > #define SCENE           22              /* scene files */
53 > #define UP              23              /* view up (X, Y or Z) */
54 > #define VARIABILITY     24              /* level of light variability */
55 > #define VIEWS           25              /* view(s) for picture(s) */
56 > #define ZFILE           26              /* distance file root name */
57 > #define ZONE            27              /* simulation zone */
58                                  /* total number of variables */
59 < int NVARS = 26;
59 > int NVARS = 28;
60  
61   VARIABLE        vv[] = {                /* variable-value pairs */
62          {"AMBFILE",     3,      0,      NULL,   onevalue},
# Line 77 | Line 79 | VARIABLE       vv[] = {                /* variable-value pairs */
79          {"render",      3,      0,      NULL,   catvalues},
80          {"REPORT",      3,      0,      NULL,   onevalue},
81          {"RESOLUTION",  3,      0,      NULL,   onevalue},
82 +        {"rpict",       3,      0,      NULL,   catvalues},
83 +        {"rvu",         3,      0,      NULL,   catvalues},
84          {"scene",       3,      0,      NULL,   catvalues},
85          {"UP",          2,      0,      NULL,   onevalue},
86          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
# Line 112 | Line 116 | int    sayview = 0;            /* print view out */
116   char    *rvdevice = NULL;       /* rvu output device */
117   char    *viewselect = NULL;     /* specific view only */
118  
119 + #define DEF_RPICT_PATH  "rpict"         /* default rpict path */
120 +
121 +                                /* command paths */
122 + char    c_oconv[256] = "oconv";
123 + char    c_mkillum[256] = "mkillum";
124 + char    c_rvu[256] = "rvu";
125 + char    c_rpict[256] = DEF_RPICT_PATH;
126 + char    c_rpiece[] = "rpiece";
127 + char    c_pfilt[256] = "pfilt";
128 +
129   int     overture = 0;           /* overture calculation needed */
130  
131   int     children_running = 0;   /* set negative in children */
# Line 151 | Line 165 | static int touch(char  *fn);
165   static int runcom(char  *cs);
166   static int rmfile(char  *fn);
167   static int mvfile(char  *fold, char     *fnew);
168 < static int next_process(void);
168 > static int next_process(int     reserve);
169   static void wait_process(int    all);
170   static void finish_process(void);
171   static void badvalue(int        vc);
# Line 207 | Line 221 | main(
221          if (i >= argc)
222                  goto userr;
223          rifname = argv[i];
210                                /* check command-line options */
211        if ((nprocs > 1) & (viewselect != NULL))
212                nprocs = 1;
224                                  /* assign Radiance root file name */
225          rootname(radname, rifname);
226                                  /* load variable values */
# Line 480 | Line 491 | oconv(void)                            /* run oconv and mkillum if necessary *
491                          touch(vval(OCTREE));
492                  else {                          /* build command */
493                          if (vdef(MATERIAL))
494 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
495 <                                                vval(MATERIAL), vval(SCENE),
496 <                                                vval(OCTREE));
494 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
495 >                                                ocopts, vval(MATERIAL),
496 >                                                vval(SCENE), vval(OCTREE));
497                          else
498 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
498 >                                sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts,
499                                                  vval(SCENE), vval(OCTREE));
500                          
501                          if (runcom(combuf)) {           /* run it */
# Line 510 | Line 521 | oconv(void)                            /* run oconv and mkillum if necessary *
521                          touch(oct0name);
522                  else {                          /* build command */
523                          if (octreedate)
524 <                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
525 <                                        vval(OCTREE), vval(ILLUM), oct0name);
524 >                                sprintf(combuf, "%s%s -i %s %s > %s", c_oconv,
525 >                                        ocopts, vval(OCTREE),
526 >                                        vval(ILLUM), oct0name);
527                          else if (vdef(MATERIAL))
528 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
529 <                                        vval(MATERIAL), vval(ILLUM), oct0name);
518 <                        else
519 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
528 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
529 >                                        ocopts, vval(MATERIAL),
530                                          vval(ILLUM), oct0name);
531 +                        else
532 +                                sprintf(combuf, "%s%s %s > %s", c_oconv,
533 +                                        ocopts, vval(ILLUM), oct0name);
534                          if (runcom(combuf)) {           /* run it */
535                                  fprintf(stderr,
536                                  "%s: error generating octree\n\t%s removed\n",
# Line 537 | Line 550 | oconv(void)                            /* run oconv and mkillum if necessary *
550          else {
551                  mkillumopts(mkopts);            /* build mkillum command */
552                  mktemp(illumtmp);
553 <                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
553 >                sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts,
554                                  oct0name, vval(ILLUM), illumtmp);
555                  if (runcom(combuf)) {                   /* run it */
556 <                        fprintf(stderr, "%s: error running mkillum\n",
557 <                                        progname);
556 >                        fprintf(stderr, "%s: error running %s\n",
557 >                                        progname, c_mkillum);
558                          unlink(illumtmp);
559                          quit(1);
560                  }
561 +                rmfile(oct0name);
562                                                  /* make octree1 (frozen) */
563                  if (octreedate)
564 <                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
565 <                                vval(OCTREE), illumtmp, oct1name);
564 >                        sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
565 >                                ocopts, vval(OCTREE), illumtmp, oct1name);
566                  else if (vdef(MATERIAL))
567 <                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
568 <                                vval(MATERIAL), illumtmp, oct1name);
567 >                        sprintf(combuf, "%s%s -f %s %s > %s", c_oconv,
568 >                                ocopts, vval(MATERIAL), illumtmp, oct1name);
569                  else
570 <                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
570 >                        sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts,
571                                  illumtmp, oct1name);
572                  if (runcom(combuf)) {           /* run it */
573                          fprintf(stderr,
# Line 572 | Line 586 | oconv(void)                            /* run oconv and mkillum if necessary *
586  
587  
588   static char *
589 < addarg(                         /* add argument and advance pointer */
589 > addarg(                         /* append argument and advance pointer */
590   register char   *op,
591   register char   *arg
592   )
593   {
594 +        while (*op)
595 +                op++;
596          *op = ' ';
597          while ( (*++op = *arg++) )
598                  ;
# Line 593 | Line 609 | oconvopts(                             /* get oconv options */
609  
610          *oo = '\0';
611          if (vdef(OCONV))
612 <                addarg(oo, vval(OCONV));
612 >                if (vval(OCONV)[0] != '-') {
613 >                        atos(c_oconv, sizeof(c_oconv), vval(OCONV));
614 >                        oo = addarg(oo, sskip2(vval(OCONV), 1));
615 >                } else
616 >                        oo = addarg(oo, vval(OCONV));
617   }
618  
619  
# Line 604 | Line 624 | mkillumopts(                           /* get mkillum options */
624   {
625          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
626  
627 <        if (nprocs > 1) {
627 >        if (nprocs > 1)
628                  sprintf(mo, " -n %d", nprocs);
629 <                while (*mo)
610 <                        mo++;
611 <        } else
629 >        else
630                  *mo = '\0';
631          if (vdef(MKILLUM))
632 <                addarg(mo, vval(MKILLUM));
632 >                if (vval(MKILLUM)[0] != '-') {
633 >                        atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
634 >                        mo = addarg(mo, sskip2(vval(MKILLUM), 1));
635 >                } else
636 >                        mo = addarg(mo, vval(MKILLUM));
637   }
638  
639  
# Line 667 | Line 689 | renderopts(                    /* set rendering options */
689                  hiqopts(op, po);
690                  break;
691          }
692 +        if (vdef(RENDER))
693 +                op = addarg(op, vval(RENDER));
694 +        if (rvdevice != NULL) {
695 +                if (vdef(RVU))
696 +                        if (vval(RVU)[0] != '-') {
697 +                                atos(c_rvu, sizeof(c_rvu), vval(RVU));
698 +                                po = addarg(po, sskip2(vval(RVU), 1));
699 +                        } else
700 +                                po = addarg(po, vval(RVU));
701 +        } else {
702 +                if (vdef(RPICT))
703 +                        if (vval(RPICT)[0] != '-') {
704 +                                atos(c_rpict, sizeof(c_rpict), vval(RPICT));
705 +                                po = addarg(po, sskip2(vval(RPICT), 1));
706 +                        } else
707 +                                po = addarg(po, vval(RPICT));
708 +        }
709   }
710  
711  
# Line 713 | Line 752 | lowqopts(                      /* low quality rendering options */
752                  op = addarg(op, "-ds .4");
753          else
754                  op = addarg(op, "-ds 0");
755 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
755 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5");
756          if (vdef(AMBFILE)) {
757                  sprintf(op, " -af %s", vval(AMBFILE));
758                  op += strlen(op);
# Line 734 | Line 773 | lowqopts(                      /* low quality rendering options */
773          d = ambval();
774          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
775          op += strlen(op);
776 <        op = addarg(op, "-lr 6 -lw .01");
738 <        if (vdef(RENDER))
739 <                op = addarg(op, vval(RENDER));
776 >        op = addarg(op, "-lr 6 -lw .003");
777   }
778  
779  
# Line 787 | Line 824 | medqopts(                      /* medium quality rendering options */
824          }
825          po = addarg(po, "-pt .08");
826          if (vbool(PENUMBRAS))
827 <                op = addarg(op, "-ds .2 -dj .5");
827 >                op = addarg(op, "-ds .2 -dj .9");
828          else
829                  op = addarg(op, "-ds .3");
830 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
830 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
831          if ( (overture = vint(INDIRECT)) ) {
832                  sprintf(op, " -ab %d", overture);
833                  op += strlen(op);
# Line 814 | Line 851 | medqopts(                      /* medium quality rendering options */
851          d = ambval();
852          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
853          op += strlen(op);
854 <        op = addarg(op, "-lr 8 -lw .002");
818 <        if (vdef(RENDER))
819 <                op = addarg(op, vval(RENDER));
854 >        op = addarg(op, "-lr 8 -lw 1e-4");
855   }
856  
857  
# Line 867 | Line 902 | hiqopts(                               /* high quality rendering options */
902          }
903          po = addarg(po, "-pt .04");
904          if (vbool(PENUMBRAS))
905 <                op = addarg(op, "-ds .1 -dj .65");
905 >                op = addarg(op, "-ds .1 -dj .9");
906          else
907                  op = addarg(op, "-ds .2");
908 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
908 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
909          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
910          op += strlen(op);
911          if (vdef(AMBFILE)) {
# Line 892 | Line 927 | hiqopts(                               /* high quality rendering options */
927          d = ambval();
928          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
929          op += strlen(op);
930 <        op = addarg(op, "-lr 12 -lw .0005");
896 <        if (vdef(RENDER))
897 <                op = addarg(op, vval(RENDER));
930 >        op = addarg(op, "-lr 12 -lw 1e-5");
931   }
932  
933  
# Line 950 | Line 983 | pfiltopts(                             /* get pfilt options */
983                  break;
984          }
985          if (vdef(PFILT))
986 <                po = addarg(po, vval(PFILT));
986 >                if (vval(PFILT)[0] != '-') {
987 >                        atos(c_pfilt, sizeof(c_pfilt), vval(PFILT));
988 >                        po = addarg(po, sskip2(vval(PFILT), 1));
989 >                } else
990 >                        po = addarg(po, vval(PFILT));
991   }
992  
993  
# Line 1012 | Line 1049 | specview(                              /* get proper view spec from vs */
1049          } else if (*vs == 'z') {
1050                  zpos = -1; vs++;
1051          }
1052 <        viewtype = 'v';
1053 <        if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c'))
1052 >        switch (*vs) {
1053 >        case VT_PER:
1054 >        case VT_PAR:
1055 >        case VT_ANG:
1056 >        case VT_HEM:
1057 >        case VT_PLS:
1058 >        case VT_CYL:
1059                  viewtype = *vs++;
1060 +                break;
1061 +        default:
1062 +                viewtype = VT_PER;
1063 +                break;
1064 +        }
1065          cp = viewopts;
1066          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1067                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
# Line 1056 | Line 1103 | specview(                              /* get proper view spec from vs */
1103                  }
1104                  cp = addarg(cp, vup[upax+3]);
1105                  switch (viewtype) {
1106 <                case 'v':
1106 >                case VT_PER:
1107                          cp = addarg(cp, "-vh 45 -vv 45");
1108                          break;
1109 <                case 'l':
1109 >                case VT_PAR:
1110                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1111                          sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1112                          cp += strlen(cp);
1113                          break;
1114 <                case 'a':
1115 <                case 'h':
1114 >                case VT_ANG:
1115 >                case VT_HEM:
1116 >                case VT_PLS:
1117                          cp = addarg(cp, "-vh 180 -vv 180");
1118                          break;
1119 <                case 'c':
1119 >                case VT_CYL:
1120                          cp = addarg(cp, "-vh 180 -vv 90");
1121                          break;
1122                  }
# Line 1076 | Line 1124 | specview(                              /* get proper view spec from vs */
1124                  while (!isspace(*vs))           /* else skip id */
1125                          if (!*vs++)
1126                                  return(NULL);
1127 <                if (upax) {                     /* specify up vector */
1127 >                if (upax) {                     /* prepend up vector */
1128                          strcpy(cp, vup[upax+3]);
1129                          cp += strlen(cp);
1130                  }
# Line 1105 | Line 1153 | getview(                               /* get view n, or NULL if none */
1153          if (viewselect != NULL) {               /* command-line selected */
1154                  if (n)                          /* only do one */
1155                          return(NULL);
1156 +                                        
1157 +                if (isint(viewselect)) {        /* view number? */
1158 +                        n = atoi(viewselect)-1;
1159 +                        goto numview;
1160 +                }
1161                  if (viewselect[0] == '-') {     /* already specified */
1162 <                        if (vn != NULL) *vn = '\0';
1162 >                        if (vn != NULL)
1163 >                                strcpy(vn, "0");
1164                          return(viewselect);
1165                  }
1166                  if (vn != NULL) {
# Line 1115 | Line 1169 | getview(                               /* get view n, or NULL if none */
1169                                  ;
1170                          *vn = '\0';
1171                  }
1118                                                /* view number? */
1119                if (isint(viewselect))
1120                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1172                                                  /* check list */
1173                  while ((mv = nvalue(VIEWS, n++)) != NULL)
1174                          if (matchword(viewselect, mv))
1175                                  return(specview(mv));
1176 +
1177                  return(specview(viewselect));   /* standard view? */
1178          }
1179 + numview:
1180          mv = nvalue(VIEWS, n);          /* use view n */
1181 <        if ((vn != NULL) & (mv != NULL)) {
1182 <                register char   *mv2 = mv;
1183 <                if (*mv2 != '-')
1181 >        if ((vn != NULL) & (mv != NULL))
1182 >                if (*mv != '-') {
1183 >                        register char   *mv2 = mv;
1184                          while (*mv2 && !isspace(*mv2))
1185                                  *vn++ = *mv2++;
1186 <                *vn = '\0';
1187 <        }
1186 >                        *vn = '\0';
1187 >                } else
1188 >                        sprintf(vn, "%d", n+1);
1189 >
1190          return(specview(mv));
1191   }
1192  
# Line 1185 | Line 1240 | rvu(                           /* run rvu with first view */
1240                  return;
1241          if (sayview)
1242                  myprintview(vw, stdout);
1243 <        sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname);
1243 >        sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname);
1244 >        if (nprocs > 1)
1245 >                sprintf(combuf+strlen(combuf), "-n %d ", nprocs);
1246          if (rvdevice != NULL)
1247                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1248          if (vdef(EXPOSURE))
1249                  sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1250          strcat(combuf, oct1name);
1251          if (runcom(combuf)) {           /* run it */
1252 <                fprintf(stderr, "%s: error running rvu\n", progname);
1252 >                fprintf(stderr, "%s: error running %s\n", progname, c_rvu);
1253                  quit(1);
1254          }
1255   }
1256  
1257  
1258 + static int
1259 + syncf_done(                     /* check if an rpiece sync file is complete */
1260 +        char *sfname
1261 + )
1262 + {
1263 +        FILE    *fp = fopen(sfname, "r");
1264 +        int     todo = 1;
1265 +        int     x, y;
1266 +
1267 +        if (fp == NULL)
1268 +                return(0);
1269 +        if (fscanf(fp, "%d %d", &x, &y) != 2)
1270 +                goto checked;
1271 +        todo = x*y;             /* total number of tiles */
1272 +        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1273 +                goto checked;
1274 +                                /* XXX assume no redundant tiles */
1275 +        while (fscanf(fp, "%d %d", &x, &y) == 2)
1276 +                if (!--todo)
1277 +                        break;
1278 + checked:
1279 +        fclose(fp);
1280 +        return(!todo);
1281 + }
1282 +
1283 +
1284   static void
1285   rpict(                          /* run rpict and pfilt for each view */
1286          char    *opts,
1287          char    *po
1288   )
1289   {
1290 <        char    combuf[PATH_MAX];
1290 > #define do_rpiece       (sfile[0]!='\0')
1291 >        char    combuf[5*PATH_MAX+512];
1292          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1293          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1294 <        char    rppopt[128], *pfile = NULL;
1294 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1295          char    pfopts[128];
1296          char    vs[32], *vw;
1297          int     vn, mult;
1298          FILE    *fp;
1299          time_t  rfdt, pfdt;
1300 +        int     xres, yres;
1301 +        double  aspect;
1302 +        int     n;
1303                                          /* get pfilt options */
1304          pfiltopts(pfopts);
1305                                          /* get resolution, reporting */
# Line 1227 | Line 1314 | rpict(                         /* run rpict and pfilt for each view */
1314                  mult = 3;
1315                  break;
1316          }
1317 <        {
1318 <                int     xres, yres;
1319 <                double  aspect;
1320 <                int     n;
1321 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1322 <                if (n == 3)
1323 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1324 <                                        mult*xres, mult*yres, aspect);
1325 <                else if (n) {
1326 <                        if (n == 1) yres = xres;
1240 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1241 <                } else
1242 <                        badvalue(RESOLUTION);
1243 <        }
1317 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1318 >        if (n == 3)
1319 >                sprintf(res, "-x %d -y %d -pa %.3f",
1320 >                                mult*xres, mult*yres, aspect);
1321 >        else if (n) {
1322 >                aspect = 1.;
1323 >                if (n == 1) yres = xres;
1324 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1325 >        } else
1326 >                badvalue(RESOLUTION);
1327          rep[0] = '\0';
1328          if (vdef(REPORT)) {
1329                  double  minutes;
1247                int     n;
1330                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1331                  if (n == 2)
1332                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1254 | Line 1336 | rpict(                         /* run rpict and pfilt for each view */
1336                          badvalue(REPORT);
1337          }
1338                                          /* set up parallel rendering */
1339 <        if ((nprocs > 1) & (!vdef(ZFILE))) {
1340 <                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1341 <                pfile = rppopt+9;
1342 <                if (mktemp(pfile) == NULL)
1339 >        sfile[0] = '\0';
1340 >        if ((nprocs > 1) & !touchonly & !vdef(ZFILE) &&
1341 >                                        getview(0, vs) != NULL) {
1342 >                if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1343 >                                getview(1, NULL) == NULL) {
1344 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1345 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1346 >                                        vs);
1347 >                        strcpy(rppopt, "-PP pfXXXXXX");
1348 >                } else {
1349 >                        strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1350 >                }
1351 >                pfile = rppopt + strlen(rppopt) - 8;
1352 >                if (mktemp(pfile) == NULL) {
1353 >                        if (do_rpiece) {
1354 >                                fprintf(stderr, "%s: cannot create\n", pfile);
1355 >                                quit(1);
1356 >                        }
1357                          pfile = NULL;
1358 +                }
1359          }
1360          vn = 0;                                 /* do each view */
1361          while ((vw = getview(vn++, vs)) != NULL) {
1362                  if (sayview)
1363                          myprintview(vw, stdout);
1364 <                if (!vs[0])
1268 <                        sprintf(vs, "%d", vn);
1269 <                sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1364 >                sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1365                  if (vdef(ZFILE))
1366                          sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1367                  else
# Line 1287 | Line 1382 | rpict(                         /* run rpict and pfilt for each view */
1382                                  touch(picfile);
1383                          continue;
1384                  }
1385 <                if (next_process()) {           /* parallel running? */
1385 >                                                /* parallel running? */
1386 >                if (do_rpiece) {
1387 >                        if (rfdt < oct1date || !fdate(sfile)) {
1388 >                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1389 >                                if (rfdt >= oct1date) {
1390 >                                        fprintf(stderr,
1391 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1392 >                                        quit(1);
1393 >                                }
1394 >                                if (rfdt) {     /* start fresh */
1395 >                                        rmfile(rawfile);
1396 >                                        rfdt = 0;
1397 >                                }
1398 >                                if (!silent)
1399 >                                        printf("\techo %d %d > %s\n",
1400 >                                                        xdiv, ydiv, sfile);
1401 >                                if ((fp = fopen(sfile, "w")) == NULL) {
1402 >                                        fprintf(stderr, "%s: cannot create\n",
1403 >                                                        sfile);
1404 >                                        quit(1);
1405 >                                }
1406 >                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1407 >                                fclose(fp);
1408 >                        }
1409 >                } else if (next_process(0)) {
1410                          if (pfile != NULL)
1411 <                                sleep(20);
1411 >                                sleep(10);
1412                          continue;
1413 <                }
1413 >                } else if (!inchild())
1414 >                        pfile = NULL;
1415                  /* XXX Remember to call finish_process() */
1416                                                  /* build rpict command */
1417 <                if (rfdt >= oct1date) {         /* recover */
1418 <                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1419 <                                rep, po, opts, zopt, rawfile, oct1name);
1420 <                        if (runcom(combuf))     /* run rpict */
1417 >                if (rfdt >= oct1date) {         /* already in progress */
1418 >                        if (do_rpiece) {
1419 >                                sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1420 >                                                c_rpiece, sfile, rppopt, rep, vw,
1421 >                                                res, opts, po, rawfile, oct1name);
1422 >                                while (next_process(1)) {
1423 >                                        sleep(10);
1424 >                                        combuf[strlen(c_rpiece)+2] = 'F';
1425 >                                }
1426 >                        } else
1427 >                                sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1428 >                                        rep, opts, po, zopt, rawfile, oct1name);
1429 >                        if (runcom(combuf))     /* run rpict/rpiece */
1430                                  goto rperror;
1431                  } else {
1432                          if (overture) {         /* run overture calculation */
1433                                  sprintf(combuf,
1434 <                                "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1435 <                                                rep, vw, opts,
1434 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1435 >                                                c_rpict, rep, vw, opts,
1436                                                  oct1name, overfile);
1437 <                                if (runcom(combuf)) {
1438 <                                        fprintf(stderr,
1437 >                                if (!do_rpiece || !next_process(0)) {
1438 >                                        if (runcom(combuf)) {
1439 >                                                fprintf(stderr,
1440                                          "%s: error in overture for view %s\n",
1441 <                                                progname, vs);
1442 <                                        quit(1);
1443 <                                }
1441 >                                                        progname, vs);
1442 >                                                quit(1);
1443 >                                        }
1444   #ifndef NULL_DEVICE
1445 <                                rmfile(overfile);
1445 >                                        rmfile(overfile);
1446   #endif
1447 +                                } else if (do_rpiece)
1448 +                                        sleep(20);
1449                          }
1450 <                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1451 <                                        rep, vw, res, po, opts,
1452 <                                        zopt, oct1name, rawfile);
1453 <                        if (pfile != NULL && inchild()) {
1454 <                                                /* rpict persistent mode */
1455 <                                if (!silent) {
1450 >                        if (do_rpiece) {
1451 >                                sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1452 >                                                c_rpiece, sfile, rppopt, rep, vw,
1453 >                                                res, opts, po, rawfile, oct1name);
1454 >                                while (next_process(1))
1455 >                                        sleep(10);
1456 >                        } else {
1457 >                                sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1458 >                                                c_rpict, rep, vw, res, opts, po,
1459 >                                                zopt, oct1name, rawfile);
1460 >                        }
1461 >                        if ((pfile != NULL) & !do_rpiece) {
1462 >                                if (!silent)
1463                                          printf("\t%s\n", combuf);
1325                                        fflush(stdout);
1326                                }
1327                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1328                                                rep, rppopt, res, po, opts,
1329                                                oct1name, rawfile);
1464                                  fflush(stdout);
1465 +                                sprintf(combuf, "%s%s %s %s%s%s %s > %s",
1466 +                                                c_rpict, rep, rppopt, res,
1467 +                                                opts, po, oct1name, rawfile);
1468                                  fp = popen(combuf, "w");
1469                                  if (fp == NULL)
1470                                          goto rperror;
1471                                  myprintview(vw, fp);
1472                                  if (pclose(fp))
1473                                          goto rperror;
1474 <                        } else {                /* rpict normal mode */
1475 <                                if (runcom(combuf))
1476 <                                        goto rperror;
1474 >                        } else if (runcom(combuf))
1475 >                                goto rperror;
1476 >                }
1477 >                if (do_rpiece) {                /* need to finish raw, first */
1478 >                        finish_process();
1479 >                        wait_process(1);
1480 >                        if (!syncf_done(sfile)) {
1481 >                                fprintf(stderr,
1482 >                        "%s: %s did not complete rendering of view %s\n",
1483 >                                                progname, c_rpiece, vs);
1484 >                                quit(1);
1485                          }
1486                  }
1487                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1488                                                  /* build pfilt command */
1489 <                        if (mult > 1)
1490 <                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1491 <                                        pfopts, mult, mult, rawfile, picfile);
1489 >                        if (do_rpiece)
1490 >                                sprintf(combuf,
1491 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1492 >                                        c_pfilt, pfopts, xres, yres, aspect,
1493 >                                        rawfile, picfile);
1494 >                        else if (mult > 1)
1495 >                                sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1496 >                                        c_pfilt, pfopts, mult, mult,
1497 >                                        rawfile, picfile);
1498                          else
1499 <                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1500 <                                                rawfile, picfile);
1499 >                                sprintf(combuf, "%s%s %s > %s", c_pfilt,
1500 >                                        pfopts, rawfile, picfile);
1501                          if (runcom(combuf)) {   /* run pfilt */
1502                                  fprintf(stderr,
1503                                  "%s: error filtering view %s\n\t%s removed\n",
# Line 1357 | Line 1508 | rpict(                         /* run rpict and pfilt for each view */
1508                  }
1509                                                  /* remove/rename raw file */
1510                  if (vdef(RAWFILE)) {
1511 <                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1511 >                        sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs);
1512                          mvfile(rawfile, combuf);
1513                  } else
1514                          rmfile(rawfile);
1515 <                finish_process();               /* exit if child */
1515 >                if (do_rpiece)                  /* done with sync file */
1516 >                        rmfile(sfile);
1517 >                else
1518 >                        finish_process();       /* exit if child */
1519          }
1520          wait_process(1);                /* wait for children to finish */
1521 <        if (pfile != NULL) {            /* clean up rpict persistent mode */
1521 >        if (pfile != NULL) {            /* clean up persistent rpict */
1522                  RT_PID  pid;
1523                  fp = fopen(pfile, "r");
1524                  if (fp != NULL) {
# Line 1378 | Line 1532 | rpict(                         /* run rpict and pfilt for each view */
1532   rperror:
1533          fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1534          quit(1);
1535 + #undef do_rpiece
1536   }
1537  
1538  
# Line 1390 | Line 1545 | touch(                 /* update a file */
1545                  printf("\ttouch %s\n", fn);
1546          if (!nprocs)
1547                  return(0);
1393 #ifdef notused
1394        if (access(fn, F_OK) == -1)             /* create it */
1395                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1396                        return(-1);
1397 #endif
1548          return(setfdate(fn, time((time_t *)NULL)));
1549   }
1550  
# Line 1408 | Line 1558 | runcom(                        /* run command */
1558                  printf("\t%s\n", cs);
1559          if (!nprocs)
1560                  return(0);
1561 <        fflush(stdout);         /* flush output and pass to shell */
1561 >        fflush(NULL);           /* flush output and pass to shell */
1562          return(system(cs));
1563   }
1564  
# Line 1442 | Line 1592 | mvfile(                /* move a file */
1592  
1593   #ifdef RHAS_FORK_EXEC
1594   static int
1595 < next_process(void)                      /* fork the next process (max. nprocs) */
1595 > next_process(int reserve)               /* fork the next process */
1596   {
1597          RT_PID  child_pid;
1598  
# Line 1453 | Line 1603 | next_process(void)                     /* fork the next process (max. np
1603                                  progname);
1604                  quit(1);
1605          }
1606 +        if (reserve > 0 && children_running >= nprocs-reserve)
1607 +                return(0);              /* caller holding back process(es) */
1608          if (children_running >= nprocs)
1609                  wait_process(0);        /* wait for someone to finish */
1610 <        fflush(stdout);
1610 >        fflush(NULL);                   /* flush output */
1611          child_pid = fork();             /* split process */
1612          if (child_pid == 0) {           /* we're the child */
1613                  children_running = -1;
1614 +                nprocs = 1;
1615                  return(0);
1616          }
1617          if (child_pid > 0) {            /* we're the parent */
# Line 1474 | Line 1627 | wait_process(                  /* wait for process(es) to finish */
1627          int     all
1628   )
1629   {
1630 <        int     ourstatus = 0;
1631 <        RT_PID  pid, status;
1630 >        int     ourstatus = 0, status;
1631 >        RT_PID  pid;
1632  
1633          if (all)
1634                  all = children_running;
# Line 1500 | Line 1653 | wait_process(                  /* wait for process(es) to finish */
1653   }
1654   #else   /* ! RHAS_FORK_EXEC */
1655   static int
1656 < next_process(void)
1656 > next_process(int reserve)
1657   {
1658          return(0);                      /* cannot start new process */
1659   }
# Line 1512 | Line 1665 | int    all;
1665   }
1666   int
1667   kill(pid, sig) /* win|unix_process.c should also wait and kill */
1668 < RT_PID pid, sig;
1668 > RT_PID pid;
1669 > int sig;
1670   {
1671          return 0;
1672   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines