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.9 by schorsch, Mon Nov 10 12:28:56 2003 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";
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 42 | Line 51 | int    argc;
51   char    *argv[];
52   {
53          int     i;
54 <        char    combuf[256];
46 <        Cursor  curs;
54 >        char    combuf[PATH_MAX];
55  
56          progname = argv[0];
57          for (i = 1; i < argc-2; i++)
# Line 53 | Line 61 | char   *argv[];
61                          break;
62          if (i > argc-2) {
63                  fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n",
64 <                                argv[0]);
64 >                                progname);
65                  exit(1);
66          }
67 +        picture = argv[argc-1];
68                                          /* get the viewing parameters */
69 <        if (viewfile(argv[argc-1], &ourview, &xres, &yres) <= 0 ||
69 >        if (viewfile(picture, &ourview, &ourres) <= 0 ||
70                          setview(&ourview) != NULL) {
71                  fprintf(stderr, "%s: cannot get view from \"%s\"\n",
72 <                                argv[0], argv[argc-1]);
72 >                                progname, picture);
73                  exit(1);
74          }
75                                          /* open the display */
76          if ((theDisplay = XOpenDisplay(NULL)) == NULL) {
77                  fprintf(stderr,
78                  "%s: cannot open display; DISPLAY variable set?\n",
79 <                                argv[0]);
79 >                                progname);
80                  exit(1);
81          }
82                                          /* build input command */
83 <        sprintf(combuf, "%s %s | %s", xicom, argv[argc-1], rtcom);
83 >        sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom);
84          for ( ; i < argc-1; i++) {
85                  strcat(combuf, " ");
86                  strcat(combuf, argv[i]);
# Line 81 | Line 90 | char   *argv[];
90                  exit(1);
91                                          /* loop on input */
92          mainloop();
93 <
93 >                                        /* close pipe and exit */
94 >        pclose(pin);
95          exit(0);
96   }
97  
# Line 128 | Line 138 | mainloop()                             /* get and process input */
138   freetree(tp)                            /* free a trace tree */
139   struct node     *tp;
140   {
141 <        register struct node    *kid;
141 >        register struct node    *kid, *k2;
142  
143 <        for (kid = tp->daughter; kid != NULL; kid = kid->sister)
143 >        for (kid = tp->daughter; kid != NULL; kid = k2) {
144 >                k2 = kid->sister;
145                  freetree(kid);
146 <        free((char *)tp);
146 >        }
147 >        free((void *)tp);
148   }
149  
150  
# Line 149 | Line 161 | struct node    *tp;
161  
162  
163   strtoipt(ipt, str)              /* convert string x y z to image point */
164 < double  ipt[2];
164 > int     ipt[2];
165   char    *str;
166   {
167 <        FVECT   pt;
167 >        FVECT   im_pt, pt;
168  
169 <        if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3)
169 >        if (!sscanvec(str, pt))
170                  return(-1);
171 <        viewpixel(&ipt[0], &ipt[1], NULL, &ourview, pt);
171 >        if (DOT(pt,pt) <= FTINY)                /* origin is really infinity */
172 >                ipt[0] = ipt[1] = -1;                   /* null vector */
173 >        else {
174 >                viewloc(im_pt, &ourview, pt);
175 >                loc2pix(ipt, &ourres, im_pt[0], im_pt[1]);
176 >        }
177          return(0);
178   }
179  
# Line 170 | Line 187 | int    xoff, yoff;
187  
188  
189   setvec(ipt)                     /* set up vector drawing for pick */
190 < double  ipt[2];
190 > int     ipt[2];
191   {
192 +        extern Window   xfindwind();
193          XWindowAttributes       wa;
194          XColor  xc;
195          XGCValues       gcv;
196 <        int     pm, rx, ry, wx, wy, rw, cw;
196 >        int     rx, ry, wx, wy;
197 >        Window  rw, cw;
198 >        unsigned int    pm;
199                                          /* compute pointer location */
200          if (gwind == 0) {
201 <                XQueryPointer(theDisplay, rwind, &rw, &gwind,
202 <                                &rx, &ry, &wx, &wy, &pm);
201 >                register char   *wn;
202 >                for (wn = picture; *wn; wn++);
203 >                while (wn > picture && wn[-1] != '/') wn--;
204 >                if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) {
205 >                        fprintf(stderr, "%s: cannot find display window!\n",
206 >                                        progname);
207 >                        exit(1);
208 >                }
209          }
210 <        XQueryPointer(theDisplay, gwind, &rw, &cw,
211 <                        &rx, &ry, &wx, &wy, &pm);
212 <        xoff = wx - ipt[0]*xres;
187 <        yoff = wy - (1.-ipt[1])*yres;
210 >        XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm);
211 >        xoff = wx - ipt[0];
212 >        yoff = wy - ipt[1];
213                                          /* set graphics context */
214          if (vecGC == 0) {
215                  XGetWindowAttributes(theDisplay, gwind, &wa);
# Line 202 | Line 227 | double ipt[2];
227  
228  
229   vector(ip1, ip2)                /* draw a vector */
230 < double  ip1[2], ip2[2];
230 > int     ip1[2], ip2[2];
231   {
232 +        if (ip2[0] == -1 && ip2[1] == -1)
233 +                return;                 /* null vector */
234          XDrawLine(theDisplay, gwind, vecGC,
235 <                        (int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff,
236 <                        (int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff);
235 >                        ip1[0]+xoff, ip1[1]+yoff,
236 >                        ip2[0]+xoff, ip2[1]+yoff);
237          if (slow) {
238                  XFlush(theDisplay);
239                  sleep(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines