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 |
< |
char rtcom[] = "rtrace -h -otp -fa -x 1"; |
21 |
< |
char xicom[] = "x11image"; |
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"; |
28 |
+ |
|
29 |
|
VIEW ourview = STDVIEW; /* view for picture */ |
30 |
< |
int xres, yres; |
30 |
> |
RESOLU ourres; /* picture resolution */ |
31 |
|
|
32 |
|
char *progname; /* program name */ |
33 |
|
|
34 |
+ |
char *picture; /* picture name */ |
35 |
+ |
|
36 |
|
FILE *pin; /* input stream */ |
37 |
|
|
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 |
|
}; |
54 |
|
{ |
55 |
|
int i; |
56 |
|
char combuf[256]; |
46 |
– |
Cursor curs; |
57 |
|
|
58 |
|
progname = argv[0]; |
59 |
|
for (i = 1; i < argc-2; i++) |
63 |
|
break; |
64 |
|
if (i > argc-2) { |
65 |
|
fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n", |
66 |
< |
argv[0]); |
66 |
> |
progname); |
67 |
|
exit(1); |
68 |
|
} |
69 |
+ |
picture = argv[argc-1]; |
70 |
|
/* get the viewing parameters */ |
71 |
< |
if (viewfile(argv[argc-1], &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 |
< |
argv[0], argv[argc-1]); |
74 |
> |
progname, picture); |
75 |
|
exit(1); |
76 |
|
} |
77 |
|
/* open the display */ |
78 |
|
if ((theDisplay = XOpenDisplay(NULL)) == NULL) { |
79 |
|
fprintf(stderr, |
80 |
|
"%s: cannot open display; DISPLAY variable set?\n", |
81 |
< |
argv[0]); |
81 |
> |
progname); |
82 |
|
exit(1); |
83 |
|
} |
84 |
|
/* build input command */ |
85 |
< |
sprintf(combuf, "%s %s | %s", xicom, argv[argc-1], rtcom); |
85 |
> |
sprintf(combuf, "%s %s | %s", xicom, picture, rtcom); |
86 |
|
for ( ; i < argc-1; i++) { |
87 |
|
strcat(combuf, " "); |
88 |
|
strcat(combuf, argv[i]); |
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 |
|
XWindowAttributes wa; |
193 |
|
XColor xc; |
194 |
|
XGCValues gcv; |
195 |
< |
int pm, rx, ry, wx, wy, rw, cw; |
195 |
> |
int rx, ry, wx, wy; |
196 |
> |
Window rw, cw; |
197 |
> |
unsigned int pm; |
198 |
|
/* compute pointer location */ |
199 |
< |
if (gwind == 0) { |
200 |
< |
XQueryPointer(theDisplay, rwind, &rw, &gwind, |
201 |
< |
&rx, &ry, &wx, &wy, &pm); |
199 |
> |
if (gwind == 0 && |
200 |
> |
(gwind = xfindwind(theDisplay, rwind, picture, 2)) == 0) { |
201 |
> |
fprintf(stderr, "%s: cannot find display window!\n", progname); |
202 |
> |
exit(1); |
203 |
|
} |
204 |
< |
XQueryPointer(theDisplay, gwind, &rw, &cw, |
205 |
< |
&rx, &ry, &wx, &wy, &pm); |
206 |
< |
xoff = wx - ipt[0]*xres; |
187 |
< |
yoff = wy - (1.-ipt[1])*yres; |
204 |
> |
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
205 |
> |
xoff = wx - ipt[0]; |
206 |
> |
yoff = wy - ipt[1]; |
207 |
|
/* set graphics context */ |
208 |
|
if (vecGC == 0) { |
209 |
|
XGetWindowAttributes(theDisplay, gwind, &wa); |
221 |
|
|
222 |
|
|
223 |
|
vector(ip1, ip2) /* draw a vector */ |
224 |
< |
double ip1[2], ip2[2]; |
224 |
> |
int ip1[2], ip2[2]; |
225 |
|
{ |
226 |
+ |
if (ip2[0] == -1 && ip2[1] == -1) |
227 |
+ |
return; /* null vector */ |
228 |
|
XDrawLine(theDisplay, gwind, vecGC, |
229 |
< |
(int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff, |
230 |
< |
(int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff); |
229 |
> |
ip1[0]+xoff, ip1[1]+yoff, |
230 |
> |
ip2[0]+xoff, ip2[1]+yoff); |
231 |
|
if (slow) { |
232 |
|
XFlush(theDisplay); |
233 |
|
sleep(1); |