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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines