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.21 by greg, Sun Sep 19 08:42:22 2004 UTC vs.
Revision 2.30 by greg, Tue Sep 18 19:51:07 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines