ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/vwrays.c
Revision: 3.2
Committed: Fri Oct 17 10:13:56 1997 UTC (26 years, 6 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.1: +8 -3 lines
Log Message:
added aft view distance to ray output

File Contents

# User Rev Content
1 gregl 3.1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Compute rays corresponding to a given picture or view.
9     */
10    
11    
12     #include "standard.h"
13    
14     #include "view.h"
15    
16     #include "resolu.h"
17    
18     extern int putf(), putd(), puta();
19    
20     int (*putr)() = puta;
21    
22     VIEW vw = STDVIEW;
23    
24     RESOLU rs = {PIXSTANDARD, 512, 512};
25    
26     double pa = 1.;
27    
28     int zfd = -1;
29    
30     char *progname;
31    
32    
33     main(argc, argv)
34     int argc;
35     char *argv[];
36     {
37     char *err;
38     int rval, getdim = 0;
39     register int i;
40    
41     progname = argv[0];
42     if (argc < 2)
43     goto userr;
44     for (i = 1; i < argc && argv[i][0] == '-'; i++)
45     switch (argv[i][1]) {
46     case 'f': /* output format */
47     switch (argv[i][2]) {
48     case 'a': /* ASCII */
49     putr = puta;
50     break;
51     case 'f': /* float */
52     putr = putf;
53     break;
54     case 'd': /* double */
55     putr = putd;
56     break;
57     default:
58     goto userr;
59     }
60     break;
61     case 'v': /* view file or option */
62     if (argv[i][2] == 'f') {
63     rval = viewfile(argv[++i], &vw, NULL);
64     if (rval <= 0) {
65     fprintf(stderr,
66     "%s: no view in file\n",
67     argv[i]);
68     exit(1);
69     }
70     break;
71     }
72     rval = getviewopt(&vw, argc-i, argv+i);
73     if (rval < 0)
74     goto userr;
75     i += rval;
76     break;
77     case 'd': /* report dimensions only */
78     getdim++;
79     break;
80     case 'x': /* x resolution */
81     rs.xr = atoi(argv[++i]);
82     if (rs.xr <= 0) {
83     fprintf(stderr, "%s: bad x resolution\n",
84     progname);
85     exit(1);
86     }
87     break;
88     case 'y': /* y resolution */
89     rs.yr = atoi(argv[++i]);
90     if (rs.yr <= 0) {
91     fprintf(stderr, "%s: bad y resolution\n",
92     progname);
93     exit(1);
94     }
95     break;
96     case 'p': /* pixel aspect ratio */
97     pa = atof(argv[++i]);
98     break;
99     default:
100     goto userr;
101     }
102     if (i > argc | i+2 < argc)
103     goto userr;
104     if (i < argc) {
105     rval = viewfile(argv[i], &vw, &rs);
106     if (rval <= 0) {
107     fprintf(stderr, "%s: no view in picture\n", argv[i]);
108     exit(1);
109     }
110     if (i+1 < argc) {
111     zfd = open(argv[i+1], O_RDONLY);
112     if (zfd < 0) {
113     fprintf(stderr,
114     "%s: cannot open depth buffer\n",
115     argv[i+1]);
116     exit(1);
117     }
118     }
119     }
120     if ((err = setview(&vw)) != NULL) {
121     fprintf(stderr, "%s: %s\n", progname, err);
122     exit(1);
123     }
124     if (i == argc)
125     normaspect(viewaspect(&vw), &pa, &rs.xr, &rs.yr);
126     if (getdim) {
127     printf("-x %d -y %d\n", rs.xr, rs.yr);
128     exit(0);
129     }
130     putrays();
131     exit(0);
132     userr:
133     fprintf(stderr,
134     "Usage: %s [ -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
135     progname);
136     exit(1);
137     }
138    
139    
140     putrays()
141     {
142 gregl 3.2 static FLOAT loc[2];
143     static FVECT rorg, rdir;
144 gregl 3.1 float *zbuf;
145     int sc;
146 gregl 3.2 double d;
147 gregl 3.1 register int si, i;
148    
149     if (zfd >= 0) {
150     zbuf = (float *)malloc(scanlen(&rs)*sizeof(float));
151     if (zbuf == NULL) {
152     fprintf(stderr, "%s: not enough memory\n", progname);
153     exit(1);
154     }
155     }
156     for (sc = 0; sc < numscans(&rs); sc++) {
157     if (zfd >= 0) {
158     if (read(zfd, zbuf, scanlen(&rs)*sizeof(float)) <
159     scanlen(&rs)*sizeof(float)) {
160     fprintf(stderr, "%s: depth buffer read error\n",
161     progname);
162     exit(1);
163     }
164     }
165     for (si = 0; si < scanlen(&rs); si++) {
166     pix2loc(loc, &rs, si, sc);
167 gregl 3.2 d = viewray(rorg, rdir, &vw, loc[0], loc[1]);
168     if (d < -FTINY)
169 gregl 3.1 rorg[0] = rorg[1] = rorg[2] =
170     rdir[0] = rdir[1] = rdir[2] = 0.;
171     else if (zfd >= 0)
172     for (i = 0; i < 3; i++) {
173     rorg[i] += rdir[i]*zbuf[si];
174     rdir[i] = -rdir[i];
175     }
176 gregl 3.2 else if (d > FTINY) {
177     rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
178     }
179 gregl 3.1 (*putr)(rorg, rdir);
180     }
181     }
182     if (zfd >= 0)
183     free((char *)zbuf);
184     }
185    
186    
187     puta(ro, rd) /* put out ray in ASCII format */
188     FVECT ro, rd;
189     {
190     printf("%.5e %.5e %.5e %.5e %.5e %.5e\n",
191     ro[0], ro[1], ro[2],
192     rd[0], rd[1], rd[2]);
193     }
194    
195    
196     putf(ro, rd) /* put out ray in float format */
197     FVECT ro, rd;
198     {
199     float v[6];
200    
201     v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2];
202     v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2];
203     fwrite(v, sizeof(float), 6, stdout);
204     }
205    
206    
207     putd(ro, rd) /* put out ray in double format */
208     FVECT ro, rd;
209     {
210     double v[6];
211    
212     v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2];
213     v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2];
214     fwrite(v, sizeof(double), 6, stdout);
215     }