ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/genrhgrid.c
Revision: 3.6
Committed: Mon Oct 20 16:01:55 2003 UTC (20 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.5: +3 -2 lines
Log Message:
Included "platform.h" wherever lseek() was called

File Contents

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