--- ray/src/px/xshowtrace.c 1990/09/22 10:53:57 1.1 +++ ray/src/px/xshowtrace.c 1991/11/12 16:04:29 2.1 @@ -1,3 +1,5 @@ +/* Copyright (c) 1991 Regents of the University of California */ + #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif @@ -14,58 +16,67 @@ static char SCCSid[] = "$SunId$ LBL"; #define MAXDEPTH 32 /* ridiculous ray tree depth */ -char rtcom[] = "rtrace -h -otp -fa -x 1"; -char xicom[] = "x11image"; +char rtcom[] = "rtrace -h- -otp -fa -x 1"; +char xicom[] = "ximage"; VIEW ourview = STDVIEW; /* view for picture */ int xres, yres; char *progname; /* program name */ +char *picture; /* picture name */ + FILE *pin; /* input stream */ Display *theDisplay = NULL; /* connection to server */ struct node { /* ray tree node */ - double ipt[2]; + FVECT ipt; struct node *sister; struct node *daughter; }; #define newnode() (struct node *)calloc(1, sizeof(struct node)) +int slow = 0; /* slow trace? */ + main(argc, argv) /* takes both the octree and the image */ int argc; char *argv[]; { int i; char combuf[256]; - Cursor curs; progname = argv[0]; - if (argc < 3) { - fprintf(stderr, "Usage: %s [rtrace args] octree picture\n", - argv[0]); + for (i = 1; i < argc-2; i++) + if (!strcmp(argv[i], "-s")) + slow++; + else + break; + if (i > argc-2) { + fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n", + progname); exit(1); } + picture = argv[argc-1]; /* get the viewing parameters */ - if (viewfile(argv[argc-1], &ourview, &xres, &yres) <= 0 || + if (viewfile(picture, &ourview, &xres, &yres) <= 0 || setview(&ourview) != NULL) { fprintf(stderr, "%s: cannot get view from \"%s\"\n", - argv[0], argv[argc-1]); + progname, picture); exit(1); } /* open the display */ if ((theDisplay = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "%s: cannot open display; DISPLAY variable set?\n", - argv[0]); + progname); exit(1); } /* build input command */ - sprintf(combuf, "%s %s | %s", xicom, argv[argc-1], rtcom); - for (i = 1; i < argc-1; i++) { + sprintf(combuf, "%s %s | %s", xicom, picture, rtcom); + for ( ; i < argc-1; i++) { strcat(combuf, " "); strcat(combuf, argv[i]); } @@ -109,9 +120,10 @@ mainloop() /* get and process input */ if (i == 0) { setvec(sis[0]->ipt); tracerays(sis[0]); - XFlush(theDisplay); freetree(sis[0]); sis[0] = NULL; + if (!slow) + XFlush(theDisplay); } } } @@ -134,21 +146,21 @@ struct node *tp; register struct node *kid; for (kid = tp->daughter; kid != NULL; kid = kid->sister) { - tracerays(kid); vector(tp->ipt, kid->ipt); + tracerays(kid); } } strtoipt(ipt, str) /* convert string x y z to image point */ -double ipt[2]; +FVECT ipt; char *str; { FVECT pt; if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3) return(-1); - viewpixel(&ipt[0], &ipt[1], NULL, &ourview, pt); + viewloc(ipt, &ourview, pt); return(0); } @@ -167,14 +179,16 @@ double ipt[2]; XWindowAttributes wa; XColor xc; XGCValues gcv; - int pm, rx, ry, wx, wy, rw, cw; + int rx, ry, wx, wy; + Window rw, cw; + unsigned int pm; /* compute pointer location */ - if (gwind == 0) { - XQueryPointer(theDisplay, rwind, &rw, &gwind, - &rx, &ry, &wx, &wy, &pm); + if (gwind == 0 && + (gwind = xfindwind(theDisplay, rwind, picture, 2)) == 0) { + fprintf(stderr, "%s: cannot find display window!\n", progname); + exit(1); } - XQueryPointer(theDisplay, gwind, &rw, &cw, - &rx, &ry, &wx, &wy, &pm); + XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); xoff = wx - ipt[0]*xres; yoff = wy - (1.-ipt[1])*yres; /* set graphics context */ @@ -199,4 +213,8 @@ double ip1[2], ip2[2]; XDrawLine(theDisplay, gwind, vecGC, (int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff, (int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff); + if (slow) { + XFlush(theDisplay); + sleep(1); + } }