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.2 by greg, Tue Jul 23 16:13:28 1991 UTC vs.
Revision 2.6 by greg, Tue Sep 21 17:09:59 1993 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include  "mkillum.h"
12  
13 + #include  <signal.h>
14 +
15   #include  <ctype.h>
16  
17                                  /* default parameters */
18 < #define  SAMPDENS       128             /* points per projected steradian */
18 > #define  SAMPDENS       48              /* points per projected steradian */
19   #define  NSAMPS         32              /* samples per point */
20   #define  DFLMAT         "illum_mat"     /* material name */
21 + #define  DFLDAT         "illum"         /* data file name */
22                                  /* selection options */
23   #define  S_NONE         0               /* select none */
24   #define  S_ELEM         1               /* select specified element */
# Line 23 | Line 26 | static char SCCSid[] = "$SunId$ LBL";
26   #define  S_ALL          3               /* select all */
27  
28                                  /* rtrace command and defaults */
29 < char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-ab", "2",
30 <                "-ad", "256", "-as", "128", "-aa", ".15" };
31 < int  rtargc = 13;
29 > char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-",
30 >                "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", };
31 > int  rtargc = 14;
32                                  /* overriding rtrace options */
33 < char  *myrtopts[] = { "-I-", "-i-", "-di+", "-ov", "-h-", "-fff", NULL };
33 > char  *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-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  
43 int     sampdens = SAMPDENS;    /* sample point density */
48   char    matcheck[MAXSTR];       /* current material to include or exclude */
49   int     matselect = S_ALL;      /* selection criterion */
50  
# Line 56 | Line 60 | int    doneheader = 0;         /* printed header yet? */
60   int     warnings = 1;           /* print warnings? */
61  
62   extern char     *fgetline(), *fgetword(), *sskip(),
63 <                *atos(), *iskip(), *fskip();
63 >                *atos(), *iskip(), *fskip(), *strcpy();
64   extern FILE     *popen();
65  
66  
# Line 66 | Line 70 | char   *argv[];
70   {
71          extern char     *getenv(), *getpath();
72          char    *rtpath;
73 +        FILE    *fp;
74          register int    i;
75                                  /* set global arguments */
76 <        gargc = argc; gargv = argv;
76 >        gargv = argv;
77                                  /* set up rtrace command */
78 <        if (argc < 2)
79 <                error(USER, "too few arguments");
80 <        for (i = 1; i < argc-1; i++) {
78 >        for (i = 1; i < argc; i++) {
79 >                if (argv[i][0] == '<' && argv[i][1] == '\0')
80 >                        break;
81                  rtargv[rtargc++] = argv[i];
82                  if (argv[i][0] == '-' && argv[i][1] == 'w')
83 <                        warnings = !warnings;
83 >                        switch (argv[i][2]) {
84 >                        case '\0':
85 >                                warnings = !warnings;
86 >                                break;
87 >                        case '+':
88 >                        case 'T': case 't':
89 >                        case 'Y': case 'y':
90 >                        case '1':
91 >                                warnings = 1;
92 >                                break;
93 >                        case '-':
94 >                        case 'F': case 'f':
95 >                        case 'N': case 'n':
96 >                        case '0':
97 >                                warnings = 0;
98 >                                break;
99 >                        }
100          }
101 +        gargc = i;
102 +        rtargc--;
103          for (i = 0; myrtopts[i] != NULL; i++)
104                  rtargv[rtargc++] = myrtopts[i];
105 <        rtargv[rtargc++] = argv[argc-1];
105 >        rtargv[rtargc++] = argv[gargc-1];
106          rtargv[rtargc] = NULL;
107                                  /* just asking for defaults? */
108 <        if (!strcmp(argv[argc-1], "-defaults")) {
108 >        if (!strcmp(argv[gargc-1], "-defaults")) {
109 >                printopts(); fflush(stdout);
110                  rtpath = getpath(rtargv[0], getenv("PATH"), X_OK);
111                  if (rtpath == NULL) {
112                          eputs(rtargv[0]);
# Line 93 | Line 117 | char   *argv[];
117                  perror(rtpath);
118                  exit(1);
119          }
120 +        if (gargc < 2 || argv[gargc-1][0] == '-')
121 +                error(USER, "missing octree argument");
122                                  /* else initialize and run our calculation */
123          init();
124 <        filter(stdin, "standard input");
124 >        if (gargc+1 < argc)
125 >                for (i = gargc+1; i < argc; i++) {
126 >                        if ((fp = fopen(argv[i], "r")) == NULL) {
127 >                                sprintf(errmsg,
128 >                                "cannot open scene file \"%s\"", argv[i]);
129 >                                error(SYSTEM, errmsg);
130 >                        }
131 >                        filter(fp, argv[i]);
132 >                        fclose(fp);
133 >                }
134 >        else
135 >                filter(stdin, "standard input");
136          quit(0);
137   }
138  
139  
140 + quit(status)                    /* exit with status */
141 + int  status;
142 + {
143 +        int     rtstat;
144 +
145 +        rtstat = close_process(rt.pd);
146 +        if (status == 0)
147 +                if (rtstat < 0)
148 +                        error(WARNING,
149 +                        "unknown return status from rtrace process");
150 +                else
151 +                        status = rtstat;
152 +        exit(status);
153 + }
154 +
155 +
156   init()                          /* start rtrace and set up buffers */
157   {
158 +        extern int  o_face(), o_sphere(), o_ring();
159          int     maxbytes;
160 <
160 >                                        /* set up object functions */
161 >        ofun[OBJ_FACE].funp = o_face;
162 >        ofun[OBJ_SPHERE].funp = o_sphere;
163 >        ofun[OBJ_RING].funp = o_ring;
164 >                                        /* set up signal handling */
165 >        signal(SIGPIPE, quit);
166 >                                        /* start rtrace process */
167 >        errno = 0;
168          maxbytes = open_process(rt.pd, rtargv);
169          if (maxbytes == 0) {
170                  eputs(rtargv[0]);
# Line 113 | Line 174 | init()                         /* start rtrace and set up buffers */
174          if (maxbytes < 0)
175                  error(SYSTEM, "cannot start rtrace process");
176          rt.bsiz = maxbytes/(6*sizeof(float));
177 <        rt.buf = (float *)malloc(rt.bsiz*(6*sizeof(float)));
178 <        if (rt.buf == NULL)
177 >        rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--);
178 >        rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz);
179 >        if (rt.buf == NULL || rt.dest == NULL)
180                  error(SYSTEM, "out of memory in init");
119        rt.bsiz--;                      /* allow for flush ray */
181          rt.nrays = 0;
182 +                                        /* set up urand */
183 +        initurand(2048);
184   }
185  
186  
124 quit(status)                    /* exit with status */
125 int  status;
126 {
127        int     rtstat;
128
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
187   eputs(s)                                /* put string to stderr */
188   register char  *s;
189   {
# Line 229 | Line 276 | char   *nm;
276                          if (*++cp != '=')
277                                  break;
278                          if (!*++cp) {
279 +                                strcpy(thisillum.datafile,thisillum.matname);
280 +                                thisillum.dfnum = 0;
281                                  thisillum.flags &= ~IL_DATCLB;
282                                  continue;
283                          }
# Line 239 | Line 288 | char   *nm;
288                          continue;
289                  case 'i':                       /* include material */
290                  case 'e':                       /* exclude material */
291 <                        matselect = (*cp == 'i') ? S_ELEM : S_COMPL;
243 <                        if (*++cp != '=')
291 >                        if (cp[1] != '=')
292                                  break;
293 <                        atos(matcheck, MAXSTR, ++cp);
293 >                        matselect = (*cp == 'i') ? S_ELEM : S_COMPL;
294 >                        cp += 2;
295 >                        atos(matcheck, MAXSTR, cp);
296                          cp = sskip(cp);
297                          continue;
298                  case 'a':                       /* use everything */
# Line 258 | Line 308 | char   *nm;
308                                  break;
309                          switch (*++cp) {
310                          case 'a':                       /* average */
311 <                                thisillum.flags |= IL_COLAVG;
312 <                                thisillum.flags &= ~IL_COLDST;
311 >                                thisillum.flags = (thisillum.flags|IL_COLAVG)
312 >                                                        & ~IL_COLDST;
313                                  break;
314                          case 'd':                       /* distribution */
315 <                                thisillum.flags |= IL_COLDST;
266 <                                thisillum.flags &= ~IL_COLAVG;
315 >                                thisillum.flags |= (IL_COLDST|IL_COLAVG);
316                                  break;
317                          case 'n':                       /* none */
318                                  thisillum.flags &= ~(IL_COLAVG|IL_COLDST);
# Line 278 | Line 327 | char   *nm;
327                                  break;
328                          if (!isintd(++cp, " \t\n"))
329                                  break;
330 <                        sampdens = atoi(cp);
330 >                        thisillum.sampdens = atoi(cp);
331                          cp = sskip(cp);
332                          continue;
333                  case 's':                       /* point super-samples */
# Line 289 | Line 338 | char   *nm;
338                          thisillum.nsamps = atoi(cp);
339                          cp = sskip(cp);
340                          continue;
341 +                case 'l':                       /* light sources */
342 +                        cp++;
343 +                        if (*cp == '+')
344 +                                thisillum.flags |= IL_LIGHT;
345 +                        else if (*cp == '-')
346 +                                thisillum.flags &= ~IL_LIGHT;
347 +                        else
348 +                                break;
349 +                        cp++;
350 +                        continue;
351 +                case 'b':                       /* brightness */
352 +                        if (*++cp != '=')
353 +                                break;
354 +                        if (!isfltd(++cp, " \t\n"))
355 +                                break;
356 +                        thisillum.minbrt = atof(cp);
357 +                        if (thisillum.minbrt < 0.)
358 +                                thisillum.minbrt = 0.;
359 +                        cp = sskip(cp);
360 +                        continue;
361                  case 'o':                       /* output file */
362                          if (*++cp != '=')
363                                  break;
# Line 303 | Line 372 | char   *nm;
372                          }
373                          doneheader = 0;
374                          continue;
375 +                case '!':                       /* processed file! */
376 +                        sprintf(errmsg, "(%s): already processed!", nm);
377 +                        error(WARNING, errmsg);
378 +                        matselect = S_NONE;
379 +                        return;
380                  }
381          opterr:                                 /* skip faulty option */
382                  cp = sskip(cp);
# Line 320 | Line 394 | char   *nm;
394                                  progname, nerrs);
395          }
396                                                  /* print pure comment */
397 <        putchar('#'); putchar(' '); fputs(s+2, stdout);
397 >        printf("# %s", s+2);
398   }
399  
400  
401 + printopts()                     /* print out option default values */
402 + {
403 +        printf("m=%-15s\t\t# material name\n", thisillum.matname);
404 +        printf("f=%-15s\t\t# data file name\n", thisillum.datafile);
405 +        if (thisillum.flags & IL_COLAVG)
406 +                if (thisillum.flags & IL_COLDST)
407 +                        printf("c=d\t\t\t\t# color distribution\n");
408 +                else
409 +                        printf("c=a\t\t\t\t# color average\n");
410 +        else
411 +                printf("c=n\t\t\t\t# color none\n");
412 +        if (thisillum.flags & IL_LIGHT)
413 +                printf("l+\t\t\t\t# light type on\n");
414 +        else
415 +                printf("l-\t\t\t\t# light type off\n");
416 +        printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens);
417 +        printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps);
418 +        printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt);
419 + }
420 +
421 +
422   printhead(ac, av)                       /* print out header */
423   register int  ac;
424   register char  **av;
# Line 333 | Line 428 | register char  **av;
428                  putchar(' ');
429                  fputs(*av++, stdout);
430          }
431 <        putchar('\n');
431 >        fputs("\n#@mkillum !\n", stdout);
432   }
433  
434  
# Line 356 | Line 451 | char  *nm;
451                  printf("\n%s %s %s", thisillum.altmat, ALIASID, str);
452                  if (fgetword(str, MAXSTR, fp) == NULL)
453                          goto readerr;
454 <                printf(" %s\n", str);
454 >                printf("\t%s\n", str);
455                  return;
456          }
457 <        thisobj.omod = OVOID;
457 >        thisobj.omod = OVOID;           /* unused field */
458          if ((thisobj.otype = otype(str)) < 0) {
459                  sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str);
460                  error(USER, errmsg);
# Line 376 | Line 471 | char  *nm;
471                  doit = 0;
472                  break;
473          case S_ALL:
474 <                doit = issurface(thisobj.otype);
474 >                doit = 1;
475                  break;
476          case S_ELEM:
477                  doit = !strcmp(thisillum.altmat, matcheck);
# Line 385 | Line 480 | char  *nm;
480                  doit = strcmp(thisillum.altmat, matcheck);
481                  break;
482          }
483 <        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 <                }
483 >        doit = doit && issurface(thisobj.otype);
484                                                  /* print header? */
485          checkhead();
486                                                  /* process object */
487          if (doit)
488 <                mkillum(&thisobj, &thisillum, &rt);
488 >                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm);
489          else
490                  printobj(thisillum.altmat, &thisobj);
491                                                  /* free arguments */
# Line 414 | Line 495 | readerr:
495          sprintf(errmsg, "(%s): error reading scene", nm);
496          error(USER, errmsg);
497   }
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