12 |
|
|
13 |
|
#include "standard.h" |
14 |
|
#include "view.h" |
15 |
+ |
#include "resolu.h" |
16 |
+ |
#include <signal.h> |
17 |
|
#include <X11/Xlib.h> |
18 |
|
#include <X11/Xutil.h> |
19 |
|
|
20 |
+ |
#ifndef BSD |
21 |
+ |
#define vfork fork |
22 |
+ |
#endif |
23 |
+ |
|
24 |
+ |
#define XIM "ximage" |
25 |
+ |
|
26 |
|
#define NSEG 30 /* number of segments per circle */ |
27 |
|
|
28 |
+ |
#define FONTNAME "8x13" /* text font we'll use */ |
29 |
+ |
|
30 |
+ |
float col[3] = {1.,0.,0.}; /* color */ |
31 |
+ |
|
32 |
|
VIEW ourview = STDVIEW; /* view for picture */ |
33 |
< |
int xres, yres; /* picture resolution */ |
33 |
> |
RESOLU pres; /* picture resolution */ |
34 |
|
|
35 |
|
char *progname; /* program name */ |
36 |
|
|
39 |
|
#define rwind RootWindow(theDisplay,ourScreen) |
40 |
|
#define ourScreen DefaultScreen(theDisplay) |
41 |
|
|
42 |
< |
GC vecGC; |
42 |
> |
GC vecGC, strGC; |
43 |
|
Window gwind; |
32 |
– |
Cursor pickcursor; |
44 |
|
|
45 |
|
|
46 |
|
main(argc, argv) |
47 |
|
int argc; |
48 |
|
char *argv[]; |
49 |
|
{ |
50 |
+ |
extern double atof(); |
51 |
+ |
char *windowname = NULL; |
52 |
|
FILE *fp; |
53 |
|
|
54 |
< |
progname = argv[0]; |
55 |
< |
if (argc < 2 || argc > 3) { |
56 |
< |
fprintf(stderr, "Usage: %s picture [glaresrc]\n", |
54 |
> |
progname = *argv++; argc--; |
55 |
> |
while (argc > 0 && argv[0][0] == '-') { |
56 |
> |
switch (argv[0][1]) { |
57 |
> |
case 'n': |
58 |
> |
windowname = *++argv; |
59 |
> |
argc--; |
60 |
> |
break; |
61 |
> |
case 'c': |
62 |
> |
col[0] = atof(*++argv); |
63 |
> |
col[1] = atof(*++argv); |
64 |
> |
col[2] = atof(*++argv); |
65 |
> |
argc -= 3; |
66 |
> |
break; |
67 |
> |
} |
68 |
> |
argv++; argc--; |
69 |
> |
} |
70 |
> |
if (argc < 1 || argc > 2) { |
71 |
> |
fprintf(stderr, |
72 |
> |
"Usage: %s [-n windowname][-c color] picture [glaresrc]\n", |
73 |
|
progname); |
74 |
|
exit(1); |
75 |
|
} |
76 |
< |
init(argv[1]); |
77 |
< |
if (argc < 3) |
76 |
> |
init(argv[0], windowname); |
77 |
> |
if (argc < 2) |
78 |
|
fp = stdin; |
79 |
< |
else if ((fp = fopen(argv[2], "r")) == NULL) { |
80 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
52 |
< |
progname, argv[2]); |
79 |
> |
else if ((fp = fopen(argv[1], "r")) == NULL) { |
80 |
> |
fprintf(stderr, "%s: cannot open \"%s\"\n", progname, argv[1]); |
81 |
|
exit(1); |
82 |
|
} |
83 |
|
circle_sources(fp); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
< |
init(name) /* set up vector drawing from pick */ |
89 |
< |
char *name; |
88 |
> |
init(pname, wname) /* get view and find window */ |
89 |
> |
char *pname, *wname; |
90 |
|
{ |
91 |
|
extern Window xfindwind(); |
92 |
|
XWindowAttributes wa; |
93 |
|
XColor xc; |
94 |
|
XGCValues gcv; |
95 |
|
/* get the viewing parameters */ |
96 |
< |
if (viewfile(name, &ourview, &xres, &yres) <= 0 || |
96 |
> |
if (viewfile(pname, &ourview, &pres) <= 0 || |
97 |
|
setview(&ourview) != NULL) { |
98 |
|
fprintf(stderr, "%s: cannot get view from \"%s\"\n", |
99 |
< |
progname, name); |
99 |
> |
progname, pname); |
100 |
|
exit(1); |
101 |
|
} |
102 |
|
/* open the display */ |
107 |
|
exit(1); |
108 |
|
} |
109 |
|
/* find our window */ |
110 |
< |
gwind = xfindwind(theDisplay, rwind, name, 2); |
110 |
> |
if (wname == NULL) |
111 |
> |
wname = pname; |
112 |
> |
gwind = xfindwind(theDisplay, rwind, wname, 2); |
113 |
|
if (gwind == None) { |
114 |
< |
fprintf(stderr, "%s: cannot find \"%s\" window\n", |
115 |
< |
progname, name); |
116 |
< |
exit(2); |
117 |
< |
} |
118 |
< |
XMapRaised(theDisplay, gwind); |
119 |
< |
XGetWindowAttributes(theDisplay, gwind, &wa); |
120 |
< |
sleep(4); |
121 |
< |
if (wa.width != xres || wa.height != yres) { |
114 |
> |
if (wname != pname) { |
115 |
> |
fprintf(stderr, "%s: cannot find \"%s\" window\n", |
116 |
> |
progname, wname); |
117 |
> |
exit(2); |
118 |
> |
} |
119 |
> |
/* start ximage */ |
120 |
> |
if (vfork() == 0) { |
121 |
> |
execlp(XIM, XIM, pname, 0); |
122 |
> |
perror(XIM); |
123 |
> |
fprintf(stderr, "%s: cannot start %s\n", |
124 |
> |
progname, XIM); |
125 |
> |
kill(getppid(), SIGPIPE); |
126 |
> |
_exit(1); |
127 |
> |
} |
128 |
> |
do |
129 |
> |
sleep(8); |
130 |
> |
while ((gwind=xfindwind(theDisplay,rwind,pname,2)) == None); |
131 |
> |
} else |
132 |
> |
XMapRaised(theDisplay, gwind); |
133 |
> |
do { |
134 |
> |
XGetWindowAttributes(theDisplay, gwind, &wa); |
135 |
> |
sleep(6); |
136 |
> |
} while (wa.map_state != IsViewable); |
137 |
> |
if (wa.width != scanlen(&pres) || wa.height != numscans(&pres)) { |
138 |
|
fprintf(stderr, |
139 |
|
"%s: warning -- window seems to be the wrong size!\n", |
140 |
|
progname); |
141 |
< |
xres = wa.width; |
142 |
< |
yres = wa.height; |
141 |
> |
if (pres.or & YMAJOR) { |
142 |
> |
pres.xr = wa.width; |
143 |
> |
pres.yr = wa.height; |
144 |
> |
} else { |
145 |
> |
pres.xr = wa.height; |
146 |
> |
pres.yr = wa.width; |
147 |
> |
} |
148 |
|
} |
149 |
|
/* set graphics context */ |
150 |
< |
xc.red = 65535; xc.green = 0; xc.blue = 0; |
150 |
> |
gcv.font = XLoadFont(theDisplay, FONTNAME); |
151 |
> |
if (gcv.font == 0) { |
152 |
> |
fprintf(stderr, "%s: cannot load font \"%s\"\n", |
153 |
> |
progname, FONTNAME); |
154 |
> |
exit(1); |
155 |
> |
} |
156 |
> |
xc.red = col[0] >= 1.0 ? 65535 : (unsigned)(65536*col[0]); |
157 |
> |
xc.green = col[1] >= 1.0 ? 65535 : (unsigned)(65536*col[1]); |
158 |
> |
xc.blue = col[2] >= 1.0 ? 65535 : (unsigned)(65536*col[2]); |
159 |
|
xc.flags = DoRed|DoGreen|DoBlue; |
160 |
+ |
gcv.background = xc.green >= 32768 ? |
161 |
+ |
BlackPixel(theDisplay,DefaultScreen(theDisplay)) : |
162 |
+ |
WhitePixel(theDisplay,DefaultScreen(theDisplay)) ; |
163 |
|
if (XAllocColor(theDisplay, wa.colormap, &xc)) { |
164 |
|
gcv.foreground = xc.pixel; |
165 |
< |
vecGC = XCreateGC(theDisplay,gwind,GCForeground,&gcv); |
165 |
> |
vecGC = XCreateGC(theDisplay,gwind, |
166 |
> |
GCForeground|GCBackground|GCFont,&gcv); |
167 |
> |
strGC = vecGC; |
168 |
|
} else { |
169 |
|
gcv.function = GXinvert; |
170 |
|
vecGC = XCreateGC(theDisplay,gwind,GCFunction,&gcv); |
171 |
+ |
gcv.foreground = xc.green < 32768 ? |
172 |
+ |
BlackPixel(theDisplay,DefaultScreen(theDisplay)) : |
173 |
+ |
WhitePixel(theDisplay,DefaultScreen(theDisplay)) ; |
174 |
+ |
strGC = XCreateGC(theDisplay,gwind, |
175 |
+ |
GCForeground|GCBackground|GCFont,&gcv); |
176 |
|
} |
177 |
|
} |
178 |
|
|
183 |
|
char linbuf[256]; |
184 |
|
int reading = 0; |
185 |
|
FVECT dir; |
186 |
< |
double dom; |
186 |
> |
double dom, lum; |
187 |
|
|
188 |
|
while (fgets(linbuf, sizeof(linbuf), fp) != NULL) |
189 |
|
if (reading) { |
191 |
|
XFlush(theDisplay); |
192 |
|
return; |
193 |
|
} |
194 |
< |
if (sscanf(linbuf, "%lf %lf %lf %lf", |
194 |
> |
if (sscanf(linbuf, "%lf %lf %lf %lf %lf", |
195 |
|
&dir[0], &dir[1], &dir[2], |
196 |
< |
&dom) != 4) |
196 |
> |
&dom, &lum) != 5) |
197 |
|
break; |
198 |
|
circle(dir, dom); |
199 |
+ |
value(dir, lum); |
200 |
|
} else if (!strcmp(linbuf, "BEGIN glare source\n")) |
201 |
|
reading++; |
202 |
|
|
211 |
|
{ |
212 |
|
FVECT start, cur; |
213 |
|
XPoint pt[NSEG+1]; |
214 |
< |
double px, py, pz; |
214 |
> |
FVECT pp; |
215 |
> |
int ip[2]; |
216 |
|
register int i; |
217 |
|
|
218 |
|
fcross(cur, dir, ourview.vup); |
224 |
|
cur[0] += ourview.vp[0]; |
225 |
|
cur[1] += ourview.vp[1]; |
226 |
|
cur[2] += ourview.vp[2]; |
227 |
< |
viewpixel(&px, &py, &pz, &ourview, cur); |
228 |
< |
if (pz <= 0.0) |
227 |
> |
viewloc(pp, &ourview, cur); |
228 |
> |
if (pp[2] <= 0.0) |
229 |
|
goto fail; |
230 |
< |
pt[i].x = px*xres; |
231 |
< |
pt[i].y = yres-1 - (int)(py*yres); |
230 |
> |
loc2pix(ip, &pres, pp[0], pp[1]); |
231 |
> |
pt[i].x = ip[0]; |
232 |
> |
pt[i].y = ip[1]; |
233 |
|
} |
234 |
|
XDrawLines(theDisplay, gwind, vecGC, pt, NSEG+1, CoordModeOrigin); |
235 |
|
return; |
236 |
|
fail: |
237 |
|
fprintf(stderr, "%s: cannot draw source at (%f,%f,%f)\n", |
238 |
|
progname, dir[0], dir[1], dir[2]); |
239 |
+ |
} |
240 |
+ |
|
241 |
+ |
|
242 |
+ |
value(dir, v) /* print value on image */ |
243 |
+ |
FVECT dir; |
244 |
+ |
double v; |
245 |
+ |
{ |
246 |
+ |
FVECT pos; |
247 |
+ |
FVECT pp; |
248 |
+ |
int ip[2]; |
249 |
+ |
char buf[32]; |
250 |
+ |
|
251 |
+ |
pos[0] = ourview.vp[0] + dir[0]; |
252 |
+ |
pos[1] = ourview.vp[1] + dir[1]; |
253 |
+ |
pos[2] = ourview.vp[2] + dir[2]; |
254 |
+ |
viewloc(pp, &ourview, pos); |
255 |
+ |
if (pp[2] <= 0.0) |
256 |
+ |
return; |
257 |
+ |
loc2pix(ip, &pres, pp[0], pp[1]); |
258 |
+ |
sprintf(buf, "%.0f", v); |
259 |
+ |
XDrawImageString(theDisplay, gwind, strGC, |
260 |
+ |
ip[0], ip[1], buf, strlen(buf)); |
261 |
|
} |