ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/genrhgrid.c
Revision: 3.4
Committed: Fri Jun 20 00:25:49 2003 UTC (20 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.3: +2 -2 lines
Log Message:
Changed instances of "int4" to "int32" and "int2" to "int16"

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: genrhgrid.c,v 3.3 2003/05/29 16:26:21 greg Exp $";
3 #endif
4 /*
5 * Generate renderable grids from a holodeck file
6 */
7
8 #include "holo.h"
9
10 char *progname; /* global argv[0] */
11
12 char *mat, *name; /* material and object id */
13 double rad; /* grid line radius */
14
15
16 main(argc, argv)
17 int argc;
18 char *argv[];
19 {
20 int sect;
21
22 progname = argv[0];
23 if (argc < 5 | argc > 6)
24 goto userr;
25 mat = argv[1];
26 name = argv[2];
27 rad = atof(argv[3]);
28 sect = argc==5 ? -1 : atoi(argv[5]);
29 fputs("# ", stdout);
30 printargs(argc, argv, stdout);
31 gridsect(argv[4], sect);
32 quit(0);
33 userr:
34 fprintf(stderr, "Usage: %s mat name rad input.hdk [section]\n",
35 progname);
36 exit(1);
37 }
38
39
40 gridsect(fname, sect) /* get specified section(s) and print grids */
41 char *fname;
42 int sect;
43 {
44 FILE *fp;
45 HOLO hdsect;
46 int fd;
47 int32 nextloc;
48 int n;
49 /* open holodeck file */
50 if ((fp = fopen(fname, "r")) == NULL) {
51 sprintf(errmsg, "cannot open \"%s\"", fname);
52 error(SYSTEM, errmsg);
53 }
54 /* check header and magic number */
55 if (checkheader(fp, HOLOFMT, NULL) < 0 || getw(fp) != HOLOMAGIC) {
56 sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
57 error(USER, errmsg);
58 }
59 fd = dup(fileno(fp)); /* dup file handle */
60 nextloc = ftell(fp); /* get stdio position */
61 fclose(fp); /* done with stdio */
62 for (n = 0; nextloc > 0L; n++) { /* get the section(s) */
63 lseek(fd, (off_t)nextloc, 0);
64 read(fd, (char *)&nextloc, sizeof(nextloc));
65 if (sect < 0 | n == sect) {
66 read(fd, (char *)&hdsect, sizeof(HDGRID));
67 hdcompgrid(&hdsect);
68 putgrid(&hdsect); /* print grid */
69 }
70 }
71 }
72
73
74 putgrid(hp) /* run through holodeck section grid lines */
75 register HOLO *hp;
76 {
77 register int w, i;
78 int g0, g1;
79 FVECT wp[2], mov;
80 double d;
81 /* do each wall on this section */
82 for (w = 0; w < 6; w++) {
83 g0 = hdwg0[w];
84 g1 = hdwg1[w];
85 d = 1.0/hp->grid[g0];
86 mov[0] = d * hp->xv[g0][0];
87 mov[1] = d * hp->xv[g0][1];
88 mov[2] = d * hp->xv[g0][2];
89 if (w & 1) {
90 VSUM(wp[0], hp->orig, hp->xv[w>>1], 1.);
91 VSUM(wp[0], wp[0], mov, 1.);
92 } else
93 VCOPY(wp[0], hp->orig);
94 VSUM(wp[1], wp[0], hp->xv[g1], 1.);
95 for (i = hp->grid[g0]; ; ) { /* g0 lines */
96 putline(wp);
97 if (!--i) break;
98 wp[0][0] += mov[0]; wp[0][1] += mov[1];
99 wp[0][2] += mov[2]; wp[1][0] += mov[0];
100 wp[1][1] += mov[1]; wp[1][2] += mov[2];
101 }
102 d = 1.0/hp->grid[g1];
103 mov[0] = d * hp->xv[g1][0];
104 mov[1] = d * hp->xv[g1][1];
105 mov[2] = d * hp->xv[g1][2];
106 if (w & 1)
107 VSUM(wp[0], hp->orig, hp->xv[w>>1], 1.);
108 else
109 VSUM(wp[0], hp->orig, mov, 1.);
110 VSUM(wp[1], wp[0], hp->xv[g0], 1.);
111 for (i = hp->grid[g1]; ; ) { /* g1 lines */
112 putline(wp);
113 if (!--i) break;
114 wp[0][0] += mov[0]; wp[0][1] += mov[1];
115 wp[0][2] += mov[2]; wp[1][0] += mov[0];
116 wp[1][1] += mov[1]; wp[1][2] += mov[2];
117 }
118 }
119 }
120
121
122 putline(wp) /* put out a line */
123 register FVECT wp[2];
124 {
125 static int cnt = 0;
126
127 printf("\n%s cylinder %s.%d\n0\n0\n7\n", mat, name, ++cnt);
128 printf("\t%.4e %.4e %.4e\n", wp[0][0], wp[0][1], wp[0][2]);
129 printf("\t%.4e %.4e %.4e\n", wp[1][0], wp[1][1], wp[1][2]);
130 printf("\t%.4e\n", rad);
131 }