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 "resolu.h" |
16 |
– |
#include <X11/Xlib.h> |
15 |
|
|
16 |
|
#define MAXDEPTH 32 /* ridiculous ray tree depth */ |
17 |
|
|
18 |
< |
#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 |
18 |
> |
#define sscanvec(s,v) (sscanf(s,FVFORMAT,v,v+1,v+2)==3) |
19 |
|
|
20 |
< |
char rtcom[] = "rtrace -h- -otp -fa -x 1"; |
20 |
> |
char rtcom[64] = "rtrace -h- -otp -fa -x 1"; |
21 |
|
char xicom[] = "ximage -c 256"; |
22 |
|
|
23 |
|
VIEW ourview = STDVIEW; /* view for picture */ |
41 |
|
|
42 |
|
int slow = 0; /* slow trace? */ |
43 |
|
|
44 |
+ |
void mainloop(void); |
45 |
+ |
static void freetree(struct node *tp); |
46 |
+ |
static void tracerays(struct node *tp); |
47 |
+ |
static int strtoipt(int ipt[2], char *str); |
48 |
+ |
static void setvec(int ipt[2]); |
49 |
+ |
static void vector(int ip1[2], int ip2[2]); |
50 |
|
|
51 |
< |
main(argc, argv) /* takes both the octree and the image */ |
52 |
< |
int argc; |
53 |
< |
char *argv[]; |
51 |
> |
|
52 |
> |
int |
53 |
> |
main( /* takes both the octree and the image */ |
54 |
> |
int argc, |
55 |
> |
char *argv[] |
56 |
> |
) |
57 |
|
{ |
58 |
|
int i; |
59 |
< |
char combuf[256]; |
59 |
> |
char combuf[PATH_MAX]; |
60 |
|
|
61 |
|
progname = argv[0]; |
62 |
|
for (i = 1; i < argc-2; i++) |
63 |
|
if (!strcmp(argv[i], "-s")) |
64 |
|
slow++; |
65 |
+ |
else if (!strcmp(argv[i], "-T")) |
66 |
+ |
strcat(rtcom, " -oTp"); |
67 |
|
else |
68 |
|
break; |
69 |
|
if (i > argc-2) { |
70 |
< |
fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n", |
70 |
> |
fprintf(stderr, "Usage: %s [-s][-T] [rtrace args] octree picture\n", |
71 |
|
progname); |
72 |
|
exit(1); |
73 |
|
} |
87 |
|
exit(1); |
88 |
|
} |
89 |
|
/* build input command */ |
90 |
< |
sprintf(combuf, "%s %s | %s", xicom, picture, rtcom); |
90 |
> |
sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom); |
91 |
|
for ( ; i < argc-1; i++) { |
92 |
|
strcat(combuf, " "); |
93 |
|
strcat(combuf, argv[i]); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
< |
mainloop() /* get and process input */ |
106 |
> |
void |
107 |
> |
mainloop(void) /* get and process input */ |
108 |
|
{ |
109 |
|
static struct node *sis[MAXDEPTH]; |
110 |
|
register struct node *newp; |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
< |
freetree(tp) /* free a trace tree */ |
147 |
< |
struct node *tp; |
146 |
> |
static void |
147 |
> |
freetree( /* free a trace tree */ |
148 |
> |
struct node *tp |
149 |
> |
) |
150 |
|
{ |
151 |
< |
register struct node *kid; |
151 |
> |
register struct node *kid, *k2; |
152 |
|
|
153 |
< |
for (kid = tp->daughter; kid != NULL; kid = kid->sister) |
153 |
> |
for (kid = tp->daughter; kid != NULL; kid = k2) { |
154 |
> |
k2 = kid->sister; |
155 |
|
freetree(kid); |
156 |
< |
free((char *)tp); |
156 |
> |
} |
157 |
> |
free((void *)tp); |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
< |
tracerays(tp) /* trace a ray tree */ |
162 |
< |
struct node *tp; |
161 |
> |
static void |
162 |
> |
tracerays( /* trace a ray tree */ |
163 |
> |
struct node *tp |
164 |
> |
) |
165 |
|
{ |
166 |
|
register struct node *kid; |
167 |
|
|
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
< |
strtoipt(ipt, str) /* convert string x y z to image point */ |
176 |
< |
int ipt[2]; |
177 |
< |
char *str; |
175 |
> |
static int |
176 |
> |
strtoipt( /* convert string x y z to image point */ |
177 |
> |
int ipt[2], |
178 |
> |
char *str |
179 |
> |
) |
180 |
|
{ |
181 |
|
FVECT im_pt, pt; |
182 |
|
|
200 |
|
int xoff, yoff; |
201 |
|
|
202 |
|
|
203 |
< |
setvec(ipt) /* set up vector drawing for pick */ |
204 |
< |
int ipt[2]; |
203 |
> |
static void |
204 |
> |
setvec( /* set up vector drawing for pick */ |
205 |
> |
int ipt[2] |
206 |
> |
) |
207 |
|
{ |
208 |
|
extern Window xfindwind(); |
209 |
|
XWindowAttributes wa; |
213 |
|
Window rw, cw; |
214 |
|
unsigned int pm; |
215 |
|
/* compute pointer location */ |
216 |
< |
if (gwind == 0 && |
217 |
< |
(gwind = xfindwind(theDisplay, rwind, picture, 4)) == 0) { |
218 |
< |
fprintf(stderr, "%s: cannot find display window!\n", progname); |
219 |
< |
exit(1); |
216 |
> |
if (gwind == 0) { |
217 |
> |
register char *wn; |
218 |
> |
for (wn = picture; *wn; wn++); |
219 |
> |
while (wn > picture && wn[-1] != '/') wn--; |
220 |
> |
if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) { |
221 |
> |
fprintf(stderr, "%s: cannot find display window!\n", |
222 |
> |
progname); |
223 |
> |
exit(1); |
224 |
> |
} |
225 |
|
} |
226 |
|
XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); |
227 |
|
xoff = wx - ipt[0]; |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
< |
vector(ip1, ip2) /* draw a vector */ |
246 |
< |
int ip1[2], ip2[2]; |
245 |
> |
static void |
246 |
> |
vector( /* draw a vector */ |
247 |
> |
int ip1[2], |
248 |
> |
int ip2[2] |
249 |
> |
) |
250 |
|
{ |
251 |
|
if (ip2[0] == -1 && ip2[1] == -1) |
252 |
|
return; /* null vector */ |