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 1.13 by greg, Mon Aug 26 10:16:54 1991 UTC vs.
Revision 2.43 by greg, Mon Jul 20 15:54:29 2020 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Make illum sources for optimizing rendering process
6   */
7  
11 #include  "mkillum.h"
12
8   #include  <signal.h>
14
9   #include  <ctype.h>
10  
11 + #include  "paths.h"             /* win_popen() */
12 + #include  "mkillum.h"
13 +
14                                  /* default parameters */
15   #define  SAMPDENS       48              /* points per projected steradian */
16   #define  NSAMPS         32              /* samples per point */
# Line 25 | Line 22 | static char SCCSid[] = "$SunId$ LBL";
22   #define  S_COMPL        2               /* select all but element */
23   #define  S_ALL          3               /* select all */
24  
28                                /* rtrace command and defaults */
29 char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-di+",
30                "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", };
31 int  rtargc = 14;
32                                /* overriding rtrace options */
33 char  *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", 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 < extern char     *fgetline(), *fgetword(), *sskip(),
48 <                *atos(), *iskip(), *fskip(), *strcpy();
49 < extern FILE     *popen();
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  
55 < main(argc, argv)                /* compute illum distributions using rtrace */
56 < int     argc;
57 < char    *argv[];
55 > int
56 > main(           /* compute illum distributions using rtrace */
57 >        int     argc,
58 >        char    *argv[]
59 > )
60   {
61 <        extern char     *getenv(), *getpath();
72 <        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])
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 <                        warnings = !warnings;
84 <        }
85 <        if ((gargc = i) < 2)
86 <                error(USER, "too few arguments");
87 <        rtargc--;
88 <        for (i = 0; myrtopts[i] != NULL; i++)
89 <                rtargv[rtargc++] = myrtopts[i];
90 <        rtargv[rtargc++] = argv[gargc-1];
91 <        rtargv[rtargc] = NULL;
92 <                                /* just asking for defaults? */
93 <        if (!strcmp(argv[gargc-1], "-defaults")) {
94 <                printopts(); fflush(stdout);
95 <                rtpath = getpath(rtargv[0], getenv("PATH"), X_OK);
96 <                if (rtpath == NULL) {
97 <                        eputs(rtargv[0]);
98 <                        eputs(": command not found\n");
99 <                        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 +        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 114 | 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 < quit(status)                    /* exit with status */
131 < int  status;
130 > void
131 > init(char *octnm, int np)               /* start rendering process(es) */
132   {
126        int     rtstat;
127
128        rtstat = close_process(rt.pd);
129        if (status == 0)
130                if (rtstat < 0)
131                        error(WARNING,
132                        "unknown return status from rtrace process");
133                else
134                        status = rtstat;
135        exit(status);
136 }
137
138
139 init()                          /* start rtrace and set up buffers */
140 {
141        extern int  o_face(), o_sphere(), o_ring();
142        int     maxbytes;
143                                        /* set up object functions */
144        ofun[OBJ_FACE].funp = o_face;
145        ofun[OBJ_SPHERE].funp = o_sphere;
146        ofun[OBJ_RING].funp = o_ring;
133                                          /* set up signal handling */
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 <                                        /* start rtrace process */
144 <        maxbytes = open_process(rt.pd, rtargv);
145 <        if (maxbytes == 0) {
152 <                eputs(rtargv[0]);
153 <                eputs(": command not found\n");
154 <                exit(1);
155 <        }
156 <        if (maxbytes < 0)
157 <                error(SYSTEM, "cannot start rtrace process");
158 <        rt.bsiz = maxbytes/(6*sizeof(float));
159 <        rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--);
160 <        rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz);
161 <        if (rt.buf == NULL || rt.dest == NULL)
162 <                error(SYSTEM, "out of memory in init");
163 <        rt.nrays = 0;
164 <                                        /* set up urand */
165 <        initurand(2048);
143 > #endif
144 >                                        /* start rendering process(es) */
145 >        ray_pinit(octnm, np);
146   }
147  
148  
149 < eputs(s)                                /* put string to stderr */
150 < register char  *s;
149 > void
150 > eputs(                          /* put string to stderr */
151 >        char  *s
152 > )
153   {
154          static int  midline = 0;
155  
# Line 181 | Line 163 | register char  *s;
163   }
164  
165  
166 + void
167   wputs(s)                        /* print warning if enabled */
168   char  *s;
169   {
# Line 189 | 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 +        else if (ray_pnprocs < 0)
182 +                _exit(ec);      /* avoid flush() in child */
183 +        exit(ec);
184 + }
185 +
186 +
187 + void
188 + filter(         /* process stream */
189 +        FILE    *infp,
190 +        char    *name
191 + )
192 + {
193          char    buf[512];
194          FILE    *pfp;
195 <        register int    c;
195 >        int     c;
196  
197          while ((c = getc(infp)) != EOF) {
198                  if (isspace(c))
# Line 221 | Line 218 | char   *name;
218   }
219  
220  
221 < xoptions(s, nm)                 /* process options in string s */
222 < char    *s;
223 < char    *nm;
221 > void
222 > xoptions(                       /* process options in string s */
223 >        char    *s,
224 >        char    *nm
225 > )
226   {
228        extern FILE     *freopen();
227          char    buf[64];
228 +        int     negax;
229          int     nerrs = 0;
230 <        register char   *cp;
230 >        char    *cp;
231  
232          if (strncmp(s, "#@mkillum", 9) || !isspace(s[9])) {
233                  fputs(s, stdout);               /* not for us */
# Line 240 | Line 239 | char   *nm;
239                  case ' ':
240                  case '\t':
241                  case '\n':
242 +                case '\r':
243 +                case '\f':
244                          cp++;
245                          continue;
246                  case 'm':                       /* material name */
247                          if (*++cp != '=')
248                                  break;
249 <                        if (!*++cp)
249 >                        if (!*++cp || isspace(*cp))
250                                  break;
251                          atos(thisillum.matname, MAXSTR, cp);
252                          cp = sskip(cp);
# Line 257 | Line 258 | char   *nm;
258                  case 'f':                       /* data file name */
259                          if (*++cp != '=')
260                                  break;
261 <                        if (!*++cp) {
261 >                        if (!*++cp || isspace(*cp)) {
262                                  strcpy(thisillum.datafile,thisillum.matname);
263                                  thisillum.dfnum = 0;
264                                  thisillum.flags &= ~IL_DATCLB;
# Line 304 | Line 305 | char   *nm;
305                          }
306                          cp = sskip(cp);
307                          continue;
308 <                case 'd':                       /* point sample density */
308 >                case 'd':                       /* sample density */
309                          if (*++cp != '=')
310                                  break;
311 <                        if (!isintd(++cp, " \t\n"))
312 <                                break;
313 <                        thisillum.sampdens = atoi(cp);
311 >                        if (!*++cp || isspace(*cp))
312 >                                continue;
313 >                        if (isintd(cp, " \t\n\r")) {
314 >                                thisillum.sampdens = atoi(cp);
315 >                        } else {
316 >                                error(WARNING, "direct BSDF input unsupported");
317 >                                goto opterr;
318 >                        }
319                          cp = sskip(cp);
320                          continue;
321 <                case 's':                       /* point super-samples */
321 >                case 's':                       /* surface super-samples */
322                          if (*++cp != '=')
323                                  break;
324 <                        if (!isintd(++cp, " \t\n"))
324 >                        if (!isintd(++cp, " \t\n\r"))
325                                  break;
326                          thisillum.nsamps = atoi(cp);
327                          cp = sskip(cp);
# Line 333 | Line 339 | char   *nm;
339                  case 'b':                       /* brightness */
340                          if (*++cp != '=')
341                                  break;
342 <                        if (!isfltd(++cp, " \t\n"))
342 >                        if (!isfltd(++cp, " \t\n\r"))
343                                  break;
344                          thisillum.minbrt = atof(cp);
345                          if (thisillum.minbrt < 0.)
# Line 343 | Line 349 | char   *nm;
349                  case 'o':                       /* output file */
350                          if (*++cp != '=')
351                                  break;
352 <                        if (!*++cp)
352 >                        if (!*++cp || isspace(*cp))
353                                  break;
354                          atos(buf, sizeof(buf), cp);
355                          cp = sskip(cp);
# Line 361 | Line 367 | char   *nm;
367                          return;
368                  }
369          opterr:                                 /* skip faulty option */
370 <                cp = sskip(cp);
370 >                while (*cp && !isspace(*cp))
371 >                        cp++;
372                  nerrs++;
373          }
374                                                  /* print header? */
# Line 379 | Line 386 | char   *nm;
386          printf("# %s", s+2);
387   }
388  
389 <
390 < printopts()                     /* print out option default values */
389 > void
390 > printopts(void)                 /* print out option default values */
391   {
392          printf("m=%-15s\t\t# material name\n", thisillum.matname);
393          printf("f=%-15s\t\t# data file name\n", thisillum.datafile);
394 <        printf("c=n\t\t\t\t# color none\n");
395 <        printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens);
396 <        printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps);
394 >        if (thisillum.flags & IL_COLAVG)
395 >                if (thisillum.flags & IL_COLDST)
396 >                        printf("c=d\t\t\t\t# color distribution\n");
397 >                else
398 >                        printf("c=a\t\t\t\t# color average\n");
399 >        else
400 >                printf("c=n\t\t\t\t# color none\n");
401 >        if (thisillum.flags & IL_LIGHT)
402 >                printf("l+\t\t\t\t# light type on\n");
403 >        else
404 >                printf("l-\t\t\t\t# light type off\n");
405 >        printf("d=%d\t\t\t\t# density of directions\n", thisillum.sampdens);
406 >        printf("s=%d\t\t\t\t# samples per direction\n", thisillum.nsamps);
407          printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt);
408   }
409  
410  
411 < printhead(ac, av)                       /* print out header */
412 < register int  ac;
413 < register char  **av;
411 > void
412 > printhead(                      /* print out header */
413 >        int  ac,
414 >        char  **av
415 > )
416   {
417          putchar('#');
418          while (ac-- > 0) {
# Line 404 | Line 423 | register char  **av;
423   }
424  
425  
426 < xobject(fp, nm)                         /* translate an object from fp */
427 < FILE  *fp;
428 < char  *nm;
426 > void
427 > xobject(                                /* translate an object from fp */
428 >        FILE  *fp,
429 >        char  *nm
430 > )
431   {
432          OBJREC  thisobj;
433          char  str[MAXSTR];
# Line 417 | Line 438 | char  *nm;
438          if (fgetword(str, MAXSTR, fp) == NULL)
439                  goto readerr;
440                                          /* is it an alias? */
441 <        if (!strcmp(str, ALIASID)) {
441 >        if (!strcmp(str, ALIASKEY)) {
442                  if (fgetword(str, MAXSTR, fp) == NULL)
443                          goto readerr;
444 <                printf("\n%s %s %s", thisillum.altmat, ALIASID, str);
444 >                printf("\n%s %s %s", thisillum.altmat, ALIASKEY, str);
445                  if (fgetword(str, MAXSTR, fp) == NULL)
446                          goto readerr;
447                  printf("\t%s\n", str);
# Line 457 | Line 478 | char  *nm;
478          checkhead();
479                                                  /* process object */
480          if (doit)
481 <                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm);
481 >                switch (thisobj.otype) {
482 >                case OBJ_FACE:
483 >                        my_face(&thisobj, &thisillum, nm);
484 >                        break;
485 >                case OBJ_SPHERE:
486 >                        my_sphere(&thisobj, &thisillum, nm);
487 >                        break;
488 >                case OBJ_RING:
489 >                        my_ring(&thisobj, &thisillum, nm);
490 >                        break;
491 >                default:
492 >                        my_default(&thisobj, &thisillum, nm);
493 >                        break;
494 >                }
495          else
496                  printobj(thisillum.altmat, &thisobj);
497                                                  /* free arguments */
498          freefargs(&thisobj.oargs);
499          return;
500   readerr:
501 <        sprintf(errmsg, "(%s): error reading scene", nm);
501 >        sprintf(errmsg, "(%s): error reading input", nm);
502          error(USER, errmsg);
503   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines