ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/xform.c
(Generate patch)

Comparing ray/src/gen/xform.c (file contents):
Revision 1.4 by greg, Wed Jun 7 08:40:59 1989 UTC vs.
Revision 1.12 by greg, Sat Dec 15 14:58:03 1990 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1990 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12   *     11/6/86          Finally added error checking!
13   */
14  
15 < #include  <stdio.h>
15 > #include  "standard.h"
16  
17   #include  <ctype.h>
18  
19 + #include  "otypes.h"
20  
20 typedef struct {
21        char  *funame;                  /* function name */
22        int  (*funp)();                 /* pointer to function */
23 }  FUN;
24
21   int  xac;                               /* global xform argument count */
22   char  **xav;                            /* global xform argument pointer */
23   int  xfa;                               /* start of xf arguments */
24  
25 < double  totxform[4][4];                 /* total transformation matrix */
30 < double  totscale;                       /* total scale factor */
25 > XF  tot;                                /* total transformation */
26   int  reverse;                           /* boolean true if scene inverted */
27  
28   int  expand = 0;                        /* boolean true to expand commands */
29  
30   char  *idprefix = NULL;                 /* prefix for object identifiers */
31  
32 < extern int  o_source();
38 < extern int  o_sphere();
39 < extern int  o_face();
40 < extern int  o_cone();
41 < extern int  o_cylinder();
42 < extern int  o_ring();
43 < extern int  m_dielectric();
44 < extern int  m_interface();
45 < extern int  text();
46 < extern int  alias();
47 < extern int  passargs();
48 < extern int  addxform();
32 > #define  ALIAS          NUMOTYPE        /* put alias at end of array */
33  
34 < FUN  ofun[] = {
51 <        { "source", o_source },
52 <        { "sphere", o_sphere },
53 <        { "bubble", o_sphere },
54 <        { "polygon", o_face },
55 <        { "cone", o_cone },
56 <        { "cup", o_cone },
57 <        { "cylinder", o_cylinder },
58 <        { "tube", o_cylinder },
59 <        { "ring", o_ring },
60 <        { "instance", addxform },
61 <        { "alias", alias },
62 <        { "antimatter", passargs },
63 <        { "dielectric", m_dielectric },
64 <        { "interface", m_interface },
65 <        { "colortext", text },
66 <        { "brighttext", text },
67 <        { "texfunc", addxform },
68 <        { "texdata", addxform },
69 <        { "colorfunc", addxform },
70 <        { "brightfunc", addxform },
71 <        { "colorpict", addxform },
72 <        { "colordata", addxform },
73 <        { "brightdata", addxform },
74 <        { "mixfunc", addxform },
75 <        { "mixdata", addxform },
76 <        { "mixtext", text },
77 <        { "light", passargs },
78 <        { "illum", passargs },
79 <        { "glow", passargs },
80 <        { "plastic", passargs },
81 <        { "metal", passargs },
82 <        { "trans", passargs },
83 <        { "glass", passargs },
84 <        { 0 }                                   /* terminator */
85 < };
34 > #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
35  
36 < #define  issurface(t)           ((t)<=9)
36 > FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
37  
38   typedef struct {
39          short  nsargs;                  /* # of string arguments */
# Line 110 | Line 59 | char  *argv[];
59          FILE  *fopen();
60          FILE  *fp;
61          int  a;
62 +                                        /* check for array */
63 +        for (a = 1; a < argc; a++)
64 +                if (!strcmp(argv[a], "-a"))
65 +                        return(doarray(argc, argv, a));
66  
67 <        xav = argv;
67 >        initotypes();
68  
69          for (a = 1; a < argc; a++) {
70                  if (argv[a][0] == '-')
71                          switch (argv[a][1]) {
72                          case 'n':
73 +                                if (argv[a][2] || a+1 >= argc)
74 +                                        break;
75                                  idprefix = argv[++a];
76                                  continue;
77                          case 'e':
78 +                                if (argv[a][2])
79 +                                        break;
80                                  expand = 1;
81                                  continue;
82                          }
83                  break;
84          }
85  
86 +        xav = argv;
87          xfa = a;
88  
89 <        totscale = 1.0;
132 <        setident4(totxform);
89 >        a += xf(&tot, argc-a, argv+a);
90  
91 <        a += xf(totxform, &totscale, argc-a, argv+a);
91 >        if (reverse = tot.sca < 0.0)
92 >                tot.sca = -tot.sca;
93  
94 <        if (reverse = totscale < 0.0)
95 <                totscale = -totscale;
94 >        if (a < argc && argv[a][0] == '-') {
95 >                fprintf(stderr, "%s: command line error at '%s'\n",
96 >                                argv[0], argv[a]);
97 >                exit(1);
98 >        }
99  
100          xac = a;
101 <
102 <        putchar('#');                           /* simple header */
101 >                                        /* simple header */
102 >        putchar('#');
103          for (a = 0; a < xac; a++)
104                  printf(" %s", xav[a]);
105          putchar('\n');
106 <
107 <        if (a == argc)
106 >                                        /* transform input */
107 >        if (xac == argc)
108                  xform("standard input", stdin);
109          else
110 <                for ( ; a < argc; a++) {
110 >                for (a = xac; a < argc; a++) {
111                          if ((fp = fopen(argv[a], "r")) == NULL) {
112                                  fprintf(stderr, "%s: cannot open \"%s\"\n",
113                                                  progname, argv[a]);
# Line 156 | Line 117 | char  *argv[];
117                          fclose(fp);
118                  }
119  
120 <        exit(0);
120 >        return(0);
121   }
122  
123  
124 < xform(name, fin)                        /* transform stream by totxform */
124 > doarray(ac, av, ai)                     /* make array */
125 > char  **av;
126 > int  ac, ai;
127 > {
128 >        char  *newav[256], **avp;
129 >        char  newid[128], repts[32];
130 >        char  *oldid = NULL;
131 >        int  i, err;
132 >        
133 >        avp = newav+2;
134 >        avp[0] = av[0];
135 >        for (i = 1; i < ac; i++)
136 >                if (!strcmp(av[i-1], "-n")) {
137 >                        oldid = av[i];
138 >                        avp[i] = newid;
139 >                } else
140 >                        avp[i] = av[i];
141 >        avp[ai] = "-i";
142 >        avp[ai+1] = repts;
143 >        avp[i] = NULL;
144 >        if (oldid == NULL) {
145 >                newav[0] = av[0];
146 >                newav[1] = "-n";
147 >                newav[2] = newid;
148 >                avp = newav;
149 >                ac += 2;
150 >        }
151 >        err = 0;
152 >        for (i = 0; i < atoi(av[ai+1]); i++) {
153 >                if (oldid == NULL)
154 >                        sprintf(newid, "a%d", i);
155 >                else
156 >                        sprintf(newid, "%s.%d", oldid, i);
157 >                sprintf(repts, "%d", i);
158 >                err |= main(ac, avp);
159 >        }
160 >        return(err);
161 > }
162 >
163 >
164 > xform(name, fin)                        /* transform stream by tot.xfm */
165   char  *name;
166   register FILE  *fin;
167   {
# Line 178 | Line 179 | register FILE  *fin;
179                          } while (c != '\n');
180                  } else if (c == '!') {                  /* command */
181                          ungetc(c, fin);
182 <                        if (expand)
182 <                                xfcomm(name, fin);
183 <                        else {
184 <                                putchar('\n');
185 <                                while ((c = getc(fin)) != EOF && c != '\n')
186 <                                        putchar(c);
187 <                                printf(" |");
188 <                                for (c = 0; c < xac; c++)
189 <                                        printf(" %s", xav[c]);
190 <                                putchar('\n');
191 <                        }
182 >                        xfcomm(name, fin);
183                  } else {                                /* object */
184                          ungetc(c, fin);
185                          xfobject(name, fin);
# Line 197 | Line 188 | register FILE  *fin;
188   }
189  
190  
191 < xfcomm(fname, fin)                              /* expand a command */
191 > xfcomm(fname, fin)                      /* transform a command */
192   FILE  *fin;
193   {
194          FILE  *popen();
195 <        char  *fgets();
195 >        char  *fgetline();
196          FILE  *pin;
197          char  buf[512];
198 +        int  i;
199  
200 <        fgets(buf, sizeof(buf), fin);
201 <        if (buf[strlen(buf)-1] == '\n')
202 <                buf[strlen(buf)-1] = '\0';
203 <        if ((pin = popen(buf+1, "r")) == NULL) {
204 <                fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n",
205 <                                progname, fname, buf);
206 <                exit(1);
200 >        fgetline(buf, sizeof(buf), fin);
201 >        if (expand) {
202 >                if (xac > 2) {
203 >                        if ((pin = popen(buf+1, "r")) == NULL) {
204 >                                fprintf(stderr,
205 >                                "%s: (%s): cannot execute \"%s\"\n",
206 >                                                progname, fname, buf);
207 >                                exit(1);
208 >                        }
209 >                        xform(buf, pin);
210 >                        pclose(pin);
211 >                } else {
212 >                        fflush(stdout);
213 >                        system(buf+1);
214 >                }
215 >        } else {
216 >                printf("\n%s", buf);
217 >                if (xac > 1) {
218 >                        printf(" | %s -e", xav[0]);
219 >                        for (i = 1; i < xac; i++)
220 >                                printf(" %s", xav[i]);
221 >                }
222 >                putchar('\n');
223          }
216        xform(buf, pin);
217        pclose(pin);
224   }
225  
226  
# Line 248 | Line 254 | FILE  *fin;
254   }
255  
256  
257 < passargs(fin)                   /* pass on arguments unchanged */
257 > o_default(fin)                  /* pass on arguments unchanged */
258   FILE  *fin;
259   {
260          register int  i;
# Line 312 | Line 318 | register char  *ofname;
318   {
319          register int  i;
320  
321 <        for (i = 0; ofun[i].funame != NULL; i++)
321 >        for (i = 0; i < NUMTYPES; i++)
322                  if (!strcmp(ofun[i].funame, ofname))
323                          return(i);
324  
# Line 323 | Line 329 | register char  *ofname;
329   alias(fin)                      /* transfer alias */
330   FILE  *fin;
331   {
332 <        char  alias[MAXSTR];
332 >        char  aliasnm[MAXSTR];
333  
334 <        if (fscanf(fin, "%s", alias) != 1)
334 >        if (fscanf(fin, "%s", aliasnm) != 1)
335                  return(-1);
336 <        printf("\t%s\n", alias);
336 >        printf("\t%s\n", aliasnm);
337          return(0);
338   }
339  
340  
341 + m_glow(fin)                     /* transform arguments for proximity light */
342 + FILE  *fin;
343 + {
344 +        register FUNARGS  *fa;
345 +
346 +        if ((fa = getfargs(fin)) == NULL)
347 +                return(-1);
348 +        if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4)
349 +                return(-1);
350 +        printf("0\n0\n4");
351 +        printf(" %18.12g %18.12g %18.12g",
352 +                        fa->farg[0], fa->farg[1], fa->farg[2]);
353 +        printf(" %18.12g\n", fa->farg[3] * tot.sca);
354 +        freefargs(fa);
355 +        return(0);
356 + }
357 +
358 +
359 + m_spot(fin)                     /* transform arguments for spotlight */
360 + FILE  *fin;
361 + {
362 +        double  v[3];
363 +        register FUNARGS  *fa;
364 +
365 +        if ((fa = getfargs(fin)) == NULL)
366 +                return(-1);
367 +        if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 7)
368 +                return(-1);
369 +        printf("0\n0\n7");
370 +        printf(" %18.12g %18.12g %18.12g %18.12g\n",
371 +                        fa->farg[0], fa->farg[1], fa->farg[2], fa->farg[3]);
372 +        multv3(v, fa->farg+4, tot.xfm);
373 +        printf("\t%18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
374 +        freefargs(fa);
375 +        return(0);
376 + }
377 +
378 +
379   m_dielectric(fin)               /* transform arguments for dielectric */
380   FILE  *fin;
381   {
# Line 344 | Line 388 | FILE  *fin;
388                  return(-1);
389          printf("0\n0\n5");
390          printf(" %18.12g %18.12g %18.12g",
391 <                pow(fa->farg[0], 1.0/totscale),
392 <                pow(fa->farg[1], 1.0/totscale),
393 <                pow(fa->farg[2], 1.0/totscale));
391 >                pow(fa->farg[0], 1.0/tot.sca),
392 >                pow(fa->farg[1], 1.0/tot.sca),
393 >                pow(fa->farg[2], 1.0/tot.sca));
394          printf(" %18.12g %18.12g\n", fa->farg[3], fa->farg[4]);
395          freefargs(fa);
396          return(0);
# Line 365 | Line 409 | FILE  *fin;
409                  return(-1);
410          printf("0\n0\n8\n");
411          printf("%18.12g %18.12g %18.12g",
412 <                pow(fa->farg[0], 1.0/totscale),
413 <                pow(fa->farg[1], 1.0/totscale),
414 <                pow(fa->farg[2], 1.0/totscale));
412 >                pow(fa->farg[0], 1.0/tot.sca),
413 >                pow(fa->farg[1], 1.0/tot.sca),
414 >                pow(fa->farg[2], 1.0/tot.sca));
415          printf(" %18.12g\n", fa->farg[3]);
416          printf("%18.12g %18.12g %18.12g",
417 <                pow(fa->farg[4], 1.0/totscale),
418 <                pow(fa->farg[5], 1.0/totscale),
419 <                pow(fa->farg[6], 1.0/totscale));
417 >                pow(fa->farg[4], 1.0/tot.sca),
418 >                pow(fa->farg[5], 1.0/tot.sca),
419 >                pow(fa->farg[6], 1.0/tot.sca));
420          printf(" %18.12g\n", fa->farg[7]);
421          freefargs(fa);
422          return(0);
# Line 397 | Line 441 | FILE  *fin;
441                  printf(" %s", fa->sarg[i]);
442          printf("\n0\n%d\n", fa->nfargs);
443                                          /* anchor point */
444 <        multp3(v, fa->farg, totxform);
444 >        multp3(v, fa->farg, tot.xfm);
445          printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
446                                          /* right vector */
447 <        multv3(v, fa->farg+3, totxform);
447 >        multv3(v, fa->farg+3, tot.xfm);
448          printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
449                                          /* down vector */
450 <        multv3(v, fa->farg+6, totxform);
450 >        multv3(v, fa->farg+6, tot.xfm);
451          printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
452                                          /* forground and background */
453          if (fa->nfargs == 11)
# Line 430 | Line 474 | FILE  *fin;
474          if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4)
475                  return(-1);
476                                          /* transform direction vector */
477 <        multv3(dv, fa->farg, totxform);
477 >        multv3(dv, fa->farg, tot.xfm);
478                                          /* output */
479          printf("0\n0\n4");
480          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 451 | Line 495 | FILE  *fin;
495          if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4)
496                  return(-1);
497          
498 <        multp3(cent, fa->farg, totxform);       /* transform center */
498 >        multp3(cent, fa->farg, tot.xfm);        /* transform center */
499          
500 <        rad = fa->farg[3] * totscale;           /* scale radius */
500 >        rad = fa->farg[3] * tot.sca;            /* scale radius */
501          
502          printf("0\n0\n4");
503          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 479 | Line 523 | FILE  *fin;
523          
524          for (i = 0; i < fa->nfargs; i += 3) {
525                  if (reverse)
526 <                        multp3(p, fa->farg+(fa->nfargs-i-3), totxform);
526 >                        multp3(p, fa->farg+(fa->nfargs-i-3), tot.xfm);
527                  else
528 <                        multp3(p, fa->farg+i, totxform);
528 >                        multp3(p, fa->farg+i, tot.xfm);
529                  printf(" %18.12g %18.12g %18.12g\n", p[0], p[1], p[2]);
530          }
531          freefargs(fa);
# Line 502 | Line 546 | FILE  *fin;
546  
547          printf("0\n0\n8\n");
548  
549 <        multp3(p0, fa->farg, totxform);
550 <        multp3(p1, fa->farg+3, totxform);
551 <        r0 = fa->farg[6] * totscale;
552 <        r1 = fa->farg[7] * totscale;
549 >        multp3(p0, fa->farg, tot.xfm);
550 >        multp3(p1, fa->farg+3, tot.xfm);
551 >        r0 = fa->farg[6] * tot.sca;
552 >        r1 = fa->farg[7] * tot.sca;
553          printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]);
554          printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]);
555          printf(" %18.12g %18.12g\n", r0, r1);
# Line 528 | Line 572 | FILE  *fin;
572  
573          printf("0\n0\n7\n");
574  
575 <        multp3(p0, fa->farg, totxform);
576 <        multp3(p1, fa->farg+3, totxform);
577 <        rad = fa->farg[6] * totscale;
575 >        multp3(p0, fa->farg, tot.xfm);
576 >        multp3(p1, fa->farg+3, tot.xfm);
577 >        rad = fa->farg[6] * tot.sca;
578          printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]);
579          printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]);
580          printf(" %18.12g\n", rad);
# Line 552 | Line 596 | FILE  *fin;
596  
597          printf("0\n0\n8\n");
598  
599 <        multp3(p0, fa->farg, totxform);
600 <        multv3(pd, fa->farg+3, totxform);
601 <        r0 = fa->farg[6] * totscale;
602 <        r1 = fa->farg[7] * totscale;
599 >        multp3(p0, fa->farg, tot.xfm);
600 >        multv3(pd, fa->farg+3, tot.xfm);
601 >        r0 = fa->farg[6] * tot.sca;
602 >        r1 = fa->farg[7] * tot.sca;
603          printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]);
604          printf(" %18.12g %18.12g %18.12g\n", pd[0], pd[1], pd[2]);
605          printf(" %18.12g %18.12g\n", r0, r1);
# Line 634 | Line 678 | register FUNARGS  *fa;
678          if (fa->nfargs)
679                  free(fa->farg);
680          free(fa);
681 + }
682 +
683 +
684 + initotypes()                    /* initialize ofun[] array */
685 + {
686 +        extern int  o_source();
687 +        extern int  o_sphere();
688 +        extern int  o_face();
689 +        extern int  o_cone();
690 +        extern int  o_cylinder();
691 +        extern int  o_ring();
692 +        extern int  m_glow();
693 +        extern int  m_spot();
694 +        extern int  m_dielectric();
695 +        extern int  m_interface();
696 +        extern int  text();
697 +        extern int  alias();
698 +        extern int  passargs();
699 +        extern int  addxform();
700 +        register int  i;
701 +
702 +        if (ofun[OBJ_SOURCE].funp == o_source)
703 +                return;                 /* done already */
704 +                                        /* alias is additional */
705 +        ofun[ALIAS].funame = ALIASID;
706 +        ofun[ALIAS].flags = 0;
707 +                                        /* functions get new transform */
708 +        for (i = 0; i < NUMTYPES; i++)
709 +                if (hasfunc(i))
710 +                        ofun[i].funp = addxform;
711 +                                        /* special cases */
712 +        ofun[OBJ_SOURCE].funp = o_source;
713 +        ofun[OBJ_SPHERE].funp =
714 +        ofun[OBJ_BUBBLE].funp = o_sphere;
715 +        ofun[OBJ_FACE].funp = o_face;
716 +        ofun[OBJ_CONE].funp =
717 +        ofun[OBJ_CUP].funp = o_cone;
718 +        ofun[OBJ_CYLINDER].funp =
719 +        ofun[OBJ_TUBE].funp = o_cylinder;
720 +        ofun[OBJ_RING].funp = o_ring;
721 +        ofun[OBJ_INSTANCE].funp = addxform;
722 +        ofun[MAT_GLOW].funp = m_glow;
723 +        ofun[MAT_SPOT].funp = m_spot;
724 +        ofun[MAT_DIELECTRIC].funp = m_dielectric;
725 +        ofun[MAT_INTERFACE].funp = m_interface;
726 +        ofun[PAT_CTEXT].funp =
727 +        ofun[PAT_BTEXT].funp =
728 +        ofun[MIX_TEXT].funp = text;
729 +        ofun[ALIAS].funp = alias;
730   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines