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

Comparing ray/src/px/xshowtrace.c (file contents):
Revision 1.2 by greg, Sat Sep 22 18:53:15 1990 UTC vs.
Revision 2.13 by greg, Fri Apr 11 20:27:23 2014 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
4
4   /*
5   *  Display an image and watch the rays get traced.
6   *
7   *      9/21/90 Greg Ward
8   */
9  
10 + #include <X11/Xlib.h>
11 +
12   #include "standard.h"
13 + #include "paths.h"
14   #include "view.h"
13 #include <X11/Xlib.h>
15  
16   #define MAXDEPTH        32              /* ridiculous ray tree depth */
17  
18 < char    rtcom[] = "rtrace -h -otp -fa -x 1";
18 < char    xicom[] = "x11image";
18 > #define  sscanvec(s,v)  (sscanf(s,FVFORMAT,v,v+1,v+2)==3)
19  
20 + char    rtcom[64] = "rtrace -h- -otp -fa -x 1";
21 + char    xicom[] = "ximage -c 256";
22 +
23   VIEW    ourview = STDVIEW;              /* view for picture */
24 < int     xres, yres;
24 > RESOLU  ourres;                         /* picture resolution */
25  
26   char    *progname;                      /* program name */
27  
28 + char    *picture;                       /* picture name */
29 +
30   FILE    *pin;                           /* input stream */
31  
32   Display *theDisplay = NULL;             /* connection to server */
33  
34   struct node {                           /* ray tree node */
35 <        double  ipt[2];
35 >        int     ipt[2];
36          struct node     *sister;
37          struct node     *daughter;
38   };
# Line 36 | Line 41 | struct node {                          /* ray tree node */
41  
42   int     slow = 0;               /* slow trace? */
43  
44 + void mainloop(void);
45 + static void freetree(struct node        *tp);
46 + static void tracerays(struct node       *tp);
47 + static int strtoipt(int ipt[2], char    *str);
48 + static void setvec(int  ipt[2]);
49 + static void vector(int  ip1[2], int     ip2[2]);
50  
51 < main(argc, argv)                /* takes both the octree and the image */
52 < int     argc;
53 < char    *argv[];
51 >
52 > int
53 > main(           /* takes both the octree and the image */
54 >        int     argc,
55 >        char    *argv[]
56 > )
57   {
58          int     i;
59 <        char    combuf[256];
46 <        Cursor  curs;
59 >        char    combuf[PATH_MAX];
60  
61          progname = argv[0];
62          for (i = 1; i < argc-2; i++)
63                  if (!strcmp(argv[i], "-s"))
64                          slow++;
65 +                else if (!strcmp(argv[i], "-T"))
66 +                        strcat(rtcom, " -oTp");
67                  else
68                          break;
69          if (i > argc-2) {
70 <                fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n",
71 <                                argv[0]);
70 >                fprintf(stderr, "Usage: %s [-s][-T] [rtrace args] octree picture\n",
71 >                                progname);
72                  exit(1);
73          }
74 +        picture = argv[argc-1];
75                                          /* get the viewing parameters */
76 <        if (viewfile(argv[argc-1], &ourview, &xres, &yres) <= 0 ||
76 >        if (viewfile(picture, &ourview, &ourres) <= 0 ||
77                          setview(&ourview) != NULL) {
78                  fprintf(stderr, "%s: cannot get view from \"%s\"\n",
79 <                                argv[0], argv[argc-1]);
79 >                                progname, picture);
80                  exit(1);
81          }
82                                          /* open the display */
83          if ((theDisplay = XOpenDisplay(NULL)) == NULL) {
84                  fprintf(stderr,
85                  "%s: cannot open display; DISPLAY variable set?\n",
86 <                                argv[0]);
86 >                                progname);
87                  exit(1);
88          }
89                                          /* build input command */
90 <        sprintf(combuf, "%s %s | %s", xicom, argv[argc-1], rtcom);
90 >        sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom);
91          for ( ; i < argc-1; i++) {
92                  strcat(combuf, " ");
93                  strcat(combuf, argv[i]);
# Line 81 | Line 97 | char   *argv[];
97                  exit(1);
98                                          /* loop on input */
99          mainloop();
100 <
100 >                                        /* close pipe and exit */
101 >        pclose(pin);
102          exit(0);
103   }
104  
105  
106 < mainloop()                              /* get and process input */
106 > void
107 > mainloop(void)                          /* get and process input */
108   {
109          static struct node      *sis[MAXDEPTH];
110          register struct node    *newp;
# Line 125 | Line 143 | mainloop()                             /* get and process input */
143   }
144  
145  
146 < freetree(tp)                            /* free a trace tree */
147 < struct node     *tp;
146 > static void
147 > freetree(                               /* free a trace tree */
148 >        struct node     *tp
149 > )
150   {
151 <        register struct node    *kid;
151 >        register struct node    *kid, *k2;
152  
153 <        for (kid = tp->daughter; kid != NULL; kid = kid->sister)
153 >        for (kid = tp->daughter; kid != NULL; kid = k2) {
154 >                k2 = kid->sister;
155                  freetree(kid);
156 <        free((char *)tp);
156 >        }
157 >        free((void *)tp);
158   }
159  
160  
161 < tracerays(tp)                           /* trace a ray tree */
162 < struct node     *tp;
161 > static void
162 > tracerays(                              /* trace a ray tree */
163 >        struct node     *tp
164 > )
165   {
166          register struct node    *kid;
167  
# Line 148 | Line 172 | struct node    *tp;
172   }
173  
174  
175 < strtoipt(ipt, str)              /* convert string x y z to image point */
176 < double  ipt[2];
177 < char    *str;
175 > static int
176 > strtoipt(               /* convert string x y z to image point */
177 >        int     ipt[2],
178 >        char    *str
179 > )
180   {
181 <        FVECT   pt;
181 >        FVECT   im_pt, pt;
182  
183 <        if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3)
183 >        if (!sscanvec(str, pt))
184                  return(-1);
185 <        viewpixel(&ipt[0], &ipt[1], NULL, &ourview, pt);
185 >        if (DOT(pt,pt) <= FTINY)                /* origin is really infinity */
186 >                ipt[0] = ipt[1] = -1;                   /* null vector */
187 >        else {
188 >                viewloc(im_pt, &ourview, pt);
189 >                loc2pix(ipt, &ourres, im_pt[0], im_pt[1]);
190 >        }
191          return(0);
192   }
193  
# Line 169 | Line 200 | Window gwind = 0;
200   int     xoff, yoff;
201  
202  
203 < setvec(ipt)                     /* set up vector drawing for pick */
204 < double  ipt[2];
203 > static void
204 > setvec(                 /* set up vector drawing for pick */
205 >        int     ipt[2]
206 > )
207   {
208 +        extern Window   xfindwind();
209          XWindowAttributes       wa;
210          XColor  xc;
211          XGCValues       gcv;
212 <        int     pm, rx, ry, wx, wy, rw, cw;
212 >        int     rx, ry, wx, wy;
213 >        Window  rw, cw;
214 >        unsigned int    pm;
215                                          /* compute pointer location */
216          if (gwind == 0) {
217 <                XQueryPointer(theDisplay, rwind, &rw, &gwind,
218 <                                &rx, &ry, &wx, &wy, &pm);
217 >                register char   *wn;
218 >                for (wn = picture; *wn; wn++);
219 >                while (wn > picture && wn[-1] != '/') wn--;
220 >                if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) {
221 >                        fprintf(stderr, "%s: cannot find display window!\n",
222 >                                        progname);
223 >                        exit(1);
224 >                }
225          }
226 <        XQueryPointer(theDisplay, gwind, &rw, &cw,
227 <                        &rx, &ry, &wx, &wy, &pm);
228 <        xoff = wx - ipt[0]*xres;
187 <        yoff = wy - (1.-ipt[1])*yres;
226 >        XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm);
227 >        xoff = wx - ipt[0];
228 >        yoff = wy - ipt[1];
229                                          /* set graphics context */
230          if (vecGC == 0) {
231                  XGetWindowAttributes(theDisplay, gwind, &wa);
# Line 201 | Line 242 | double ipt[2];
242   }
243  
244  
245 < vector(ip1, ip2)                /* draw a vector */
246 < double  ip1[2], ip2[2];
245 > static void
246 > vector(         /* draw a vector */
247 >        int     ip1[2],
248 >        int     ip2[2]
249 > )
250   {
251 +        if (ip2[0] == -1 && ip2[1] == -1)
252 +                return;                 /* null vector */
253          XDrawLine(theDisplay, gwind, vecGC,
254 <                        (int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff,
255 <                        (int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff);
254 >                        ip1[0]+xoff, ip1[1]+yoff,
255 >                        ip2[0]+xoff, ip2[1]+yoff);
256          if (slow) {
257                  XFlush(theDisplay);
258                  sleep(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines