ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/genrhgrid.c
Revision: 3.11
Committed: Fri Jun 6 19:11:21 2025 UTC (2 weeks, 6 days ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.10: +3 -5 lines
Log Message:
refactor: Making use of printargs() more consistent with fixargv0()

File Contents

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