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.7 by greg, Thu Jul 25 12:52:16 1991 UTC vs.
Revision 2.14 by schorsch, Thu Jun 26 00:58:09 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   */
7  
11 #include  "mkillum.h"
12
8   #include  <signal.h>
14
9   #include  <ctype.h>
10 + #include  <stdio.h>
11  
12 + #include  "standard.h"
13 + #include  "platform.h"
14 + #include  "mkillum.h"
15 +
16                                  /* default parameters */
17 < #define  SAMPDENS       128             /* points per projected steradian */
17 > #define  SAMPDENS       48              /* points per projected steradian */
18   #define  NSAMPS         32              /* samples per point */
19   #define  DFLMAT         "illum_mat"     /* material name */
20 + #define  DFLDAT         "illum"         /* data file name */
21                                  /* selection options */
22   #define  S_NONE         0               /* select none */
23   #define  S_ELEM         1               /* select specified element */
# Line 25 | Line 25 | static char SCCSid[] = "$SunId$ LBL";
25   #define  S_ALL          3               /* select all */
26  
27                                  /* rtrace command and defaults */
28 < char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-di+",
28 > char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-",
29                  "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", };
30   int  rtargc = 14;
31                                  /* overriding rtrace options */
32 < char  *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", NULL };
32 > char  *myrtopts[] = { "-I-", "-i-", "-ld-", "-ov", "-h-",
33 >                        "-fff", "-y", "0", NULL };
34  
35   struct rtproc   rt;             /* our rtrace process */
36  
37   struct illum_args  thisillum = {        /* our illum and default values */
38                  0,
39                  DFLMAT,
40 <                DFLMAT,
40 >                DFLDAT,
41                  0,
42                  VOIDID,
43                  SAMPDENS,
44                  NSAMPS,
45 +                0.,
46          };
47  
48   char    matcheck[MAXSTR];       /* current material to include or exclude */
# Line 57 | Line 59 | int    doneheader = 0;         /* printed header yet? */
59  
60   int     warnings = 1;           /* print warnings? */
61  
60 extern char     *fgetline(), *fgetword(), *sskip(),
61                *atos(), *iskip(), *fskip(), *strcpy();
62 extern FILE     *popen();
62  
64
63   main(argc, argv)                /* compute illum distributions using rtrace */
64   int     argc;
65   char    *argv[];
66   {
69        extern char     *getenv(), *getpath();
67          char    *rtpath;
68          FILE    *fp;
69          register int    i;
# Line 74 | Line 71 | char   *argv[];
71          gargv = argv;
72                                  /* set up rtrace command */
73          for (i = 1; i < argc; i++) {
74 <                if (argv[i][0] == '<' && !argv[i][1])
74 >                if (argv[i][0] == '<' && argv[i][1] == '\0')
75                          break;
76                  rtargv[rtargc++] = argv[i];
77                  if (argv[i][0] == '-' && argv[i][1] == 'w')
78 <                        warnings = !warnings;
78 >                        switch (argv[i][2]) {
79 >                        case '\0':
80 >                                warnings = !warnings;
81 >                                break;
82 >                        case '+':
83 >                        case 'T': case 't':
84 >                        case 'Y': case 'y':
85 >                        case '1':
86 >                                warnings = 1;
87 >                                break;
88 >                        case '-':
89 >                        case 'F': case 'f':
90 >                        case 'N': case 'n':
91 >                        case '0':
92 >                                warnings = 0;
93 >                                break;
94 >                        }
95          }
96 <        if ((gargc = i) < 2)
84 <                error(USER, "too few arguments");
96 >        gargc = i;
97          rtargc--;
98          for (i = 0; myrtopts[i] != NULL; i++)
99                  rtargv[rtargc++] = myrtopts[i];
# Line 89 | Line 101 | char   *argv[];
101          rtargv[rtargc] = NULL;
102                                  /* just asking for defaults? */
103          if (!strcmp(argv[gargc-1], "-defaults")) {
104 +                printopts(); fflush(stdout);
105                  rtpath = getpath(rtargv[0], getenv("PATH"), X_OK);
106                  if (rtpath == NULL) {
107                          eputs(rtargv[0]);
# Line 99 | Line 112 | char   *argv[];
112                  perror(rtpath);
113                  exit(1);
114          }
115 +        if (gargc < 2 || argv[gargc-1][0] == '-')
116 +                error(USER, "missing octree argument");
117                                  /* else initialize and run our calculation */
118          init();
119          if (gargc+1 < argc)
# Line 117 | Line 132 | char   *argv[];
132   }
133  
134  
135 + void
136   quit(status)                    /* exit with status */
137   int  status;
138   {
139          int     rtstat;
140  
141 <        rtstat = close_process(rt.pd);
141 >        rtstat = close_process(&(rt.pd));
142          if (status == 0)
143                  if (rtstat < 0)
144                          error(WARNING,
# Line 142 | Line 158 | init()                         /* start rtrace and set up buffers */
158          ofun[OBJ_SPHERE].funp = o_sphere;
159          ofun[OBJ_RING].funp = o_ring;
160                                          /* set up signal handling */
161 + #ifdef SIGPIPE /* not present on Windows */
162          signal(SIGPIPE, quit);
163 + #endif
164                                          /* start rtrace process */
165 <        maxbytes = open_process(rt.pd, rtargv);
165 >        errno = 0;
166 >        maxbytes = open_process(&(rt.pd), rtargv);
167          if (maxbytes == 0) {
168                  eputs(rtargv[0]);
169                  eputs(": command not found\n");
# Line 159 | Line 178 | init()                         /* start rtrace and set up buffers */
178                  error(SYSTEM, "out of memory in init");
179          rt.nrays = 0;
180                                          /* set up urand */
181 <        initurand(2048);
181 >        initurand(16384);
182   }
183  
184  
185 + void
186   eputs(s)                                /* put string to stderr */
187   register char  *s;
188   {
# Line 178 | Line 198 | register char  *s;
198   }
199  
200  
201 + void
202   wputs(s)                        /* print warning if enabled */
203   char  *s;
204   {
# Line 237 | Line 258 | char   *nm;
258                  case ' ':
259                  case '\t':
260                  case '\n':
261 +                case '\r':
262 +                case '\f':
263                          cp++;
264                          continue;
265                  case 'm':                       /* material name */
266                          if (*++cp != '=')
267                                  break;
268 <                        if (!*++cp)
268 >                        if (!*++cp || isspace(*cp))
269                                  break;
270                          atos(thisillum.matname, MAXSTR, cp);
271                          cp = sskip(cp);
# Line 254 | Line 277 | char   *nm;
277                  case 'f':                       /* data file name */
278                          if (*++cp != '=')
279                                  break;
280 <                        if (!*++cp) {
280 >                        if (!*++cp || isspace(*cp)) {
281                                  strcpy(thisillum.datafile,thisillum.matname);
282 +                                thisillum.dfnum = 0;
283                                  thisillum.flags &= ~IL_DATCLB;
284                                  continue;
285                          }
# Line 303 | Line 327 | char   *nm;
327                  case 'd':                       /* point sample density */
328                          if (*++cp != '=')
329                                  break;
330 <                        if (!isintd(++cp, " \t\n"))
330 >                        if (!isintd(++cp, " \t\n\r"))
331                                  break;
332                          thisillum.sampdens = atoi(cp);
333                          cp = sskip(cp);
# Line 311 | Line 335 | char   *nm;
335                  case 's':                       /* point super-samples */
336                          if (*++cp != '=')
337                                  break;
338 <                        if (!isintd(++cp, " \t\n"))
338 >                        if (!isintd(++cp, " \t\n\r"))
339                                  break;
340                          thisillum.nsamps = atoi(cp);
341                          cp = sskip(cp);
# Line 326 | Line 350 | char   *nm;
350                                  break;
351                          cp++;
352                          continue;
353 +                case 'b':                       /* brightness */
354 +                        if (*++cp != '=')
355 +                                break;
356 +                        if (!isfltd(++cp, " \t\n\r"))
357 +                                break;
358 +                        thisillum.minbrt = atof(cp);
359 +                        if (thisillum.minbrt < 0.)
360 +                                thisillum.minbrt = 0.;
361 +                        cp = sskip(cp);
362 +                        continue;
363                  case 'o':                       /* output file */
364                          if (*++cp != '=')
365                                  break;
366 <                        if (!*++cp)
366 >                        if (!*++cp || isspace(*cp))
367                                  break;
368                          atos(buf, sizeof(buf), cp);
369                          cp = sskip(cp);
# Line 347 | Line 381 | char   *nm;
381                          return;
382                  }
383          opterr:                                 /* skip faulty option */
384 <                cp = sskip(cp);
384 >                while (*cp && !isspace(*cp))
385 >                        cp++;
386                  nerrs++;
387          }
388                                                  /* print header? */
# Line 366 | Line 401 | char   *nm;
401   }
402  
403  
404 + printopts()                     /* print out option default values */
405 + {
406 +        printf("m=%-15s\t\t# material name\n", thisillum.matname);
407 +        printf("f=%-15s\t\t# data file name\n", thisillum.datafile);
408 +        if (thisillum.flags & IL_COLAVG)
409 +                if (thisillum.flags & IL_COLDST)
410 +                        printf("c=d\t\t\t\t# color distribution\n");
411 +                else
412 +                        printf("c=a\t\t\t\t# color average\n");
413 +        else
414 +                printf("c=n\t\t\t\t# color none\n");
415 +        if (thisillum.flags & IL_LIGHT)
416 +                printf("l+\t\t\t\t# light type on\n");
417 +        else
418 +                printf("l-\t\t\t\t# light type off\n");
419 +        printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens);
420 +        printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps);
421 +        printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt);
422 + }
423 +
424 +
425   printhead(ac, av)                       /* print out header */
426   register int  ac;
427   register char  **av;
# Line 392 | Line 448 | char  *nm;
448          if (fgetword(str, MAXSTR, fp) == NULL)
449                  goto readerr;
450                                          /* is it an alias? */
451 <        if (!strcmp(str, ALIASID)) {
451 >        if (!strcmp(str, ALIASKEY)) {
452                  if (fgetword(str, MAXSTR, fp) == NULL)
453                          goto readerr;
454 <                printf("\n%s %s %s", thisillum.altmat, ALIASID, str);
454 >                printf("\n%s %s %s", thisillum.altmat, ALIASKEY, str);
455                  if (fgetword(str, MAXSTR, fp) == NULL)
456                          goto readerr;
457                  printf("\t%s\n", str);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines