ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/genrhgrid.c
Revision: 3.12
Committed: Sat Jun 7 05:09:46 2025 UTC (3 hours, 11 minutes ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 3.11: +1 -3 lines
Log Message:
refactor: Put some declarations into "paths.h" and included in "platform.h"

File Contents

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