ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genprism.c
Revision: 2.3
Committed: Fri Jun 4 14:32:05 1993 UTC (30 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +2 -4 lines
Log Message:
Removed unnecessary declaration of atof()

File Contents

# Content
1 /* Copyright (c) 1987 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * genprism.c - generate a prism.
9 * 2D vertices in the xy plane are given on the
10 * command line or from a file. Their order together
11 * with the extrude direction will determine surface
12 * orientation.
13 *
14 * 8/24/87
15 */
16
17 #include <stdio.h>
18
19 #include <math.h>
20
21 #include <ctype.h>
22
23 #define MAXVERT 1024 /* maximum # vertices */
24
25 char *pmtype; /* material type */
26 char *pname; /* name */
27
28 double lvect[3] = {0.0, 0.0, 1.0};
29
30 double vert[MAXVERT][2];
31 int nverts = 0;
32
33 int do_ends = 1; /* include end caps */
34 int iscomplete = 0; /* polygon is already completed */
35
36
37 main(argc, argv)
38 int argc;
39 char **argv;
40 {
41 int an;
42
43 if (argc < 4)
44 goto userr;
45
46 pmtype = argv[1];
47 pname = argv[2];
48
49 if (!strcmp(argv[3], "-")) {
50 readverts(NULL);
51 an = 4;
52 } else if (isdigit(argv[3][0])) {
53 nverts = atoi(argv[3]);
54 if (argc-3 < 2*nverts)
55 goto userr;
56 for (an = 0; an < nverts; an++) {
57 vert[an][0] = atof(argv[2*an+4]);
58 vert[an][1] = atof(argv[2*an+5]);
59 }
60 an = 2*nverts+4;
61 } else {
62 readverts(argv[3]);
63 an = 4;
64 }
65 if (nverts < 3) {
66 fprintf(stderr, "%s: not enough vertices\n", argv[0]);
67 exit(1);
68 }
69
70 for ( ; an < argc; an++) {
71 if (argv[an][0] != '-')
72 goto userr;
73 switch (argv[an][1]) {
74 case 'l': /* length vector */
75 lvect[0] = atof(argv[++an]);
76 lvect[1] = atof(argv[++an]);
77 lvect[2] = atof(argv[++an]);
78 break;
79 case 'e': /* ends */
80 do_ends = !do_ends;
81 break;
82 case 'c': /* complete */
83 iscomplete = !iscomplete;
84 break;
85 default:
86 goto userr;
87 }
88 }
89
90 printhead(argc, argv);
91
92 if (do_ends)
93 printends();
94 printsides();
95
96 return(0);
97 userr:
98 fprintf(stderr, "Usage: %s material name ", argv[0]);
99 fprintf(stderr, "{ - | vfile | N v1 v2 .. vN } ");
100 fprintf(stderr, "[-l lvect][-c][-e]\n");
101 exit(1);
102 }
103
104
105 readverts(fname) /* read vertices from a file */
106 char *fname;
107 {
108 FILE *fp;
109
110 if (fname == NULL)
111 fp = stdin;
112 else if ((fp = fopen(fname, "r")) == NULL) {
113 fprintf(stderr, "%s: cannot open\n", fname);
114 exit(1);
115 }
116 while (fscanf(fp, "%lf %lf", &vert[nverts][0], &vert[nverts][1]) == 2)
117 nverts++;
118 fclose(fp);
119 }
120
121
122 printends() /* print ends of prism */
123 {
124 register int i;
125
126 printf("\n%s polygon %s.b\n", pmtype, pname);
127 printf("0\n0\n%d\n", nverts*3);
128 for (i = 0; i < nverts; i++) {
129 printf("\t%18.12g\t%18.12g\t%18.12g\n",
130 vert[i][0],
131 vert[i][1],
132 0.0);
133 }
134 printf("\n%s polygon %s.e\n", pmtype, pname);
135 printf("0\n0\n%d\n", nverts*3);
136 for (i = nverts-1; i >= 0; i--) {
137 printf("\t%18.12g\t%18.12g\t%18.12g\n",
138 vert[i][0]+lvect[0],
139 vert[i][1]+lvect[1],
140 lvect[2]);
141 }
142 }
143
144
145 printsides() /* print prism sides */
146 {
147 register int i;
148
149 for (i = 0; i < nverts-1; i++)
150 side(i, i+1);
151 if (!iscomplete)
152 side(nverts-1, 0);
153 }
154
155
156 side(n1, n2) /* print single side */
157 register int n1, n2;
158 {
159 printf("\n%s polygon %s.%d\n", pmtype, pname, n1+1);
160 printf("0\n0\n12\n");
161 printf("\t%18.12g\t%18.12g\t%18.12g\n",
162 vert[n1][0],
163 vert[n1][1],
164 0.0);
165 printf("\t%18.12g\t%18.12g\t%18.12g\n",
166 vert[n1][0]+lvect[0],
167 vert[n1][1]+lvect[1],
168 lvect[2]);
169 printf("\t%18.12g\t%18.12g\t%18.12g\n",
170 vert[n2][0]+lvect[0],
171 vert[n2][1]+lvect[1],
172 lvect[2]);
173 printf("\t%18.12g\t%18.12g\t%18.12g\n",
174 vert[n2][0],
175 vert[n2][1],
176 0.0);
177 }
178
179
180 printhead(ac, av) /* print command header */
181 register int ac;
182 register char **av;
183 {
184 putchar('#');
185 while (ac--) {
186 putchar(' ');
187 fputs(*av++, stdout);
188 }
189 putchar('\n');
190 }