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.24 by greg, Wed May 25 04:44:25 2005 UTC vs.
Revision 2.34 by greg, Sat Apr 18 16:14:26 2009 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8   #include  <signal.h>
9   #include  <ctype.h>
10  
11 #include  "platform.h"
11   #include  "mkillum.h"
13 #include  "random.h"
12  
13                                  /* default parameters */
14   #define  SAMPDENS       48              /* points per projected steradian */
# Line 23 | Line 21 | static const char RCSid[] = "$Id$";
21   #define  S_COMPL        2               /* select all but element */
22   #define  S_ALL          3               /* select all */
23  
26                                /* rtrace command and defaults */
27 char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-",
28                "-ab", "2", "-ad", "1024", "-as", "512", "-aa", ".1", };
29 int  rtargc = 14;
30                                /* overriding rtrace options */
31 char  *myrtopts[] = { "-I-", "-i-", "-ld-", "-ov", "-h-",
32                        "-fff", "-y", "0", NULL };
33
34 struct rtproc   rt0;            /* head of rtrace process list */
35
24   struct illum_args  thisillum = {        /* our illum and default values */
25                  0,
26 +                UDzpos,
27 +                0.,
28                  DFLMAT,
29                  DFLDAT,
30                  0,
31                  VOIDID,
32                  SAMPDENS,
33                  NSAMPS,
34 +                NULL,
35                  0.,
36          };
37  
38   char    matcheck[MAXSTR];       /* current material to include or exclude */
39   int     matselect = S_ALL;      /* selection criterion */
40  
50 FUN     ofun[NUMOTYPE] = INIT_OTYPE;    /* object types */
51
52 char    persistfn[] = "pfXXXXXX";       /* persist file name */
53
41   int     gargc;                  /* global argc */
42   char    **gargv;                /* global argv */
56 #define  progname       gargv[0]
43  
44   int     doneheader = 0;         /* printed header yet? */
45   #define  checkhead()    if (!doneheader++) printhead(gargc,gargv)
46  
47   int     warnings = 1;           /* print warnings? */
48  
49 < int done_rprocs(struct rtproc *rtp);
64 < void init(int np);
49 > void init(char *octnm, int np);
50   void filter(register FILE       *infp, char     *name);
51   void xoptions(char      *s, char        *nm);
52   void printopts(void);
# Line 76 | Line 61 | main(          /* compute illum distributions using rtrace */
61   )
62   {
63          int     nprocs = 1;
79        char    *rtpath;
64          FILE    *fp;
65 +        int     rval;
66          register int    i;
67                                  /* set global arguments */
68          gargv = argv;
69 <                                /* check for -n option */
70 <        if (!strcmp(argv[1], "-n")) {
71 <                nprocs = atoi(argv[2]);
72 <                if (nprocs <= 0)
73 <                        error(USER, "illegal number of processes");
74 <                i = 3;
75 <        } else
76 <                i = 1;
77 <                                /* set up rtrace command */
78 <        for ( ; i < argc; i++) {
79 <                if (argv[i][0] == '<' && argv[i][1] == '\0')
69 >        progname = gargv[0];
70 >                                /* set up rendering defaults */
71 >        dstrsrc = 0.25;
72 >        directrelay = 3;
73 >        directvis = 0;
74 >        ambounce = 2;
75 >                                /* get options from command line */
76 >        for (i = 1; i < argc; i++) {
77 >                while ((rval = expandarg(&argc, &argv, i)) > 0)
78 >                        ;
79 >                if (rval < 0) {
80 >                        sprintf(errmsg, "cannot expand '%s'", argv[i]);
81 >                        error(SYSTEM, errmsg);
82 >                }
83 >                if (argv[i][0] != '-')
84                          break;
85 <                rtargv[rtargc++] = argv[i];
86 <                if (argv[i][0] == '-' && argv[i][1] == 'w')
87 <                        switch (argv[i][2]) {
99 <                        case '\0':
100 <                                warnings = !warnings;
101 <                                break;
102 <                        case '+':
103 <                        case 'T': case 't':
104 <                        case 'Y': case 'y':
105 <                        case '1':
106 <                                warnings = 1;
107 <                                break;
108 <                        case '-':
109 <                        case 'F': case 'f':
110 <                        case 'N': case 'n':
111 <                        case '0':
112 <                                warnings = 0;
113 <                                break;
114 <                        }
115 <        }
116 <        gargc = i;
117 <        if (!strcmp(rtargv[--rtargc], "-defaults"))
118 <                nprocs = 0;
119 <        if (nprocs > 1) {       /* add persist file if parallel invocation */
120 <                rtargv[rtargc++] = "-PP";
121 <                rtargv[rtargc++] = mktemp(persistfn);
122 <        }
123 <                                /* add "mandatory" rtrace options */
124 <        for (i = 0; myrtopts[i] != NULL; i++)
125 <                rtargv[rtargc++] = myrtopts[i];
126 <                                /* finally, put back final argument */
127 <        rtargv[rtargc++] = argv[gargc-1];
128 <        rtargv[rtargc] = NULL;
129 <        if (!nprocs) {          /* just asking for defaults? */
130 <                printopts(); fflush(stdout);
131 <                rtpath = getpath(rtargv[0], getenv("PATH"), X_OK);
132 <                if (rtpath == NULL) {
133 <                        eputs(rtargv[0]);
134 <                        eputs(": command not found\n");
135 <                        exit(1);
85 >                if (!strcmp(argv[i], "-w")) {
86 >                        warnings = 0;
87 >                        continue;
88                  }
89 <                execv(rtpath, rtargv);
90 <                perror(rtpath); /* execv() should not return */
91 <                exit(1);
89 >                if (!strcmp(argv[i], "-n")) {
90 >                        nprocs = atoi(argv[++i]);
91 >                        if (nprocs <= 0)
92 >                                error(USER, "illegal number of processes");
93 >                        continue;
94 >                }
95 >                if (!strcmp(argv[i], "-defaults")) {
96 >                        printopts();
97 >                        print_rdefaults();
98 >                        quit(0);
99 >                }
100 >                rval = getrenderopt(argc-i, argv+i);
101 >                if (rval < 0) {
102 >                        sprintf(errmsg, "bad render option at '%s'", argv[i]);
103 >                        error(USER, errmsg);
104 >                }
105 >                i += rval;
106          }
107 <        if (gargc < 2 || argv[gargc-1][0] == '-')
107 >        gargc = ++i;
108 >                                /* add "mandatory" render options */
109 >        do_irrad = 0;
110 >        if (gargc > argc || argv[gargc-1][0] == '-')
111                  error(USER, "missing octree argument");
112                                  /* else initialize and run our calculation */
113 <        init(nprocs);
114 <        if (gargc+1 < argc)
113 >        init(argv[gargc-1], nprocs);
114 >        if (gargc < argc) {
115 >                if (gargc == argc-1 || argv[gargc][0] != '<' || argv[gargc][1])
116 >                        error(USER, "use '< file1 file2 ..' for multiple inputs");
117                  for (i = gargc+1; i < argc; i++) {
118                          if ((fp = fopen(argv[i], "r")) == NULL) {
119                                  sprintf(errmsg,
# Line 152 | Line 123 | main(          /* compute illum distributions using rtrace */
123                          filter(fp, argv[i]);
124                          fclose(fp);
125                  }
126 <        else
126 >        } else
127                  filter(stdin, "standard input");
128          quit(0);
129 +        return 0; /* pro forma return */
130   }
131  
160 static void
161 killpersist(void)                       /* kill persistent rtrace process */
162 {
163        FILE    *fp = fopen(persistfn, "r");
164        int     pid;
132  
166        if (fp == NULL)
167                return;
168        if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0)
169                unlink(persistfn);
170        fclose(fp);
171 }
172
173 int
174 done_rprocs(struct rtproc *rtp)
175 {
176        int     st0, st1 = 0;
177
178        if (rtp->next != NULL) {        /* close last opened first! */
179                st1 = done_rprocs(rtp->next);
180                free((void *)rtp->next);
181                rtp->next = NULL;
182        }
183        st0 = close_process(&rtp->pd);
184        if (st0 < 0)
185                error(WARNING, "unknown return status from rtrace process");
186        else if (st0 > 0)
187                return(st0);
188        return(st1);
189 }
190
133   void
134 < quit(int status)                        /* exit with status */
134 > init(char *octnm, int np)               /* start rendering process(es) */
135   {
194        int     rtstat;
195
196        if (rt0.next != NULL)           /* terminate persistent rtrace */
197                killpersist();
198                                        /* clean up rtrace process(es) */
199        rtstat = done_rprocs(&rt0);
200        if (status == 0)
201                status = rtstat;
202        exit(status);
203 }
204
205 void
206 init(int np)                            /* start rtrace and set up buffers */
207 {
208        struct rtproc   *rtp;
209        int     i;
210        int     maxbytes;
211                                        /* set up object functions */
212        ofun[OBJ_FACE].funp = o_face;
213        ofun[OBJ_SPHERE].funp = o_sphere;
214        ofun[OBJ_RING].funp = o_ring;
136                                          /* set up signal handling */
137 < #ifdef SIGPIPE /* not present on Windows */
137 >        signal(SIGINT, quit);
138 > #ifdef SIGHUP
139 >        signal(SIGHUP, quit);
140 > #endif
141 > #ifdef SIGTERM
142 >        signal(SIGTERM, quit);
143 > #endif
144 > #ifdef SIGPIPE
145          signal(SIGPIPE, quit);
146   #endif
147 <        rtp = &rt0;                     /* start rtrace process(es) */
148 <        for (i = 0; i++ < np; ) {
221 <                errno = 0;
222 <                maxbytes = open_process(&rtp->pd, rtargv);
223 <                if (maxbytes == 0) {
224 <                        eputs(rtargv[0]);
225 <                        eputs(": command not found\n");
226 <                        exit(1);
227 <                }
228 <                if (maxbytes < 0)
229 <                        error(SYSTEM, "cannot start rtrace process");
230 <                rtp->bsiz = maxbytes/(6*sizeof(float));
231 <                rtp->buf = (float *)malloc(6*sizeof(float)*rtp->bsiz--);
232 <                rtp->dest = (float **)calloc(rtp->bsiz, sizeof(float *));
233 <                if (rtp->buf == NULL || rtp->dest == NULL)
234 <                        error(SYSTEM, "out of memory in init");
235 <                rtp->nrays = 0;
236 <                if (i == np)            /* last process? */
237 <                        break;
238 <                if (np > 1)
239 <                        sleep(2);       /* wait for persist file */
240 <                rtp->next = (struct rtproc *)malloc(sizeof(struct rtproc));
241 <                if (rtp->next == NULL)
242 <                        error(SYSTEM, "out of memory in init");
243 <                rtp = rtp->next;
244 <        }
245 <        rtp->next = NULL;
246 <                                        /* set up urand */
247 <        initurand(16384);
147 >                                        /* start rendering process(es) */
148 >        ray_pinit(octnm, np);
149   }
150  
151  
# Line 316 | Line 217 | xoptions(                      /* process options in string s */
217   {
218          extern FILE     *freopen();
219          char    buf[64];
220 +        int     negax;
221          int     nerrs = 0;
222          register char   *cp;
223  
# Line 395 | Line 297 | xoptions(                      /* process options in string s */
297                          }
298                          cp = sskip(cp);
299                          continue;
300 <                case 'd':                       /* point sample density */
300 >                case 'd':                       /* sample density / BSDF data */
301                          if (*++cp != '=')
302                                  break;
303 <                        if (!isintd(++cp, " \t\n\r"))
304 <                                break;
305 <                        thisillum.sampdens = atoi(cp);
303 >                        if (thisillum.sd != NULL) {
304 >                                free_BSDF(thisillum.sd);
305 >                                thisillum.sd = NULL;
306 >                        }
307 >                        if (!*++cp || isspace(*cp))
308 >                                continue;
309 >                        if (isintd(cp, " \t\n\r")) {
310 >                                thisillum.sampdens = atoi(cp);
311 >                        } else {
312 >                                atos(buf, sizeof(buf), cp);
313 >                                thisillum.sd = load_BSDF(buf);
314 >                                if (thisillum.sd == NULL)
315 >                                        break;
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 445 | Line 358 | xoptions(                      /* process options in string s */
358                          }
359                          doneheader = 0;
360                          continue;
361 +                case 'u':                       /* up direction */
362 +                        if (*++cp != '=')
363 +                                break;
364 +                        if (!*++cp || isspace(*cp)) {
365 +                                thisillum.udir = UDunknown;
366 +                                continue;
367 +                        }
368 +                        negax = 0;
369 +                        if (*cp == '+')
370 +                                cp++;
371 +                        else if (*cp == '-') {
372 +                                negax++;
373 +                                cp++;
374 +                        }
375 +                        switch (*cp++) {
376 +                        case 'x':
377 +                        case 'X':
378 +                                thisillum.udir = negax ? UDxneg : UDxpos;
379 +                                break;
380 +                        case 'y':
381 +                        case 'Y':
382 +                                thisillum.udir = negax ? UDyneg : UDypos;
383 +                                break;
384 +                        case 'z':
385 +                        case 'Z':
386 +                                thisillum.udir = negax ? UDzneg : UDzpos;
387 +                                break;
388 +                        default:
389 +                                thisillum.udir = UDunknown;
390 +                                break;
391 +                        }
392 +                        if (thisillum.udir == UDunknown || !isspace(*cp))
393 +                                break;
394 +                        continue;
395 +                case 't':                       /* object thickness */
396 +                        if (*++cp != '=')
397 +                                break;
398 +                        if (!isfltd(++cp, " \t\n\r"))
399 +                                break;
400 +                        thisillum.thick = atof(cp);
401 +                        if (thisillum.thick < .0)
402 +                                thisillum.thick = .0;
403 +                        cp = sskip(cp);
404 +                        continue;
405                  case '!':                       /* processed file! */
406                          sprintf(errmsg, "(%s): already processed!", nm);
407                          error(WARNING, errmsg);
# Line 487 | Line 444 | printopts(void)                        /* print out option default values *
444                  printf("l+\t\t\t\t# light type on\n");
445          else
446                  printf("l-\t\t\t\t# light type off\n");
447 <        printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens);
448 <        printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps);
447 >        printf("d=%d\t\t\t\t# density of directions\n", thisillum.sampdens);
448 >        printf("s=%d\t\t\t\t# samples per direction\n", thisillum.nsamps);
449          printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt);
450 +        switch (thisillum.udir) {
451 +        case UDzneg:
452 +                fputs("u=-Z\t\t\t\t# up is negative Z\n", stdout);
453 +                break;
454 +        case UDyneg:
455 +                fputs("u=-Y\t\t\t\t# up is negative Y\n", stdout);
456 +                break;
457 +        case UDxneg:
458 +                fputs("u=-X\t\t\t\t# up is negative X\n", stdout);
459 +                break;
460 +        case UDxpos:
461 +                fputs("u=+X\t\t\t\t# up is positive X\n", stdout);
462 +                break;
463 +        case UDypos:
464 +                fputs("u=+Y\t\t\t\t# up is positive Y\n", stdout);
465 +                break;
466 +        case UDzpos:
467 +                fputs("u=+Z\t\t\t\t# up is positive Z\n", stdout);
468 +                break;
469 +        case UDunknown:
470 +                break;
471 +        }
472 +        printf("t=%f\t\t\t# object thickness\n", thisillum.thick);
473   }
474  
475  
# Line 563 | Line 543 | xobject(                               /* translate an object from fp */
543          checkhead();
544                                                  /* process object */
545          if (doit)
546 <                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt0, nm);
546 >                switch (thisobj.otype) {
547 >                case OBJ_FACE:
548 >                        my_face(&thisobj, &thisillum, nm);
549 >                        break;
550 >                case OBJ_SPHERE:
551 >                        my_sphere(&thisobj, &thisillum, nm);
552 >                        break;
553 >                case OBJ_RING:
554 >                        my_ring(&thisobj, &thisillum, nm);
555 >                        break;
556 >                default:
557 >                        my_default(&thisobj, &thisillum, nm);
558 >                        break;
559 >                }
560          else
561                  printobj(thisillum.altmat, &thisobj);
562                                                  /* free arguments */
563          freefargs(&thisobj.oargs);
564          return;
565   readerr:
566 <        sprintf(errmsg, "(%s): error reading scene", nm);
566 >        sprintf(errmsg, "(%s): error reading input", nm);
567          error(USER, errmsg);
568   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines