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.99 by greg, Fri Oct 8 22:11:57 2010 UTC vs.
Revision 2.131 by greg, Sat Jun 10 15:49:55 2023 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include <ctype.h>
11   #include <time.h>
12 + #include <signal.h>
13  
14   #include "platform.h"
15   #include "rtprocess.h"
# Line 16 | Line 17 | static const char      RCSid[] = "$Id$";
17   #include "paths.h"
18   #include "vars.h"
19  
20 < #ifdef _WIN32
20 > #if defined(_WIN32) || defined(_WIN64)
21    #define DELCMD "del"
22    #define RENAMECMD "rename"
23   #else
# Line 24 | Line 25 | static const char      RCSid[] = "$Id$";
25    #define RENAMECMD "mv"
26    #include <sys/types.h>
27    #include <sys/wait.h>
28 +  #include <signal.h>
29   #endif
30  
31                                  /* variables (alphabetical by name) */
# Line 35 | Line 37 | static const char      RCSid[] = "$Id$";
37   #define INDIRECT        5               /* indirection in lighting */
38   #define MATERIAL        6               /* material files */
39   #define MKILLUM         7               /* mkillum options */
40 < #define OBJECT          8               /* object files */
41 < #define OCONV           9               /* oconv options */
42 < #define OCTREE          10              /* octree file name */
43 < #define OPTFILE         11              /* rendering options file */
44 < #define PENUMBRAS       12              /* shadow penumbras are desired */
45 < #define PFILT           13              /* pfilt options */
46 < #define PICTURE         14              /* picture file root name */
47 < #define QUALITY         15              /* desired rendering quality */
48 < #define RAWFILE         16              /* raw picture file root name */
49 < #define RENDER          17              /* rendering options */
50 < #define REPORT          18              /* report frequency and errfile */
51 < #define RESOLUTION      19              /* maximum picture resolution */
52 < #define RPICT           20              /* rpict parameters */
53 < #define RVU             21              /* rvu parameters */
54 < #define SCENE           22              /* scene files */
55 < #define UP              23              /* view up (X, Y or Z) */
56 < #define VARIABILITY     24              /* level of light variability */
57 < #define VIEWS           25              /* view(s) for picture(s) */
58 < #define ZFILE           26              /* distance file root name */
59 < #define ZONE            27              /* simulation zone */
40 > #define MKPMAP          8               /* mkpmap options */
41 > #define OBJECT          9               /* object files */
42 > #define OCONV           10              /* oconv options */
43 > #define OCTREE          11              /* octree file name */
44 > #define OPTFILE         12              /* rendering options file */
45 > #define PCMAP           13              /* caustic photon map */
46 > #define PENUMBRAS       14              /* shadow penumbras are desired */
47 > #define PFILT           15              /* pfilt options */
48 > #define PGMAP           16              /* global photon map */
49 > #define PICTURE         17              /* picture file root name */
50 > #define QUALITY         18              /* desired rendering quality */
51 > #define RAWFILE         19              /* raw picture file root name */
52 > #define RENDER          20              /* rendering options */
53 > #define REPORT          21              /* report frequency and errfile */
54 > #define RESOLUTION      22              /* maximum picture resolution */
55 > #define RPICT           23              /* rpict parameters */
56 > #define RVU             24              /* rvu parameters */
57 > #define SCENE           25              /* scene files */
58 > #define UP              26              /* view up (X, Y or Z) */
59 > #define VARIABILITY     27              /* level of light variability */
60 > #define VIEWS           28              /* view(s) for picture(s) */
61 > #define ZFILE           29              /* distance file root name */
62 > #define ZONE            30              /* simulation zone */
63                                  /* total number of variables */
64 < int NVARS = 28;
64 > int NVARS = 31;
65  
66   VARIABLE        vv[] = {                /* variable-value pairs */
67 <        {"AMBFILE",     3,      0,      NULL,   onevalue},
67 >        {"AMBFILE",     3,      0,      NULL,   strvalue},
68          {"DETAIL",      3,      0,      NULL,   qualvalue},
69          {"EXPOSURE",    3,      0,      NULL,   fltvalue},
70          {"EYESEP",      3,      0,      NULL,   fltvalue},
# Line 67 | Line 72 | VARIABLE       vv[] = {                /* variable-value pairs */
72          {"INDIRECT",    3,      0,      NULL,   intvalue},
73          {"materials",   3,      0,      NULL,   catvalues},
74          {"mkillum",     3,      0,      NULL,   catvalues},
75 +        {"mkpmap",      3,      0,      NULL,   catvalues},
76          {"objects",     3,      0,      NULL,   catvalues},
77          {"oconv",       3,      0,      NULL,   catvalues},
78 <        {"OCTREE",      3,      0,      NULL,   onevalue},
79 <        {"OPTFILE",     3,      0,      NULL,   onevalue},
78 >        {"OCTREE",      3,      0,      NULL,   strvalue},
79 >        {"OPTFILE",     3,      0,      NULL,   strvalue},
80 >        {"PCMAP",       2,      0,      NULL,   strvalue},
81          {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
82          {"pfilt",       2,      0,      NULL,   catvalues},
83 <        {"PICTURE",     3,      0,      NULL,   onevalue},
83 >        {"PGMAP",       2,      0,      NULL,   strvalue},
84 >        {"PICTURE",     3,      0,      NULL,   strvalue},
85          {"QUALITY",     3,      0,      NULL,   qualvalue},
86 <        {"RAWFILE",     3,      0,      NULL,   onevalue},
86 >        {"RAWFILE",     3,      0,      NULL,   strvalue},
87          {"render",      3,      0,      NULL,   catvalues},
88          {"REPORT",      3,      0,      NULL,   onevalue},
89          {"RESOLUTION",  3,      0,      NULL,   onevalue},
# Line 85 | Line 93 | VARIABLE       vv[] = {                /* variable-value pairs */
93          {"UP",          2,      0,      NULL,   onevalue},
94          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
95          {"view",        2,      0,      NULL,   NULL},
96 <        {"ZFILE",       2,      0,      NULL,   onevalue},
96 >        {"ZFILE",       2,      0,      NULL,   strvalue},
97          {"ZONE",        2,      0,      NULL,   onevalue},
98   };
99  
# Line 107 | Line 115 | time_t oct0date;               /* date of pre-mkillum octree */
115   char    *oct1name;              /* name of post-mkillum octree */
116   time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
117  
118 + char    *pgmapname;             /* name of global photon map */
119 + time_t  pgmapdate;              /* date of global photon map (>= oct1date) */
120 + char    *pcmapname;             /* name of caustic photon map */
121 + time_t  pcmapdate;              /* date of caustic photon map (>= oct1date) */
122 +
123   int     nowarn = 0;             /* no warnings */
124   int     explicate = 0;          /* explicate variables */
125   int     silent = 0;             /* do work silently */
# Line 121 | Line 134 | char   *viewselect = NULL;     /* specific view only */
134                                  /* command paths */
135   char    c_oconv[256] = "oconv";
136   char    c_mkillum[256] = "mkillum";
137 + char    c_mkpmap[256] = "mkpmap";
138   char    c_rvu[256] = "rvu";
139   char    c_rpict[256] = DEF_RPICT_PATH;
140   char    c_rpiece[] = "rpiece";
# Line 144 | Line 158 | static void checkfiles(void);
158   static void getoctcube(double   org[3], double  *sizp);
159   static void setdefaults(void);
160   static void oconv(void);
161 + static void mkpmap(void);
162   static char * addarg(char       *op, char       *arg);
163   static void oconvopts(char      *oo);
164   static void mkillumopts(char    *mo);
165 + static void mkpmapopts(char     *mo);
166   static void checkambfile(void);
167   static double ambval(void);
168   static void renderopts(char     *op, char       *po);
# Line 226 | Line 242 | main(
242                                  /* load variable values */
243          loadvars(rifname);
244                                  /* get any additional assignments */
245 <        for (i++; i < argc; i++)
246 <                if (setvariable(argv[i], matchvar) < 0) {
247 <                        fprintf(stderr, "%s: unknown variable: %s\n",
245 >        for (i++; i < argc; i++) {
246 >                int     rv = setvariable(argv[i], matchvar);
247 >                if (rv < 0) {
248 >                        fprintf(stderr, "%s: unknown setting: %s\n",
249                                          progname, argv[i]);
250                          quit(1);
251                  }
252 +                if (!rv)
253 +                        fprintf(stderr,
254 +                        "%s: bad variable assignment: %s (ignored)\n",
255 +                                        progname, argv[i]);
256 +        }
257                                  /* check assignments */
258          checkvalues();
259                                  /* check files and dates */
# Line 243 | Line 265 | main(
265                  printvars(stdout);
266                                  /* build octree (and run mkillum) */
267          oconv();
268 +                                /* run mkpmap if indicated */
269 +        mkpmap();
270                                  /* check date on ambient file */
271          checkambfile();
272                                  /* run simulation */
# Line 264 | Line 288 | userr:
288  
289   static void
290   rootname(               /* remove tail from end of fn */
291 <        register char   *rn,
292 <        register char   *fn
291 >        char    *rn,
292 >        char    *fn
293   )
294   {
295          char    *tp, *dp;
# Line 282 | Line 306 | rootname(              /* remove tail from end of fn */
306  
307   static time_t
308   checklast(                      /* check files and find most recent */
309 <        register char   *fnames
309 >        char    *fnames
310   )
311   {
312          char    thisfile[PATH_MAX];
# Line 312 | Line 336 | newfname(              /* create modified file name */
336          int     pred
337   )
338   {
339 <        register char   *cp;
340 <        register int    n;
339 >        char    *cp;
340 >        int     n;
341          int     suffix;
342  
343          n = 0; cp = orig; suffix = -1;          /* suffix position, length */
# Line 335 | Line 359 | newfname(              /* create modified file name */
359   static void
360   checkfiles(void)                        /* check for existence and modified times */
361   {
362 +        char    fntemp[256];
363          time_t  objdate;
364  
365          if (!vdef(OCTREE)) {
# Line 364 | Line 389 | checkfiles(void)                       /* check for existence and modified
389                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
390                  quit(1);
391          }
392 +        if (vdef(PGMAP)) {
393 +                if (!*sskip2(vval(PGMAP),1)) {
394 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
395 +                                        progname, vnam(PGMAP));
396 +                        quit(1);
397 +                }
398 +                atos(fntemp, sizeof(fntemp), vval(PGMAP));
399 +                pgmapname = savqstr(fntemp);
400 +                pgmapdate = fdate(pgmapname);
401 +        }
402 +        if (vdef(PCMAP)) {
403 +                if (!*sskip2(vval(PCMAP),1)) {
404 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
405 +                                        progname, vnam(PCMAP));
406 +                        quit(1);
407 +                }
408 +                atos(fntemp, sizeof(fntemp), vval(PCMAP));
409 +                pcmapname = savqstr(fntemp);
410 +                pcmapdate = fdate(pcmapname);
411 +        }
412          matdate = checklast(vval(MATERIAL));
413   }      
414  
# Line 378 | Line 423 | getoctcube(            /* get octree bounding cube */
423          double  min[3], max[3];
424          char    buf[1024];
425          FILE    *fp;
426 <        register int    i;
426 >        int     i;
427  
428          if (osiz <= FTINY) {
429                  if (!nprocs && fdate(oct1name) <
# Line 517 | Line 562 | oconv(void)                            /* run oconv and mkillum if necessary *
562                  return;
563                                                  /* make octree0 */
564          if ((oct0date < scenedate) | (oct0date < illumdate)) {
565 <                if (touchonly && oct0date)
566 <                        touch(oct0name);
567 <                else {                          /* build command */
565 >                if (touchonly && (oct0date || oct1date)) {
566 >                        if (oct0date)
567 >                                touch(oct0name);
568 >                } else {                        /* build command */
569                          if (octreedate)
570                                  sprintf(combuf, "%s%s -i %s %s > %s", c_oconv,
571                                          ocopts, vval(OCTREE),
# Line 544 | Line 590 | oconv(void)                            /* run oconv and mkillum if necessary *
590                          oct0date = octreedate;
591                  if (oct0date < illumdate)       /* ditto */
592                          oct0date = illumdate;
593 <                }
593 >        }
594          if (touchonly && oct1date)
595                  touch(oct1name);
596          else {
# Line 558 | Line 604 | oconv(void)                            /* run oconv and mkillum if necessary *
604                          unlink(illumtmp);
605                          quit(1);
606                  }
607 +                rmfile(oct0name);
608                                                  /* make octree1 (frozen) */
609                  if (octreedate)
610                          sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
# Line 584 | Line 631 | oconv(void)                            /* run oconv and mkillum if necessary *
631   }
632  
633  
634 + static void
635 + mkpmap(void)                    /* run mkpmap if indicated */
636 + {
637 +        char    combuf[2048], *cp;
638 +        time_t  tnow;
639 +                                /* nothing to do? */
640 +        if ((pgmapname == NULL) | (pgmapdate >= oct1date) &&
641 +                        (pcmapname == NULL) | (pcmapdate >= oct1date))
642 +                return;
643 +                                /* just update existing file dates? */
644 +        if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) &&
645 +                        (pcmapname == NULL) | (pcmapdate > 0)) {
646 +                if (pgmapname != NULL)
647 +                        touch(pgmapname);
648 +                if (pcmapname != NULL)
649 +                        touch(pcmapname);
650 +        } else {                /* else need to (re)run pkpmap */
651 +                strcpy(combuf, c_mkpmap);
652 +                for (cp = combuf; *cp; cp++)
653 +                        ;
654 +                mkpmapopts(cp);
655 +                                /* force file overwrite */
656 +                cp = addarg(cp, "-fo+");
657 +                if (vdef(REPORT)) {
658 +                        char    errfile[256];
659 +                        int     n;
660 +                        double  minutes;
661 +                        n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile);
662 +                        if (n == 2)
663 +                                sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile);
664 +                        else if (n == 1)
665 +                                sprintf(cp, " -t %d", (int)(minutes*60));
666 +                        else
667 +                                badvalue(REPORT);
668 +                }
669 +                if (pgmapname != NULL && pgmapdate < oct1date) {
670 +                        cp = addarg(cp, "-apg");
671 +                        addarg(cp, vval(PGMAP));
672 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
673 +                        *cp = '\0';
674 +                }
675 +                if (pcmapname != NULL && pcmapdate < oct1date) {
676 +                        cp = addarg(cp, "-apc");
677 +                        addarg(cp, vval(PCMAP));
678 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
679 +                        *cp = '\0';
680 +                }
681 +                cp = addarg(cp, oct1name);
682 +                if (runcom(combuf)) {
683 +                        fprintf(stderr, "%s: error running %s\n",
684 +                                        progname, c_mkpmap);
685 +                        if (pgmapname != NULL && pgmapdate < oct1date)
686 +                                unlink(pgmapname);
687 +                        if (pcmapname != NULL && pcmapdate < oct1date)
688 +                                unlink(pcmapname);
689 +                        quit(1);
690 +                }
691 +        }
692 +        tnow = time((time_t *)NULL);
693 +        if (pgmapname != NULL)
694 +                pgmapdate = tnow;
695 +        if (pcmapname != NULL)
696 +                pcmapdate = tnow;
697 +        oct1date = tnow;        /* trigger ambient file removal if needed */
698 + }
699 +
700 +
701   static char *
702   addarg(                         /* append argument and advance pointer */
703 < register char   *op,
704 < register char   *arg
703 > char    *op,
704 > char    *arg
705   )
706   {
707          while (*op)
# Line 601 | Line 715 | register char  *arg
715  
716   static void
717   oconvopts(                              /* get oconv options */
718 <        register char   *oo
718 >        char    *oo
719   )
720   {
721          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
722  
723          *oo = '\0';
724 <        if (vdef(OCONV))
725 <                if (vval(OCONV)[0] != '-') {
726 <                        atos(c_oconv, sizeof(c_oconv), vval(OCONV));
727 <                        oo = addarg(oo, sskip2(vval(OCONV), 1));
728 <                } else
729 <                        oo = addarg(oo, vval(OCONV));
724 >        if (!vdef(OCONV))
725 >                return;
726 >        if (vval(OCONV)[0] != '-') {
727 >                atos(c_oconv, sizeof(c_oconv), vval(OCONV));
728 >                oo = addarg(oo, sskip2(vval(OCONV), 1));
729 >        } else
730 >                oo = addarg(oo, vval(OCONV));
731   }
732  
733  
# Line 627 | Line 742 | mkillumopts(                           /* get mkillum options */
742                  sprintf(mo, " -n %d", nprocs);
743          else
744                  *mo = '\0';
745 <        if (vdef(MKILLUM))
746 <                if (vval(MKILLUM)[0] != '-') {
747 <                        atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
748 <                        mo = addarg(mo, sskip2(vval(MKILLUM), 1));
749 <                } else
750 <                        mo = addarg(mo, vval(MKILLUM));
745 >        if (!vdef(MKILLUM))
746 >                return;
747 >        if (vval(MKILLUM)[0] != '-') {
748 >                atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
749 >                mo = addarg(mo, sskip2(vval(MKILLUM), 1));
750 >        } else
751 >                mo = addarg(mo, vval(MKILLUM));
752   }
753  
754  
755   static void
756 + mkpmapopts(                             /* get mkpmap options */
757 +        char    *mo
758 + )
759 + {
760 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
761 +
762 +        if (nprocs > 1)
763 +                sprintf(mo, " -n %d", nprocs);
764 +        else
765 +                *mo = '\0';
766 +        if (!vdef(MKPMAP))
767 +                return;
768 +        if (vval(MKPMAP)[0] != '-') {
769 +                atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP));
770 +                mo = addarg(mo, sskip2(vval(MKPMAP), 1));
771 +        } else
772 +                mo = addarg(mo, vval(MKPMAP));
773 + }
774 +
775 +
776 + static void
777   checkambfile(void)                      /* check date on ambient file */
778   {
779          time_t  afdate;
# Line 659 | Line 796 | ambval(void)                           /* compute ambient value */
796   {
797          if (vdef(EXPOSURE)) {
798                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
799 <                        return(.5/pow(2.,vflt(EXPOSURE)));
800 <                return(.5/vflt(EXPOSURE));
799 >                        return(.18/pow(2.,vflt(EXPOSURE)));
800 >                return(.18/vflt(EXPOSURE));
801          }
802          if (vlet(ZONE) == 'E')
803                  return(10.);
# Line 677 | Line 814 | renderopts(                    /* set rendering options */
814          char    *po
815   )
816   {
817 +        char    pmapf[256], *bw;
818 +
819 +        if (vdef(PGMAP)) {
820 +                *op = '\0';
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          switch(vscale(QUALITY)) {
827          case LOW:
828                  lowqopts(op, po);
# Line 688 | Line 834 | renderopts(                    /* set rendering options */
834                  hiqopts(op, po);
835                  break;
836          }
837 <        if (vdef(RENDER))
837 >        if (vdef(PCMAP)) {
838 >                bw = sskip2(vval(PCMAP), 2);
839 >                atos(pmapf, sizeof(pmapf), vval(PCMAP));
840 >                op = addarg(addarg(op, "-ap"), pmapf);
841 >                if (atoi(bw) > 0) op = addarg(op, bw);
842 >        }
843 >        if (vdef(RENDER)) {
844                  op = addarg(op, vval(RENDER));
845 +                bw = strstr(vval(RENDER), "-aa ");
846 +                if (bw != NULL && atof(bw+4) <= FTINY)
847 +                        overture = 0;
848 +        }
849          if (rvdevice != NULL) {
850 <                if (vdef(RVU))
850 >                if (vdef(RVU)) {
851                          if (vval(RVU)[0] != '-') {
852                                  atos(c_rvu, sizeof(c_rvu), vval(RVU));
853                                  po = addarg(po, sskip2(vval(RVU), 1));
854                          } else
855                                  po = addarg(po, vval(RVU));
856 +                }
857          } else {
858 <                if (vdef(RPICT))
858 >                if (vdef(RPICT)) {
859                          if (vval(RPICT)[0] != '-') {
860                                  atos(c_rpict, sizeof(c_rpict), vval(RPICT));
861                                  po = addarg(po, sskip2(vval(RPICT), 1));
862                          } else
863                                  po = addarg(po, vval(RPICT));
864 +                }
865          }
866   }
867  
868  
869   static void
870   lowqopts(                       /* low quality rendering options */
871 <        register char   *op,
871 >        char    *op,
872          char    *po
873   )
874   {
# Line 772 | Line 930 | lowqopts(                      /* low quality rendering options */
930          d = ambval();
931          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
932          op += strlen(op);
933 <        op = addarg(op, "-lr 6 -lw .01");
933 >        op = addarg(op, "-lr 6 -lw .001");
934   }
935  
936  
937   static void
938   medqopts(                       /* medium quality rendering options */
939 <        register char   *op,
939 >        char    *op,
940          char    *po
941   )
942   {
# Line 826 | Line 984 | medqopts(                      /* medium quality rendering options */
984                  op = addarg(op, "-ds .2 -dj .9");
985          else
986                  op = addarg(op, "-ds .3");
987 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss .7 -st .1");
987 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
988          if ( (overture = vint(INDIRECT)) ) {
989                  sprintf(op, " -ab %d", overture);
990                  op += strlen(op);
# Line 850 | Line 1008 | medqopts(                      /* medium quality rendering options */
1008          d = ambval();
1009          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1010          op += strlen(op);
1011 <        op = addarg(op, "-lr 8 -lw .002");
1011 >        op = addarg(op, "-lr 8 -lw 1e-4");
1012   }
1013  
1014  
1015   static void
1016   hiqopts(                                /* high quality rendering options */
1017 <        register char   *op,
1017 >        char    *op,
1018          char    *po
1019   )
1020   {
# Line 904 | Line 1062 | hiqopts(                               /* high quality rendering options */
1062                  op = addarg(op, "-ds .1 -dj .9");
1063          else
1064                  op = addarg(op, "-ds .2");
1065 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 1 -st .01");
1065 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
1066          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1067          op += strlen(op);
1068          if (vdef(AMBFILE)) {
# Line 926 | Line 1084 | hiqopts(                               /* high quality rendering options */
1084          d = ambval();
1085          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1086          op += strlen(op);
1087 <        op = addarg(op, "-lr 12 -lw .0005");
1087 >        op = addarg(op, "-lr 12 -lw 5e-6");
1088   }
1089  
1090  
1091 + #if defined(_WIN32) || defined(_WIN64)
1092   static void
1093 + setenv(                 /* set an environment variable */
1094 +        char    *vname,
1095 +        char    *value
1096 + )
1097 + {
1098 +        char    *evp;
1099 +
1100 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1101 +        if (evp == NULL)
1102 +                syserr(progname);
1103 +        sprintf(evp, "%s=%s", vname, value);
1104 +        if (putenv(evp) != 0) {
1105 +                fprintf(stderr, "%s: out of environment space\n", progname);
1106 +                quit(1);
1107 +        }
1108 +        if (!silent)
1109 +                printf("set %s\n", evp);
1110 + }
1111 + #endif
1112 +
1113 +
1114 + static void
1115   xferopts(                               /* transfer options if indicated */
1116          char    *ro
1117   )
1118   {
1119          int     fd, n;
1120 <        register char   *cp;
1120 >        char    *cp;
1121          
1122          n = strlen(ro);
1123          if (n < 2)
# Line 954 | Line 1135 | xferopts(                              /* transfer options if indicated */
1135                          syserr(vval(OPTFILE));
1136                  sprintf(ro, " @%s", vval(OPTFILE));
1137          }
1138 < #ifdef _WIN32
1138 > #if defined(_WIN32) || defined(_WIN64)
1139          else if (n > 50) {
1140                  setenv("ROPT", ro+1);
1141                  strcpy(ro, " $ROPT");
# Line 965 | Line 1146 | xferopts(                              /* transfer options if indicated */
1146  
1147   static void
1148   pfiltopts(                              /* get pfilt options */
1149 <        register char   *po
1149 >        char    *po
1150   )
1151   {
1152          *po = '\0';
# Line 981 | Line 1162 | pfiltopts(                             /* get pfilt options */
1162                  po = addarg(po, "-m .25");
1163                  break;
1164          }
1165 <        if (vdef(PFILT))
1165 >        if (vdef(PFILT)) {
1166                  if (vval(PFILT)[0] != '-') {
1167                          atos(c_pfilt, sizeof(c_pfilt), vval(PFILT));
1168                          po = addarg(po, sskip2(vval(PFILT), 1));
1169                  } else
1170                          po = addarg(po, vval(PFILT));
1171 +        }
1172   }
1173  
1174  
1175   static int
1176   matchword(                      /* match white-delimited words */
1177 <        register char   *s1,
1178 <        register char   *s2
1177 >        char    *s1,
1178 >        char    *s2
1179   )
1180   {
1181          while (isspace(*s1)) s1++;
# Line 1007 | Line 1189 | matchword(                     /* match white-delimited words */
1189  
1190   static char *
1191   specview(                               /* get proper view spec from vs */
1192 <        register char   *vs
1192 >        char    *vs
1193   )
1194   {
1195          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1196                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1197          static char     viewopts[128];
1198 <        register char   *cp;
1198 >        char    *cp;
1199          int     xpos, ypos, zpos, viewtype, upax;
1200 <        register int    i;
1200 >        int     i;
1201          double  cent[3], dim[3], mult, d;
1202  
1203          if (vs == NULL || *vs == '-')
# Line 1075 | Line 1257 | specview(                              /* get proper view spec from vs */
1257                          cent[i] += .5*dim[i];
1258                  }
1259                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
1260 <                sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1260 >                sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g",
1261                                  cent[0]+xpos*mult*dim[0],
1262                                  cent[1]+ypos*mult*dim[1],
1263                                  cent[2]+zpos*mult*dim[2],
# Line 1107 | Line 1289 | specview(                              /* get proper view spec from vs */
1289                          break;
1290                  case VT_PAR:
1291                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1292 <                        sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1292 >                        sprintf(cp, " -vh %.3g -vv %.3g", d, d);
1293                          cp += strlen(cp);
1294                          break;
1295                  case VT_ANG:
# Line 1131 | Line 1313 | specview(                              /* get proper view spec from vs */
1313          if (cp == viewopts)             /* append any additional options */
1314                  vs++;           /* skip prefixed space if unneeded */
1315          strcpy(cp, vs);
1316 < #ifdef _WIN32
1316 > #if defined(_WIN32) || defined(_WIN64)
1317          if (strlen(viewopts) > 40) {
1318                  setenv("VIEW", viewopts);
1319                  return("$VIEW");
# Line 1147 | Line 1329 | getview(                               /* get view n, or NULL if none */
1329          char    *vn             /* returned view name */
1330   )
1331   {
1332 <        register char   *mv;
1332 >        char    *mv;
1333  
1334          if (viewselect != NULL) {               /* command-line selected */
1335                  if (n)                          /* only do one */
# Line 1177 | Line 1359 | getview(                               /* get view n, or NULL if none */
1359          }
1360   numview:
1361          mv = nvalue(VIEWS, n);          /* use view n */
1362 <        if ((vn != NULL) & (mv != NULL))
1362 >        if ((vn != NULL) & (mv != NULL)) {
1363                  if (*mv != '-') {
1364 <                        register char   *mv2 = mv;
1364 >                        char    *mv2 = mv;
1365                          while (*mv2 && !isspace(*mv2))
1366                                  *vn++ = *mv2++;
1367                          *vn = '\0';
1368                  } else
1369                          sprintf(vn, "%d", n+1);
1370 <
1370 >        }
1371          return(specview(mv));
1372   }
1373  
1374  
1375   static int
1376   myprintview(                    /* print out selected view */
1377 <        register char   *vopts,
1377 >        char    *vopts,
1378          FILE    *fp
1379   )
1380   {
1381          VIEW    vwr;
1382          char    buf[128];
1383 <        register char   *cp;
1384 < #ifdef _WIN32
1383 >        char    *cp;
1384 > #if defined(_WIN32) || defined(_WIN64)
1385   /* XXX Should we allow something like this for all platforms? */
1386   /* XXX Or is it still required at all? */
1387   again:
1388   #endif
1389          if (vopts == NULL)
1390                  return(-1);
1391 < #ifdef _WIN32
1391 > #if defined(_WIN32) || defined(_WIN64)
1392          if (vopts[0] == '$') {
1393                  vopts = getenv(vopts+1);
1394                  goto again;
# Line 1254 | Line 1436 | rvu(                           /* run rvu with first view */
1436   }
1437  
1438  
1439 + static int
1440 + syncf_done(                     /* check if an rpiece sync file is complete */
1441 +        char *sfname
1442 + )
1443 + {
1444 +        FILE    *fp = fopen(sfname, "r");
1445 +        int     todo = 1;
1446 +        int     x, y;
1447 +
1448 +        if (fp == NULL)
1449 +                return(0);
1450 +        if (fscanf(fp, "%d %d", &x, &y) != 2)
1451 +                goto checked;
1452 +        todo = x*y;             /* total number of tiles */
1453 +        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1454 +                goto checked;
1455 +                                /* XXX assume no redundant tiles */
1456 +        while (fscanf(fp, "%d %d", &x, &y) == 2)
1457 +                if (!--todo)
1458 +                        break;
1459 + checked:
1460 +        fclose(fp);
1461 +        return(!todo);
1462 + }
1463 +
1464 +
1465   static void
1466   rpict(                          /* run rpict and pfilt for each view */
1467          char    *opts,
# Line 1261 | Line 1469 | rpict(                         /* run rpict and pfilt for each view */
1469   )
1470   {
1471   #define do_rpiece       (sfile[0]!='\0')
1472 <        char    combuf[4*PATH_MAX+512];
1472 >        char    combuf[5*PATH_MAX+512];
1473          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1474          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1475 <        char    rppopt[128], sfile[64], *pfile = NULL;
1475 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1476          char    pfopts[128];
1477          char    vs[32], *vw;
1478          int     vn, mult;
1479          FILE    *fp;
1480          time_t  rfdt, pfdt;
1481 +        int     xres, yres;
1482 +        double  aspect;
1483 +        int     n;
1484                                          /* get pfilt options */
1485          pfiltopts(pfopts);
1486                                          /* get resolution, reporting */
# Line 1284 | Line 1495 | rpict(                         /* run rpict and pfilt for each view */
1495                  mult = 3;
1496                  break;
1497          }
1498 <        {
1499 <                int     xres, yres;
1500 <                double  aspect;
1501 <                int     n;
1502 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1503 <                if (n == 3)
1504 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1505 <                                        mult*xres, mult*yres, aspect);
1506 <                else if (n) {
1507 <                        if (n == 1) yres = xres;
1297 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1298 <                } else
1299 <                        badvalue(RESOLUTION);
1300 <        }
1498 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1499 >        if (n == 3)
1500 >                sprintf(res, "-x %d -y %d -pa %.3f",
1501 >                                mult*xres, mult*yres, aspect);
1502 >        else if (n) {
1503 >                aspect = 1.;
1504 >                if (n == 1) yres = xres;
1505 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1506 >        } else
1507 >                badvalue(RESOLUTION);
1508          rep[0] = '\0';
1509          if (vdef(REPORT)) {
1510                  double  minutes;
1304                int     n;
1511                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1512                  if (n == 2)
1513                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1316 | Line 1522 | rpict(                         /* run rpict and pfilt for each view */
1522                                          getview(0, vs) != NULL) {
1523                  if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1524                                  getview(1, NULL) == NULL) {
1525 <                        sprintf(sfile, "rpsync_%s.txt", vs);
1525 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1526 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1527 >                                        vs);
1528                          strcpy(rppopt, "-PP pfXXXXXX");
1529                  } else {
1530                          strcpy(rppopt, "-S 1 -PP pfXXXXXX");
# Line 1327 | Line 1535 | rpict(                         /* run rpict and pfilt for each view */
1535                                  fprintf(stderr, "%s: cannot create\n", pfile);
1536                                  quit(1);
1537                          }
1538 +                        pfile[-5] = '\0';
1539                          pfile = NULL;
1540                  }
1541          }
# Line 1359 | Line 1568 | rpict(                         /* run rpict and pfilt for each view */
1568                  if (do_rpiece) {
1569                          if (rfdt < oct1date || !fdate(sfile)) {
1570                                  int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1571 <                                rfdt = 0;               /* start fresh */
1571 >                                if (rfdt >= oct1date) {
1572 >                                        fprintf(stderr,
1573 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1574 >                                        quit(1);
1575 >                                }
1576 >                                if (rfdt) {     /* start fresh */
1577 >                                        rmfile(rawfile);
1578 >                                        rfdt = 0;
1579 >                                }
1580                                  if (!silent)
1581                                          printf("\techo %d %d > %s\n",
1582                                                          xdiv, ydiv, sfile);
# Line 1396 | Line 1613 | rpict(                         /* run rpict and pfilt for each view */
1613                  } else {
1614                          if (overture) {         /* run overture calculation */
1615                                  sprintf(combuf,
1616 <                                "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1616 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1617                                                  c_rpict, rep, vw, opts,
1618                                                  oct1name, overfile);
1619 <                                if (do_rpiece)
1620 <                                        while (next_process(1))
1621 <                                                sleep(5);
1405 <                                if (runcom(combuf)) {
1406 <                                        fprintf(stderr,
1619 >                                if (!do_rpiece || !next_process(0)) {
1620 >                                        if (runcom(combuf)) {
1621 >                                                fprintf(stderr,
1622                                          "%s: error in overture for view %s\n",
1623 <                                                progname, vs);
1624 <                                        quit(1);
1625 <                                }
1411 <                                if (do_rpiece) {
1412 <                                        finish_process();
1413 <                                        wait_process(1);
1414 <                                }
1623 >                                                        progname, vs);
1624 >                                                quit(1);
1625 >                                        }
1626   #ifndef NULL_DEVICE
1627 <                                rmfile(overfile);
1627 >                                        rmfile(overfile);
1628   #endif
1629 +                                } else if (do_rpiece)
1630 +                                        sleep(20);
1631                          }
1632                          if (do_rpiece) {
1633                                  sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
# Line 1446 | Line 1659 | rpict(                         /* run rpict and pfilt for each view */
1659                  if (do_rpiece) {                /* need to finish raw, first */
1660                          finish_process();
1661                          wait_process(1);
1662 <                        /* XXX should check sync file to see if really done? */
1662 >                        if (!syncf_done(sfile)) {
1663 >                                fprintf(stderr,
1664 >                        "%s: %s did not complete rendering of view %s\n",
1665 >                                                progname, c_rpiece, vs);
1666 >                                quit(1);
1667 >                        }
1668                  }
1669                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1670                                                  /* build pfilt command */
1671 <                        if (mult > 1)
1671 >                        if (do_rpiece)
1672 >                                sprintf(combuf,
1673 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1674 >                                        c_pfilt, pfopts, xres, yres, aspect,
1675 >                                        rawfile, picfile);
1676 >                        else if (mult > 1)
1677                                  sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1678                                          c_pfilt, pfopts, mult, mult,
1679                                          rawfile, picfile);
# Line 1570 | Line 1793 | next_process(int reserve)              /* fork the next process */
1793          child_pid = fork();             /* split process */
1794          if (child_pid == 0) {           /* we're the child */
1795                  children_running = -1;
1796 +                nprocs = 1;
1797                  return(0);
1798          }
1799          if (child_pid > 0) {            /* we're the parent */
# Line 1637 | Line 1861 | finish_process(void)                   /* exit a child process */
1861                  return;                 /* in parent -- noop */
1862          exit(0);
1863   }
1640
1641 #ifdef _WIN32
1642 setenv(vname, value)            /* set an environment variable */
1643 char    *vname, *value;
1644 {
1645        register char   *evp;
1646
1647        evp = bmalloc(strlen(vname)+strlen(value)+2);
1648        if (evp == NULL)
1649                syserr(progname);
1650        sprintf(evp, "%s=%s", vname, value);
1651        if (putenv(evp) != 0) {
1652                fprintf(stderr, "%s: out of environment space\n", progname);
1653                quit(1);
1654        }
1655        if (!silent)
1656                printf("set %s\n", evp);
1657 }
1658 #endif
1864  
1865  
1866   static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines