ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/genrhgrid.c
Revision: 3.2
Committed: Sat Feb 22 02:07:24 2003 UTC (21 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 3.1: +2 -5 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 gregl 3.1 #ifndef lint
2 greg 3.2 static const char RCSid[] = "$Id$";
3 gregl 3.1 #endif
4     /*
5     * Generate renderable grids from a holodeck file
6     */
7    
8     #include "holo.h"
9    
10     char *progname; /* global argv[0] */
11    
12     char *mat, *name; /* material and object id */
13     double rad; /* grid line radius */
14    
15    
16     main(argc, argv)
17     int argc;
18     char *argv[];
19     {
20     int sect;
21    
22     progname = argv[0];
23     if (argc < 5 | argc > 6)
24     goto userr;
25     mat = argv[1];
26     name = argv[2];
27     rad = atof(argv[3]);
28     sect = argc==5 ? -1 : atoi(argv[5]);
29     fputs("# ", stdout);
30     printargs(argc, argv, stdout);
31     gridsect(argv[4], sect);
32     quit(0);
33     userr:
34     fprintf(stderr, "Usage: %s mat name rad input.hdk [section]\n",
35     progname);
36     exit(1);
37     }
38    
39    
40     gridsect(fname, sect) /* get specified section(s) and print grids */
41     char *fname;
42     int sect;
43     {
44     extern long ftell();
45     FILE *fp;
46     HOLO hdsect;
47     int fd;
48     int4 nextloc;
49     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.2 lseek(fd, (off_t)nextloc, 0);
65 gregl 3.1 read(fd, (char *)&nextloc, sizeof(nextloc));
66     if (sect < 0 | n == sect) {
67     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     }