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.15 by greg, Tue Jul 23 15:24:21 1991 UTC vs.
Revision 2.9 by greg, Fri Oct 27 08:56:18 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 25 | Line 25 | char  **xav;                           /* global xform argument pointer */
25   int  xfa;                               /* start of xf arguments */
26  
27   XF  tot;                                /* total transformation */
28 < int  reverse;                           /* boolean true if scene inverted */
28 > int  reverse;                           /* boolean true if scene mirrored */
29  
30 + int  invert = 0;                        /* boolean true to invert surfaces */
31 +
32   int  expand = 0;                        /* boolean true to expand commands */
33  
34   char  *newmod = NULL;                   /* new modifier for surfaces */
35  
36   char  *idprefix = NULL;                 /* prefix for object identifiers */
37  
38 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
38 > #define  ALIAS          NUMOTYPE        /* put alias at end of array */
39  
40 < #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
40 > #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
41  
42   FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
43  
44 + short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
45 +
46   extern char  *malloc(), *fgetword();
47  
48 < #define  progname  (xav[0])
48 > #define  progname  (xav[0])
49  
50  
51   main(argc, argv)                /* get transform options and transform file */
# Line 76 | Line 80 | char  *argv[];
80                                          break;
81                                  expand = 1;
82                                  continue;
83 +                        case 'I':
84 +                                if (argv[a][2])
85 +                                        break;
86 +                                invert = 1;
87 +                                continue;
88                          }
89                  break;
90          }
# Line 87 | Line 96 | char  *argv[];
96  
97          if (reverse = tot.sca < 0.0)
98                  tot.sca = -tot.sca;
99 +        if (invert)
100 +                reverse = !reverse;
101  
102          if (a < argc && argv[a][0] == '-') {
103                  fprintf(stderr, "%s: command line error at '%s'\n",
# Line 162 | Line 173 | xform(name, fin)                       /* transform stream by tot.xfm */
173   char  *name;
174   register FILE  *fin;
175   {
176 +        int  nobjs = 0;
177          register int  c;
178  
179          while ((c = getc(fin)) != EOF) {
# Line 177 | Line 189 | register FILE  *fin;
189                  } else if (c == '!') {                  /* command */
190                          ungetc(c, fin);
191                          xfcomm(name, fin);
192 +                        nobjs++;
193                  } else {                                /* object */
194                          ungetc(c, fin);
195                          xfobject(name, fin);
196 +                        nobjs++;
197                  }
198          }
199 +        if (nobjs == 0)
200 +                fprintf(stderr, "%s: (%s): warning - empty file\n",
201 +                                progname, name);
202   }
203  
204  
205   xfcomm(fname, fin)                      /* transform a command */
206 + char  *fname;
207   FILE  *fin;
208   {
209          FILE  *popen();
# Line 196 | Line 214 | FILE  *fin;
214  
215          fgetline(buf, sizeof(buf), fin);
216          if (expand) {
217 <                if (xac > 2) {
218 <                        if ((pin = popen(buf+1, "r")) == NULL) {
219 <                                fprintf(stderr,
220 <                                "%s: (%s): cannot execute \"%s\"\n",
203 <                                                progname, fname, buf);
204 <                                exit(1);
205 <                        }
206 <                        xform(buf, pin);
207 <                        pclose(pin);
208 <                } else {
209 <                        fflush(stdout);
210 <                        system(buf+1);
217 >                if ((pin = popen(buf+1, "r")) == NULL) {
218 >                        fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n",
219 >                                        progname, fname, buf);
220 >                        exit(1);
221                  }
222 +                xform(buf, pin);
223 +                pclose(pin);
224          } else {
225                  printf("\n%s", buf);
226                  if (xac > 1) {
# Line 225 | Line 237 | xfobject(fname, fin)                           /* transform an object */
237   char  *fname;
238   FILE  *fin;
239   {
240 +        extern char  *strcpy();
241          char  typ[16], nam[MAXSTR];
242          int  fn;
243                                                  /* modifier and type */
# Line 236 | Line 249 | FILE  *fin;
249                                  progname, fname, typ);
250                  exit(1);
251          }
252 <        printf("\n%s %s ", newmod!=NULL && issurface(fn) ? newmod : nam, typ);
252 >        if (ismodifier(fn))
253 >                printf("\n%s %s ", nam, typ);
254 >        else
255 >                printf("\n%s %s ", newmod != NULL ? newmod : nam,
256 >                                invert ? ofun[tinvers[fn]].funame : typ);
257                                                  /* object name */
258          fgetword(nam, sizeof(nam), fin);
259 <        if (idprefix != NULL && issurface(fn))
243 <                printf("%s.%s\n", idprefix, nam);
244 <        else
259 >        if (idprefix == NULL || ismodifier(fn))
260                  printf("%s\n", nam);
261 +        else
262 +                printf("%s.%s\n", idprefix, nam);
263                                                  /* transform arguments */
264          if ((*ofun[fn].funp)(fin) < 0) {
265                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 256 | Line 273 | o_default(fin)                 /* pass on arguments unchanged */
273   FILE  *fin;
274   {
275          register int  i;
276 <        FUNARGS  fa;
276 >        FUNARGS  fa;
277  
278          if (readfargs(&fa, fin) != 1)
279                  return(-1);
# Line 265 | Line 282 | FILE  *fin;
282          for (i = 0; i < fa.nsargs; i++)
283                  printf(" %s", fa.sarg[i]);
284          printf("\n");
285 < #ifdef  IARGS
285 > #ifdef  IARGS
286                                          /* integer arguments */
287          printf("%d", fa.niargs);
288          for (i = 0; i < fa.niargs; i++)
# Line 288 | Line 305 | addxform(fin)                  /* add xf arguments to strings */
305   FILE  *fin;
306   {
307          register int  i;
308 <        FUNARGS  fa;
308 >        int  resetarr = 0;
309 >        FUNARGS  fa;
310  
311          if (readfargs(&fa, fin) != 1)
312                  return(-1);
313                                          /* string arguments */
314 <        printf("%d", fa.nsargs + xac-xfa);
314 >        if (xac > xfa && strcmp(xav[xfa], "-i"))
315 >                resetarr = 2;
316 >        printf("%d", fa.nsargs + resetarr + xac-xfa);
317          for (i = 0; i < fa.nsargs; i++)
318                  printf(" %s", fa.sarg[i]);
319 +        if (resetarr)
320 +                printf(" -i 1");
321          for (i = xfa; i < xac; i++)     /* add xf arguments */
322                  printf(" %s", xav[i]);
323          printf("\n");
324 < #ifdef  IARGS
324 > #ifdef  IARGS
325                                          /* integer arguments */
326          printf("%d", fa.niargs);
327          for (i = 0; i < fa.niargs; i++)
# Line 347 | Line 369 | FILE  *fin;
369   m_glow(fin)                     /* transform arguments for proximity light */
370   FILE  *fin;
371   {
372 <        FUNARGS  fa;
372 >        FUNARGS  fa;
373  
374          if (readfargs(&fa, fin) != 1)
375                  return(-1);
# Line 365 | Line 387 | FILE  *fin;
387   m_spot(fin)                     /* transform arguments for spotlight */
388   FILE  *fin;
389   {
390 <        double  v[3];
391 <        FUNARGS  fa;
390 >        FVECT  v;
391 >        FUNARGS  fa;
392  
393          if (readfargs(&fa, fin) != 1)
394                  return(-1);
# Line 385 | Line 407 | FILE  *fin;
407   m_dielectric(fin)               /* transform arguments for dielectric */
408   FILE  *fin;
409   {
410 <        double  pow();
389 <        FUNARGS  fa;
410 >        FUNARGS  fa;
411  
412          if (readfargs(&fa, fin) != 1)
413                  return(-1);
# Line 406 | Line 427 | FILE  *fin;
427   m_interface(fin)                /* transform arguments for interface */
428   FILE  *fin;
429   {
430 <        double  pow();
410 <        FUNARGS  fa;
430 >        FUNARGS  fa;
431  
432          if (readfargs(&fa, fin) != 1)
433                  return(-1);
# Line 433 | Line 453 | text(fin)                      /* transform text arguments */
453   FILE  *fin;
454   {
455          int  i;
456 <        double  v[3];
457 <        FUNARGS  fa;
456 >        FVECT  v;
457 >        FUNARGS  fa;
458  
459          if (readfargs(&fa, fin) != 1)
460                  return(-1);
461 <        if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15)
461 >        if (fa.nfargs < 9)
462                  return(-1);
463                                          /* string arguments */
464          printf("%d", fa.nsargs);
# Line 453 | Line 473 | FILE  *fin;
473          printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
474                                          /* down vector */
475          multv3(v, fa.farg+6, tot.xfm);
476 <        printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
477 <                                        /* forground and background */
478 <        if (fa.nfargs == 11)
479 <                printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]);
480 <        else if (fa.nfargs == 15) {
481 <                printf(" %18.12g %18.12g %18.12g\n",
462 <                                fa.farg[9], fa.farg[10], fa.farg[11]);
463 <                printf(" %18.12g %18.12g %18.12g\n",
464 <                                fa.farg[12], fa.farg[13], fa.farg[14]);
476 >        printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]);
477 >                                        /* remaining arguments */
478 >        for (i = 9; i < fa.nfargs; i++) {
479 >                if (i%3 == 0)
480 >                        putchar('\n');
481 >                printf(" %18.12g", fa.farg[i]);
482          }
483 +        putchar('\n');
484          freefargs(&fa);
485          return(0);
486   }
# Line 471 | Line 489 | FILE  *fin;
489   o_source(fin)                   /* transform source arguments */
490   FILE  *fin;
491   {
492 <        double  dv[3];
493 <        FUNARGS  fa;
492 >        FVECT  dv;
493 >        FUNARGS  fa;
494  
495          if (readfargs(&fa, fin) != 1)
496                  return(-1);
# Line 492 | Line 510 | FILE  *fin;
510   o_sphere(fin)                   /* transform sphere arguments */
511   FILE  *fin;
512   {
513 <        double  cent[3], rad;
514 <        FUNARGS  fa;
513 >        FVECT  cent;
514 >        double  rad;
515 >        FUNARGS  fa;
516  
517          if (readfargs(&fa, fin) != 1)
518                  return(-1);
519          if (fa.nsargs != 0  || fa.nfargs != 4)
520                  return(-1);
521          
522 <        multp3(cent, fa.farg, tot.xfm); /* transform center */
522 >        multp3(cent, fa.farg, tot.xfm); /* transform center */
523          
524          rad = fa.farg[3] * tot.sca;             /* scale radius */
525          
# Line 515 | Line 534 | FILE  *fin;
534   o_face(fin)                     /* transform face arguments */
535   FILE  *fin;
536   {
537 <        double  p[3];
537 >        FVECT  p;
538          register int  i;
539 <        FUNARGS  fa;
539 >        FUNARGS  fa;
540  
541          if (readfargs(&fa, fin) != 1)
542                  return(-1);
# Line 541 | Line 560 | FILE  *fin;
560   o_cone(fin)                     /* transform cone and cup arguments */
561   FILE  *fin;
562   {
563 <        double  p0[3], p1[3], r0, r1;
564 <        FUNARGS  fa;
563 >        FVECT  p0, p1;
564 >        double  r0, r1;
565 >        FUNARGS  fa;
566  
567          if (readfargs(&fa, fin) != 1)
568                  return(-1);
# Line 567 | Line 587 | FILE  *fin;
587   o_cylinder(fin)                 /* transform cylinder and tube arguments */
588   FILE  *fin;
589   {
590 <        double  p0[3], p1[3], rad;
591 <        FUNARGS  fa;
590 >        FVECT  p0, p1;
591 >        double  rad;
592 >        FUNARGS  fa;
593  
594          if (readfargs(&fa, fin) != 1)
595                  return(-1);
# Line 591 | Line 612 | FILE  *fin;
612   o_ring(fin)                     /* transform ring arguments */
613   FILE  *fin;
614   {
615 <        double  p0[3], pd[3], r0, r1;
616 <        FUNARGS  fa;
615 >        FVECT  p0, pd;
616 >        double  r0, r1;
617 >        FUNARGS  fa;
618  
619          if (readfargs(&fa, fin) != 1)
620                  return(-1);
# Line 603 | Line 625 | FILE  *fin;
625  
626          multp3(p0, fa.farg, tot.xfm);
627          multv3(pd, fa.farg+3, tot.xfm);
628 +        if (invert) {
629 +                pd[0] = -pd[0];
630 +                pd[1] = -pd[1];
631 +                pd[2] = -pd[2];
632 +        }
633          r0 = fa.farg[6] * tot.sca;
634          r1 = fa.farg[7] * tot.sca;
635          printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]);
# Line 615 | Line 642 | FILE  *fin;
642  
643   initotypes()                    /* initialize ofun[] array */
644   {
618        extern int  o_source();
619        extern int  o_sphere();
620        extern int  o_face();
621        extern int  o_cone();
622        extern int  o_cylinder();
623        extern int  o_ring();
624        extern int  m_glow();
625        extern int  m_spot();
626        extern int  m_dielectric();
627        extern int  m_interface();
628        extern int  text();
629        extern int  alias();
630        extern int  passargs();
631        extern int  addxform();
645          register int  i;
646  
647          if (ofun[OBJ_SOURCE].funp == o_source)
# Line 659 | Line 672 | initotypes()                   /* initialize ofun[] array */
672          ofun[PAT_BTEXT].funp =
673          ofun[MIX_TEXT].funp = text;
674          ofun[ALIAS].funp = alias;
675 +                                        /* surface inverses */
676 +        tinvers[OBJ_FACE] = OBJ_FACE;
677 +        tinvers[OBJ_SOURCE] = OBJ_SOURCE;
678 +        tinvers[OBJ_CONE] = OBJ_CUP;
679 +        tinvers[OBJ_CUP] = OBJ_CONE;
680 +        tinvers[OBJ_SPHERE] = OBJ_BUBBLE;
681 +        tinvers[OBJ_BUBBLE] = OBJ_SPHERE;
682 +        tinvers[OBJ_RING] = OBJ_RING;
683 +        tinvers[OBJ_CYLINDER] = OBJ_TUBE;
684 +        tinvers[OBJ_TUBE] = OBJ_CYLINDER;
685 +        tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
686   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines