ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/xglaresrc.c
Revision: 1.4
Committed: Wed Apr 17 12:14:52 1991 UTC (32 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
changed pointer cursor

File Contents

# Content
1 /* Copyright (c) 1991 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Circle sources in a displayed image.
9 *
10 * 18 Mar 1991 Greg Ward
11 */
12
13 #include "standard.h"
14 #include "view.h"
15 #include <X11/Xlib.h>
16 #include <X11/cursorfont.h>
17 #include <X11/Xutil.h>
18
19 #define NSEG 30 /* number of segments per circle */
20
21 VIEW ourview = STDVIEW; /* view for picture */
22 int xres, yres; /* picture resolution */
23
24 char *progname; /* program name */
25
26 Display *theDisplay = NULL; /* connection to server */
27
28 #define rwind RootWindow(theDisplay,ourScreen)
29 #define ourScreen DefaultScreen(theDisplay)
30
31 GC vecGC;
32 Window gwind;
33 Cursor pickcursor;
34
35
36 main(argc, argv)
37 int argc;
38 char *argv[];
39 {
40 FILE *fp;
41
42 progname = argv[0];
43 if (argc < 2 || argc > 3) {
44 fprintf(stderr, "Usage: %s picture [glaresrc]\n",
45 progname);
46 exit(1);
47 }
48 init(argv[1]);
49 if (argc < 3)
50 fp = stdin;
51 else if ((fp = fopen(argv[2], "r")) == NULL) {
52 fprintf(stderr, "%s: cannot open \"%s\"\n",
53 progname, argv[2]);
54 exit(1);
55 }
56 circle_sources(fp);
57 exit(0);
58 }
59
60
61 init(name) /* set up vector drawing from pick */
62 char *name;
63 {
64 XWindowAttributes wa;
65 XEvent xev;
66 XColor xc;
67 XGCValues gcv;
68 /* get the viewing parameters */
69 if (viewfile(name, &ourview, &xres, &yres) <= 0 ||
70 setview(&ourview) != NULL) {
71 fprintf(stderr, "%s: cannot get view from \"%s\"\n",
72 progname, name);
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 progname);
80 exit(1);
81 }
82 pickcursor = XCreateFontCursor(theDisplay, XC_hand2);
83 /* find our window */
84 while (XGrabPointer(theDisplay, rwind, True, ButtonPressMask,
85 GrabModeAsync, GrabModeAsync, None, pickcursor,
86 CurrentTime) != GrabSuccess)
87 sleep(2);
88 printf("%s: click mouse in \"%s\" display window\n", progname, name);
89 XNextEvent(theDisplay, &xev);
90 XUngrabPointer(theDisplay, CurrentTime);
91 if (((XButtonEvent *)&xev)->subwindow == None) {
92 fprintf(stderr, "%s: no window selected\n", progname);
93 exit(1);
94 }
95 gwind = ((XButtonEvent *)&xev)->subwindow;
96 XRaiseWindow(theDisplay, gwind);
97 XGetWindowAttributes(theDisplay, gwind, &wa);
98 sleep(4);
99 if (wa.width != xres || wa.height != yres) {
100 fprintf(stderr,
101 "%s: warning -- window seems to be the wrong size!\n",
102 progname);
103 xres = wa.width;
104 yres = wa.height;
105 }
106 /* set graphics context */
107 xc.red = 65535; xc.green = 0; xc.blue = 0;
108 xc.flags = DoRed|DoGreen|DoBlue;
109 if (XAllocColor(theDisplay, wa.colormap, &xc)) {
110 gcv.foreground = xc.pixel;
111 vecGC = XCreateGC(theDisplay,gwind,GCForeground,&gcv);
112 } else {
113 gcv.function = GXinvert;
114 vecGC = XCreateGC(theDisplay,gwind,GCFunction,&gcv);
115 }
116 }
117
118
119 circle_sources(fp) /* circle sources listed in fp */
120 FILE *fp;
121 {
122 char linbuf[256];
123 int reading = 0;
124 FVECT dir;
125 double dom;
126
127 while (fgets(linbuf, sizeof(linbuf), fp) != NULL)
128 if (reading) {
129 if (!strncmp(linbuf, "END", 3)) {
130 XFlush(theDisplay);
131 return;
132 }
133 if (sscanf(linbuf, "%lf %lf %lf %lf",
134 &dir[0], &dir[1], &dir[2],
135 &dom) != 4)
136 break;
137 circle(dir, dom);
138 } else if (!strcmp(linbuf, "BEGIN glare source\n"))
139 reading++;
140
141 fprintf(stderr, "%s: error reading glare sources\n", progname);
142 exit(1);
143 }
144
145
146 circle(dir, dom) /* indicate a solid angle on image */
147 FVECT dir;
148 double dom;
149 {
150 FVECT start, cur;
151 XPoint pt[NSEG+1];
152 double px, py, pz;
153 register int i;
154
155 fcross(cur, dir, ourview.vup);
156 if (normalize(cur) == 0.0)
157 goto fail;
158 spinvector(start, dir, cur, acos(1.-dom/(2.*PI)));
159 for (i = 0; i <= NSEG; i++) {
160 spinvector(cur, start, dir, 2.*PI*i/NSEG);
161 cur[0] += ourview.vp[0];
162 cur[1] += ourview.vp[1];
163 cur[2] += ourview.vp[2];
164 viewpixel(&px, &py, &pz, &ourview, cur);
165 if (pz <= 0.0)
166 goto fail;
167 pt[i].x = px*xres;
168 pt[i].y = yres-1 - (int)(py*yres);
169 }
170 XDrawLines(theDisplay, gwind, vecGC, pt, NSEG+1, CoordModeOrigin);
171 return;
172 fail:
173 fprintf(stderr, "%s: cannot draw source at (%f,%f,%f)\n",
174 progname, dir[0], dir[1], dir[2]);
175 }