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.27 by schorsch, Wed Jun 7 17:52:04 2006 UTC vs.
Revision 2.28 by greg, Thu Sep 13 06:31:21 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                  DFLMAT,
# 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
52 char    persistfn[] = "pfXXXXXX";       /* persist file name */
53
40   int     gargc;                  /* global argc */
41   char    **gargv;                /* global argv */
56 #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 < int done_rprocs(struct rtproc *rtp);
64 < void init(int np);
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 76 | Line 60 | main(          /* compute illum distributions using rtrace */
60   )
61   {
62          int     nprocs = 1;
79        char    *rtpath;
63          FILE    *fp;
64 +        int     rval;
65          register int    i;
66                                  /* set global arguments */
67          gargv = argv;
68 <                                /* check for -n option */
69 <        if (!strcmp(argv[1], "-n")) {
70 <                nprocs = atoi(argv[2]);
71 <                if (nprocs <= 0)
72 <                        error(USER, "illegal number of processes");
73 <                i = 3;
74 <        } else
75 <                i = 1;
76 <                                /* set up rtrace command */
77 <        for ( ; i < argc; i++) {
78 <                if (argv[i][0] == '<' && argv[i][1] == '\0')
68 >        progname = gargv[0];
69 >                                /* set up rendering defaults */
70 >        dstrsrc = 0.25;
71 >        directrelay = 3;
72 >        directvis = 0;
73 >        ambounce = 2;
74 >                                /* get options from command line */
75 >        for (i = 1; i < argc-1; i++) {
76 >                while ((rval = expandarg(&argc, &argv, i)) > 0)
77 >                        ;
78 >                if (rval < 0) {
79 >                        sprintf(errmsg, "cannot expand '%s'", argv[i]);
80 >                        error(SYSTEM, errmsg);
81 >                }
82 >                if (argv[i][0] != '-')
83                          break;
84 <                rtargv[rtargc++] = argv[i];
85 <                if (argv[i][0] == '-' && argv[i][1] == 'w')
86 <                        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);
84 >                if (!strcmp(argv[i], "-w")) {
85 >                        warnings = 0;
86 >                        continue;
87                  }
88 <                execv(rtpath, rtargv);
89 <                perror(rtpath); /* execv() should not return */
90 <                exit(1);
88 >                if (!strcmp(argv[i], "-n")) {
89 >                        nprocs = atoi(argv[++i]);
90 >                        if (nprocs <= 0)
91 >                                error(USER, "illegal number of processes");
92 >                        continue;
93 >                }
94 >                if (!strcmp(argv[i], "-defaults")) {
95 >                        printopts();
96 >                        print_rdefaults();
97 >                        quit(0);
98 >                }
99 >                rval = getrenderopt(argc-i, argv+i);
100 >                if (rval < 0) {
101 >                        sprintf(errmsg, "bad render option at '%s'", argv[i]);
102 >                        error(USER, errmsg);
103 >                }
104 >                i += rval;
105          }
106 <        if (gargc < 2 || argv[gargc-1][0] == '-')
106 >        gargc = ++i;
107 >                                /* add "mandatory" render options */
108 >        do_irrad = 0;
109 >        if (gargc > argc || argv[gargc-1][0] == '-')
110                  error(USER, "missing octree argument");
111                                  /* else initialize and run our calculation */
112 <        init(nprocs);
113 <        if (gargc+1 < argc)
112 >        init(argv[gargc-1], nprocs);
113 >        if (gargc < argc) {
114 >                if (gargc == argc-1 || argv[gargc][0] != '<' || argv[gargc][1])
115 >                        error(USER, "Use '< file1 file2 ..' for multiple inputs");
116                  for (i = gargc+1; i < argc; i++) {
117                          if ((fp = fopen(argv[i], "r")) == NULL) {
118                                  sprintf(errmsg,
# Line 152 | Line 122 | main(          /* compute illum distributions using rtrace */
122                          filter(fp, argv[i]);
123                          fclose(fp);
124                  }
125 <        else
125 >        } else
126                  filter(stdin, "standard input");
127          quit(0);
128          return 0; /* pro forma return */
129   }
130  
131  
162 #ifndef SIGALRM
163 #define SIGALRM SIGTERM
164 #endif
165 static void
166 killpersist(void)                       /* kill persistent rtrace process */
167 {
168        FILE    *fp = fopen(persistfn, "r");
169        int     pid;
170
171        if (fp == NULL)
172                return;
173        if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0)
174                unlink(persistfn);
175        fclose(fp);
176 }
177
178
179 int
180 done_rprocs(struct rtproc *rtp)
181 {
182        int     st0, st1 = 0;
183
184        if (rtp->next != NULL) {        /* close last opened first! */
185                st1 = done_rprocs(rtp->next);
186                free((void *)rtp->next);
187                rtp->next = NULL;
188        }
189        st0 = close_process(&rtp->pd);
190        if (st0 < 0)
191                error(WARNING, "unknown return status from rtrace process");
192        else if (st0 > 0)
193                return(st0);
194        return(st1);
195 }
196
132   void
133 < quit(int status)                        /* exit with status */
133 > init(char *octnm, int np)               /* start rendering process(es) */
134   {
200        int     rtstat;
201
202        if (rt0.next != NULL)           /* terminate persistent rtrace */
203                killpersist();
204                                        /* clean up rtrace process(es) */
205        rtstat = done_rprocs(&rt0);
206        if (status == 0)
207                status = rtstat;
208        exit(status);
209 }
210
211 void
212 init(int np)                            /* start rtrace and set up buffers */
213 {
214        struct rtproc   *rtp;
215        int     i;
216        int     maxbytes;
217                                        /* set up object functions */
218        ofun[OBJ_FACE].funp = o_face;
219        ofun[OBJ_SPHERE].funp = o_sphere;
220        ofun[OBJ_RING].funp = o_ring;
135                                          /* set up signal handling */
136          signal(SIGINT, quit);
137   #ifdef SIGHUP
# Line 229 | Line 143 | init(int np)                           /* start rtrace and set up buffers */
143   #ifdef SIGPIPE
144          signal(SIGPIPE, quit);
145   #endif
146 <        rtp = &rt0;                     /* start rtrace process(es) */
147 <        for (i = 0; i++ < np; ) {
234 <                errno = 0;
235 <                maxbytes = open_process(&rtp->pd, rtargv);
236 <                if (maxbytes == 0) {
237 <                        eputs(rtargv[0]);
238 <                        eputs(": command not found\n");
239 <                        exit(1);
240 <                }
241 <                if (maxbytes < 0)
242 <                        error(SYSTEM, "cannot start rtrace process");
243 <                rtp->bsiz = maxbytes/(6*sizeof(float));
244 <                rtp->buf = (float *)malloc(6*sizeof(float)*rtp->bsiz--);
245 <                rtp->dest = (float **)calloc(rtp->bsiz, sizeof(float *));
246 <                if (rtp->buf == NULL || rtp->dest == NULL)
247 <                        error(SYSTEM, "out of memory in init");
248 <                rtp->nrays = 0;
249 <                if (i == np)            /* last process? */
250 <                        break;
251 <                if (np > 1)
252 <                        sleep(2);       /* wait for persist file */
253 <                rtp->next = (struct rtproc *)malloc(sizeof(struct rtproc));
254 <                if (rtp->next == NULL)
255 <                        error(SYSTEM, "out of memory in init");
256 <                rtp = rtp->next;
257 <        }
258 <        rtp->next = NULL;
259 <                                        /* set up urand */
260 <        initurand(16384);
146 >                                        /* start rendering process(es) */
147 >        ray_pinit(octnm, np);
148   }
149  
150  
# Line 576 | Line 463 | xobject(                               /* translate an object from fp */
463          checkhead();
464                                                  /* process object */
465          if (doit)
466 <                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt0, nm);
466 >                switch (thisobj.otype) {
467 >                case OBJ_FACE:
468 >                        my_face(&thisobj, &thisillum, nm);
469 >                        break;
470 >                case OBJ_SPHERE:
471 >                        my_sphere(&thisobj, &thisillum, nm);
472 >                        break;
473 >                case OBJ_RING:
474 >                        my_ring(&thisobj, &thisillum, nm);
475 >                        break;
476 >                default:
477 >                        my_default(&thisobj, &thisillum, nm);
478 >                        break;
479 >                }
480          else
481                  printobj(thisillum.altmat, &thisobj);
482                                                  /* free arguments */
483          freefargs(&thisobj.oargs);
484          return;
485   readerr:
486 <        sprintf(errmsg, "(%s): error reading scene", nm);
486 >        sprintf(errmsg, "(%s): error reading input", nm);
487          error(USER, errmsg);
488   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines