1 |
+ |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
+ |
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
#endif |
12 |
|
|
13 |
|
#include "standard.h" |
14 |
|
#include "view.h" |
15 |
+ |
#include "resolu.h" |
16 |
|
#include <X11/Xlib.h> |
17 |
|
|
18 |
|
#define MAXDEPTH 32 /* ridiculous ray tree depth */ |
19 |
|
|
20 |
+ |
#ifdef SMLFLT |
21 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
22 |
+ |
#else |
23 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
24 |
+ |
#endif |
25 |
+ |
|
26 |
|
char rtcom[] = "rtrace -h- -otp -fa -x 1"; |
27 |
< |
char xicom[] = "ximage"; |
27 |
> |
char xicom[] = "ximage -c 256"; |
28 |
|
|
29 |
|
VIEW ourview = STDVIEW; /* view for picture */ |
30 |
< |
int xres, yres; |
30 |
> |
RESOLU ourres; /* picture resolution */ |
31 |
|
|
32 |
|
char *progname; /* program name */ |
33 |
|
|
38 |
|
Display *theDisplay = NULL; /* connection to server */ |
39 |
|
|
40 |
|
struct node { /* ray tree node */ |
41 |
< |
double ipt[2]; |
41 |
> |
int ipt[2]; |
42 |
|
struct node *sister; |
43 |
|
struct node *daughter; |
44 |
|
}; |
68 |
|
} |
69 |
|
picture = argv[argc-1]; |
70 |
|
/* get the viewing parameters */ |
71 |
< |
if (viewfile(picture, &ourview, &xres, &yres) <= 0 || |
71 |
> |
if (viewfile(picture, &ourview, &ourres) <= 0 || |
72 |
|
setview(&ourview) != NULL) { |
73 |
|
fprintf(stderr, "%s: cannot get view from \"%s\"\n", |
74 |
|
progname, picture); |
92 |
|
exit(1); |
93 |
|
/* loop on input */ |
94 |
|
mainloop(); |
95 |
< |
|
95 |
> |
/* close pipe and exit */ |
96 |
> |
pclose(pin); |
97 |
|
exit(0); |
98 |
|
} |
99 |
|
|
161 |
|
|
162 |
|
|
163 |
|
strtoipt(ipt, str) /* convert string x y z to image point */ |
164 |
< |
double ipt[2]; |
164 |
> |
int ipt[2]; |
165 |
|
char *str; |
166 |
|
{ |
167 |
< |
FVECT pt; |
167 |
> |
FVECT im_pt, pt; |
168 |
|
|
169 |
< |
if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3) |
169 |
> |
if (!sscanvec(str, pt)) |
170 |
|
return(-1); |
171 |
< |
viewpixel(&ipt[0], &ipt[1], NULL, &ourview, pt); |
171 |
> |
if (DOT(pt,pt) <= FTINY) /* origin is really infinity */ |
172 |
> |
ipt[0] = ipt[1] = -1; /* null vector */ |
173 |
> |
else { |
174 |
> |
viewloc(im_pt, &ourview, pt); |
175 |
> |
loc2pix(ipt, &ourres, im_pt[0], im_pt[1]); |
176 |
> |
} |
177 |
|
return(0); |
178 |
|
} |
179 |
|
|
187 |
|
|
188 |
|
|
189 |
|
setvec(ipt) /* set up vector drawing for pick */ |
190 |
< |
double ipt[2]; |
190 |
> |
int ipt[2]; |
191 |
|
{ |
192 |
+ |
extern Window xfindwind(); |
193 |
|
XWindowAttributes wa; |
194 |
|
XColor xc; |
195 |
|
XGCValues gcv; |
197 |
|
Window rw, cw; |
198 |
|
unsigned int pm; |
199 |
|
/* compute pointer location */ |
200 |
< |
if (gwind == 0 && |
201 |
< |
(gwind = xfindwind(theDisplay, rwind, picture, 2)) == 0) { |
202 |
< |
fprintf(stderr, "%s: cannot find display window!\n", progname); |
203 |
< |
exit(1); |
200 |
> |
if (gwind == 0) { |
201 |
> |
register char *wn; |
202 |
> |
for (wn = picture; *wn; wn++); |
203 |
> |
while (wn > picture && wn[-1] != '/') wn--; |
204 |
> |
if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) { |
205 |
> |
fprintf(stderr, "%s: cannot find display window!\n", |
206 |
> |
progname); |
207 |
> |
exit(1); |
208 |
> |
} |
209 |
|
} |
210 |
|
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
211 |
< |
xoff = wx - ipt[0]*xres; |
212 |
< |
yoff = wy - (1.-ipt[1])*yres; |
211 |
> |
xoff = wx - ipt[0]; |
212 |
> |
yoff = wy - ipt[1]; |
213 |
|
/* set graphics context */ |
214 |
|
if (vecGC == 0) { |
215 |
|
XGetWindowAttributes(theDisplay, gwind, &wa); |
227 |
|
|
228 |
|
|
229 |
|
vector(ip1, ip2) /* draw a vector */ |
230 |
< |
double ip1[2], ip2[2]; |
230 |
> |
int ip1[2], ip2[2]; |
231 |
|
{ |
232 |
+ |
if (ip2[0] == -1 && ip2[1] == -1) |
233 |
+ |
return; /* null vector */ |
234 |
|
XDrawLine(theDisplay, gwind, vecGC, |
235 |
< |
(int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff, |
236 |
< |
(int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff); |
235 |
> |
ip1[0]+xoff, ip1[1]+yoff, |
236 |
> |
ip2[0]+xoff, ip2[1]+yoff); |
237 |
|
if (slow) { |
238 |
|
XFlush(theDisplay); |
239 |
|
sleep(1); |