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.1 by greg, Sat Sep 22 10:53:57 1990 UTC vs.
Revision 2.2 by greg, Tue Apr 21 17:24:51 1992 UTC

# Line 1 | Line 1
1 + /* Copyright (c) 1991 Regents of the University of California */
2 +
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
5   #endif
# Line 10 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include "standard.h"
14   #include "view.h"
15 + #include "resolu.h"
16   #include <X11/Xlib.h>
17  
18   #define MAXDEPTH        32              /* ridiculous ray tree depth */
19  
20 < char    rtcom[] = "rtrace -h -otp -fa -x 1";
21 < char    xicom[] = "x11image";
20 > #ifdef  SMLFLT
21 > #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
22 > #else
23 > #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
24 > #endif
25  
26 + char    rtcom[] = "rtrace -h- -otp -fa -x 1";
27 + char    xicom[] = "ximage";
28 +
29   VIEW    ourview = STDVIEW;              /* view for picture */
30 < int     xres, yres;
30 > RESOLU  ourres;                         /* picture resolution */
31  
32   char    *progname;                      /* program name */
33  
34 + char    *picture;                       /* picture name */
35 +
36   FILE    *pin;                           /* input stream */
37  
38   Display *theDisplay = NULL;             /* connection to server */
39  
40   struct node {                           /* ray tree node */
41 <        double  ipt[2];
41 >        int     ipt[2];
42          struct node     *sister;
43          struct node     *daughter;
44   };
45  
46   #define newnode()       (struct node *)calloc(1, sizeof(struct node))
47  
48 + int     slow = 0;               /* slow trace? */
49  
50 +
51   main(argc, argv)                /* takes both the octree and the image */
52   int     argc;
53   char    *argv[];
54   {
55          int     i;
56          char    combuf[256];
44        Cursor  curs;
57  
58          progname = argv[0];
59 <        if (argc < 3) {
60 <                fprintf(stderr, "Usage: %s [rtrace args] octree picture\n",
61 <                                argv[0]);
59 >        for (i = 1; i < argc-2; i++)
60 >                if (!strcmp(argv[i], "-s"))
61 >                        slow++;
62 >                else
63 >                        break;
64 >        if (i > argc-2) {
65 >                fprintf(stderr, "Usage: %s [-s] [rtrace args] octree picture\n",
66 >                                progname);
67                  exit(1);
68          }
69 +        picture = argv[argc-1];
70                                          /* get the viewing parameters */
71 <        if (viewfile(argv[argc-1], &ourview, &xres, &yres) <= 0 ||
71 >        if (viewfile(picture, &ourview, &ourres) <= 0 ||
72                          setview(&ourview) != NULL) {
73                  fprintf(stderr, "%s: cannot get view from \"%s\"\n",
74 <                                argv[0], argv[argc-1]);
74 >                                progname, picture);
75                  exit(1);
76          }
77                                          /* open the display */
78          if ((theDisplay = XOpenDisplay(NULL)) == NULL) {
79                  fprintf(stderr,
80                  "%s: cannot open display; DISPLAY variable set?\n",
81 <                                argv[0]);
81 >                                progname);
82                  exit(1);
83          }
84                                          /* build input command */
85 <        sprintf(combuf, "%s %s | %s", xicom, argv[argc-1], rtcom);
86 <        for (i = 1; i < argc-1; i++) {
85 >        sprintf(combuf, "%s %s | %s", xicom, picture, rtcom);
86 >        for ( ; i < argc-1; i++) {
87                  strcat(combuf, " ");
88                  strcat(combuf, argv[i]);
89          }
# Line 109 | Line 127 | mainloop()                             /* get and process input */
127                  if (i == 0) {
128                          setvec(sis[0]->ipt);
129                          tracerays(sis[0]);
112                        XFlush(theDisplay);
130                          freetree(sis[0]);
131                          sis[0] = NULL;
132 +                        if (!slow)
133 +                                XFlush(theDisplay);
134                  }
135          }
136   }
# Line 134 | Line 153 | struct node    *tp;
153          register struct node    *kid;
154  
155          for (kid = tp->daughter; kid != NULL; kid = kid->sister) {
137                tracerays(kid);
156                  vector(tp->ipt, kid->ipt);
157 +                tracerays(kid);
158          }
159   }
160  
161  
162   strtoipt(ipt, str)              /* convert string x y z to image point */
163 < double  ipt[2];
163 > int     ipt[2];
164   char    *str;
165   {
166 <        FVECT   pt;
166 >        FVECT   im_pt, pt;
167  
168 <        if (sscanf(str, "%lf %lf %lf", &pt[0], &pt[1], &pt[2]) != 3)
168 >        if (!sscanvec(str, pt))
169                  return(-1);
170 <        viewpixel(&ipt[0], &ipt[1], NULL, &ourview, pt);
170 >        if (DOT(pt,pt) <= FTINY)                /* origin is really infinity */
171 >                ipt[0] = ipt[1] = -1;                   /* null vector */
172 >        else {
173 >                viewloc(im_pt, &ourview, pt);
174 >                loc2pix(ipt, &ourres, im_pt[0], im_pt[1]);
175 >        }
176          return(0);
177   }
178  
# Line 162 | Line 186 | int    xoff, yoff;
186  
187  
188   setvec(ipt)                     /* set up vector drawing for pick */
189 < double  ipt[2];
189 > int     ipt[2];
190   {
191          XWindowAttributes       wa;
192          XColor  xc;
193          XGCValues       gcv;
194 <        int     pm, rx, ry, wx, wy, rw, cw;
194 >        int     rx, ry, wx, wy;
195 >        Window  rw, cw;
196 >        unsigned int    pm;
197                                          /* compute pointer location */
198 <        if (gwind == 0) {
199 <                XQueryPointer(theDisplay, rwind, &rw, &gwind,
200 <                                &rx, &ry, &wx, &wy, &pm);
198 >        if (gwind == 0 &&
199 >                (gwind = xfindwind(theDisplay, rwind, picture, 2)) == 0) {
200 >                fprintf(stderr, "%s: cannot find display window!\n", progname);
201 >                exit(1);
202          }
203 <        XQueryPointer(theDisplay, gwind, &rw, &cw,
204 <                        &rx, &ry, &wx, &wy, &pm);
205 <        xoff = wx - ipt[0]*xres;
179 <        yoff = wy - (1.-ipt[1])*yres;
203 >        XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm);
204 >        xoff = wx - ipt[0];
205 >        yoff = wy - ipt[1];
206                                          /* set graphics context */
207          if (vecGC == 0) {
208                  XGetWindowAttributes(theDisplay, gwind, &wa);
# Line 194 | Line 220 | double ipt[2];
220  
221  
222   vector(ip1, ip2)                /* draw a vector */
223 < double  ip1[2], ip2[2];
223 > int     ip1[2], ip2[2];
224   {
225 +        if (ip2[0] == -1 && ip2[1] == -1)
226 +                return;                 /* null vector */
227          XDrawLine(theDisplay, gwind, vecGC,
228 <                        (int)(ip1[0]*xres)+xoff, (int)((1.-ip1[1])*yres)+yoff,
229 <                        (int)(ip2[0]*xres)+xoff, (int)((1.-ip2[1])*yres)+yoff);
228 >                        ip1[0]+xoff, ip1[1]+yoff,
229 >                        ip2[0]+xoff, ip2[1]+yoff);
230 >        if (slow) {
231 >                XFlush(theDisplay);
232 >                sleep(1);
233 >        }
234   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines