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.3 by greg, Tue Jul 23 17:18:21 1991 UTC vs.
Revision 2.11 by greg, Sat Feb 22 02:07:24 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Make illum sources for optimizing rendering process
6   */
# Line 15 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12   #include  <ctype.h>
13  
14                                  /* default parameters */
15 < #define  SAMPDENS       128             /* points per projected steradian */
15 > #define  SAMPDENS       48              /* points per projected steradian */
16   #define  NSAMPS         32              /* samples per point */
17   #define  DFLMAT         "illum_mat"     /* material name */
18 + #define  DFLDAT         "illum"         /* data file name */
19                                  /* selection options */
20   #define  S_NONE         0               /* select none */
21   #define  S_ELEM         1               /* select specified element */
# Line 25 | Line 23 | static char SCCSid[] = "$SunId$ LBL";
23   #define  S_ALL          3               /* select all */
24  
25                                  /* rtrace command and defaults */
26 < char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-ab", "2",
27 <                "-ad", "256", "-as", "128", "-aa", ".15" };
28 < int  rtargc = 13;
26 > char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-",
27 >                "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", };
28 > int  rtargc = 14;
29                                  /* overriding rtrace options */
30 < char  *myrtopts[] = { "-I-", "-i-", "-di+", "-ov", "-h-", "-fff", NULL };
30 > char  *myrtopts[] = { "-I-", "-i-", "-ld-", "-ov", "-h-",
31 >                        "-fff", "-y", "0", NULL };
32  
33   struct rtproc   rt;             /* our rtrace process */
34  
35   struct illum_args  thisillum = {        /* our illum and default values */
36                  0,
37                  DFLMAT,
38 <                DFLMAT,
38 >                DFLDAT,
39                  0,
40                  VOIDID,
41                  SAMPDENS,
42                  NSAMPS,
43 +                0.,
44          };
45  
46   char    matcheck[MAXSTR];       /* current material to include or exclude */
# Line 57 | Line 57 | int    doneheader = 0;         /* printed header yet? */
57  
58   int     warnings = 1;           /* print warnings? */
59  
60 extern char     *fgetline(), *fgetword(), *sskip(),
61                *atos(), *iskip(), *fskip();
62 extern FILE     *popen();
60  
64
61   main(argc, argv)                /* compute illum distributions using rtrace */
62   int     argc;
63   char    *argv[];
64   {
69        extern char     *getenv(), *getpath();
65          char    *rtpath;
66          FILE    *fp;
67          register int    i;
# Line 74 | Line 69 | char   *argv[];
69          gargv = argv;
70                                  /* set up rtrace command */
71          for (i = 1; i < argc; i++) {
72 <                if (argv[i][0] == '<' && !argv[i][1])
72 >                if (argv[i][0] == '<' && argv[i][1] == '\0')
73                          break;
74                  rtargv[rtargc++] = argv[i];
75                  if (argv[i][0] == '-' && argv[i][1] == 'w')
76 <                        warnings = !warnings;
76 >                        switch (argv[i][2]) {
77 >                        case '\0':
78 >                                warnings = !warnings;
79 >                                break;
80 >                        case '+':
81 >                        case 'T': case 't':
82 >                        case 'Y': case 'y':
83 >                        case '1':
84 >                                warnings = 1;
85 >                                break;
86 >                        case '-':
87 >                        case 'F': case 'f':
88 >                        case 'N': case 'n':
89 >                        case '0':
90 >                                warnings = 0;
91 >                                break;
92 >                        }
93          }
94 <        if ((gargc = i) < 2)
84 <                error(USER, "too few arguments");
94 >        gargc = i;
95          rtargc--;
96          for (i = 0; myrtopts[i] != NULL; i++)
97                  rtargv[rtargc++] = myrtopts[i];
# Line 89 | Line 99 | char   *argv[];
99          rtargv[rtargc] = NULL;
100                                  /* just asking for defaults? */
101          if (!strcmp(argv[gargc-1], "-defaults")) {
102 +                printopts(); fflush(stdout);
103                  rtpath = getpath(rtargv[0], getenv("PATH"), X_OK);
104                  if (rtpath == NULL) {
105                          eputs(rtargv[0]);
# Line 99 | Line 110 | char   *argv[];
110                  perror(rtpath);
111                  exit(1);
112          }
113 +        if (gargc < 2 || argv[gargc-1][0] == '-')
114 +                error(USER, "missing octree argument");
115                                  /* else initialize and run our calculation */
116          init();
117          if (gargc+1 < argc)
118                  for (i = gargc+1; i < argc; i++) {
119 <                        if ((fp = fopen(argv[i], "r")) == NULL {
119 >                        if ((fp = fopen(argv[i], "r")) == NULL) {
120                                  sprintf(errmsg,
121                                  "cannot open scene file \"%s\"", argv[i]);
122                                  error(SYSTEM, errmsg);
# Line 117 | Line 130 | char   *argv[];
130   }
131  
132  
133 + void
134   quit(status)                    /* exit with status */
135   int  status;
136   {
# Line 135 | Line 149 | int  status;
149  
150   init()                          /* start rtrace and set up buffers */
151   {
152 <        extern int  o_face(), o_ring();
152 >        extern int  o_face(), o_sphere(), o_ring();
153          int     maxbytes;
154                                          /* set up object functions */
155          ofun[OBJ_FACE].funp = o_face;
156 +        ofun[OBJ_SPHERE].funp = o_sphere;
157          ofun[OBJ_RING].funp = o_ring;
158                                          /* set up signal handling */
159          signal(SIGPIPE, quit);
160                                          /* start rtrace process */
161 +        errno = 0;
162          maxbytes = open_process(rt.pd, rtargv);
163          if (maxbytes == 0) {
164                  eputs(rtargv[0]);
# Line 152 | Line 168 | init()                         /* start rtrace and set up buffers */
168          if (maxbytes < 0)
169                  error(SYSTEM, "cannot start rtrace process");
170          rt.bsiz = maxbytes/(6*sizeof(float));
171 <        rt.buf = (float *)malloc(rt.bsiz*(6*sizeof(float)));
172 <        if (rt.buf == NULL)
171 >        rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--);
172 >        rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz);
173 >        if (rt.buf == NULL || rt.dest == NULL)
174                  error(SYSTEM, "out of memory in init");
158        rt.bsiz--;                      /* allow for flush ray */
175          rt.nrays = 0;
176 +                                        /* set up urand */
177 +        initurand(16384);
178   }
179  
180  
181 + void
182   eputs(s)                                /* put string to stderr */
183   register char  *s;
184   {
# Line 175 | Line 194 | register char  *s;
194   }
195  
196  
197 + void
198   wputs(s)                        /* print warning if enabled */
199   char  *s;
200   {
# Line 234 | Line 254 | char   *nm;
254                  case ' ':
255                  case '\t':
256                  case '\n':
257 +                case '\r':
258 +                case '\f':
259                          cp++;
260                          continue;
261                  case 'm':                       /* material name */
262                          if (*++cp != '=')
263                                  break;
264 <                        if (!*++cp)
264 >                        if (!*++cp || isspace(*cp))
265                                  break;
266                          atos(thisillum.matname, MAXSTR, cp);
267                          cp = sskip(cp);
# Line 251 | Line 273 | char   *nm;
273                  case 'f':                       /* data file name */
274                          if (*++cp != '=')
275                                  break;
276 <                        if (!*++cp) {
276 >                        if (!*++cp || isspace(*cp)) {
277 >                                strcpy(thisillum.datafile,thisillum.matname);
278 >                                thisillum.dfnum = 0;
279                                  thisillum.flags &= ~IL_DATCLB;
280                                  continue;
281                          }
# Line 262 | Line 286 | char   *nm;
286                          continue;
287                  case 'i':                       /* include material */
288                  case 'e':                       /* exclude material */
289 <                        matselect = (*cp == 'i') ? S_ELEM : S_COMPL;
266 <                        if (*++cp != '=')
289 >                        if (cp[1] != '=')
290                                  break;
291 <                        atos(matcheck, MAXSTR, ++cp);
291 >                        matselect = (*cp == 'i') ? S_ELEM : S_COMPL;
292 >                        cp += 2;
293 >                        atos(matcheck, MAXSTR, cp);
294                          cp = sskip(cp);
295                          continue;
296                  case 'a':                       /* use everything */
# Line 281 | Line 306 | char   *nm;
306                                  break;
307                          switch (*++cp) {
308                          case 'a':                       /* average */
309 <                                thisillum.flags |= IL_COLAVG;
310 <                                thisillum.flags &= ~IL_COLDST;
309 >                                thisillum.flags = (thisillum.flags|IL_COLAVG)
310 >                                                        & ~IL_COLDST;
311                                  break;
312                          case 'd':                       /* distribution */
313 <                                thisillum.flags |= IL_COLDST;
289 <                                thisillum.flags &= ~IL_COLAVG;
313 >                                thisillum.flags |= (IL_COLDST|IL_COLAVG);
314                                  break;
315                          case 'n':                       /* none */
316                                  thisillum.flags &= ~(IL_COLAVG|IL_COLDST);
# Line 299 | Line 323 | char   *nm;
323                  case 'd':                       /* point sample density */
324                          if (*++cp != '=')
325                                  break;
326 <                        if (!isintd(++cp, " \t\n"))
326 >                        if (!isintd(++cp, " \t\n\r"))
327                                  break;
328                          thisillum.sampdens = atoi(cp);
329                          cp = sskip(cp);
# Line 307 | Line 331 | char   *nm;
331                  case 's':                       /* point super-samples */
332                          if (*++cp != '=')
333                                  break;
334 <                        if (!isintd(++cp, " \t\n"))
334 >                        if (!isintd(++cp, " \t\n\r"))
335                                  break;
336                          thisillum.nsamps = atoi(cp);
337                          cp = sskip(cp);
338                          continue;
339                  case 'l':                       /* light sources */
340 <                        if (*++cp != '+' && *cp != '-')
341 <                                break;
318 <                        if (*cp++ == '+')
340 >                        cp++;
341 >                        if (*cp == '+')
342                                  thisillum.flags |= IL_LIGHT;
343 <                        else
343 >                        else if (*cp == '-')
344                                  thisillum.flags &= ~IL_LIGHT;
345 +                        else
346 +                                break;
347 +                        cp++;
348                          continue;
349 +                case 'b':                       /* brightness */
350 +                        if (*++cp != '=')
351 +                                break;
352 +                        if (!isfltd(++cp, " \t\n\r"))
353 +                                break;
354 +                        thisillum.minbrt = atof(cp);
355 +                        if (thisillum.minbrt < 0.)
356 +                                thisillum.minbrt = 0.;
357 +                        cp = sskip(cp);
358 +                        continue;
359                  case 'o':                       /* output file */
360                          if (*++cp != '=')
361                                  break;
362 <                        if (!*++cp)
362 >                        if (!*++cp || isspace(*cp))
363                                  break;
364                          atos(buf, sizeof(buf), cp);
365                          cp = sskip(cp);
# Line 334 | Line 370 | char   *nm;
370                          }
371                          doneheader = 0;
372                          continue;
373 +                case '!':                       /* processed file! */
374 +                        sprintf(errmsg, "(%s): already processed!", nm);
375 +                        error(WARNING, errmsg);
376 +                        matselect = S_NONE;
377 +                        return;
378                  }
379          opterr:                                 /* skip faulty option */
380 <                cp = sskip(cp);
380 >                while (*cp && !isspace(*cp))
381 >                        cp++;
382                  nerrs++;
383          }
384                                                  /* print header? */
# Line 351 | Line 393 | char   *nm;
393                                  progname, nerrs);
394          }
395                                                  /* print pure comment */
396 <        putchar('#'); putchar(' '); fputs(s+2, stdout);
396 >        printf("# %s", s+2);
397   }
398  
399  
400 + printopts()                     /* print out option default values */
401 + {
402 +        printf("m=%-15s\t\t# material name\n", thisillum.matname);
403 +        printf("f=%-15s\t\t# data file name\n", thisillum.datafile);
404 +        if (thisillum.flags & IL_COLAVG)
405 +                if (thisillum.flags & IL_COLDST)
406 +                        printf("c=d\t\t\t\t# color distribution\n");
407 +                else
408 +                        printf("c=a\t\t\t\t# color average\n");
409 +        else
410 +                printf("c=n\t\t\t\t# color none\n");
411 +        if (thisillum.flags & IL_LIGHT)
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);
417 +        printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt);
418 + }
419 +
420 +
421   printhead(ac, av)                       /* print out header */
422   register int  ac;
423   register char  **av;
# Line 364 | Line 427 | register char  **av;
427                  putchar(' ');
428                  fputs(*av++, stdout);
429          }
430 <        putchar('\n');
430 >        fputs("\n#@mkillum !\n", stdout);
431   }
432  
433  
# Line 387 | Line 450 | char  *nm;
450                  printf("\n%s %s %s", thisillum.altmat, ALIASID, str);
451                  if (fgetword(str, MAXSTR, fp) == NULL)
452                          goto readerr;
453 <                printf(" %s\n", str);
453 >                printf("\t%s\n", str);
454                  return;
455          }
456 <        thisobj.omod = OVOID;
456 >        thisobj.omod = OVOID;           /* unused field */
457          if ((thisobj.otype = otype(str)) < 0) {
458                  sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str);
459                  error(USER, errmsg);
# Line 407 | Line 470 | char  *nm;
470                  doit = 0;
471                  break;
472          case S_ALL:
473 <                doit = issurface(thisobj.otype);
473 >                doit = 1;
474                  break;
475          case S_ELEM:
476                  doit = !strcmp(thisillum.altmat, matcheck);
# Line 416 | Line 479 | char  *nm;
479                  doit = strcmp(thisillum.altmat, matcheck);
480                  break;
481          }
482 <        if (doit && ofun[thisobj.otype].funp == o_default) {
420 <                sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"",
421 <                                nm, ofun[thisobj.otype].funame, thisobj.oname);
422 <                error(WARNING, errmsg);
423 <                doit = 0;
424 <        }
482 >        doit = doit && issurface(thisobj.otype);
483                                                  /* print header? */
484          checkhead();
485                                                  /* process object */
486          if (doit)
487 <                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt);
487 >                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm);
488          else
489                  printobj(thisillum.altmat, &thisobj);
490                                                  /* free arguments */
# Line 436 | Line 494 | readerr:
494          sprintf(errmsg, "(%s): error reading scene", nm);
495          error(USER, errmsg);
496   }
439
440
441 int
442 otype(ofname)                   /* get object function number from its name */
443 char  *ofname;
444 {
445        register int  i;
446
447        for (i = 0; i < NUMOTYPE; i++)
448                if (!strcmp(ofun[i].funame, ofname))
449                        return(i);
450
451        return(-1);             /* not found */
452 }
453
454
455 o_default() {}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines