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

Comparing ray/src/gen/replmarks.c (file contents):
Revision 1.1 by greg, Sun Feb 17 22:36:30 1991 UTC vs.
Revision 2.4 by gregl, Fri Jan 16 10:48:23 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17   #include "fvect.h"
18  
19   #ifdef  M_PI
20 < #define  PI             M_PI
20 > #define  PI             ((double)M_PI)
21   #else
22   #define  PI             3.14159265358979323846
23   #endif
24  
25 + #define  FEQ(a,b)       ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7)
26 +
27   #define  MAXVERT        6       /* maximum number of vertices for markers */
28 + #define  MAXMARK        32      /* maximum number of markers */
29  
30 + #ifdef  DCL_ATOF
31 + extern double  atof();
32 + #endif
33 +
34   typedef struct {
35          short   beg, end;               /* beginning and ending vertex */
36          float   len2;                   /* length squared */
37   }  EDGE;                        /* a marker edge */
38  
39 < int     expand = 0;             /* expand commands? */
39 > struct mrkr {
40 >        char    *modout;                /* output modifier */
41 >        double  mscale;                 /* scale by this to get unit */
42 >        char    *modin;                 /* input modifier indicating marker */
43 >        char    *objname;               /* output object file or octree */
44 >        int     doxform;                /* true if xform, false if instance */
45 > }  marker[MAXMARK];             /* array of markers */
46 > int     nmarkers = 0;           /* number of markers */
47  
48 < char    *modout = "void";       /* output modifier (for instances) */
48 > int     expand;                 /* expand commands? */
49  
36 double  markscale = 0.0;        /* scale markers by this to get unit */
37
38 char    *modin = NULL;          /* input modifier indicating marker */
39
40 char    *objname = NULL;        /* output object file (octree if instance) */
41 int     doxform;                /* true if xform, false if instance */
42
50   char    *progname;
51  
52  
# Line 51 | Line 58 | char   *argv[];
58          int     i, j;
59  
60          progname = argv[0];
61 <        for (i = 1; i < argc && argv[i][0] == '-'; i++)
62 <                switch (argv[i][1]) {
63 <                case 'i':
64 <                        doxform = 0;
65 <                        objname = argv[++i];
66 <                        break;
67 <                case 'x':
68 <                        doxform = 1;
69 <                        objname = argv[++i];
70 <                        break;
71 <                case 'e':
72 <                        expand = !expand;
73 <                        break;
74 <                case 'm':
75 <                        modout = argv[++i];
76 <                        break;
77 <                case 's':
78 <                        markscale = atof(argv[++i]);
79 <                        break;
80 <                default:
61 >        i = 1;
62 >        while (i < argc && argv[i][0] == '-') {
63 >                do {
64 >                        switch (argv[i][1]) {
65 >                        case 'i':
66 >                                marker[nmarkers].doxform = 0;
67 >                                marker[nmarkers].objname = argv[++i];
68 >                                break;
69 >                        case 'x':
70 >                                marker[nmarkers].doxform = 1;
71 >                                marker[nmarkers].objname = argv[++i];
72 >                                break;
73 >                        case 'e':
74 >                                expand = 1;
75 >                                break;
76 >                        case 'm':
77 >                                marker[nmarkers].modout = argv[++i];
78 >                                break;
79 >                        case 's':
80 >                                marker[nmarkers].mscale = atof(argv[++i]);
81 >                                break;
82 >                        default:
83 >                                goto userr;
84 >                        }
85 >                        if (++i >= argc)
86 >                                goto userr;
87 >                } while (argv[i][0] == '-');
88 >                if (marker[nmarkers].objname == NULL)
89                          goto userr;
90 <                }
91 <        if (i < argc)
92 <                modin = argv[i++];
93 <        if (objname == NULL || modin == NULL)
90 >                marker[nmarkers++].modin = argv[i++];
91 >                if (nmarkers >= MAXMARK)
92 >                        break;
93 >                marker[nmarkers].mscale = marker[nmarkers-1].mscale;
94 >        }
95 >        if (nmarkers == 0)
96                  goto userr;
97                                          /* simple header */
98          putchar('#');
# Line 98 | Line 115 | char   *argv[];
115          exit(0);
116   userr:
117          fprintf(stderr,
118 < "Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree} modname [file ..]\n",
118 > "Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree} modname .. [file ..]\n",
119                  progname);
120          exit(1);
121   }
# Line 158 | Line 175 | char   *fname;
175   FILE    *fin;
176   {
177          char    buf[128], typ[16], nam[128];
178 <        int     i, j, n;
178 >        int     i, n;
179 >        register int    j;
180  
181          if (fscanf(fin, "%s %s %s", buf, typ, nam) != 3)
182                  goto readerr;
183 <        if (!strcmp(buf, modin) && !strcmp(typ, "polygon")) {
184 <                replace(fname, nam, fin);
185 <                return;
186 <        }
183 >        if (!strcmp(typ, "polygon"))
184 >                for (j = 0; j < nmarkers; j++)
185 >                        if (!strcmp(buf, marker[j].modin)) {
186 >                                replace(fname, &marker[j], nam, fin);
187 >                                return;
188 >                        }
189          printf("\n%s %s %s\n", buf, typ, nam);
190          if (!strcmp(typ, "alias")) {            /* alias special case */
191                  if (fscanf(fin, "%s", buf) != 1)
# Line 193 | Line 213 | readerr:
213   }
214  
215  
216 < replace(fname, mark, fin)               /* replace marker */
217 < char    *fname, *mark;
216 > replace(fname, m, mark, fin)            /* replace marker */
217 > char    *fname;
218 > register struct mrkr    *m;
219 > char    *mark;
220   FILE    *fin;
221   {
222          int     n;
223          char    buf[256];
224  
225 <        if (doxform) {
225 >        if (m->doxform) {
226                  sprintf(buf, "xform -e -n %s", mark);
227 <                if (buildxf(buf+strlen(buf), fin) < 0)
227 >                if (m->modout != NULL)
228 >                        sprintf(buf+strlen(buf), " -m %s", m->modout);
229 >                if (buildxf(buf+strlen(buf), m->mscale, fin) < 0)
230                          goto badxf;
231 <                sprintf(buf+strlen(buf), " %s", objname);
231 >                sprintf(buf+strlen(buf), " %s", m->objname);
232                  if (expand) {
233                          fflush(stdout);
234                          system(buf);
235                  } else
236                          printf("\n!%s\n", buf);
237          } else {
238 <                if ((n = buildxf(buf, fin)) < 0)
238 >                if ((n = buildxf(buf, m->mscale, fin)) < 0)
239                          goto badxf;
240 <                printf("\n%s instance %s\n", modout, mark);
241 <                printf("%d %s%s\n", n+1, objname, buf);
242 <                printf("\n0\n0\n");
240 >                printf("\n%s instance %s\n",
241 >                                m->modout==NULL?"void":m->modout, mark);
242 >                printf("%d %s%s\n0\n0\n", n+1, m->objname, buf);
243          }
244          return;
245   badxf:
# Line 237 | Line 261 | EDGE   *e1, *e2;
261  
262  
263   int
264 < buildxf(xf, fin)                /* build transform for marker */
264 > buildxf(xf, markscale, fin)             /* build transform for marker */
265   char    *xf;
266 + double  markscale;
267   FILE    *fin;
268   {
269          static FVECT    vlist[MAXVERT];
# Line 321 | Line 346 | addrot(xf, xp, yp, zp)         /* compute rotation (x,y,z) =>
346   char    *xf;
347   FVECT   xp, yp, zp;
348   {
349 <        double  tx, ty, tz;
349 >        int     n;
350 >        double  theta;
351  
352 <        tx = atan2(yp[2], zp[2]);
353 <        ty = asin(-xp[2]);
354 <        tz = atan2(xp[1], xp[0]);
355 <        sprintf(xf, " -rx %f -ry %f -rz %f", tx*(180./PI),
356 <                        ty*(180./PI), tz*(180./PI));
357 <        return(6);
352 >        n = 0;
353 >        theta = atan2(yp[2], zp[2]);
354 >        if (!FEQ(theta,0.0)) {
355 >                sprintf(xf, " -rx %f", theta*(180./PI));
356 >                xf += strlen(xf);
357 >                n += 2;
358 >        }
359 >        theta = asin(-xp[2]);
360 >        if (!FEQ(theta,0.0)) {
361 >                sprintf(xf, " -ry %f", theta*(180./PI));
362 >                xf += strlen(xf);
363 >                n += 2;
364 >        }
365 >        theta = atan2(xp[1], xp[0]);
366 >        if (!FEQ(theta,0.0)) {
367 >                sprintf(xf, " -rz %f", theta*(180./PI));
368 >                /* xf += strlen(xf); */
369 >                n += 2;
370 >        }
371 >        return(n);
372   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines