| 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 | 
  | 
 *  Circle sources in a displayed image. | 
| 6 | 
  | 
 * | 
| 8 | 
  | 
 */ | 
| 9 | 
  | 
 | 
| 10 | 
  | 
#include "standard.h" | 
| 11 | 
< | 
#include "view.h" | 
| 12 | 
< | 
#include "resolu.h" | 
| 11 | 
> | 
 | 
| 12 | 
> | 
#include <unistd.h> | 
| 13 | 
  | 
#include <signal.h> | 
| 14 | 
  | 
#include <X11/Xlib.h> | 
| 15 | 
  | 
#include <X11/Xutil.h> | 
| 16 | 
  | 
 | 
| 17 | 
< | 
#ifndef BSD | 
| 21 | 
< | 
#define vfork   fork | 
| 22 | 
< | 
#endif | 
| 17 | 
> | 
#include "view.h" | 
| 18 | 
  | 
 | 
| 19 | 
  | 
#define XIM             "ximage" | 
| 20 | 
  | 
 | 
| 37 | 
  | 
GC      vecGC, strGC; | 
| 38 | 
  | 
Window  gwind; | 
| 39 | 
  | 
 | 
| 40 | 
+ | 
static void init(char *pname, char *wname); | 
| 41 | 
+ | 
static void circle_sources(FILE *fp); | 
| 42 | 
+ | 
static void circle(FVECT dir, double dom); | 
| 43 | 
+ | 
static void value(FVECT dir, double v); | 
| 44 | 
  | 
 | 
| 45 | 
< | 
main(argc, argv) | 
| 46 | 
< | 
int     argc; | 
| 47 | 
< | 
char    *argv[]; | 
| 45 | 
> | 
 | 
| 46 | 
> | 
int | 
| 47 | 
> | 
main( | 
| 48 | 
> | 
        int     argc, | 
| 49 | 
> | 
        char    *argv[] | 
| 50 | 
> | 
) | 
| 51 | 
  | 
{ | 
| 50 | 
– | 
        extern double   atof(); | 
| 52 | 
  | 
        char    *windowname = NULL; | 
| 53 | 
  | 
        FILE    *fp; | 
| 54 | 
  | 
 | 
| 86 | 
  | 
} | 
| 87 | 
  | 
 | 
| 88 | 
  | 
 | 
| 89 | 
< | 
init(pname, wname)              /* get view and find window */ | 
| 90 | 
< | 
char    *pname, *wname; | 
| 89 | 
> | 
static void | 
| 90 | 
> | 
init(           /* get view and find window */ | 
| 91 | 
> | 
        char    *pname, | 
| 92 | 
> | 
        char    *wname | 
| 93 | 
> | 
) | 
| 94 | 
  | 
{ | 
| 95 | 
  | 
        extern Window   xfindwind(); | 
| 96 | 
  | 
        XWindowAttributes       wa; | 
| 97 | 
  | 
        XColor  xc; | 
| 98 | 
  | 
        XGCValues       gcv; | 
| 99 | 
+ | 
        register int    i; | 
| 100 | 
  | 
                                        /* get the viewing parameters */ | 
| 101 | 
  | 
        if (viewfile(pname, &ourview, &pres) <= 0 || | 
| 102 | 
  | 
                        setview(&ourview) != NULL) { | 
| 112 | 
  | 
                exit(1); | 
| 113 | 
  | 
        } | 
| 114 | 
  | 
                                        /* find our window */ | 
| 115 | 
< | 
        if (wname == NULL) | 
| 116 | 
< | 
                wname = pname; | 
| 117 | 
< | 
        gwind = xfindwind(theDisplay, rwind, wname, 2); | 
| 115 | 
> | 
        if (wname == NULL) { | 
| 116 | 
> | 
                                /* remove directory prefix from name */ | 
| 117 | 
> | 
                for (i = strlen(pname); i-- > 0; ) | 
| 118 | 
> | 
                        if (pname[i] == '/') | 
| 119 | 
> | 
                                break; | 
| 120 | 
> | 
                wname = pname+i+1; | 
| 121 | 
> | 
                i = 0; | 
| 122 | 
> | 
        } else | 
| 123 | 
> | 
                i = 1; | 
| 124 | 
> | 
        gwind = xfindwind(theDisplay, rwind, wname, 4); | 
| 125 | 
  | 
        if (gwind == None) { | 
| 126 | 
< | 
                if (wname != pname) { | 
| 126 | 
> | 
                if (i) { | 
| 127 | 
  | 
                        fprintf(stderr, "%s: cannot find \"%s\" window\n", | 
| 128 | 
  | 
                                        progname, wname); | 
| 129 | 
  | 
                        exit(2); | 
| 130 | 
  | 
                } | 
| 131 | 
  | 
                                        /* start ximage */ | 
| 132 | 
< | 
                if (vfork() == 0) { | 
| 133 | 
< | 
                        execlp(XIM, XIM, pname, 0); | 
| 132 | 
> | 
                if (fork() == 0) { | 
| 133 | 
> | 
                        execlp(XIM, XIM, "-c", "256", pname, 0); | 
| 134 | 
  | 
                        perror(XIM); | 
| 135 | 
  | 
                        fprintf(stderr, "%s: cannot start %s\n", | 
| 136 | 
  | 
                                        progname, XIM); | 
| 139 | 
  | 
                } | 
| 140 | 
  | 
                do | 
| 141 | 
  | 
                        sleep(8); | 
| 142 | 
< | 
                while ((gwind=xfindwind(theDisplay,rwind,pname,2)) == None); | 
| 142 | 
> | 
                while ((gwind=xfindwind(theDisplay,rwind,wname,4)) == None); | 
| 143 | 
  | 
        } else | 
| 144 | 
  | 
                XMapRaised(theDisplay, gwind); | 
| 145 | 
  | 
        do { | 
| 150 | 
  | 
                fprintf(stderr, | 
| 151 | 
  | 
                "%s: warning -- window seems to be the wrong size!\n", | 
| 152 | 
  | 
                                progname); | 
| 153 | 
< | 
                if (pres.or & YMAJOR) { | 
| 153 | 
> | 
                if (pres.rt & YMAJOR) { | 
| 154 | 
  | 
                        pres.xr = wa.width; | 
| 155 | 
  | 
                        pres.yr = wa.height; | 
| 156 | 
  | 
                } else { | 
| 189 | 
  | 
} | 
| 190 | 
  | 
 | 
| 191 | 
  | 
 | 
| 192 | 
< | 
circle_sources(fp)              /* circle sources listed in fp */ | 
| 193 | 
< | 
FILE    *fp; | 
| 192 | 
> | 
static void | 
| 193 | 
> | 
circle_sources(         /* circle sources listed in fp */ | 
| 194 | 
> | 
        FILE    *fp | 
| 195 | 
> | 
) | 
| 196 | 
  | 
{ | 
| 197 | 
  | 
        char    linbuf[256]; | 
| 198 | 
  | 
        int     reading = 0; | 
| 205 | 
  | 
                                XFlush(theDisplay); | 
| 206 | 
  | 
                                return; | 
| 207 | 
  | 
                        } | 
| 208 | 
< | 
                        if (sscanf(linbuf, "%lf %lf %lf %lf %lf", | 
| 209 | 
< | 
                                        &dir[0], &dir[1], &dir[2], | 
| 210 | 
< | 
                                        &dom, &lum) != 5) | 
| 208 | 
> | 
                        if (sscanf(linbuf, FVFORMAT, | 
| 209 | 
> | 
                                        &dir[0], &dir[1], &dir[2]) != 3 || | 
| 210 | 
> | 
                                        sscanf(sskip2(linbuf, 3), "%lf %lf", | 
| 211 | 
> | 
                                                &dom, &lum) != 2) | 
| 212 | 
  | 
                                break; | 
| 213 | 
  | 
                        circle(dir, dom); | 
| 214 | 
  | 
                        value(dir, lum); | 
| 220 | 
  | 
} | 
| 221 | 
  | 
 | 
| 222 | 
  | 
 | 
| 223 | 
< | 
circle(dir, dom)                /* indicate a solid angle on image */ | 
| 224 | 
< | 
FVECT   dir; | 
| 225 | 
< | 
double  dom; | 
| 223 | 
> | 
static void | 
| 224 | 
> | 
circle(         /* indicate a solid angle on image */ | 
| 225 | 
> | 
        FVECT   dir, | 
| 226 | 
> | 
        double  dom | 
| 227 | 
> | 
) | 
| 228 | 
  | 
{ | 
| 229 | 
  | 
        FVECT   start, cur; | 
| 230 | 
  | 
        XPoint  pt[NSEG+1]; | 
| 241 | 
  | 
                cur[0] += ourview.vp[0]; | 
| 242 | 
  | 
                cur[1] += ourview.vp[1]; | 
| 243 | 
  | 
                cur[2] += ourview.vp[2]; | 
| 244 | 
< | 
                viewloc(pp, &ourview, cur); | 
| 228 | 
< | 
                if (pp[2] <= 0.0) | 
| 244 | 
> | 
                if (viewloc(pp, &ourview, cur) != VL_GOOD) | 
| 245 | 
  | 
                        goto fail; | 
| 246 | 
  | 
                loc2pix(ip, &pres, pp[0], pp[1]); | 
| 247 | 
  | 
                pt[i].x = ip[0]; | 
| 255 | 
  | 
} | 
| 256 | 
  | 
 | 
| 257 | 
  | 
 | 
| 258 | 
< | 
value(dir, v)                   /* print value on image */ | 
| 259 | 
< | 
FVECT   dir; | 
| 260 | 
< | 
double  v; | 
| 258 | 
> | 
static void | 
| 259 | 
> | 
value(                  /* print value on image */ | 
| 260 | 
> | 
        FVECT   dir, | 
| 261 | 
> | 
        double  v | 
| 262 | 
> | 
) | 
| 263 | 
  | 
{ | 
| 264 | 
  | 
        FVECT   pos; | 
| 265 | 
  | 
        FVECT   pp; | 
| 269 | 
  | 
        pos[0] = ourview.vp[0] + dir[0]; | 
| 270 | 
  | 
        pos[1] = ourview.vp[1] + dir[1]; | 
| 271 | 
  | 
        pos[2] = ourview.vp[2] + dir[2]; | 
| 272 | 
< | 
        viewloc(pp, &ourview, pos); | 
| 255 | 
< | 
        if (pp[2] <= 0.0) | 
| 272 | 
> | 
        if (viewloc(pp, &ourview, pos) != VL_GOOD) | 
| 273 | 
  | 
                return; | 
| 274 | 
  | 
        loc2pix(ip, &pres, pp[0], pp[1]); | 
| 275 | 
  | 
        sprintf(buf, "%.0f", v); |