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"; |
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 |
|
XWindowAttributes wa; |
193 |
|
XColor xc; |
202 |
|
exit(1); |
203 |
|
} |
204 |
|
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
205 |
< |
xoff = wx - ipt[0]*xres; |
206 |
< |
yoff = wy - (1.-ipt[1])*yres; |
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); |