ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genprism.c
Revision: 1.2
Committed: Tue Mar 14 15:08:35 1989 UTC (35 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
fixed mistaken parameter

File Contents

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