ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/xglaresrc.c
(Generate patch)

Comparing ray/src/util/xglaresrc.c (file contents):
Revision 1.1 by greg, Tue Mar 19 14:12:11 1991 UTC vs.
Revision 2.5 by greg, Thu Apr 29 12:58:20 1993 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines