| 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 |
|
* |
| 7 |
|
* 9/21/90 Greg Ward |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
+ |
#include <X11/Xlib.h> |
| 11 |
+ |
|
| 12 |
|
#include "standard.h" |
| 13 |
+ |
#include "paths.h" |
| 14 |
|
#include "view.h" |
| 13 |
– |
#include <X11/Xlib.h> |
| 15 |
|
|
| 16 |
|
#define MAXDEPTH 32 /* ridiculous ray tree depth */ |
| 17 |
|
|
| 18 |
< |
char rtcom[] = "rtrace -h -otp -fa -x 1"; |
| 18 |
< |
char xicom[] = "x11image -f"; |
| 18 |
> |
#define sscanvec(s,v) (sscanf(s,FVFORMAT,v,v+1,v+2)==3) |
| 19 |
|
|
| 20 |
+ |
char rtcom[64] = "rtrace -h- -otp -fa -x 1"; |
| 21 |
+ |
char xicom[] = "ximage -c 256"; |
| 22 |
+ |
|
| 23 |
|
VIEW ourview = STDVIEW; /* view for picture */ |
| 24 |
< |
int xres, yres; |
| 24 |
> |
RESOLU ourres; /* picture resolution */ |
| 25 |
|
|
| 26 |
< |
char *progname; /* program name */ |
| 26 |
> |
char *picture; /* picture name */ |
| 27 |
|
|
| 28 |
|
FILE *pin; /* input stream */ |
| 29 |
|
|
| 30 |
|
Display *theDisplay = NULL; /* connection to server */ |
| 31 |
|
|
| 32 |
|
struct node { /* ray tree node */ |
| 33 |
< |
double ipt[2]; |
| 33 |
> |
int ipt[2]; |
| 34 |
|
struct node *sister; |
| 35 |
|
struct node *daughter; |
| 36 |
|
}; |
| 39 |
|
|
| 40 |
|
int slow = 0; /* slow trace? */ |
| 41 |
|
|
| 42 |
+ |
void mainloop(void); |
| 43 |
+ |
static void freetree(struct node *tp); |
| 44 |
+ |
static void tracerays(struct node *tp); |
| 45 |
+ |
static int strtoipt(int ipt[2], char *str); |
| 46 |
+ |
static void setvec(int ipt[2]); |
| 47 |
+ |
static void vector(int ip1[2], int ip2[2]); |
| 48 |
|
|
| 49 |
< |
main(argc, argv) /* takes both the octree and the image */ |
| 50 |
< |
int argc; |
| 51 |
< |
char *argv[]; |
| 49 |
> |
|
| 50 |
> |
int |
| 51 |
> |
main( /* takes both the octree and the image */ |
| 52 |
> |
int argc, |
| 53 |
> |
char *argv[] |
| 54 |
> |
) |
| 55 |
|
{ |
| 56 |
|
int i; |
| 57 |
< |
char combuf[256]; |
| 46 |
< |
Cursor curs; |
| 57 |
> |
char combuf[PATH_MAX]; |
| 58 |
|
|
| 59 |
< |
progname = argv[0]; |
| 59 |
> |
fixargv0(argv[0]); /* sets global progname */ |
| 60 |
|
for (i = 1; i < argc-2; i++) |
| 61 |
|
if (!strcmp(argv[i], "-s")) |
| 62 |
|
slow++; |
| 63 |
+ |
else if (!strcmp(argv[i], "-T")) |
| 64 |
+ |
strcat(rtcom, " -oTp"); |
| 65 |
|
else |
| 66 |
|
break; |
| 67 |
|
if (i > argc-2) { |
| 68 |
< |
fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n", |
| 69 |
< |
argv[0]); |
| 68 |
> |
fprintf(stderr, "Usage: %s [-s][-T] [rtrace args] octree picture\n", |
| 69 |
> |
progname); |
| 70 |
|
exit(1); |
| 71 |
|
} |
| 72 |
+ |
picture = argv[argc-1]; |
| 73 |
|
/* get the viewing parameters */ |
| 74 |
< |
if (viewfile(argv[argc-1], &ourview, &xres, &yres) <= 0 || |
| 74 |
> |
if (viewfile(picture, &ourview, &ourres) <= 0 || |
| 75 |
|
setview(&ourview) != NULL) { |
| 76 |
|
fprintf(stderr, "%s: cannot get view from \"%s\"\n", |
| 77 |
< |
argv[0], argv[argc-1]); |
| 77 |
> |
progname, picture); |
| 78 |
|
exit(1); |
| 79 |
|
} |
| 80 |
|
/* open the display */ |
| 81 |
|
if ((theDisplay = XOpenDisplay(NULL)) == NULL) { |
| 82 |
|
fprintf(stderr, |
| 83 |
|
"%s: cannot open display; DISPLAY variable set?\n", |
| 84 |
< |
argv[0]); |
| 84 |
> |
progname); |
| 85 |
|
exit(1); |
| 86 |
|
} |
| 87 |
|
/* build input command */ |
| 88 |
< |
sprintf(combuf, "%s %s | %s", xicom, argv[argc-1], rtcom); |
| 88 |
> |
sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom); |
| 89 |
|
for ( ; i < argc-1; i++) { |
| 90 |
|
strcat(combuf, " "); |
| 91 |
|
strcat(combuf, argv[i]); |
| 95 |
|
exit(1); |
| 96 |
|
/* loop on input */ |
| 97 |
|
mainloop(); |
| 98 |
< |
|
| 98 |
> |
/* close pipe and exit */ |
| 99 |
> |
pclose(pin); |
| 100 |
|
exit(0); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
< |
mainloop() /* get and process input */ |
| 104 |
> |
void |
| 105 |
> |
mainloop(void) /* get and process input */ |
| 106 |
|
{ |
| 107 |
|
static struct node *sis[MAXDEPTH]; |
| 108 |
|
register struct node *newp; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
< |
freetree(tp) /* free a trace tree */ |
| 145 |
< |
struct node *tp; |
| 144 |
> |
static void |
| 145 |
> |
freetree( /* free a trace tree */ |
| 146 |
> |
struct node *tp |
| 147 |
> |
) |
| 148 |
|
{ |
| 149 |
< |
register struct node *kid; |
| 149 |
> |
register struct node *kid, *k2; |
| 150 |
|
|
| 151 |
< |
for (kid = tp->daughter; kid != NULL; kid = kid->sister) |
| 151 |
> |
for (kid = tp->daughter; kid != NULL; kid = k2) { |
| 152 |
> |
k2 = kid->sister; |
| 153 |
|
freetree(kid); |
| 154 |
< |
free((char *)tp); |
| 154 |
> |
} |
| 155 |
> |
free((void *)tp); |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
< |
tracerays(tp) /* trace a ray tree */ |
| 160 |
< |
struct node *tp; |
| 159 |
> |
static void |
| 160 |
> |
tracerays( /* trace a ray tree */ |
| 161 |
> |
struct node *tp |
| 162 |
> |
) |
| 163 |
|
{ |
| 164 |
|
register struct node *kid; |
| 165 |
|
|
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
|
| 173 |
< |
strtoipt(ipt, str) /* convert string x y z to image point */ |
| 174 |
< |
double ipt[2]; |
| 175 |
< |
char *str; |
| 173 |
> |
static int |
| 174 |
> |
strtoipt( /* convert string x y z to image point */ |
| 175 |
> |
int ipt[2], |
| 176 |
> |
char *str |
| 177 |
> |
) |
| 178 |
|
{ |
| 179 |
< |
FVECT pt; |
| 179 |
> |
FVECT im_pt, pt; |
| 180 |
|
|
| 181 |
< |
if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3) |
| 181 |
> |
if (!sscanvec(str, pt)) |
| 182 |
|
return(-1); |
| 183 |
< |
viewpixel(&ipt[0], &ipt[1], NULL, &ourview, pt); |
| 183 |
> |
if (DOT(pt,pt) <= FTINY) /* origin is really infinity */ |
| 184 |
> |
ipt[0] = ipt[1] = -1; /* null vector */ |
| 185 |
> |
else { |
| 186 |
> |
viewloc(im_pt, &ourview, pt); |
| 187 |
> |
loc2pix(ipt, &ourres, im_pt[0], im_pt[1]); |
| 188 |
> |
} |
| 189 |
|
return(0); |
| 190 |
|
} |
| 191 |
|
|
| 198 |
|
int xoff, yoff; |
| 199 |
|
|
| 200 |
|
|
| 201 |
< |
setvec(ipt) /* set up vector drawing for pick */ |
| 202 |
< |
double ipt[2]; |
| 201 |
> |
static void |
| 202 |
> |
setvec( /* set up vector drawing for pick */ |
| 203 |
> |
int ipt[2] |
| 204 |
> |
) |
| 205 |
|
{ |
| 206 |
+ |
extern Window xfindwind(); |
| 207 |
|
XWindowAttributes wa; |
| 208 |
|
XColor xc; |
| 209 |
|
XGCValues gcv; |
| 210 |
< |
int pm, rx, ry, wx, wy, rw, cw; |
| 210 |
> |
int rx, ry, wx, wy; |
| 211 |
> |
Window rw, cw; |
| 212 |
> |
unsigned int pm; |
| 213 |
|
/* compute pointer location */ |
| 214 |
|
if (gwind == 0) { |
| 215 |
< |
XQueryPointer(theDisplay, rwind, &rw, &gwind, |
| 216 |
< |
&rx, &ry, &wx, &wy, &pm); |
| 215 |
> |
register char *wn; |
| 216 |
> |
for (wn = picture; *wn; wn++); |
| 217 |
> |
while (wn > picture && wn[-1] != '/') wn--; |
| 218 |
> |
if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) { |
| 219 |
> |
fprintf(stderr, "%s: cannot find display window!\n", |
| 220 |
> |
progname); |
| 221 |
> |
exit(1); |
| 222 |
> |
} |
| 223 |
|
} |
| 224 |
< |
XQueryPointer(theDisplay, gwind, &rw, &cw, |
| 225 |
< |
&rx, &ry, &wx, &wy, &pm); |
| 226 |
< |
xoff = wx - ipt[0]*xres; |
| 187 |
< |
yoff = wy - (1.-ipt[1])*yres; |
| 224 |
> |
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
| 225 |
> |
xoff = wx - ipt[0]; |
| 226 |
> |
yoff = wy - ipt[1]; |
| 227 |
|
/* set graphics context */ |
| 228 |
|
if (vecGC == 0) { |
| 229 |
|
XGetWindowAttributes(theDisplay, gwind, &wa); |
| 240 |
|
} |
| 241 |
|
|
| 242 |
|
|
| 243 |
< |
vector(ip1, ip2) /* draw a vector */ |
| 244 |
< |
double ip1[2], ip2[2]; |
| 243 |
> |
static void |
| 244 |
> |
vector( /* draw a vector */ |
| 245 |
> |
int ip1[2], |
| 246 |
> |
int ip2[2] |
| 247 |
> |
) |
| 248 |
|
{ |
| 249 |
+ |
if (ip2[0] == -1 && ip2[1] == -1) |
| 250 |
+ |
return; /* null vector */ |
| 251 |
|
XDrawLine(theDisplay, gwind, vecGC, |
| 252 |
< |
(int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff, |
| 253 |
< |
(int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff); |
| 252 |
> |
ip1[0]+xoff, ip1[1]+yoff, |
| 253 |
> |
ip2[0]+xoff, ip2[1]+yoff); |
| 254 |
|
if (slow) { |
| 255 |
|
XFlush(theDisplay); |
| 256 |
|
sleep(1); |