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.39 by greg, Sat Oct 13 20:15:43 2012 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 +                0.,
28                  DFLMAT,
29                  DFLDAT,
30                  0,
# Line 47 | Line 37 | struct illum_args  thisillum = {       /* our illum and defa
37   char    matcheck[MAXSTR];       /* current material to include or exclude */
38   int     matselect = S_ALL;      /* selection criterion */
39  
50 FUN     ofun[NUMOTYPE] = INIT_OTYPE;    /* object types */
51
40   int     gargc;                  /* global argc */
41   char    **gargv;                /* global argv */
54 #define  progname       gargv[0]
42  
43   int     doneheader = 0;         /* printed header yet? */
44   #define  checkhead()    if (!doneheader++) printhead(gargc,gargv)
45  
46   int     warnings = 1;           /* print warnings? */
47  
48 < void init(void);
48 > void init(char *octnm, int np);
49   void filter(register FILE       *infp, char     *name);
50   void xoptions(char      *s, char        *nm);
51   void printopts(void);
# Line 72 | Line 59 | main(          /* compute illum distributions using rtrace */
59          char    *argv[]
60   )
61   {
62 <        char    *rtpath;
62 >        int     nprocs = 1;
63          FILE    *fp;
64 +        int     rval;
65          register int    i;
66                                  /* set global arguments */
67          gargv = argv;
68 <                                /* set up rtrace command */
68 >        progname = gargv[0];
69 >                                /* set up rendering defaults */
70 >        dstrsrc = 0.5;
71 >        directrelay = 3;
72 >        ambounce = 2;
73 >                                /* get options from command line */
74          for (i = 1; i < argc; i++) {
75 <                if (argv[i][0] == '<' && argv[i][1] == '\0')
75 >                while ((rval = expandarg(&argc, &argv, i)) > 0)
76 >                        ;
77 >                if (rval < 0) {
78 >                        sprintf(errmsg, "cannot expand '%s'", argv[i]);
79 >                        error(SYSTEM, errmsg);
80 >                }
81 >                if (argv[i][0] != '-')
82                          break;
83 <                rtargv[rtargc++] = argv[i];
84 <                if (argv[i][0] == '-' && argv[i][1] == 'w')
85 <                        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);
83 >                if (!strcmp(argv[i], "-w")) {
84 >                        warnings = 0;
85 >                        continue;
86                  }
87 <                execv(rtpath, rtargv);
88 <                perror(rtpath);
89 <                exit(1);
87 >                if (!strcmp(argv[i], "-n")) {
88 >                        nprocs = atoi(argv[++i]);
89 >                        if (nprocs <= 0)
90 >                                error(USER, "illegal number of processes");
91 >                        continue;
92 >                }
93 >                if (!strcmp(argv[i], "-defaults")) {
94 >                        printopts();
95 >                        print_rdefaults();
96 >                        quit(0);
97 >                }
98 >                rval = getrenderopt(argc-i, argv+i);
99 >                if (rval < 0) {
100 >                        sprintf(errmsg, "bad render option at '%s'", argv[i]);
101 >                        error(USER, errmsg);
102 >                }
103 >                i += rval;
104          }
105 <        if (gargc < 2 || argv[gargc-1][0] == '-')
105 >        gargc = ++i;
106 >                                /* add "mandatory" render options */
107 >        do_irrad = 0;
108 >        if (gargc > argc || argv[gargc-1][0] == '-')
109                  error(USER, "missing octree argument");
110                                  /* else initialize and run our calculation */
111 <        init();
112 <        if (gargc+1 < argc)
111 >        init(argv[gargc-1], nprocs);
112 >        if (gargc < argc) {
113 >                if (gargc == argc-1 || argv[gargc][0] != '<' || argv[gargc][1])
114 >                        error(USER, "use '< file1 file2 ..' for multiple inputs");
115                  for (i = gargc+1; i < argc; i++) {
116                          if ((fp = fopen(argv[i], "r")) == NULL) {
117                                  sprintf(errmsg,
# Line 134 | Line 121 | main(          /* compute illum distributions using rtrace */
121                          filter(fp, argv[i]);
122                          fclose(fp);
123                  }
124 <        else
124 >        } else
125                  filter(stdin, "standard input");
126 <        return 0;
126 >        quit(0);
127 >        return 0; /* pro forma return */
128   }
129  
130  
131   void
132 < quit(status)                    /* exit with status */
145 < int  status;
132 > init(char *octnm, int np)               /* start rendering process(es) */
133   {
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;
134                                          /* set up signal handling */
135 < #ifdef SIGPIPE /* not present on Windows */
135 >        signal(SIGINT, quit);
136 > #ifdef SIGHUP
137 >        signal(SIGHUP, quit);
138 > #endif
139 > #ifdef SIGTERM
140 >        signal(SIGTERM, quit);
141 > #endif
142 > #ifdef SIGPIPE
143          signal(SIGPIPE, quit);
144   #endif
145 <                                        /* start rtrace process */
146 <        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);
145 >                                        /* start rendering process(es) */
146 >        ray_pinit(octnm, np);
147   }
148  
149  
# Line 218 | Line 174 | char  *s;
174  
175  
176   void
177 + quit(ec)                        /* make sure exit is called */
178 + int     ec;
179 + {
180 +        if (ray_pnprocs > 0)    /* close children if any */
181 +                ray_pclose(0);          
182 +        exit(ec);
183 + }
184 +
185 +
186 + void
187   filter(         /* process stream */
188          register FILE   *infp,
189          char    *name
# Line 259 | Line 225 | xoptions(                      /* process options in string s */
225   {
226          extern FILE     *freopen();
227          char    buf[64];
228 +        int     negax;
229          int     nerrs = 0;
230          register char   *cp;
231  
# Line 338 | Line 305 | xoptions(                      /* process options in string s */
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\r"))
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\r"))
# Line 388 | Line 360 | xoptions(                      /* process options in string s */
360                          }
361                          doneheader = 0;
362                          continue;
363 +                case 't':                       /* object thickness */
364 +                        if (*++cp != '=')
365 +                                break;
366 +                        if (!isfltd(++cp, " \t\n\r"))
367 +                                break;
368 +                        thisillum.thick = atof(cp);
369 +                        if (thisillum.thick < .0)
370 +                                thisillum.thick = .0;
371 +                        cp = sskip(cp);
372 +                        continue;
373                  case '!':                       /* processed file! */
374                          sprintf(errmsg, "(%s): already processed!", nm);
375                          error(WARNING, errmsg);
# Line 430 | Line 412 | printopts(void)                        /* print out option default values *
412                  printf("l+\t\t\t\t# light type on\n");
413          else
414                  printf("l-\t\t\t\t# light type off\n");
415 <        printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens);
416 <        printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps);
415 >        printf("d=%d\t\t\t\t# density of directions\n", thisillum.sampdens);
416 >        printf("s=%d\t\t\t\t# samples per direction\n", thisillum.nsamps);
417          printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt);
418 +        printf("t=%f\t\t\t# object thickness\n", thisillum.thick);
419   }
420  
421  
# Line 506 | Line 489 | xobject(                               /* translate an object from fp */
489          checkhead();
490                                                  /* process object */
491          if (doit)
492 <                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm);
492 >                switch (thisobj.otype) {
493 >                case OBJ_FACE:
494 >                        my_face(&thisobj, &thisillum, nm);
495 >                        break;
496 >                case OBJ_SPHERE:
497 >                        my_sphere(&thisobj, &thisillum, nm);
498 >                        break;
499 >                case OBJ_RING:
500 >                        my_ring(&thisobj, &thisillum, nm);
501 >                        break;
502 >                default:
503 >                        my_default(&thisobj, &thisillum, nm);
504 >                        break;
505 >                }
506          else
507                  printobj(thisillum.altmat, &thisobj);
508                                                  /* free arguments */
509          freefargs(&thisobj.oargs);
510          return;
511   readerr:
512 <        sprintf(errmsg, "(%s): error reading scene", nm);
512 >        sprintf(errmsg, "(%s): error reading input", nm);
513          error(USER, errmsg);
514   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines