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.12 by greg, Tue Sep 28 17:54:18 2004 UTC vs.
Revision 2.22 by greg, Tue Jun 3 21:31:51 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 "paths.h"
18   #include "fvect.h"
19  
20   #ifdef  M_PI
# Line 23 | Line 23 | static const char RCSid[] = "$Id$";
23   #define  PI             3.14159265358979323846
24   #endif
25  
26 #define  FEQ(a,b)       ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7)
27
26   #define  MAXVERT        6       /* maximum number of vertices for markers */
27 < #define  MAXMARK        32      /* maximum number of markers */
27 > #define  MAXMARK        128     /* maximum number of markers */
28  
29   #define  USE_XFORM      1       /* use !xform inline command */
30   #define  USE_INSTANCE   2       /* use instance primitive */
# Line 43 | Line 41 | struct mrkr {
41          char    *modin;                 /* input modifier indicating marker */
42          char    *objname;               /* output object file or octree */
43          int     usetype;                /* one of USE_* above */
44 < }  marker[MAXMARK];             /* array of markers */
44 > }  marker[MAXMARK+1];           /* array of markers */
45   int     nmarkers = 0;           /* number of markers */
46  
47   int     expand;                 /* expand commands? */
48  
51 char    *progname;
52
49   static void convert(char *name, FILE *fin);
50   static void cvcomm(char *fname, FILE *fin);
51   static void cvobject(char *fname, FILE *fin);
# Line 68 | Line 64 | main(
64          FILE    *fp;
65          int     i, j;
66  
67 <        progname = argv[0];
67 >        fixargv0(argv[0]);              /* sets global progname */
68          i = 1;
69          while (i < argc && argv[i][0] == '-') {
70                  do {
# Line 102 | Line 98 | main(
98                  } while (argv[i][0] == '-');
99                  if (marker[nmarkers].objname == NULL)
100                          goto userr;
101 +                if (nmarkers >= MAXMARK) {
102 +                        fprintf(stderr, "%s: too many markers\n", progname);
103 +                        return 1;
104 +                }
105                  marker[nmarkers++].modin = argv[i++];
106                if (nmarkers >= MAXMARK)
107                        break;
106                  marker[nmarkers].mscale = marker[nmarkers-1].mscale;
107          }
108          if (nmarkers == 0)
# Line 139 | Line 137 | userr:
137   void
138   convert(                /* replace marks in a stream */
139          char    *name,
140 <        register FILE   *fin
140 >        FILE    *fin
141   )
142   {
143 <        register int    c;
143 >        int     c;
144  
145          while ((c = getc(fin)) != EOF) {
146                  if (isspace(c))                         /* blank */
# Line 172 | Line 170 | cvcomm(                /* convert a command */
170   )
171   {
172          FILE    *pin;
173 <        char    buf[512], *fgetline();
173 >        char    buf[512];
174  
175          fgetline(buf, sizeof(buf), fin);
176          if (expand) {
# Line 183 | Line 181 | cvcomm(                /* convert a command */
181                          exit(1);
182                  }
183                  convert(buf, pin);
184 <                pclose(pin);
184 >                if (pclose(pin) != 0)
185 >                        fprintf(stderr,
186 >                        "%s: (%s): warning - bad status from \"%s\"\n",
187 >                                        progname, fname, buf);
188          } else
189                  printf("\n%s\n", buf);
190   }
# Line 195 | Line 196 | cvobject(              /* convert an object */
196          FILE    *fin
197   )
198   {
198        extern char     *fgetword();
199          char    buf[128], typ[16], nam[128];
200          int     i, n;
201 <        register int    j;
201 >        int     j;
202  
203 <        if (fscanf(fin, "%s %s %s", buf, typ, nam) != 3)
203 >        if (fgetword(buf, sizeof(buf), fin) == NULL ||
204 >                        fgetword(typ, sizeof(typ), fin) == NULL ||
205 >                        fgetword(nam, sizeof(nam), fin) == NULL)
206                  goto readerr;
207          if (!strcmp(typ, "polygon"))
208                  for (j = 0; j < nmarkers; j++)
# Line 208 | Line 210 | cvobject(              /* convert an object */
210                                  replace(fname, &marker[j], nam, fin);
211                                  return;
212                          }
213 <        printf("\n%s %s %s\n", buf, typ, nam);
213 >        putchar('\n'); fputword(buf, stdout);
214 >        printf(" %s ", typ);
215 >        fputword(nam, stdout); putchar('\n');
216          if (!strcmp(typ, "alias")) {            /* alias special case */
217 <                if (fscanf(fin, "%s", buf) != 1)
217 >                if (fgetword(buf, sizeof(buf), fin) == NULL)
218                          goto readerr;
219 <                printf("\t%s\n", buf);
219 >                putchar('\t'); fputword(buf, stdout); putchar('\n');
220                  return;
221          }
222          for (i = 0; i < 3; i++) {               /* pass along arguments */
# Line 239 | Line 243 | readerr:
243   void
244   replace(                /* replace marker */
245          char    *fname,
246 <        register struct mrkr    *m,
246 >        struct mrkr     *m,
247          char    *mark,
248          FILE    *fin
249   )
# Line 293 | Line 297 | edgecmp(                       /* compare two edges, descending order */
297  
298   int
299   buildxf(                /* build transform for marker */
300 <        register char   *xf,
300 >        char    *xf,
301          double  markscale,
302          FILE    *fin
303   )
# Line 303 | Line 307 | buildxf(               /* build transform for marker */
307          FVECT   xvec, yvec, zvec;
308          double  xlen;
309          int     n;
310 <        register int    i;
310 >        int     i;
311          /*
312           * Read and sort vectors:  longest is hypotenuse,
313           *      second longest is x' axis,
# Line 376 | Line 380 | buildxf(               /* build transform for marker */
380  
381   int
382   addrot(         /* compute rotation (x,y,z) => (xp,yp,zp) */
383 <        register char   *xf,
383 >        char    *xf,
384          FVECT xp,
385          FVECT yp,
386          FVECT zp
# Line 385 | Line 389 | addrot(                /* compute rotation (x,y,z) => (xp,yp,zp) */
389          int     n;
390          double  theta;
391  
392 +        if (yp[2]*yp[2] + zp[2]*zp[2] < 2.*FTINY*FTINY) {
393 +                /* Special case for X' along Z-axis */
394 +                theta = -atan2(yp[0], yp[1]);
395 +                sprintf(xf, " -ry %f -rz %f",
396 +                                xp[2] < 0.0 ? 90.0 : -90.0,
397 +                                theta*(180./PI));
398 +                return(4);
399 +        }
400          n = 0;
401          theta = atan2(yp[2], zp[2]);
402 <        if (!FEQ(theta,0.0)) {
402 >        if (!FABSEQ(theta,0.0)) {
403                  sprintf(xf, " -rx %f", theta*(180./PI));
404                  while (*xf) ++xf;
405                  n += 2;
406          }
407 <        theta = asin(-xp[2]);
408 <        if (!FEQ(theta,0.0)) {
407 >        theta = Asin(-xp[2]);
408 >        if (!FABSEQ(theta,0.0)) {
409                  sprintf(xf, " -ry %f", theta*(180./PI));
410                  while (*xf) ++xf;
411                  n += 2;
412          }
413          theta = atan2(xp[1], xp[0]);
414 <        if (!FEQ(theta,0.0)) {
414 >        if (!FABSEQ(theta,0.0)) {
415                  sprintf(xf, " -rz %f", theta*(180./PI));
416                  /* while (*xf) ++xf; */
417                  n += 2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines