|
|
1.1 root 1: #include <stdio.h>
2: #define READFN
3: #include <poly.h>
4:
5: #define RAD (180/3.1415926535897932384626433832795028841971693993751)
6:
7: Polyhedron net;
8: char names[MAXNETS][128];
9: int ns;
10: int fflag;
11: int sflag;
12: int nflag;
13: int cflag;
14: int iflag;
15: int hflag;
16: int pflag;
17: int full;
18: double minx, minz, maxx, maxz, miny, maxy;
19:
20: main(argc, argv)
21: char **argv;
22: {
23: register i, k;
24:
25: for(argc--, argv++; argc-- && (**argv == '-'); argv++)
26: switch(argv[0][1])
27: {
28: case 's': sflag++; break;
29: case 'f': fflag++; break;
30: case 'n': nflag++; break;
31: case 'c': cflag++; sflag++; break;
32: case 'i': iflag++; break;
33: case 'h': hflag++; break;
34: case 'p': pflag++; break;
35: default: printf("usage: polypr [-fcsiehn] [n]\n"); exit(1);
36: }
37: full = !(fflag || nflag || sflag || hflag);
38:
39: if((ns = poly_finit(iflag? "/dev/stdin" : (char *)0)) == 0)
40: exit(1);
41:
42: for(i = 0; i < ns; i++)
43: {
44: poly_read(&net, i);
45: strcpy(&names[i][0], net.name);
46: }
47:
48: if(*argv)
49: {
50: while(*argv)
51: {
52: k = lkpoly(*argv++);
53: if(k < 0) continue;
54: poly_read(&net, k);
55: dumppoly(&net, k);
56: }
57: }
58: else
59: for(i = 0; i < ns; i++)
60: {
61: poly_read(&net, i);
62: dumppoly(&net, i);
63: }
64: exit(0);
65: }
66:
67: lkpoly(s)
68: char *s;
69: {
70: register i;
71: register char *ss;
72: int n = strlen(s);
73:
74: for(i = 0; i < ns; i++)
75: if(strncmp(&names[i][0], s, n) == 0) return(i);
76: for(ss = s; *ss; ss++)
77: if((*ss < '0') || (*ss > '9')) break;
78: if(*ss == 0)
79: {
80: n = atoi(s);
81: if((n >= 0) || (n < ns))
82: return(n);
83: fprintf(stderr, "number %d out of range\n", n);
84: return(-1);
85: }
86: fprintf(stderr, "no solid '%s'\n", s);
87: return(-1);
88: }
89:
90: dumppoly(p, num)
91: register Polyhedron *p;
92: {
93: register i, j;
94: register Point *pp;
95:
96: if(nflag)
97: {
98: printf("%3d: %s\n", num, p->name);
99: return;
100: }
101: if(cflag)
102: cpr(p);
103: if(full || hflag)
104: printf("[%d] %s: %d faces, %d hinges\n", num, p->name,
105: p->nfaces, p->nhinges);
106: if(full || fflag)
107: {
108: if(full)
109: printf("Flat:\n");
110: for(i = 0; i < p->nfaces; i++)
111: {
112: printf("data=%d %d vert:", p->faces[i].data, p->faces[i].n);
113: for(j = 0, pp = p->pts+p->faces[i].f; j < p->faces[i].n; j++, pp++)
114: printf(" (%.4g,%.4g,%.4g)", pp->x, pp->y, pp->z);
115: printf("\n");
116: }
117: }
118: if(full || sflag)
119: {
120: if(full)
121: printf("Solid:\n");
122: for(i = 0; i < p->nfaces; i++)
123: {
124: if(cflag)
125: printf("p -128", p->faces[i].data);
126: else
127: printf("data=%d %d vert:", p->faces[i].data, p->faces[i].n);
128: for(j = 0, pp = p->pts+p->faces[i].s; j < p->faces[i].n; j++, pp++)
129: printf(cflag?" %.8g %.8g %.8g":" (%.4g,%.4g,%.4g)",
130: pp->x, pp->y, pp->z);
131: if(cflag) printf(";");
132: printf("\n");
133: }
134: }
135: if(full)
136: for(i = 0; i < p->nhinges; i++)
137: printf("%d:: %d,%d --- %d,%d theta=%g (%.1f)\n", i,
138: p->hinges[i].fa, p->hinges[i].ea,
139: p->hinges[i].fb, p->hinges[i].eb,
140: p->hinges[i].dihedral, p->hinges[i].dihedral*RAD);
141:
142: }
143:
144: cpr(p)
145: register Polyhedron *p;
146: {
147: double cx, cz, eyey, fov, d;
148: register i;
149: register Point *pp;
150:
151: {
152: minx = 1e30, maxx = -1e30, minz = 1e30;
153: maxz = -1e30, miny = 1e30, maxy = -1e30;
154: for(i = p->npts/2, pp = &p->pts[i]; i < p->npts; pp++, i++)
155: {
156: if(minx > pp->x) minx = pp->x;
157: if(maxx < pp->x) maxx = pp->x;
158: if(minz > pp->z) minz = pp->z;
159: if(maxz < pp->z) maxz = pp->z;
160: if(miny > pp->y) miny = pp->y;
161: if(maxy < pp->y) maxy = pp->y;
162: }
163: }
164: cx = (minx+maxx)/2;
165: cz = (minz+maxz)/2;
166: fov = pflag? 30:1;
167: d = maxx - minx;
168: if((maxz-minz) > d) d = maxz-minz;
169: eyey = miny - (pflag? 2:100)*d;
170: miny = miny-eyey-.1;
171: maxy = maxy-eyey+.1;
172: printf("v %g %g %g %g %g %g 0 1 0 0 0 1\n", fov, miny, maxy, cx, eyey, cz);
173: printf("l .4 1 .5\n");
174: printf("c 128 30 30 255 255\n");
175: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.