ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/vwrays.c
(Generate patch)

Comparing ray/src/util/vwrays.c (file contents):
Revision 3.3 by gregl, Fri Oct 17 10:42:45 1997 UTC vs.
Revision 3.10 by schorsch, Fri Mar 26 23:34:23 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Compute rays corresponding to a given picture or view.
6   */
7  
8 <
8 > #include "platform.h"
9   #include "standard.h"
13
10   #include "view.h"
11  
12 < #include "resolu.h"
12 > typedef void putfunc(FVECT ro, FVECT rd);
13 > static putfunc puta;
14 > static putfunc putf;
15 > static putfunc putd;
16 > static void pix2rays(FILE *fp);
17 > static void putrays(void);
18  
19 < extern int      putf(), putd(), puta();
19 > static putfunc *putr = puta;
20  
20 int     (*putr)() = puta;
21
21   VIEW    vw = STDVIEW;
22  
23   RESOLU  rs = {PIXSTANDARD, 512, 512};
# Line 27 | Line 26 | double pa = 1.;
26  
27   int     zfd = -1;
28  
29 + int     fromstdin = 0;
30 +
31   char    *progname;
32  
33  
34 < main(argc, argv)
35 < int     argc;
36 < char    *argv[];
34 > int
35 > main(
36 >        int     argc,
37 >        char    *argv[]
38 > )
39   {
40          char    *err;
41          int     rval, getdim = 0;
# Line 96 | Line 99 | char   *argv[];
99                  case 'p':                       /* pixel aspect ratio */
100                          pa = atof(argv[++i]);
101                          break;
102 +                case 'i':                       /* get pixels from stdin */
103 +                        fromstdin = 1;
104 +                        break;
105                  default:
106                          goto userr;
107                  }
108 <        if (i > argc | i+2 < argc)
108 >        if ((i > argc) | (i+2 < argc))
109                  goto userr;
110          if (i < argc) {
111                  rval = viewfile(argv[i], &vw, &rs);
# Line 128 | Line 134 | char   *argv[];
134                                  vw.vaft > FTINY ? '+' : '-');
135                  exit(0);
136          }
137 <        putrays();
137 >        if (fromstdin)
138 >                pix2rays(stdin);
139 >        else
140 >                putrays();
141          exit(0);
142   userr:
143          fprintf(stderr,
144 <        "Usage: %s [ -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
144 >        "Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
145                          progname);
146          exit(1);
147   }
148  
149  
150 < putrays()
150 > static void
151 > pix2rays(
152 >        FILE *fp
153 > )
154   {
143        static FLOAT    loc[2];
155          static FVECT    rorg, rdir;
156 <        float   *zbuf;
156 >        float   zval;
157 >        double  px, py;
158 >        int     pp[2];
159 >        double  d;
160 >        register int    i;
161 >
162 >        while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
163 >                if (px < 0 || px >= rs.xr ||
164 >                                py < 0 || py >= rs.yr) {
165 >                        fprintf(stderr,
166 >                                "%s: (x,y) pair (%.0f,%.0f) out of range\n",
167 >                                        progname, px, py);
168 >                        exit(1);
169 >                }
170 >                if (zfd >= 0) {
171 >                        loc2pix(pp, &rs, px/rs.xr, py/rs.yr);
172 >                        if (lseek(zfd,
173 >                                (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
174 >                                                SEEK_SET) < 0 ||
175 >                                        read(zfd, &zval, sizeof(float))
176 >                                                < sizeof(float)) {
177 >                                fprintf(stderr, "%s: depth buffer read error\n",
178 >                                                progname);
179 >                                exit(1);
180 >                        }
181 >                }
182 >                d = viewray(rorg, rdir, &vw, px/rs.xr, py/rs.yr);
183 >                if (d < -FTINY)
184 >                        rorg[0] = rorg[1] = rorg[2] =
185 >                        rdir[0] = rdir[1] = rdir[2] = 0.;
186 >                else if (zfd >= 0)
187 >                        for (i = 0; i < 3; i++) {
188 >                                rorg[i] += rdir[i]*zval;
189 >                                rdir[i] = -rdir[i];
190 >                        }
191 >                else if (d > FTINY) {
192 >                        rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
193 >                }
194 >                (*putr)(rorg, rdir);
195 >        }
196 >        if (!feof(fp)) {
197 >                fprintf(stderr, "%s: expected px py on input\n", progname);
198 >                exit(1);
199 >        }
200 > }
201 >
202 >
203 > static void
204 > putrays(void)
205 > {
206 >        static RREAL    loc[2];
207 >        static FVECT    rorg, rdir;
208 >        float   *zbuf = NULL;
209          int     sc;
210          double  d;
211          register int    si, i;
# Line 181 | Line 244 | putrays()
244                  }
245          }
246          if (zfd >= 0)
247 <                free((char *)zbuf);
247 >                free((void *)zbuf);
248   }
249  
250  
251 < puta(ro, rd)            /* put out ray in ASCII format */
252 < FVECT   ro, rd;
251 > static void
252 > puta(           /* put out ray in ASCII format */
253 >        FVECT   ro,
254 >        FVECT   rd
255 > )
256   {
257          printf("%.5e %.5e %.5e %.5e %.5e %.5e\n",
258                          ro[0], ro[1], ro[2],
# Line 194 | Line 260 | FVECT  ro, rd;
260   }
261  
262  
263 < putf(ro, rd)            /* put out ray in float format */
264 < FVECT   ro, rd;
263 > static void
264 > putf(           /* put out ray in float format */
265 >        FVECT   ro,
266 >        FVECT   rd
267 > )
268   {
269          float v[6];
270  
# Line 205 | Line 274 | FVECT  ro, rd;
274   }
275  
276  
277 < putd(ro, rd)            /* put out ray in double format */
278 < FVECT   ro, rd;
277 > static void
278 > putd(           /* put out ray in double format */
279 >        FVECT   ro,
280 >        FVECT   rd
281 > )
282   {
283          double v[6];
284  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines