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

Comparing ray/src/gen/replmarks.c (file contents):
Revision 2.14 by greg, Wed Dec 28 18:35:42 2005 UTC vs.
Revision 2.23 by greg, Sat Jun 7 05:09:45 2025 UTC

# Line 14 | Line 14 | static const char RCSid[] = "$Id$";
14  
15   #include "platform.h"
16   #include "rtio.h"
17 #include "rtprocess.h"
17   #include "fvect.h"
18  
19   #ifdef  M_PI
# Line 23 | Line 22 | static const char RCSid[] = "$Id$";
22   #define  PI             3.14159265358979323846
23   #endif
24  
26 #define  FEQ(a,b)       ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7)
27
25   #define  MAXVERT        6       /* maximum number of vertices for markers */
26   #define  MAXMARK        128     /* maximum number of markers */
27  
# Line 48 | Line 45 | int    nmarkers = 0;           /* number of markers */
45  
46   int     expand;                 /* expand commands? */
47  
51 char    *progname;
52
48   static void convert(char *name, FILE *fin);
49   static void cvcomm(char *fname, FILE *fin);
50   static void cvobject(char *fname, FILE *fin);
# Line 68 | Line 63 | main(
63          FILE    *fp;
64          int     i, j;
65  
66 <        progname = argv[0];
66 >        fixargv0(argv[0]);              /* sets global progname */
67          i = 1;
68          while (i < argc && argv[i][0] == '-') {
69                  do {
# Line 141 | Line 136 | userr:
136   void
137   convert(                /* replace marks in a stream */
138          char    *name,
139 <        register FILE   *fin
139 >        FILE    *fin
140   )
141   {
142 <        register int    c;
142 >        int     c;
143  
144          while ((c = getc(fin)) != EOF) {
145                  if (isspace(c))                         /* blank */
# Line 174 | Line 169 | cvcomm(                /* convert a command */
169   )
170   {
171          FILE    *pin;
172 <        char    buf[512], *fgetline();
172 >        char    buf[512];
173  
174          fgetline(buf, sizeof(buf), fin);
175          if (expand) {
# Line 185 | Line 180 | cvcomm(                /* convert a command */
180                          exit(1);
181                  }
182                  convert(buf, pin);
183 <                pclose(pin);
183 >                if (pclose(pin) != 0)
184 >                        fprintf(stderr,
185 >                        "%s: (%s): warning - bad status from \"%s\"\n",
186 >                                        progname, fname, buf);
187          } else
188                  printf("\n%s\n", buf);
189   }
# Line 197 | Line 195 | cvobject(              /* convert an object */
195          FILE    *fin
196   )
197   {
200        extern char     *fgetword();
198          char    buf[128], typ[16], nam[128];
199          int     i, n;
200 <        register int    j;
200 >        int     j;
201  
202          if (fgetword(buf, sizeof(buf), fin) == NULL ||
203                          fgetword(typ, sizeof(typ), fin) == NULL ||
# Line 245 | Line 242 | readerr:
242   void
243   replace(                /* replace marker */
244          char    *fname,
245 <        register struct mrkr    *m,
245 >        struct mrkr     *m,
246          char    *mark,
247          FILE    *fin
248   )
# Line 299 | Line 296 | edgecmp(                       /* compare two edges, descending order */
296  
297   int
298   buildxf(                /* build transform for marker */
299 <        register char   *xf,
299 >        char    *xf,
300          double  markscale,
301          FILE    *fin
302   )
# Line 309 | Line 306 | buildxf(               /* build transform for marker */
306          FVECT   xvec, yvec, zvec;
307          double  xlen;
308          int     n;
309 <        register int    i;
309 >        int     i;
310          /*
311           * Read and sort vectors:  longest is hypotenuse,
312           *      second longest is x' axis,
# Line 382 | Line 379 | buildxf(               /* build transform for marker */
379  
380   int
381   addrot(         /* compute rotation (x,y,z) => (xp,yp,zp) */
382 <        register char   *xf,
382 >        char    *xf,
383          FVECT xp,
384          FVECT yp,
385          FVECT zp
# Line 391 | Line 388 | addrot(                /* compute rotation (x,y,z) => (xp,yp,zp) */
388          int     n;
389          double  theta;
390  
391 +        if (yp[2]*yp[2] + zp[2]*zp[2] < 2.*FTINY*FTINY) {
392 +                /* Special case for X' along Z-axis */
393 +                theta = -atan2(yp[0], yp[1]);
394 +                sprintf(xf, " -ry %f -rz %f",
395 +                                xp[2] < 0.0 ? 90.0 : -90.0,
396 +                                theta*(180./PI));
397 +                return(4);
398 +        }
399          n = 0;
400          theta = atan2(yp[2], zp[2]);
401 <        if (!FEQ(theta,0.0)) {
401 >        if (!FABSEQ(theta,0.0)) {
402                  sprintf(xf, " -rx %f", theta*(180./PI));
403                  while (*xf) ++xf;
404                  n += 2;
405          }
406 <        theta = asin(-xp[2]);
407 <        if (!FEQ(theta,0.0)) {
406 >        theta = Asin(-xp[2]);
407 >        if (!FABSEQ(theta,0.0)) {
408                  sprintf(xf, " -ry %f", theta*(180./PI));
409                  while (*xf) ++xf;
410                  n += 2;
411          }
412          theta = atan2(xp[1], xp[0]);
413 <        if (!FEQ(theta,0.0)) {
413 >        if (!FABSEQ(theta,0.0)) {
414                  sprintf(xf, " -rz %f", theta*(180./PI));
415                  /* while (*xf) ++xf; */
416                  n += 2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines