1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
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" |
15 |
– |
#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[] = "ximage"; |
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[64] = "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 |
|
|
36 |
|
Display *theDisplay = NULL; /* connection to server */ |
37 |
|
|
38 |
|
struct node { /* ray tree node */ |
39 |
< |
FVECT ipt; |
39 |
> |
int ipt[2]; |
40 |
|
struct node *sister; |
41 |
|
struct node *daughter; |
42 |
|
}; |
45 |
|
|
46 |
|
int slow = 0; /* slow trace? */ |
47 |
|
|
48 |
+ |
void mainloop(void); |
49 |
+ |
static void freetree(struct node *tp); |
50 |
+ |
static void tracerays(struct node *tp); |
51 |
+ |
static int strtoipt(int ipt[2], char *str); |
52 |
+ |
static void setvec(int ipt[2]); |
53 |
+ |
static void vector(int ip1[2], int ip2[2]); |
54 |
|
|
55 |
< |
main(argc, argv) /* takes both the octree and the image */ |
56 |
< |
int argc; |
57 |
< |
char *argv[]; |
55 |
> |
|
56 |
> |
int |
57 |
> |
main( /* takes both the octree and the image */ |
58 |
> |
int argc, |
59 |
> |
char *argv[] |
60 |
> |
) |
61 |
|
{ |
62 |
|
int i; |
63 |
< |
char combuf[256]; |
63 |
> |
char combuf[PATH_MAX]; |
64 |
|
|
65 |
|
progname = argv[0]; |
66 |
|
for (i = 1; i < argc-2; i++) |
67 |
|
if (!strcmp(argv[i], "-s")) |
68 |
|
slow++; |
69 |
+ |
else if (!strcmp(argv[i], "-T")) |
70 |
+ |
strcat(rtcom, " -oTp"); |
71 |
|
else |
72 |
|
break; |
73 |
|
if (i > argc-2) { |
77 |
|
} |
78 |
|
picture = argv[argc-1]; |
79 |
|
/* get the viewing parameters */ |
80 |
< |
if (viewfile(picture, &ourview, &xres, &yres) <= 0 || |
80 |
> |
if (viewfile(picture, &ourview, &ourres) <= 0 || |
81 |
|
setview(&ourview) != NULL) { |
82 |
|
fprintf(stderr, "%s: cannot get view from \"%s\"\n", |
83 |
|
progname, picture); |
91 |
|
exit(1); |
92 |
|
} |
93 |
|
/* build input command */ |
94 |
< |
sprintf(combuf, "%s %s | %s", xicom, picture, rtcom); |
94 |
> |
sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom); |
95 |
|
for ( ; i < argc-1; i++) { |
96 |
|
strcat(combuf, " "); |
97 |
|
strcat(combuf, argv[i]); |
101 |
|
exit(1); |
102 |
|
/* loop on input */ |
103 |
|
mainloop(); |
104 |
< |
|
104 |
> |
/* close pipe and exit */ |
105 |
> |
pclose(pin); |
106 |
|
exit(0); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
< |
mainloop() /* get and process input */ |
110 |
> |
void |
111 |
> |
mainloop(void) /* get and process input */ |
112 |
|
{ |
113 |
|
static struct node *sis[MAXDEPTH]; |
114 |
|
register struct node *newp; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
< |
freetree(tp) /* free a trace tree */ |
151 |
< |
struct node *tp; |
150 |
> |
static void |
151 |
> |
freetree( /* free a trace tree */ |
152 |
> |
struct node *tp |
153 |
> |
) |
154 |
|
{ |
155 |
< |
register struct node *kid; |
155 |
> |
register struct node *kid, *k2; |
156 |
|
|
157 |
< |
for (kid = tp->daughter; kid != NULL; kid = kid->sister) |
157 |
> |
for (kid = tp->daughter; kid != NULL; kid = k2) { |
158 |
> |
k2 = kid->sister; |
159 |
|
freetree(kid); |
160 |
< |
free((char *)tp); |
160 |
> |
} |
161 |
> |
free((void *)tp); |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
< |
tracerays(tp) /* trace a ray tree */ |
166 |
< |
struct node *tp; |
165 |
> |
static void |
166 |
> |
tracerays( /* trace a ray tree */ |
167 |
> |
struct node *tp |
168 |
> |
) |
169 |
|
{ |
170 |
|
register struct node *kid; |
171 |
|
|
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
< |
strtoipt(ipt, str) /* convert string x y z to image point */ |
180 |
< |
FVECT ipt; |
181 |
< |
char *str; |
179 |
> |
static int |
180 |
> |
strtoipt( /* convert string x y z to image point */ |
181 |
> |
int ipt[2], |
182 |
> |
char *str |
183 |
> |
) |
184 |
|
{ |
185 |
< |
FVECT pt; |
185 |
> |
FVECT im_pt, pt; |
186 |
|
|
187 |
< |
if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3) |
187 |
> |
if (!sscanvec(str, pt)) |
188 |
|
return(-1); |
189 |
< |
viewloc(ipt, &ourview, pt); |
189 |
> |
if (DOT(pt,pt) <= FTINY) /* origin is really infinity */ |
190 |
> |
ipt[0] = ipt[1] = -1; /* null vector */ |
191 |
> |
else { |
192 |
> |
viewloc(im_pt, &ourview, pt); |
193 |
> |
loc2pix(ipt, &ourres, im_pt[0], im_pt[1]); |
194 |
> |
} |
195 |
|
return(0); |
196 |
|
} |
197 |
|
|
204 |
|
int xoff, yoff; |
205 |
|
|
206 |
|
|
207 |
< |
setvec(ipt) /* set up vector drawing for pick */ |
208 |
< |
double ipt[2]; |
207 |
> |
static void |
208 |
> |
setvec( /* set up vector drawing for pick */ |
209 |
> |
int ipt[2] |
210 |
> |
) |
211 |
|
{ |
212 |
+ |
extern Window xfindwind(); |
213 |
|
XWindowAttributes wa; |
214 |
|
XColor xc; |
215 |
|
XGCValues gcv; |
217 |
|
Window rw, cw; |
218 |
|
unsigned int pm; |
219 |
|
/* compute pointer location */ |
220 |
< |
if (gwind == 0 && |
221 |
< |
(gwind = xfindwind(theDisplay, rwind, picture, 2)) == 0) { |
222 |
< |
fprintf(stderr, "%s: cannot find display window!\n", progname); |
223 |
< |
exit(1); |
220 |
> |
if (gwind == 0) { |
221 |
> |
register char *wn; |
222 |
> |
for (wn = picture; *wn; wn++); |
223 |
> |
while (wn > picture && wn[-1] != '/') wn--; |
224 |
> |
if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) { |
225 |
> |
fprintf(stderr, "%s: cannot find display window!\n", |
226 |
> |
progname); |
227 |
> |
exit(1); |
228 |
> |
} |
229 |
|
} |
230 |
|
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
231 |
< |
xoff = wx - ipt[0]*xres; |
232 |
< |
yoff = wy - (1.-ipt[1])*yres; |
231 |
> |
xoff = wx - ipt[0]; |
232 |
> |
yoff = wy - ipt[1]; |
233 |
|
/* set graphics context */ |
234 |
|
if (vecGC == 0) { |
235 |
|
XGetWindowAttributes(theDisplay, gwind, &wa); |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
< |
vector(ip1, ip2) /* draw a vector */ |
250 |
< |
double ip1[2], ip2[2]; |
249 |
> |
static void |
250 |
> |
vector( /* draw a vector */ |
251 |
> |
int ip1[2], |
252 |
> |
int ip2[2] |
253 |
> |
) |
254 |
|
{ |
255 |
+ |
if (ip2[0] == -1 && ip2[1] == -1) |
256 |
+ |
return; /* null vector */ |
257 |
|
XDrawLine(theDisplay, gwind, vecGC, |
258 |
< |
(int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff, |
259 |
< |
(int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff); |
258 |
> |
ip1[0]+xoff, ip1[1]+yoff, |
259 |
> |
ip2[0]+xoff, ip2[1]+yoff); |
260 |
|
if (slow) { |
261 |
|
XFlush(theDisplay); |
262 |
|
sleep(1); |