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.9 by greg, Wed Oct 22 02:06:35 2003 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  
16 #include "resolu.h"
17
12   extern int      putf(), putd(), puta();
13  
14   int     (*putr)() = puta;
# Line 27 | Line 21 | double pa = 1.;
21  
22   int     zfd = -1;
23  
24 + int     fromstdin = 0;
25 +
26   char    *progname;
27  
28  
# Line 96 | Line 92 | char   *argv[];
92                  case 'p':                       /* pixel aspect ratio */
93                          pa = atof(argv[++i]);
94                          break;
95 +                case 'i':                       /* get pixels from stdin */
96 +                        fromstdin = 1;
97 +                        break;
98                  default:
99                          goto userr;
100                  }
101 <        if (i > argc | i+2 < argc)
101 >        if ((i > argc) | (i+2 < argc))
102                  goto userr;
103          if (i < argc) {
104                  rval = viewfile(argv[i], &vw, &rs);
# Line 128 | Line 127 | char   *argv[];
127                                  vw.vaft > FTINY ? '+' : '-');
128                  exit(0);
129          }
130 <        putrays();
130 >        if (fromstdin)
131 >                pix2rays(stdin);
132 >        else
133 >                putrays();
134          exit(0);
135   userr:
136          fprintf(stderr,
137 <        "Usage: %s [ -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
137 >        "Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n",
138                          progname);
139          exit(1);
140   }
141  
142  
143 + pix2rays(FILE *fp)
144 + {
145 +        static FVECT    rorg, rdir;
146 +        float   zval;
147 +        double  px, py;
148 +        int     pp[2];
149 +        double  d;
150 +        register int    i;
151 +
152 +        while (fscanf(fp, "%lf %lf", &px, &py) == 2) {
153 +                if (px < 0 || px >= rs.xr ||
154 +                                py < 0 || py >= rs.yr) {
155 +                        fprintf(stderr,
156 +                                "%s: (x,y) pair (%.0f,%.0f) out of range\n",
157 +                                        progname, px, py);
158 +                        exit(1);
159 +                }
160 +                if (zfd >= 0) {
161 +                        loc2pix(pp, &rs, px/rs.xr, py/rs.yr);
162 +                        if (lseek(zfd,
163 +                                (pp[1]*scanlen(&rs)+pp[0])*sizeof(float),
164 +                                                SEEK_SET) < 0 ||
165 +                                        read(zfd, &zval, sizeof(float))
166 +                                                < sizeof(float)) {
167 +                                fprintf(stderr, "%s: depth buffer read error\n",
168 +                                                progname);
169 +                                exit(1);
170 +                        }
171 +                }
172 +                d = viewray(rorg, rdir, &vw, px/rs.xr, py/rs.yr);
173 +                if (d < -FTINY)
174 +                        rorg[0] = rorg[1] = rorg[2] =
175 +                        rdir[0] = rdir[1] = rdir[2] = 0.;
176 +                else if (zfd >= 0)
177 +                        for (i = 0; i < 3; i++) {
178 +                                rorg[i] += rdir[i]*zval;
179 +                                rdir[i] = -rdir[i];
180 +                        }
181 +                else if (d > FTINY) {
182 +                        rdir[0] *= d; rdir[1] *= d; rdir[2] *= d;
183 +                }
184 +                (*putr)(rorg, rdir);
185 +        }
186 +        if (!feof(fp)) {
187 +                fprintf(stderr, "%s: expected px py on input\n", progname);
188 +                exit(1);
189 +        }
190 + }
191 +
192 +
193   putrays()
194   {
195 <        static FLOAT    loc[2];
195 >        static RREAL    loc[2];
196          static FVECT    rorg, rdir;
197          float   *zbuf;
198          int     sc;
# Line 181 | Line 233 | putrays()
233                  }
234          }
235          if (zfd >= 0)
236 <                free((char *)zbuf);
236 >                free((void *)zbuf);
237   }
238  
239  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines