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 1.5 by greg, Wed Jul 24 16:48:22 1991 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 */
# Line 23 | 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", "-ab", "2",
29 <                "-ad", "256", "-as", "128", "-aa", ".15" };
30 < int  rtargc = 13;
28 > char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-di+",
29 >                "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", };
30 > int  rtargc = 14;
31                                  /* overriding rtrace options */
32 < char  *myrtopts[] = { "-I-", "-i-", "-di+", "-ov", "-h-", "-fff", NULL };
32 > char  *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", NULL };
33  
34   struct rtproc   rt;             /* our rtrace process */
35  
# Line 37 | Line 39 | struct illum_args  thisillum = {       /* our illum and defa
39                  DFLMAT,
40                  0,
41                  VOIDID,
42 +                SAMPDENS,
43                  NSAMPS,
44          };
45  
43 int     sampdens = SAMPDENS;    /* sample point density */
46   char    matcheck[MAXSTR];       /* current material to include or exclude */
47   int     matselect = S_ALL;      /* selection criterion */
48  
# Line 66 | Line 68 | char   *argv[];
68   {
69          extern char     *getenv(), *getpath();
70          char    *rtpath;
71 +        FILE    *fp;
72          register int    i;
73                                  /* set global arguments */
74 <        gargc = argc; gargv = argv;
74 >        gargv = argv;
75                                  /* set up rtrace command */
76 <        if (argc < 2)
77 <                error(USER, "too few arguments");
78 <        for (i = 1; i < argc-1; i++) {
76 >        for (i = 1; i < argc; i++) {
77 >                if (argv[i][0] == '<' && !argv[i][1])
78 >                        break;
79                  rtargv[rtargc++] = argv[i];
80                  if (argv[i][0] == '-' && argv[i][1] == 'w')
81                          warnings = !warnings;
82          }
83 +        if ((gargc = i) < 2)
84 +                error(USER, "too few arguments");
85 +        rtargc--;
86          for (i = 0; myrtopts[i] != NULL; i++)
87                  rtargv[rtargc++] = myrtopts[i];
88 <        rtargv[rtargc++] = argv[argc-1];
88 >        rtargv[rtargc++] = argv[gargc-1];
89          rtargv[rtargc] = NULL;
90                                  /* just asking for defaults? */
91 <        if (!strcmp(argv[argc-1], "-defaults")) {
91 >        if (!strcmp(argv[gargc-1], "-defaults")) {
92                  rtpath = getpath(rtargv[0], getenv("PATH"), X_OK);
93                  if (rtpath == NULL) {
94                          eputs(rtargv[0]);
# Line 95 | Line 101 | char   *argv[];
101          }
102                                  /* else initialize and run our calculation */
103          init();
104 <        filter(stdin, "standard input");
104 >        if (gargc+1 < argc)
105 >                for (i = gargc+1; i < argc; i++) {
106 >                        if ((fp = fopen(argv[i], "r")) == NULL) {
107 >                                sprintf(errmsg,
108 >                                "cannot open scene file \"%s\"", argv[i]);
109 >                                error(SYSTEM, errmsg);
110 >                        }
111 >                        filter(fp, argv[i]);
112 >                        fclose(fp);
113 >                }
114 >        else
115 >                filter(stdin, "standard input");
116          quit(0);
117   }
118  
119  
120 + quit(status)                    /* exit with status */
121 + int  status;
122 + {
123 +        int     rtstat;
124 +
125 +        rtstat = close_process(rt.pd);
126 +        if (status == 0)
127 +                if (rtstat < 0)
128 +                        error(WARNING,
129 +                        "unknown return status from rtrace process");
130 +                else
131 +                        status = rtstat;
132 +        exit(status);
133 + }
134 +
135 +
136   init()                          /* start rtrace and set up buffers */
137   {
138 +        extern int  o_face(), o_sphere(), o_ring();
139          int     maxbytes;
140 <
140 >                                        /* set up object functions */
141 >        ofun[OBJ_FACE].funp = o_face;
142 >        ofun[OBJ_SPHERE].funp = o_sphere;
143 >        ofun[OBJ_RING].funp = o_ring;
144 >                                        /* set up signal handling */
145 >        signal(SIGPIPE, quit);
146 >                                        /* start rtrace process */
147          maxbytes = open_process(rt.pd, rtargv);
148          if (maxbytes == 0) {
149                  eputs(rtargv[0]);
# Line 113 | Line 153 | init()                         /* start rtrace and set up buffers */
153          if (maxbytes < 0)
154                  error(SYSTEM, "cannot start rtrace process");
155          rt.bsiz = maxbytes/(6*sizeof(float));
156 <        rt.buf = (float *)malloc(rt.bsiz*(6*sizeof(float)));
157 <        if (rt.buf == NULL)
156 >        rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--);
157 >        rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz);
158 >        if (rt.buf == NULL || rt.dest == NULL)
159                  error(SYSTEM, "out of memory in init");
119        rt.bsiz--;                      /* allow for flush ray */
160          rt.nrays = 0;
161   }
162  
163  
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
164   eputs(s)                                /* put string to stderr */
165   register char  *s;
166   {
# Line 262 | Line 286 | char   *nm;
286                                  thisillum.flags &= ~IL_COLDST;
287                                  break;
288                          case 'd':                       /* distribution */
289 <                                thisillum.flags |= IL_COLDST;
266 <                                thisillum.flags &= ~IL_COLAVG;
289 >                                thisillum.flags |= (IL_COLDST|IL_COLAVG);
290                                  break;
291                          case 'n':                       /* none */
292                                  thisillum.flags &= ~(IL_COLAVG|IL_COLDST);
# Line 278 | Line 301 | char   *nm;
301                                  break;
302                          if (!isintd(++cp, " \t\n"))
303                                  break;
304 <                        sampdens = atoi(cp);
304 >                        thisillum.sampdens = atoi(cp);
305                          cp = sskip(cp);
306                          continue;
307                  case 's':                       /* point super-samples */
# Line 289 | Line 312 | char   *nm;
312                          thisillum.nsamps = atoi(cp);
313                          cp = sskip(cp);
314                          continue;
315 +                case 'l':                       /* light sources */
316 +                        cp++;
317 +                        if (*cp == '+')
318 +                                thisillum.flags |= IL_LIGHT;
319 +                        else if (*cp == '-')
320 +                                thisillum.flags &= ~IL_LIGHT;
321 +                        else
322 +                                break;
323 +                        cp++;
324 +                        continue;
325                  case 'o':                       /* output file */
326                          if (*++cp != '=')
327                                  break;
# Line 320 | Line 353 | char   *nm;
353                                  progname, nerrs);
354          }
355                                                  /* print pure comment */
356 <        putchar('#'); putchar(' '); fputs(s+2, stdout);
356 >        printf("# %s", s+2);
357   }
358  
359  
# Line 356 | Line 389 | char  *nm;
389                  printf("\n%s %s %s", thisillum.altmat, ALIASID, str);
390                  if (fgetword(str, MAXSTR, fp) == NULL)
391                          goto readerr;
392 <                printf(" %s\n", str);
392 >                printf("\t%s\n", str);
393                  return;
394          }
395 <        thisobj.omod = OVOID;
395 >        thisobj.omod = OVOID;           /* unused field */
396          if ((thisobj.otype = otype(str)) < 0) {
397                  sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str);
398                  error(USER, errmsg);
# Line 376 | Line 409 | char  *nm;
409                  doit = 0;
410                  break;
411          case S_ALL:
412 <                doit = issurface(thisobj.otype);
412 >                doit = 1;
413                  break;
414          case S_ELEM:
415                  doit = !strcmp(thisillum.altmat, matcheck);
# Line 385 | Line 418 | char  *nm;
418                  doit = strcmp(thisillum.altmat, matcheck);
419                  break;
420          }
421 <        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 <                }
421 >        doit = doit && issurface(thisobj.otype);
422                                                  /* print header? */
423          checkhead();
424                                                  /* process object */
425          if (doit)
426 <                mkillum(&thisobj, &thisillum, &rt);
426 >                (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm);
427          else
428                  printobj(thisillum.altmat, &thisobj);
429                                                  /* free arguments */
# Line 414 | Line 433 | readerr:
433          sprintf(errmsg, "(%s): error reading scene", nm);
434          error(USER, errmsg);
435   }
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