| 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 |
< |
FVECT ipt; |
| 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 |
< |
FVECT ipt; |
| 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 |
< |
viewloc(ipt, &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; |
| 198 |
|
unsigned int pm; |
| 199 |
|
/* compute pointer location */ |
| 200 |
|
if (gwind == 0 && |
| 201 |
< |
(gwind = xfindwind(theDisplay, rwind, picture, 2)) == 0) { |
| 201 |
> |
(gwind = xfindwind(theDisplay, rwind, picture, 4)) == 0) { |
| 202 |
|
fprintf(stderr, "%s: cannot find display window!\n", progname); |
| 203 |
|
exit(1); |
| 204 |
|
} |
| 205 |
|
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
| 206 |
< |
xoff = wx - ipt[0]*xres; |
| 207 |
< |
yoff = wy - (1.-ipt[1])*yres; |
| 206 |
> |
xoff = wx - ipt[0]; |
| 207 |
> |
yoff = wy - ipt[1]; |
| 208 |
|
/* set graphics context */ |
| 209 |
|
if (vecGC == 0) { |
| 210 |
|
XGetWindowAttributes(theDisplay, gwind, &wa); |
| 222 |
|
|
| 223 |
|
|
| 224 |
|
vector(ip1, ip2) /* draw a vector */ |
| 225 |
< |
double ip1[2], ip2[2]; |
| 225 |
> |
int ip1[2], ip2[2]; |
| 226 |
|
{ |
| 227 |
+ |
if (ip2[0] == -1 && ip2[1] == -1) |
| 228 |
+ |
return; /* null vector */ |
| 229 |
|
XDrawLine(theDisplay, gwind, vecGC, |
| 230 |
< |
(int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff, |
| 231 |
< |
(int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff); |
| 230 |
> |
ip1[0]+xoff, ip1[1]+yoff, |
| 231 |
> |
ip2[0]+xoff, ip2[1]+yoff); |
| 232 |
|
if (slow) { |
| 233 |
|
XFlush(theDisplay); |
| 234 |
|
sleep(1); |