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.19 by schorsch, Sun Nov 16 10:29:38 2003 UTC vs.
Revision 2.40 by greg, Sun Aug 11 02:57:49 2013 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  "rtprocess.h" /* win_popen() */
12   #include  "mkillum.h"
13 #include  "random.h"
13  
14                                  /* default parameters */
15   #define  SAMPDENS       48              /* points per projected steradian */
# Line 23 | Line 22 | static const char RCSid[] = "$Id$";
22   #define  S_COMPL        2               /* select all but element */
23   #define  S_ALL          3               /* select all */
24  
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   rt;             /* our rtrace process */
35
25   struct illum_args  thisillum = {        /* our illum and default values */
26                  0,
27                  DFLMAT,
# Line 47 | 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  
50 FUN     ofun[NUMOTYPE] = INIT_OTYPE;    /* object types */
51
39   int     gargc;                  /* global argc */
40   char    **gargv;                /* global argv */
54 #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(void);
47 > void init(char *octnm, int np);
48   void filter(register FILE       *infp, char     *name);
49   void xoptions(char      *s, char        *nm);
50   void printopts(void);
# Line 72 | Line 58 | main(          /* compute illum distributions using rtrace */
58          char    *argv[]
59   )
60   {
61 <        char    *rtpath;
61 >        int     nprocs = 1;
62          FILE    *fp;
63 +        int     rval;
64          register 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]) {
87 <                        case '\0':
88 <                                warnings = !warnings;
89 <                                break;
90 <                        case '+':
91 <                        case 'T': case 't':
92 <                        case 'Y': case 'y':
93 <                        case '1':
94 <                                warnings = 1;
95 <                                break;
96 <                        case '-':
97 <                        case 'F': case 'f':
98 <                        case 'N': case 'n':
99 <                        case '0':
100 <                                warnings = 0;
101 <                                break;
102 <                        }
103 <        }
104 <        gargc = i;
105 <        rtargc--;
106 <        for (i = 0; myrtopts[i] != NULL; i++)
107 <                rtargv[rtargc++] = myrtopts[i];
108 <        rtargv[rtargc++] = argv[gargc-1];
109 <        rtargv[rtargc] = NULL;
110 <                                /* just asking for defaults? */
111 <        if (!strcmp(argv[gargc-1], "-defaults")) {
112 <                printopts(); fflush(stdout);
113 <                rtpath = getpath(rtargv[0], getenv("PATH"), X_OK);
114 <                if (rtpath == NULL) {
115 <                        eputs(rtargv[0]);
116 <                        eputs(": command not found\n");
117 <                        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 134 | Line 120 | main(          /* compute illum distributions using rtrace */
120                          filter(fp, argv[i]);
121                          fclose(fp);
122                  }
123 <        else
123 >        } else
124                  filter(stdin, "standard input");
125 <        return 0;
125 >        quit(0);
126 >        return 0; /* pro forma return */
127   }
128  
129  
130   void
131 < quit(status)                    /* exit with status */
145 < int  status;
131 > init(char *octnm, int np)               /* start rendering process(es) */
132   {
147        int     rtstat;
148
149        rtstat = close_process(&(rt.pd));
150        if (status == 0) {
151                if (rtstat < 0)
152                        error(WARNING,
153                        "unknown return status from rtrace process");
154                else
155                        status = rtstat;
156        }
157        exit(status);
158 }
159
160 void
161 init(void)                              /* start rtrace and set up buffers */
162 {
163        extern int  o_face(), o_sphere(), o_ring();
164        int     maxbytes;
165                                        /* set up object functions */
166        ofun[OBJ_FACE].funp = o_face;
167        ofun[OBJ_SPHERE].funp = o_sphere;
168        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;
175 <        maxbytes = open_process(&(rt.pd), rtargv);
176 <        if (maxbytes == 0) {
177 <                eputs(rtargv[0]);
178 <                eputs(": command not found\n");
179 <                exit(1);
180 <        }
181 <        if (maxbytes < 0)
182 <                error(SYSTEM, "cannot start rtrace process");
183 <        rt.bsiz = maxbytes/(6*sizeof(float));
184 <        rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--);
185 <        rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz);
186 <        if (rt.buf == NULL || rt.dest == NULL)
187 <                error(SYSTEM, "out of memory in init");
188 <        rt.nrays = 0;
189 <                                        /* set up urand */
190 <        initurand(16384);
144 >                                        /* start rendering process(es) */
145 >        ray_pinit(octnm, np);
146   }
147  
148  
# Line 218 | Line 173 | char  *s;
173  
174  
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          register FILE   *infp,
188          char    *name
# Line 259 | Line 224 | xoptions(                      /* process options in string s */
224   {
225          extern FILE     *freopen();
226          char    buf[64];
227 +        int     negax;
228          int     nerrs = 0;
229          register char   *cp;
230  
# Line 338 | Line 304 | xoptions(                      /* process options in string s */
304                          }
305                          cp = sskip(cp);
306                          continue;
307 <                case 'd':                       /* point sample density */
307 >                case 'd':                       /* sample density */
308                          if (*++cp != '=')
309                                  break;
310 <                        if (!isintd(++cp, " \t\n\r"))
311 <                                break;
312 <                        thisillum.sampdens = atoi(cp);
310 >                        if (!*++cp || isspace(*cp))
311 >                                continue;
312 >                        if (isintd(cp, " \t\n\r")) {
313 >                                thisillum.sampdens = atoi(cp);
314 >                        } else {
315 >                                error(WARNING, "direct BSDF input unsupported");
316 >                                goto opterr;
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 430 | Line 401 | printopts(void)                        /* print out option default values *
401                  printf("l+\t\t\t\t# light type on\n");
402          else
403                  printf("l-\t\t\t\t# light type off\n");
404 <        printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens);
405 <        printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps);
404 >        printf("d=%d\t\t\t\t# density of directions\n", thisillum.sampdens);
405 >        printf("s=%d\t\t\t\t# samples per direction\n", thisillum.nsamps);
406          printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt);
407   }
408  
# Line 506 | Line 477 | xobject(                               /* translate an object from fp */
477          checkhead();
478                                                  /* process object */
479          if (doit)
480 <                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm);
480 >                switch (thisobj.otype) {
481 >                case OBJ_FACE:
482 >                        my_face(&thisobj, &thisillum, nm);
483 >                        break;
484 >                case OBJ_SPHERE:
485 >                        my_sphere(&thisobj, &thisillum, nm);
486 >                        break;
487 >                case OBJ_RING:
488 >                        my_ring(&thisobj, &thisillum, nm);
489 >                        break;
490 >                default:
491 >                        my_default(&thisobj, &thisillum, nm);
492 >                        break;
493 >                }
494          else
495                  printobj(thisillum.altmat, &thisobj);
496                                                  /* free arguments */
497          freefargs(&thisobj.oargs);
498          return;
499   readerr:
500 <        sprintf(errmsg, "(%s): error reading scene", nm);
500 >        sprintf(errmsg, "(%s): error reading input", nm);
501          error(USER, errmsg);
502   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines