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 |
|
* |
13 |
|
|
14 |
|
#define MAXDEPTH 32 /* ridiculous ray tree depth */ |
15 |
|
|
16 |
< |
char rtcom[] = "rtrace -h -otp -fa -x 1"; |
17 |
< |
char xicom[] = "x11image"; |
16 |
> |
#ifdef SMLFLT |
17 |
> |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
18 |
> |
#else |
19 |
> |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
20 |
> |
#endif |
21 |
|
|
22 |
+ |
char rtcom[] = "rtrace -h- -otp -fa -x 1"; |
23 |
+ |
char xicom[] = "ximage -c 256"; |
24 |
+ |
|
25 |
|
VIEW ourview = STDVIEW; /* view for picture */ |
26 |
< |
int xres, yres; |
26 |
> |
RESOLU ourres; /* picture resolution */ |
27 |
|
|
28 |
|
char *progname; /* program name */ |
29 |
|
|
30 |
+ |
char *picture; /* picture name */ |
31 |
+ |
|
32 |
|
FILE *pin; /* input stream */ |
33 |
|
|
34 |
|
Display *theDisplay = NULL; /* connection to server */ |
35 |
|
|
36 |
|
struct node { /* ray tree node */ |
37 |
< |
double ipt[2]; |
37 |
> |
int ipt[2]; |
38 |
|
struct node *sister; |
39 |
|
struct node *daughter; |
40 |
|
}; |
41 |
|
|
42 |
|
#define newnode() (struct node *)calloc(1, sizeof(struct node)) |
43 |
|
|
44 |
+ |
int slow = 0; /* slow trace? */ |
45 |
|
|
46 |
+ |
|
47 |
|
main(argc, argv) /* takes both the octree and the image */ |
48 |
|
int argc; |
49 |
|
char *argv[]; |
50 |
|
{ |
51 |
|
int i; |
52 |
|
char combuf[256]; |
44 |
– |
Cursor curs; |
53 |
|
|
54 |
|
progname = argv[0]; |
55 |
< |
if (argc < 3) { |
56 |
< |
fprintf(stderr, "Usage: %s [rtrace args] octree picture\n", |
57 |
< |
argv[0]); |
55 |
> |
for (i = 1; i < argc-2; i++) |
56 |
> |
if (!strcmp(argv[i], "-s")) |
57 |
> |
slow++; |
58 |
> |
else |
59 |
> |
break; |
60 |
> |
if (i > argc-2) { |
61 |
> |
fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n", |
62 |
> |
progname); |
63 |
|
exit(1); |
64 |
|
} |
65 |
+ |
picture = argv[argc-1]; |
66 |
|
/* get the viewing parameters */ |
67 |
< |
if (viewfile(argv[argc-1], &ourview, &xres, &yres) <= 0 || |
67 |
> |
if (viewfile(picture, &ourview, &ourres) <= 0 || |
68 |
|
setview(&ourview) != NULL) { |
69 |
|
fprintf(stderr, "%s: cannot get view from \"%s\"\n", |
70 |
< |
argv[0], argv[argc-1]); |
70 |
> |
progname, picture); |
71 |
|
exit(1); |
72 |
|
} |
73 |
|
/* open the display */ |
74 |
|
if ((theDisplay = XOpenDisplay(NULL)) == NULL) { |
75 |
|
fprintf(stderr, |
76 |
|
"%s: cannot open display; DISPLAY variable set?\n", |
77 |
< |
argv[0]); |
77 |
> |
progname); |
78 |
|
exit(1); |
79 |
|
} |
80 |
|
/* build input command */ |
81 |
< |
sprintf(combuf, "%s %s | %s", xicom, argv[argc-1], rtcom); |
82 |
< |
for (i = 1; i < argc-1; i++) { |
81 |
> |
sprintf(combuf, "%s %s | %s", xicom, picture, rtcom); |
82 |
> |
for ( ; i < argc-1; i++) { |
83 |
|
strcat(combuf, " "); |
84 |
|
strcat(combuf, argv[i]); |
85 |
|
} |
88 |
|
exit(1); |
89 |
|
/* loop on input */ |
90 |
|
mainloop(); |
91 |
< |
|
91 |
> |
/* close pipe and exit */ |
92 |
> |
pclose(pin); |
93 |
|
exit(0); |
94 |
|
} |
95 |
|
|
124 |
|
if (i == 0) { |
125 |
|
setvec(sis[0]->ipt); |
126 |
|
tracerays(sis[0]); |
112 |
– |
XFlush(theDisplay); |
127 |
|
freetree(sis[0]); |
128 |
|
sis[0] = NULL; |
129 |
+ |
if (!slow) |
130 |
+ |
XFlush(theDisplay); |
131 |
|
} |
132 |
|
} |
133 |
|
} |
140 |
|
|
141 |
|
for (kid = tp->daughter; kid != NULL; kid = kid->sister) |
142 |
|
freetree(kid); |
143 |
< |
free((char *)tp); |
143 |
> |
free((void *)tp); |
144 |
|
} |
145 |
|
|
146 |
|
|
150 |
|
register struct node *kid; |
151 |
|
|
152 |
|
for (kid = tp->daughter; kid != NULL; kid = kid->sister) { |
137 |
– |
tracerays(kid); |
153 |
|
vector(tp->ipt, kid->ipt); |
154 |
+ |
tracerays(kid); |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
strtoipt(ipt, str) /* convert string x y z to image point */ |
160 |
< |
double ipt[2]; |
160 |
> |
int ipt[2]; |
161 |
|
char *str; |
162 |
|
{ |
163 |
< |
FVECT pt; |
163 |
> |
FVECT im_pt, pt; |
164 |
|
|
165 |
< |
if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3) |
165 |
> |
if (!sscanvec(str, pt)) |
166 |
|
return(-1); |
167 |
< |
viewpixel(&ipt[0], &ipt[1], NULL, &ourview, pt); |
167 |
> |
if (DOT(pt,pt) <= FTINY) /* origin is really infinity */ |
168 |
> |
ipt[0] = ipt[1] = -1; /* null vector */ |
169 |
> |
else { |
170 |
> |
viewloc(im_pt, &ourview, pt); |
171 |
> |
loc2pix(ipt, &ourres, im_pt[0], im_pt[1]); |
172 |
> |
} |
173 |
|
return(0); |
174 |
|
} |
175 |
|
|
183 |
|
|
184 |
|
|
185 |
|
setvec(ipt) /* set up vector drawing for pick */ |
186 |
< |
double ipt[2]; |
186 |
> |
int ipt[2]; |
187 |
|
{ |
188 |
+ |
extern Window xfindwind(); |
189 |
|
XWindowAttributes wa; |
190 |
|
XColor xc; |
191 |
|
XGCValues gcv; |
192 |
< |
int pm, rx, ry, wx, wy, rw, cw; |
192 |
> |
int rx, ry, wx, wy; |
193 |
> |
Window rw, cw; |
194 |
> |
unsigned int pm; |
195 |
|
/* compute pointer location */ |
196 |
|
if (gwind == 0) { |
197 |
< |
XQueryPointer(theDisplay, rwind, &rw, &gwind, |
198 |
< |
&rx, &ry, &wx, &wy, &pm); |
197 |
> |
register char *wn; |
198 |
> |
for (wn = picture; *wn; wn++); |
199 |
> |
while (wn > picture && wn[-1] != '/') wn--; |
200 |
> |
if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) { |
201 |
> |
fprintf(stderr, "%s: cannot find display window!\n", |
202 |
> |
progname); |
203 |
> |
exit(1); |
204 |
> |
} |
205 |
|
} |
206 |
< |
XQueryPointer(theDisplay, gwind, &rw, &cw, |
207 |
< |
&rx, &ry, &wx, &wy, &pm); |
208 |
< |
xoff = wx - ipt[0]*xres; |
179 |
< |
yoff = wy - (1.-ipt[1])*yres; |
206 |
> |
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
207 |
> |
xoff = wx - ipt[0]; |
208 |
> |
yoff = wy - ipt[1]; |
209 |
|
/* set graphics context */ |
210 |
|
if (vecGC == 0) { |
211 |
|
XGetWindowAttributes(theDisplay, gwind, &wa); |
223 |
|
|
224 |
|
|
225 |
|
vector(ip1, ip2) /* draw a vector */ |
226 |
< |
double ip1[2], ip2[2]; |
226 |
> |
int ip1[2], ip2[2]; |
227 |
|
{ |
228 |
+ |
if (ip2[0] == -1 && ip2[1] == -1) |
229 |
+ |
return; /* null vector */ |
230 |
|
XDrawLine(theDisplay, gwind, vecGC, |
231 |
< |
(int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff, |
232 |
< |
(int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff); |
231 |
> |
ip1[0]+xoff, ip1[1]+yoff, |
232 |
> |
ip2[0]+xoff, ip2[1]+yoff); |
233 |
> |
if (slow) { |
234 |
> |
XFlush(theDisplay); |
235 |
> |
sleep(1); |
236 |
> |
} |
237 |
|
} |