Back to index

radiance  4R0+20100331
Classes | Defines | Functions | Variables
xshowtrace.c File Reference
#include <X11/Xlib.h>
#include "standard.h"
#include "paths.h"
#include "view.h"

Go to the source code of this file.

Classes

struct  node

Defines

#define MAXDEPTH   32 /* ridiculous ray tree depth */
#define sscanvec(s, v)   (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
#define newnode()   (struct node *)calloc(1, sizeof(struct node))
#define rwind   RootWindow(theDisplay,ourScreen)
#define ourScreen   DefaultScreen(theDisplay)

Functions

void mainloop (void)
static void freetree (struct node *tp)
static void tracerays (struct node *tp)
static int strtoipt (int ipt[2], char *str)
static void setvec (int ipt[2])
static void vector (int ip1[2], int ip2[2])
int main (int argc, char *argv[])

Variables

static const char RCSid [] = "$Id: xshowtrace.c,v 2.12 2005/07/30 22:02:29 greg Exp $"
char rtcom [64] = "rtrace -h- -otp -fa -x 1"
char xicom [] = "ximage -c 256"
VIEW ourview = STDVIEW
RESOLU ourres
char * progname
char * picture
FILE * pin
Display * theDisplay = NULL
int slow = 0
GC vecGC = 0
Window gwind = 0
int xoff
int yoff

Class Documentation

struct node

Definition at line 38 of file xshowtrace.c.

Collaboration diagram for node:
Class Members
struct node * daughter
int ipt
struct node * sister

Define Documentation

#define MAXDEPTH   32 /* ridiculous ray tree depth */

Definition at line 16 of file xshowtrace.c.

#define newnode ( )    (struct node *)calloc(1, sizeof(struct node))

Definition at line 44 of file xshowtrace.c.

#define ourScreen   DefaultScreen(theDisplay)

Definition at line 200 of file xshowtrace.c.

#define rwind   RootWindow(theDisplay,ourScreen)

Definition at line 199 of file xshowtrace.c.

#define sscanvec (   s,
  v 
)    (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)

Definition at line 21 of file xshowtrace.c.


Function Documentation

static void freetree ( struct node tp) [static]

Definition at line 151 of file xshowtrace.c.

{
       register struct node *kid, *k2;

       for (kid = tp->daughter; kid != NULL; kid = k2) {
              k2 = kid->sister;
              freetree(kid);
       }
       free((void *)tp);
}

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 57 of file xshowtrace.c.

{
       int    i;
       char   combuf[PATH_MAX];

       progname = argv[0];
       for (i = 1; i < argc-2; i++)
              if (!strcmp(argv[i], "-s"))
                     slow++;
              else if (!strcmp(argv[i], "-T"))
                     strcat(rtcom, " -oTp");
              else
                     break;
       if (i > argc-2) {
              fprintf(stderr, "Usage: %s [-s][-T] [rtrace args] octree picture\n",
                            progname);
              exit(1);
       }
       picture = argv[argc-1];
                                   /* get the viewing parameters */
       if (viewfile(picture, &ourview, &ourres) <= 0 ||
                     setview(&ourview) != NULL) {
              fprintf(stderr, "%s: cannot get view from \"%s\"\n",
                            progname, picture);
              exit(1);
       }
                                   /* open the display */
       if ((theDisplay = XOpenDisplay(NULL)) == NULL) {
              fprintf(stderr,
              "%s: cannot open display; DISPLAY variable set?\n",
                            progname);
              exit(1);
       }
                                   /* build input command */
       sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom);
       for ( ; i < argc-1; i++) {
              strcat(combuf, " ");
              strcat(combuf, argv[i]);
       }
                                   /* start the damn thing */
       if ((pin = popen(combuf, "r")) == NULL)
              exit(1);
                                   /* loop on input */
       mainloop();
                                   /* close pipe and exit */
       pclose(pin);
       exit(0);
}

Here is the call graph for this function:

void mainloop ( void  )

Definition at line 111 of file xshowtrace.c.

{
       static struct node   *sis[MAXDEPTH];
       register struct node *newp;
       char   buf[128];
       int    level;
       register int  i;

       level = 0;
       while (fgets(buf, sizeof(buf), pin) != NULL) {
              if ((newp = newnode()) == NULL) {
                     fprintf(stderr, "%s: memory error\n", progname);
                     return;
              }
              for (i = 0; buf[i] == '\t'; i++)
                     ;
              if (strtoipt(newp->ipt, buf+i) < 0) {
                     fprintf(stderr, "%s: bad read\n", progname);
                     return;
              }
              newp->sister = sis[i];
              sis[i] = newp;
              if (i < level) {
                     newp->daughter = sis[level];
                     sis[level] = NULL;
              }
              level = i;
              if (i == 0) {
                     setvec(sis[0]->ipt);
                     tracerays(sis[0]);
                     freetree(sis[0]);
                     sis[0] = NULL;
                     if (!slow)
                            XFlush(theDisplay);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void setvec ( int  ipt[2]) [static]

Definition at line 208 of file xshowtrace.c.

{
       extern Window xfindwind();
       XWindowAttributes    wa;
       XColor xc;
       XGCValues     gcv;
       int    rx, ry, wx, wy;
       Window rw, cw;
       unsigned int  pm;
                                   /* compute pointer location */
       if (gwind == 0) {
              register char *wn;
              for (wn = picture; *wn; wn++);
              while (wn > picture && wn[-1] != '/') wn--;
              if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) {
                     fprintf(stderr, "%s: cannot find display window!\n",
                                   progname);
                     exit(1);
              }
       }
       XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm);
       xoff = wx - ipt[0];
       yoff = wy - ipt[1];
                                   /* set graphics context */
       if (vecGC == 0) {
              XGetWindowAttributes(theDisplay, gwind, &wa);
              xc.red = 65535; xc.green = 0; xc.blue = 0;
              xc.flags = DoRed|DoGreen|DoBlue;
              if (XAllocColor(theDisplay, wa.colormap, &xc)) {
                     gcv.foreground = xc.pixel;
                     vecGC = XCreateGC(theDisplay,gwind,GCForeground,&gcv);
              } else {
                     gcv.function = GXinvert;
                     vecGC = XCreateGC(theDisplay,gwind,GCFunction,&gcv);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int strtoipt ( int  ipt[2],
char *  str 
) [static]

Definition at line 180 of file xshowtrace.c.

{
       FVECT  im_pt, pt;

       if (!sscanvec(str, pt))
              return(-1);
       if (DOT(pt,pt) <= FTINY)           /* origin is really infinity */
              ipt[0] = ipt[1] = -1;                     /* null vector */
       else {
              viewloc(im_pt, &ourview, pt);
              loc2pix(ipt, &ourres, im_pt[0], im_pt[1]);
       }
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void tracerays ( struct node tp) [static]

Definition at line 166 of file xshowtrace.c.

{
       register struct node *kid;

       for (kid = tp->daughter; kid != NULL; kid = kid->sister) {
              vector(tp->ipt, kid->ipt);
              tracerays(kid);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void vector ( int  ip1[2],
int  ip2[2] 
) [static]

Definition at line 250 of file xshowtrace.c.

{
       if (ip2[0] == -1 && ip2[1] == -1)
              return;                     /* null vector */
       XDrawLine(theDisplay, gwind, vecGC,
                     ip1[0]+xoff, ip1[1]+yoff,
                     ip2[0]+xoff, ip2[1]+yoff);
       if (slow) {
              XFlush(theDisplay);
              sleep(1);
       }
}

Here is the caller graph for this function:


Variable Documentation

Window gwind = 0

Definition at line 203 of file xshowtrace.c.

Definition at line 28 of file xshowtrace.c.

Definition at line 27 of file xshowtrace.c.

char* picture

Definition at line 32 of file xshowtrace.c.

FILE* pin

Definition at line 34 of file xshowtrace.c.

char* progname

Definition at line 30 of file xshowtrace.c.

const char RCSid[] = "$Id: xshowtrace.c,v 2.12 2005/07/30 22:02:29 greg Exp $" [static]

Definition at line 2 of file xshowtrace.c.

char rtcom[64] = "rtrace -h- -otp -fa -x 1"

Definition at line 24 of file xshowtrace.c.

int slow = 0

Definition at line 46 of file xshowtrace.c.

Display* theDisplay = NULL

Definition at line 36 of file xshowtrace.c.

GC vecGC = 0

Definition at line 202 of file xshowtrace.c.

char xicom[] = "ximage -c 256"

Definition at line 25 of file xshowtrace.c.

int xoff

Definition at line 204 of file xshowtrace.c.

int yoff

Definition at line 204 of file xshowtrace.c.