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"; |
19 |
< |
char xicom[] = "x11image"; |
18 |
> |
#ifdef SMLFLT |
19 |
> |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
20 |
> |
#else |
21 |
> |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
22 |
> |
#endif |
23 |
|
|
24 |
+ |
char rtcom[] = "rtrace -h- -otp -fa -x 1"; |
25 |
+ |
char xicom[] = "ximage -c 256"; |
26 |
+ |
|
27 |
|
VIEW ourview = STDVIEW; /* view for picture */ |
28 |
< |
int xres, yres; |
28 |
> |
RESOLU ourres; /* picture resolution */ |
29 |
|
|
30 |
|
char *progname; /* program name */ |
31 |
|
|
32 |
+ |
char *picture; /* picture name */ |
33 |
+ |
|
34 |
|
FILE *pin; /* input stream */ |
35 |
|
|
36 |
|
Display *theDisplay = NULL; /* connection to server */ |
37 |
|
|
38 |
|
struct node { /* ray tree node */ |
39 |
< |
double ipt[2]; |
39 |
> |
int ipt[2]; |
40 |
|
struct node *sister; |
41 |
|
struct node *daughter; |
42 |
|
}; |
43 |
|
|
44 |
|
#define newnode() (struct node *)calloc(1, sizeof(struct node)) |
45 |
|
|
46 |
+ |
int slow = 0; /* slow trace? */ |
47 |
|
|
48 |
+ |
|
49 |
|
main(argc, argv) /* takes both the octree and the image */ |
50 |
|
int argc; |
51 |
|
char *argv[]; |
52 |
|
{ |
53 |
|
int i; |
54 |
< |
char combuf[256]; |
44 |
< |
Cursor curs; |
54 |
> |
char combuf[PATH_MAX]; |
55 |
|
|
56 |
|
progname = argv[0]; |
57 |
< |
if (argc < 3) { |
58 |
< |
fprintf(stderr, "Usage: %s [rtrace args] octree picture\n", |
59 |
< |
argv[0]); |
57 |
> |
for (i = 1; i < argc-2; i++) |
58 |
> |
if (!strcmp(argv[i], "-s")) |
59 |
> |
slow++; |
60 |
> |
else |
61 |
> |
break; |
62 |
> |
if (i > argc-2) { |
63 |
> |
fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n", |
64 |
> |
progname); |
65 |
|
exit(1); |
66 |
|
} |
67 |
+ |
picture = argv[argc-1]; |
68 |
|
/* get the viewing parameters */ |
69 |
< |
if (viewfile(argv[argc-1], &ourview, &xres, &yres) <= 0 || |
69 |
> |
if (viewfile(picture, &ourview, &ourres) <= 0 || |
70 |
|
setview(&ourview) != NULL) { |
71 |
|
fprintf(stderr, "%s: cannot get view from \"%s\"\n", |
72 |
< |
argv[0], argv[argc-1]); |
72 |
> |
progname, picture); |
73 |
|
exit(1); |
74 |
|
} |
75 |
|
/* open the display */ |
76 |
|
if ((theDisplay = XOpenDisplay(NULL)) == NULL) { |
77 |
|
fprintf(stderr, |
78 |
|
"%s: cannot open display; DISPLAY variable set?\n", |
79 |
< |
argv[0]); |
79 |
> |
progname); |
80 |
|
exit(1); |
81 |
|
} |
82 |
|
/* build input command */ |
83 |
< |
sprintf(combuf, "%s %s | %s", xicom, argv[argc-1], rtcom); |
84 |
< |
for (i = 1; i < argc-1; i++) { |
83 |
> |
sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom); |
84 |
> |
for ( ; i < argc-1; i++) { |
85 |
|
strcat(combuf, " "); |
86 |
|
strcat(combuf, argv[i]); |
87 |
|
} |
90 |
|
exit(1); |
91 |
|
/* loop on input */ |
92 |
|
mainloop(); |
93 |
< |
|
93 |
> |
/* close pipe and exit */ |
94 |
> |
pclose(pin); |
95 |
|
exit(0); |
96 |
|
} |
97 |
|
|
126 |
|
if (i == 0) { |
127 |
|
setvec(sis[0]->ipt); |
128 |
|
tracerays(sis[0]); |
112 |
– |
XFlush(theDisplay); |
129 |
|
freetree(sis[0]); |
130 |
|
sis[0] = NULL; |
131 |
+ |
if (!slow) |
132 |
+ |
XFlush(theDisplay); |
133 |
|
} |
134 |
|
} |
135 |
|
} |
138 |
|
freetree(tp) /* free a trace tree */ |
139 |
|
struct node *tp; |
140 |
|
{ |
141 |
< |
register struct node *kid; |
141 |
> |
register struct node *kid, *k2; |
142 |
|
|
143 |
< |
for (kid = tp->daughter; kid != NULL; kid = kid->sister) |
143 |
> |
for (kid = tp->daughter; kid != NULL; kid = k2) { |
144 |
> |
k2 = kid->sister; |
145 |
|
freetree(kid); |
146 |
< |
free((char *)tp); |
146 |
> |
} |
147 |
> |
free((void *)tp); |
148 |
|
} |
149 |
|
|
150 |
|
|
154 |
|
register struct node *kid; |
155 |
|
|
156 |
|
for (kid = tp->daughter; kid != NULL; kid = kid->sister) { |
137 |
– |
tracerays(kid); |
157 |
|
vector(tp->ipt, kid->ipt); |
158 |
+ |
tracerays(kid); |
159 |
|
} |
160 |
|
} |
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; |
196 |
< |
int pm, rx, ry, wx, wy, rw, cw; |
196 |
> |
int rx, ry, wx, wy; |
197 |
> |
Window rw, cw; |
198 |
> |
unsigned int pm; |
199 |
|
/* compute pointer location */ |
200 |
|
if (gwind == 0) { |
201 |
< |
XQueryPointer(theDisplay, rwind, &rw, &gwind, |
202 |
< |
&rx, &ry, &wx, &wy, &pm); |
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, |
211 |
< |
&rx, &ry, &wx, &wy, &pm); |
212 |
< |
xoff = wx - ipt[0]*xres; |
179 |
< |
yoff = wy - (1.-ipt[1])*yres; |
210 |
> |
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
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); |
240 |
> |
} |
241 |
|
} |