ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/genrhgrid.c
Revision: 3.8
Committed: Thu Jan 1 11:21:55 2004 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1
Changes since 3.7: +26 -11 lines
Log Message:
Ansification and prototypes.

File Contents

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