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