ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genprism.c
Revision: 2.4
Committed: Mon Aug 2 14:23:04 1993 UTC (30 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +4 -0 lines
Log Message:
added conditional 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 #ifdef DCL_ATOF
26 extern double atof();
27 #endif
28
29 char *pmtype; /* material type */
30 char *pname; /* name */
31
32 double lvect[3] = {0.0, 0.0, 1.0};
33
34 double vert[MAXVERT][2];
35 int nverts = 0;
36
37 int do_ends = 1; /* include end caps */
38 int iscomplete = 0; /* polygon is already completed */
39
40
41 main(argc, argv)
42 int argc;
43 char **argv;
44 {
45 int an;
46
47 if (argc < 4)
48 goto userr;
49
50 pmtype = argv[1];
51 pname = argv[2];
52
53 if (!strcmp(argv[3], "-")) {
54 readverts(NULL);
55 an = 4;
56 } else if (isdigit(argv[3][0])) {
57 nverts = atoi(argv[3]);
58 if (argc-3 < 2*nverts)
59 goto userr;
60 for (an = 0; an < nverts; an++) {
61 vert[an][0] = atof(argv[2*an+4]);
62 vert[an][1] = atof(argv[2*an+5]);
63 }
64 an = 2*nverts+4;
65 } else {
66 readverts(argv[3]);
67 an = 4;
68 }
69 if (nverts < 3) {
70 fprintf(stderr, "%s: not enough vertices\n", argv[0]);
71 exit(1);
72 }
73
74 for ( ; an < argc; an++) {
75 if (argv[an][0] != '-')
76 goto userr;
77 switch (argv[an][1]) {
78 case 'l': /* length vector */
79 lvect[0] = atof(argv[++an]);
80 lvect[1] = atof(argv[++an]);
81 lvect[2] = atof(argv[++an]);
82 break;
83 case 'e': /* ends */
84 do_ends = !do_ends;
85 break;
86 case 'c': /* complete */
87 iscomplete = !iscomplete;
88 break;
89 default:
90 goto userr;
91 }
92 }
93
94 printhead(argc, argv);
95
96 if (do_ends)
97 printends();
98 printsides();
99
100 return(0);
101 userr:
102 fprintf(stderr, "Usage: %s material name ", argv[0]);
103 fprintf(stderr, "{ - | vfile | N v1 v2 .. vN } ");
104 fprintf(stderr, "[-l lvect][-c][-e]\n");
105 exit(1);
106 }
107
108
109 readverts(fname) /* read vertices from a file */
110 char *fname;
111 {
112 FILE *fp;
113
114 if (fname == NULL)
115 fp = stdin;
116 else if ((fp = fopen(fname, "r")) == NULL) {
117 fprintf(stderr, "%s: cannot open\n", fname);
118 exit(1);
119 }
120 while (fscanf(fp, "%lf %lf", &vert[nverts][0], &vert[nverts][1]) == 2)
121 nverts++;
122 fclose(fp);
123 }
124
125
126 printends() /* print ends of prism */
127 {
128 register int i;
129
130 printf("\n%s polygon %s.b\n", pmtype, pname);
131 printf("0\n0\n%d\n", nverts*3);
132 for (i = 0; i < nverts; i++) {
133 printf("\t%18.12g\t%18.12g\t%18.12g\n",
134 vert[i][0],
135 vert[i][1],
136 0.0);
137 }
138 printf("\n%s polygon %s.e\n", pmtype, pname);
139 printf("0\n0\n%d\n", nverts*3);
140 for (i = nverts-1; i >= 0; i--) {
141 printf("\t%18.12g\t%18.12g\t%18.12g\n",
142 vert[i][0]+lvect[0],
143 vert[i][1]+lvect[1],
144 lvect[2]);
145 }
146 }
147
148
149 printsides() /* print prism sides */
150 {
151 register int i;
152
153 for (i = 0; i < nverts-1; i++)
154 side(i, i+1);
155 if (!iscomplete)
156 side(nverts-1, 0);
157 }
158
159
160 side(n1, n2) /* print single side */
161 register int n1, n2;
162 {
163 printf("\n%s polygon %s.%d\n", pmtype, pname, n1+1);
164 printf("0\n0\n12\n");
165 printf("\t%18.12g\t%18.12g\t%18.12g\n",
166 vert[n1][0],
167 vert[n1][1],
168 0.0);
169 printf("\t%18.12g\t%18.12g\t%18.12g\n",
170 vert[n1][0]+lvect[0],
171 vert[n1][1]+lvect[1],
172 lvect[2]);
173 printf("\t%18.12g\t%18.12g\t%18.12g\n",
174 vert[n2][0]+lvect[0],
175 vert[n2][1]+lvect[1],
176 lvect[2]);
177 printf("\t%18.12g\t%18.12g\t%18.12g\n",
178 vert[n2][0],
179 vert[n2][1],
180 0.0);
181 }
182
183
184 printhead(ac, av) /* print command header */
185 register int ac;
186 register char **av;
187 {
188 putchar('#');
189 while (ac--) {
190 putchar(' ');
191 fputs(*av++, stdout);
192 }
193 putchar('\n');
194 }