ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/genrhgrid.c
Revision: 3.1
Committed: Tue Jan 6 17:19:42 1998 UTC (26 years, 3 months ago) by gregl
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

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