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 1.1 by greg, Tue Jul 23 12:00:29 1991 UTC vs.
Revision 1.2 by greg, Tue Jul 23 16:13:28 1991 UTC

# Line 8 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   * Make illum sources for optimizing rendering process
9   */
10  
11 < #include  "standard.h"
11 > #include  "mkillum.h"
12  
13 < #include  "object.h"
13 > #include  <ctype.h>
14  
15 #include  "otypes.h"
16
15                                  /* default parameters */
16   #define  SAMPDENS       128             /* points per projected steradian */
17   #define  NSAMPS         32              /* samples per point */
# Line 31 | Line 29 | int  rtargc = 13;
29                                  /* overriding rtrace options */
30   char  *myrtopts[] = { "-I-", "-i-", "-di+", "-ov", "-h-", "-fff", NULL };
31  
32 <                                /* illum flags */
35 < #define  IL_FLAT        0x1             /* flat surface */
36 < #define  IL_LIGHT       0x2             /* light rather than illum */
37 < #define  IL_COLDST      0x4             /* colored distribution */
38 < #define  IL_COLAVG      0x8             /* compute average color */
39 < #define  IL_DATCLB      0x10            /* OK to clobber data file */
32 > struct rtproc   rt;             /* our rtrace process */
33  
34 < struct illum_args {
35 <        int     flags;                  /* flags from list above */
36 <        char    matname[MAXSTR];        /* illum material name */
37 <        char    datafile[MAXSTR];       /* distribution data file name */
38 <        int     dfnum;                  /* data file number */
39 <        char    altmatname[MAXSTR];     /* alternate material name */
40 <        int     nsamps;                 /* # of samples in each direction */
41 <        int     nalt, nazi;             /* # of altitude and azimuth angles */
49 <        FVECT   orient;                 /* coordinate system orientation */
50 < } thisillum = {                 /* default values */
51 <        0,
52 <        DFLMAT,
53 <        DFLMAT,
54 <        0,
55 <        VOIDID,
56 <        NSAMPS,
57 < };
34 > struct illum_args  thisillum = {        /* our illum and default values */
35 >                0,
36 >                DFLMAT,
37 >                DFLMAT,
38 >                0,
39 >                VOIDID,
40 >                NSAMPS,
41 >        };
42  
43   int     sampdens = SAMPDENS;    /* sample point density */
44   char    matcheck[MAXSTR];       /* current material to include or exclude */
45   int     matselect = S_ALL;      /* selection criterion */
46  
47 < int     rt_pd[3];               /* rtrace pipe descriptors */
64 < float   *rt_buf;                /* rtrace i/o buffer */
65 < int     rt_bsiz;                /* maximum rays for rtrace buffer */
66 < int     rt_nrays;               /* current length of rtrace buffer */
47 > FUN     ofun[NUMOTYPE] = INIT_OTYPE;    /* object types */
48  
49   int     gargc;                  /* global argc */
50   char    **gargv;                /* global argv */
51   #define  progname       gargv[0]
52  
53   int     doneheader = 0;         /* printed header yet? */
54 + #define  checkhead()    if (!doneheader++) printhead(gargc,gargv)
55  
56 + int     warnings = 1;           /* print warnings? */
57 +
58   extern char     *fgetline(), *fgetword(), *sskip(),
59                  *atos(), *iskip(), *fskip();
60   extern FILE     *popen();
# Line 88 | Line 72 | char   *argv[];
72                                  /* set up rtrace command */
73          if (argc < 2)
74                  error(USER, "too few arguments");
75 <        for (i = 1; i < argc-1; i++)
75 >        for (i = 1; i < argc-1; i++) {
76                  rtargv[rtargc++] = argv[i];
77 +                if (argv[i][0] == '-' && argv[i][1] == 'w')
78 +                        warnings = !warnings;
79 +        }
80          for (i = 0; myrtopts[i] != NULL; i++)
81                  rtargv[rtargc++] = myrtopts[i];
82          rtargv[rtargc++] = argv[argc-1];
# Line 108 | Line 95 | char   *argv[];
95          }
96                                  /* else initialize and run our calculation */
97          init();
98 <        mkillum(stdin, "standard input");
99 <        exit(cleanup());        /* cleanup returns rtrace status */
98 >        filter(stdin, "standard input");
99 >        quit(0);
100   }
101  
102  
# Line 117 | Line 104 | init()                         /* start rtrace and set up buffers */
104   {
105          int     maxbytes;
106  
107 <        maxbytes = open_process(rt_pd, rtargv);
107 >        maxbytes = open_process(rt.pd, rtargv);
108          if (maxbytes == 0) {
109                  eputs(rtargv[0]);
110                  eputs(": command not found\n");
# Line 125 | Line 112 | init()                         /* start rtrace and set up buffers */
112          }
113          if (maxbytes < 0)
114                  error(SYSTEM, "cannot start rtrace process");
115 <        rt_bsiz = maxbytes/(6*sizeof(float));
116 <        rt_buf = (float *)malloc(rt_bsiz*(6*sizeof(float)));
117 <        if (rt_buf == NULL)
115 >        rt.bsiz = maxbytes/(6*sizeof(float));
116 >        rt.buf = (float *)malloc(rt.bsiz*(6*sizeof(float)));
117 >        if (rt.buf == NULL)
118                  error(SYSTEM, "out of memory in init");
119 <        rt_bsiz--;                      /* allow for flush ray */
120 <        rt_nrays = 0;
119 >        rt.bsiz--;                      /* allow for flush ray */
120 >        rt.nrays = 0;
121   }
122  
123  
124 < int
125 < cleanup()                       /* close rtrace process and return status */
124 > quit(status)                    /* exit with status */
125 > int  status;
126   {
127 <        int     status;
127 >        int     rtstat;
128  
129 <        free((char *)rt_buf);
130 <        rt_bsiz = 0;
131 <        status = close_process(rt_pd);
132 <        if (status < 0)
133 <                return(0);              /* unknown status */
134 <        return(status);
129 >        rtstat = close_process(rt.pd);
130 >        if (status == 0)
131 >                if (rtstat < 0)
132 >                        error(WARNING,
133 >                        "unknown return status from rtrace process");
134 >                else
135 >                        status = rtstat;
136 >        exit(status);
137   }
138  
139  
# Line 163 | Line 152 | register char  *s;
152   }
153  
154  
155 < mkillum(infp, name)             /* process stream */
155 > wputs(s)                        /* print warning if enabled */
156 > char  *s;
157 > {
158 >        if (warnings)
159 >                eputs(s);
160 > }
161 >
162 >
163 > filter(infp, name)              /* process stream */
164   register FILE   *infp;
165   char    *name;
166   {
# Line 177 | Line 174 | char   *name;
174                  if (c == '#') {                         /* comment/options */
175                          buf[0] = c;
176                          fgets(buf+1, sizeof(buf)-1, infp);
177 <                        fputs(buf, stdout);
181 <                        getoptions(buf, name);
177 >                        xoptions(buf, name);
178                  } else if (c == '!') {                  /* command */
179                          buf[0] = c;
180                          fgetline(buf+1, sizeof(buf)-1, infp);
# Line 186 | Line 182 | char   *name;
182                                  sprintf(errmsg, "cannot execute \"%s\"", buf);
183                                  error(SYSTEM, errmsg);
184                          }
185 <                        mkillum(pfp, buf);
185 >                        filter(pfp, buf);
186                          pclose(pfp);
187                  } else {                                /* object */
188                          ungetc(c, infp);
# Line 196 | Line 192 | char   *name;
192   }
193  
194  
195 < getoptions(s, nm)               /* get options from string s */
195 > xoptions(s, nm)                 /* process options in string s */
196   char    *s;
197   char    *nm;
198   {
# Line 205 | Line 201 | char   *nm;
201          int     nerrs = 0;
202          register char   *cp;
203  
204 <        if (strncmp(s, "#@mkillum", 9) || !isspace(s[9]))
204 >        if (strncmp(s, "#@mkillum", 9) || !isspace(s[9])) {
205 >                fputs(s, stdout);               /* not for us */
206                  return;
207 +        }
208          cp = s+10;
209          while (*cp) {
210                  switch (*cp) {
# Line 216 | Line 214 | char   *nm;
214                          cp++;
215                          continue;
216                  case 'm':                       /* material name */
217 <                        cp++;
220 <                        if (*cp != '=')
217 >                        if (*++cp != '=')
218                                  break;
219 <                        cp++;
219 >                        if (!*++cp)
220 >                                break;
221                          atos(thisillum.matname, MAXSTR, cp);
222                          cp = sskip(cp);
223                          if (!(thisillum.flags & IL_DATCLB)) {
# Line 228 | Line 226 | char   *nm;
226                          }
227                          continue;
228                  case 'f':                       /* data file name */
229 <                        cp++;
232 <                        if (*cp != '=')
229 >                        if (*++cp != '=')
230                                  break;
231 <                        cp++;
235 <                        if (*cp == '\0') {
231 >                        if (!*++cp) {
232                                  thisillum.flags &= ~IL_DATCLB;
233                                  continue;
234                          }
# Line 243 | Line 239 | char   *nm;
239                          continue;
240                  case 'i':                       /* include material */
241                  case 'e':                       /* exclude material */
242 <                        matselect = (*cp++ == 'i') ? S_ELEM : S_COMPL;
243 <                        if (*cp != '=')
242 >                        matselect = (*cp == 'i') ? S_ELEM : S_COMPL;
243 >                        if (*++cp != '=')
244                                  break;
245 <                        cp++;
250 <                        atos(matcheck, MAXSTR, cp);
245 >                        atos(matcheck, MAXSTR, ++cp);
246                          cp = sskip(cp);
247                          continue;
248                  case 'a':                       /* use everything */
# Line 259 | Line 254 | char   *nm;
254                          matselect = S_NONE;
255                          continue;
256                  case 'c':                       /* color calculation */
257 <                        cp++;
263 <                        if (*cp != '=')
257 >                        if (*++cp != '=')
258                                  break;
259 <                        cp++;
266 <                        switch (*cp) {
259 >                        switch (*++cp) {
260                          case 'a':                       /* average */
261                                  thisillum.flags |= IL_COLAVG;
262                                  thisillum.flags &= ~IL_COLDST;
# Line 281 | Line 274 | char   *nm;
274                          cp = sskip(cp);
275                          continue;
276                  case 'd':                       /* point sample density */
277 <                        cp++;
285 <                        if (*cp != '=')
277 >                        if (*++cp != '=')
278                                  break;
279 <                        cp++;
288 <                        if (!isintd(cp, " \t\n"))
279 >                        if (!isintd(++cp, " \t\n"))
280                                  break;
281                          sampdens = atoi(cp);
282                          cp = sskip(cp);
283                          continue;
284                  case 's':                       /* point super-samples */
285 <                        cp++;
295 <                        if (*cp != '=')
285 >                        if (*++cp != '=')
286                                  break;
287 <                        cp++;
298 <                        if (!isintd(cp, " \t\n"))
287 >                        if (!isintd(++cp, " \t\n"))
288                                  break;
289                          thisillum.nsamps = atoi(cp);
290                          cp = sskip(cp);
291                          continue;
292                  case 'o':                       /* output file */
293 <                        cp++;
305 <                        if (*cp != '=')
293 >                        if (*++cp != '=')
294                                  break;
295 <                        cp++;
295 >                        if (!*++cp)
296 >                                break;
297                          atos(buf, sizeof(buf), cp);
298                          cp = sskip(cp);
299                          if (freopen(buf, "w", stdout) == NULL) {
# Line 319 | Line 308 | char   *nm;
308                  cp = sskip(cp);
309                  nerrs++;
310          }
311 +                                                /* print header? */
312 +        checkhead();
313 +                                                /* issue warnings? */
314          if (nerrs) {
315                  sprintf(errmsg, "(%s): %d error(s) in option line:",
316                                  nm, nerrs);
317                  error(WARNING, errmsg);
318 <                eputs(s);
318 >                wputs(s);
319 >                printf("# %s: the following option line has %d error(s):\n",
320 >                                progname, nerrs);
321          }
322 +                                                /* print pure comment */
323 +        putchar('#'); putchar(' '); fputs(s+2, stdout);
324   }
325 +
326 +
327 + printhead(ac, av)                       /* print out header */
328 + register int  ac;
329 + register char  **av;
330 + {
331 +        putchar('#');
332 +        while (ac-- > 0) {
333 +                putchar(' ');
334 +                fputs(*av++, stdout);
335 +        }
336 +        putchar('\n');
337 + }
338 +
339 +
340 + xobject(fp, nm)                         /* translate an object from fp */
341 + FILE  *fp;
342 + char  *nm;
343 + {
344 +        OBJREC  thisobj;
345 +        char  str[MAXSTR];
346 +        int  doit;
347 +                                        /* read the object */
348 +        if (fgetword(thisillum.altmat, MAXSTR, fp) == NULL)
349 +                goto readerr;
350 +        if (fgetword(str, MAXSTR, fp) == NULL)
351 +                goto readerr;
352 +                                        /* is it an alias? */
353 +        if (!strcmp(str, ALIASID)) {
354 +                if (fgetword(str, MAXSTR, fp) == NULL)
355 +                        goto readerr;
356 +                printf("\n%s %s %s", thisillum.altmat, ALIASID, str);
357 +                if (fgetword(str, MAXSTR, fp) == NULL)
358 +                        goto readerr;
359 +                printf(" %s\n", str);
360 +                return;
361 +        }
362 +        thisobj.omod = OVOID;
363 +        if ((thisobj.otype = otype(str)) < 0) {
364 +                sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str);
365 +                error(USER, errmsg);
366 +        }
367 +        if (fgetword(str, MAXSTR, fp) == NULL)
368 +                goto readerr;
369 +        thisobj.oname = str;
370 +        if (readfargs(&thisobj.oargs, fp) != 1)
371 +                goto readerr;
372 +        thisobj.os = NULL;
373 +                                        /* check for translation */
374 +        switch (matselect) {
375 +        case S_NONE:
376 +                doit = 0;
377 +                break;
378 +        case S_ALL:
379 +                doit = issurface(thisobj.otype);
380 +                break;
381 +        case S_ELEM:
382 +                doit = !strcmp(thisillum.altmat, matcheck);
383 +                break;
384 +        case S_COMPL:
385 +                doit = strcmp(thisillum.altmat, matcheck);
386 +                break;
387 +        }
388 +        if (doit)                               /* make sure we can do it */
389 +                switch (thisobj.otype) {
390 +                case OBJ_SPHERE:
391 +                case OBJ_FACE:
392 +                case OBJ_RING:
393 +                        break;
394 +                default:
395 +                        sprintf(errmsg,
396 +                                "(%s): cannot make illum for %s \"%s\"",
397 +                                        nm, ofun[thisobj.otype].funame,
398 +                                        thisobj.oname);
399 +                        error(WARNING, errmsg);
400 +                        doit = 0;
401 +                        break;
402 +                }
403 +                                                /* print header? */
404 +        checkhead();
405 +                                                /* process object */
406 +        if (doit)
407 +                mkillum(&thisobj, &thisillum, &rt);
408 +        else
409 +                printobj(thisillum.altmat, &thisobj);
410 +                                                /* free arguments */
411 +        freefargs(&thisobj.oargs);
412 +        return;
413 + readerr:
414 +        sprintf(errmsg, "(%s): error reading scene", nm);
415 +        error(USER, errmsg);
416 + }
417 +
418 +
419 + int
420 + otype(ofname)                   /* get object function number from its name */
421 + char  *ofname;
422 + {
423 +        register int  i;
424 +
425 +        for (i = 0; i < NUMOTYPE; i++)
426 +                if (!strcmp(ofun[i].funame, ofname))
427 +                        return(i);
428 +
429 +        return(-1);             /* not found */
430 + }
431 +
432 +
433 + o_default() {}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines