1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
– |
|
4 |
|
/* |
5 |
|
* Display an image and watch the rays get traced. |
6 |
|
* |
13 |
|
|
14 |
|
#define MAXDEPTH 32 /* ridiculous ray tree depth */ |
15 |
|
|
16 |
+ |
#ifdef SMLFLT |
17 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
18 |
+ |
#else |
19 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
20 |
+ |
#endif |
21 |
+ |
|
22 |
|
char rtcom[] = "rtrace -h- -otp -fa -x 1"; |
23 |
< |
char xicom[] = "ximage"; |
23 |
> |
char xicom[] = "ximage -c 256"; |
24 |
|
|
25 |
|
VIEW ourview = STDVIEW; /* view for picture */ |
26 |
< |
int xres, yres; |
26 |
> |
RESOLU ourres; /* picture resolution */ |
27 |
|
|
28 |
|
char *progname; /* program name */ |
29 |
|
|
34 |
|
Display *theDisplay = NULL; /* connection to server */ |
35 |
|
|
36 |
|
struct node { /* ray tree node */ |
37 |
< |
double ipt[2]; |
37 |
> |
int ipt[2]; |
38 |
|
struct node *sister; |
39 |
|
struct node *daughter; |
40 |
|
}; |
64 |
|
} |
65 |
|
picture = argv[argc-1]; |
66 |
|
/* get the viewing parameters */ |
67 |
< |
if (viewfile(picture, &ourview, &xres, &yres) <= 0 || |
67 |
> |
if (viewfile(picture, &ourview, &ourres) <= 0 || |
68 |
|
setview(&ourview) != NULL) { |
69 |
|
fprintf(stderr, "%s: cannot get view from \"%s\"\n", |
70 |
|
progname, picture); |
88 |
|
exit(1); |
89 |
|
/* loop on input */ |
90 |
|
mainloop(); |
91 |
< |
|
91 |
> |
/* close pipe and exit */ |
92 |
> |
pclose(pin); |
93 |
|
exit(0); |
94 |
|
} |
95 |
|
|
136 |
|
freetree(tp) /* free a trace tree */ |
137 |
|
struct node *tp; |
138 |
|
{ |
139 |
< |
register struct node *kid; |
139 |
> |
register struct node *kid, *k2; |
140 |
|
|
141 |
< |
for (kid = tp->daughter; kid != NULL; kid = kid->sister) |
141 |
> |
for (kid = tp->daughter; kid != NULL; kid = k2) { |
142 |
> |
k2 = kid->sister; |
143 |
|
freetree(kid); |
144 |
< |
free((char *)tp); |
144 |
> |
} |
145 |
> |
free((void *)tp); |
146 |
|
} |
147 |
|
|
148 |
|
|
159 |
|
|
160 |
|
|
161 |
|
strtoipt(ipt, str) /* convert string x y z to image point */ |
162 |
< |
double ipt[2]; |
162 |
> |
int ipt[2]; |
163 |
|
char *str; |
164 |
|
{ |
165 |
< |
FVECT pt; |
165 |
> |
FVECT im_pt, pt; |
166 |
|
|
167 |
< |
if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3) |
167 |
> |
if (!sscanvec(str, pt)) |
168 |
|
return(-1); |
169 |
< |
viewpixel(&ipt[0], &ipt[1], NULL, &ourview, pt); |
169 |
> |
if (DOT(pt,pt) <= FTINY) /* origin is really infinity */ |
170 |
> |
ipt[0] = ipt[1] = -1; /* null vector */ |
171 |
> |
else { |
172 |
> |
viewloc(im_pt, &ourview, pt); |
173 |
> |
loc2pix(ipt, &ourres, im_pt[0], im_pt[1]); |
174 |
> |
} |
175 |
|
return(0); |
176 |
|
} |
177 |
|
|
185 |
|
|
186 |
|
|
187 |
|
setvec(ipt) /* set up vector drawing for pick */ |
188 |
< |
double ipt[2]; |
188 |
> |
int ipt[2]; |
189 |
|
{ |
190 |
+ |
extern Window xfindwind(); |
191 |
|
XWindowAttributes wa; |
192 |
|
XColor xc; |
193 |
|
XGCValues gcv; |
195 |
|
Window rw, cw; |
196 |
|
unsigned int pm; |
197 |
|
/* compute pointer location */ |
198 |
< |
if (gwind == 0 && |
199 |
< |
(gwind = xfindwind(theDisplay, rwind, picture, 2)) == 0) { |
200 |
< |
fprintf(stderr, "%s: cannot find display window!\n", progname); |
201 |
< |
exit(1); |
198 |
> |
if (gwind == 0) { |
199 |
> |
register char *wn; |
200 |
> |
for (wn = picture; *wn; wn++); |
201 |
> |
while (wn > picture && wn[-1] != '/') wn--; |
202 |
> |
if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) { |
203 |
> |
fprintf(stderr, "%s: cannot find display window!\n", |
204 |
> |
progname); |
205 |
> |
exit(1); |
206 |
> |
} |
207 |
|
} |
208 |
|
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
209 |
< |
xoff = wx - ipt[0]*xres; |
210 |
< |
yoff = wy - (1.-ipt[1])*yres; |
209 |
> |
xoff = wx - ipt[0]; |
210 |
> |
yoff = wy - ipt[1]; |
211 |
|
/* set graphics context */ |
212 |
|
if (vecGC == 0) { |
213 |
|
XGetWindowAttributes(theDisplay, gwind, &wa); |
225 |
|
|
226 |
|
|
227 |
|
vector(ip1, ip2) /* draw a vector */ |
228 |
< |
double ip1[2], ip2[2]; |
228 |
> |
int ip1[2], ip2[2]; |
229 |
|
{ |
230 |
+ |
if (ip2[0] == -1 && ip2[1] == -1) |
231 |
+ |
return; /* null vector */ |
232 |
|
XDrawLine(theDisplay, gwind, vecGC, |
233 |
< |
(int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff, |
234 |
< |
(int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff); |
233 |
> |
ip1[0]+xoff, ip1[1]+yoff, |
234 |
> |
ip2[0]+xoff, ip2[1]+yoff); |
235 |
|
if (slow) { |
236 |
|
XFlush(theDisplay); |
237 |
|
sleep(1); |