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

Comparing ray/src/gen/mkillum.c (file contents):
Revision 2.14 by schorsch, Thu Jun 26 00:58:09 2003 UTC vs.
Revision 2.42 by greg, Thu Sep 15 22:34:41 2016 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7  
8   #include  <signal.h>
9   #include  <ctype.h>
10 #include  <stdio.h>
10  
11 < #include  "standard.h"
13 < #include  "platform.h"
11 > #include  "paths.h"             /* win_popen() */
12   #include  "mkillum.h"
13  
14                                  /* default parameters */
# Line 24 | Line 22 | static const char RCSid[] = "$Id$";
22   #define  S_COMPL        2               /* select all but element */
23   #define  S_ALL          3               /* select all */
24  
27                                /* rtrace command and defaults */
28 char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-",
29                "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", };
30 int  rtargc = 14;
31                                /* overriding rtrace options */
32 char  *myrtopts[] = { "-I-", "-i-", "-ld-", "-ov", "-h-",
33                        "-fff", "-y", "0", NULL };
34
35 struct rtproc   rt;             /* our rtrace process */
36
25   struct illum_args  thisillum = {        /* our illum and default values */
26                  0,
27                  DFLMAT,
# Line 48 | Line 36 | struct illum_args  thisillum = {       /* our illum and defa
36   char    matcheck[MAXSTR];       /* current material to include or exclude */
37   int     matselect = S_ALL;      /* selection criterion */
38  
51 FUN     ofun[NUMOTYPE] = INIT_OTYPE;    /* object types */
52
39   int     gargc;                  /* global argc */
40   char    **gargv;                /* global argv */
55 #define  progname       gargv[0]
41  
42   int     doneheader = 0;         /* printed header yet? */
43   #define  checkhead()    if (!doneheader++) printhead(gargc,gargv)
44  
45   int     warnings = 1;           /* print warnings? */
46  
47 + void init(char *octnm, int np);
48 + void filter(FILE        *infp, char     *name);
49 + void xoptions(char      *s, char        *nm);
50 + void printopts(void);
51 + void printhead(int  ac, char  **av);
52 + void xobject(FILE  *fp, char  *nm);
53  
54 < main(argc, argv)                /* compute illum distributions using rtrace */
55 < int     argc;
56 < char    *argv[];
54 >
55 > int
56 > main(           /* compute illum distributions using rtrace */
57 >        int     argc,
58 >        char    *argv[]
59 > )
60   {
61 <        char    *rtpath;
61 >        int     nprocs = 1;
62          FILE    *fp;
63 <        register int    i;
63 >        int     rval;
64 >        int     i;
65                                  /* set global arguments */
66          gargv = argv;
67 <                                /* set up rtrace command */
67 >        progname = gargv[0];
68 >                                /* set up rendering defaults */
69 >        dstrsrc = 0.5;
70 >        directrelay = 3;
71 >        ambounce = 2;
72 >                                /* get options from command line */
73          for (i = 1; i < argc; i++) {
74 <                if (argv[i][0] == '<' && argv[i][1] == '\0')
74 >                while ((rval = expandarg(&argc, &argv, i)) > 0)
75 >                        ;
76 >                if (rval < 0) {
77 >                        sprintf(errmsg, "cannot expand '%s'", argv[i]);
78 >                        error(SYSTEM, errmsg);
79 >                }
80 >                if (argv[i][0] != '-')
81                          break;
82 <                rtargv[rtargc++] = argv[i];
83 <                if (argv[i][0] == '-' && argv[i][1] == 'w')
84 <                        switch (argv[i][2]) {
79 <                        case '\0':
80 <                                warnings = !warnings;
81 <                                break;
82 <                        case '+':
83 <                        case 'T': case 't':
84 <                        case 'Y': case 'y':
85 <                        case '1':
86 <                                warnings = 1;
87 <                                break;
88 <                        case '-':
89 <                        case 'F': case 'f':
90 <                        case 'N': case 'n':
91 <                        case '0':
92 <                                warnings = 0;
93 <                                break;
94 <                        }
95 <        }
96 <        gargc = i;
97 <        rtargc--;
98 <        for (i = 0; myrtopts[i] != NULL; i++)
99 <                rtargv[rtargc++] = myrtopts[i];
100 <        rtargv[rtargc++] = argv[gargc-1];
101 <        rtargv[rtargc] = NULL;
102 <                                /* just asking for defaults? */
103 <        if (!strcmp(argv[gargc-1], "-defaults")) {
104 <                printopts(); fflush(stdout);
105 <                rtpath = getpath(rtargv[0], getenv("PATH"), X_OK);
106 <                if (rtpath == NULL) {
107 <                        eputs(rtargv[0]);
108 <                        eputs(": command not found\n");
109 <                        exit(1);
82 >                if (!strcmp(argv[i], "-w")) {
83 >                        warnings = 0;
84 >                        continue;
85                  }
86 <                execv(rtpath, rtargv);
87 <                perror(rtpath);
88 <                exit(1);
86 >                if (!strcmp(argv[i], "-n")) {
87 >                        nprocs = atoi(argv[++i]);
88 >                        if (nprocs <= 0)
89 >                                error(USER, "illegal number of processes");
90 >                        continue;
91 >                }
92 >                if (!strcmp(argv[i], "-defaults")) {
93 >                        printopts();
94 >                        print_rdefaults();
95 >                        quit(0);
96 >                }
97 >                rval = getrenderopt(argc-i, argv+i);
98 >                if (rval < 0) {
99 >                        sprintf(errmsg, "bad render option at '%s'", argv[i]);
100 >                        error(USER, errmsg);
101 >                }
102 >                i += rval;
103          }
104 <        if (gargc < 2 || argv[gargc-1][0] == '-')
104 >        gargc = ++i;
105 >                                /* add "mandatory" render options */
106 >        do_irrad = 0;
107 >        if (gargc > argc || argv[gargc-1][0] == '-')
108                  error(USER, "missing octree argument");
109                                  /* else initialize and run our calculation */
110 <        init();
111 <        if (gargc+1 < argc)
110 >        init(argv[gargc-1], nprocs);
111 >        if (gargc < argc) {
112 >                if (gargc == argc-1 || argv[gargc][0] != '<' || argv[gargc][1])
113 >                        error(USER, "use '< file1 file2 ..' for multiple inputs");
114                  for (i = gargc+1; i < argc; i++) {
115                          if ((fp = fopen(argv[i], "r")) == NULL) {
116                                  sprintf(errmsg,
# Line 126 | Line 120 | char   *argv[];
120                          filter(fp, argv[i]);
121                          fclose(fp);
122                  }
123 <        else
123 >        } else
124                  filter(stdin, "standard input");
125          quit(0);
126 +        return 0; /* pro forma return */
127   }
128  
129  
130   void
131 < quit(status)                    /* exit with status */
137 < int  status;
131 > init(char *octnm, int np)               /* start rendering process(es) */
132   {
139        int     rtstat;
140
141        rtstat = close_process(&(rt.pd));
142        if (status == 0)
143                if (rtstat < 0)
144                        error(WARNING,
145                        "unknown return status from rtrace process");
146                else
147                        status = rtstat;
148        exit(status);
149 }
150
151
152 init()                          /* start rtrace and set up buffers */
153 {
154        extern int  o_face(), o_sphere(), o_ring();
155        int     maxbytes;
156                                        /* set up object functions */
157        ofun[OBJ_FACE].funp = o_face;
158        ofun[OBJ_SPHERE].funp = o_sphere;
159        ofun[OBJ_RING].funp = o_ring;
133                                          /* set up signal handling */
134 < #ifdef SIGPIPE /* not present on Windows */
134 >        signal(SIGINT, quit);
135 > #ifdef SIGHUP
136 >        signal(SIGHUP, quit);
137 > #endif
138 > #ifdef SIGTERM
139 >        signal(SIGTERM, quit);
140 > #endif
141 > #ifdef SIGPIPE
142          signal(SIGPIPE, quit);
143   #endif
144 <                                        /* start rtrace process */
145 <        errno = 0;
166 <        maxbytes = open_process(&(rt.pd), rtargv);
167 <        if (maxbytes == 0) {
168 <                eputs(rtargv[0]);
169 <                eputs(": command not found\n");
170 <                exit(1);
171 <        }
172 <        if (maxbytes < 0)
173 <                error(SYSTEM, "cannot start rtrace process");
174 <        rt.bsiz = maxbytes/(6*sizeof(float));
175 <        rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--);
176 <        rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz);
177 <        if (rt.buf == NULL || rt.dest == NULL)
178 <                error(SYSTEM, "out of memory in init");
179 <        rt.nrays = 0;
180 <                                        /* set up urand */
181 <        initurand(16384);
144 >                                        /* start rendering process(es) */
145 >        ray_pinit(octnm, np);
146   }
147  
148  
149   void
150 < eputs(s)                                /* put string to stderr */
151 < register char  *s;
150 > eputs(                          /* put string to stderr */
151 >        char  *s
152 > )
153   {
154          static int  midline = 0;
155  
# Line 207 | Line 172 | char  *s;
172   }
173  
174  
175 < filter(infp, name)              /* process stream */
176 < register FILE   *infp;
177 < char    *name;
175 > void
176 > quit(ec)                        /* make sure exit is called */
177 > int     ec;
178   {
179 +        if (ray_pnprocs > 0)    /* close children if any */
180 +                ray_pclose(0);          
181 +        exit(ec);
182 + }
183 +
184 +
185 + void
186 + filter(         /* process stream */
187 +        FILE    *infp,
188 +        char    *name
189 + )
190 + {
191          char    buf[512];
192          FILE    *pfp;
193 <        register int    c;
193 >        int     c;
194  
195          while ((c = getc(infp)) != EOF) {
196                  if (isspace(c))
# Line 239 | Line 216 | char   *name;
216   }
217  
218  
219 < xoptions(s, nm)                 /* process options in string s */
220 < char    *s;
221 < char    *nm;
219 > void
220 > xoptions(                       /* process options in string s */
221 >        char    *s,
222 >        char    *nm
223 > )
224   {
246        extern FILE     *freopen();
225          char    buf[64];
226 +        int     negax;
227          int     nerrs = 0;
228 <        register char   *cp;
228 >        char    *cp;
229  
230          if (strncmp(s, "#@mkillum", 9) || !isspace(s[9])) {
231                  fputs(s, stdout);               /* not for us */
# Line 324 | Line 303 | char   *nm;
303                          }
304                          cp = sskip(cp);
305                          continue;
306 <                case 'd':                       /* point sample density */
306 >                case 'd':                       /* sample density */
307                          if (*++cp != '=')
308                                  break;
309 <                        if (!isintd(++cp, " \t\n\r"))
310 <                                break;
311 <                        thisillum.sampdens = atoi(cp);
309 >                        if (!*++cp || isspace(*cp))
310 >                                continue;
311 >                        if (isintd(cp, " \t\n\r")) {
312 >                                thisillum.sampdens = atoi(cp);
313 >                        } else {
314 >                                error(WARNING, "direct BSDF input unsupported");
315 >                                goto opterr;
316 >                        }
317                          cp = sskip(cp);
318                          continue;
319 <                case 's':                       /* point super-samples */
319 >                case 's':                       /* surface super-samples */
320                          if (*++cp != '=')
321                                  break;
322                          if (!isintd(++cp, " \t\n\r"))
# Line 400 | Line 384 | char   *nm;
384          printf("# %s", s+2);
385   }
386  
387 <
388 < printopts()                     /* print out option default values */
387 > void
388 > printopts(void)                 /* print out option default values */
389   {
390          printf("m=%-15s\t\t# material name\n", thisillum.matname);
391          printf("f=%-15s\t\t# data file name\n", thisillum.datafile);
# Line 416 | Line 400 | printopts()                    /* print out option default values */
400                  printf("l+\t\t\t\t# light type on\n");
401          else
402                  printf("l-\t\t\t\t# light type off\n");
403 <        printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens);
404 <        printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps);
403 >        printf("d=%d\t\t\t\t# density of directions\n", thisillum.sampdens);
404 >        printf("s=%d\t\t\t\t# samples per direction\n", thisillum.nsamps);
405          printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt);
406   }
407  
408  
409 < printhead(ac, av)                       /* print out header */
410 < register int  ac;
411 < register char  **av;
409 > void
410 > printhead(                      /* print out header */
411 >        int  ac,
412 >        char  **av
413 > )
414   {
415          putchar('#');
416          while (ac-- > 0) {
# Line 435 | Line 421 | register char  **av;
421   }
422  
423  
424 < xobject(fp, nm)                         /* translate an object from fp */
425 < FILE  *fp;
426 < char  *nm;
424 > void
425 > xobject(                                /* translate an object from fp */
426 >        FILE  *fp,
427 >        char  *nm
428 > )
429   {
430          OBJREC  thisobj;
431          char  str[MAXSTR];
# Line 488 | Line 476 | char  *nm;
476          checkhead();
477                                                  /* process object */
478          if (doit)
479 <                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm);
479 >                switch (thisobj.otype) {
480 >                case OBJ_FACE:
481 >                        my_face(&thisobj, &thisillum, nm);
482 >                        break;
483 >                case OBJ_SPHERE:
484 >                        my_sphere(&thisobj, &thisillum, nm);
485 >                        break;
486 >                case OBJ_RING:
487 >                        my_ring(&thisobj, &thisillum, nm);
488 >                        break;
489 >                default:
490 >                        my_default(&thisobj, &thisillum, nm);
491 >                        break;
492 >                }
493          else
494                  printobj(thisillum.altmat, &thisobj);
495                                                  /* free arguments */
496          freefargs(&thisobj.oargs);
497          return;
498   readerr:
499 <        sprintf(errmsg, "(%s): error reading scene", nm);
499 >        sprintf(errmsg, "(%s): error reading input", nm);
500          error(USER, errmsg);
501   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines