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.9 by schorsch, Sun Nov 16 10:29:38 2003 UTC vs.
Revision 2.20 by greg, Tue Apr 22 14:51:29 2025 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char RCSid[] = "$Id";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   * Replace markers in Radiance scene description with objects or instances.
# 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 */
31 + #define  USE_MESH       3       /* use mesh primitive */
32 +
33   typedef struct {
34          short   beg, end;               /* beginning and ending vertex */
35          float   len2;                   /* length squared */
# Line 38 | Line 40 | struct mrkr {
40          double  mscale;                 /* scale by this to get unit */
41          char    *modin;                 /* input modifier indicating marker */
42          char    *objname;               /* output object file or octree */
43 <        int     doxform;                /* true if xform, false if instance */
44 < }  marker[MAXMARK];             /* array of markers */
43 >        int     usetype;                /* one of USE_* above */
44 > }  marker[MAXMARK+1];           /* array of markers */
45   int     nmarkers = 0;           /* number of markers */
46  
47   int     expand;                 /* expand commands? */
# Line 70 | Line 72 | main(
72                  do {
73                          switch (argv[i][1]) {
74                          case 'i':
75 <                                marker[nmarkers].doxform = 0;
75 >                                marker[nmarkers].usetype = USE_INSTANCE;
76                                  marker[nmarkers].objname = argv[++i];
77                                  break;
78 +                        case 'I':
79 +                                marker[nmarkers].usetype = USE_MESH;
80 +                                marker[nmarkers].objname = argv[++i];
81 +                                break;
82                          case 'x':
83 <                                marker[nmarkers].doxform = 1;
83 >                                marker[nmarkers].usetype = USE_XFORM;
84                                  marker[nmarkers].objname = argv[++i];
85                                  break;
86                          case 'e':
# Line 94 | Line 100 | main(
100                  } while (argv[i][0] == '-');
101                  if (marker[nmarkers].objname == NULL)
102                          goto userr;
103 +                if (nmarkers >= MAXMARK) {
104 +                        fprintf(stderr, "%s: too many markers\n", progname);
105 +                        return 1;
106 +                }
107                  marker[nmarkers++].modin = argv[i++];
98                if (nmarkers >= MAXMARK)
99                        break;
108                  marker[nmarkers].mscale = marker[nmarkers-1].mscale;
109          }
110          if (nmarkers == 0)
# Line 122 | Line 130 | main(
130          return 0;
131   userr:
132          fprintf(stderr,
133 < "Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree} modname .. [file ..]\n",
133 > "Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree|-I mesh} modname .. [file ..]\n",
134                  progname);
135          return 1;
136   }
# Line 175 | Line 183 | cvcomm(                /* convert a command */
183                          exit(1);
184                  }
185                  convert(buf, pin);
186 <                pclose(pin);
186 >                if (pclose(pin) != 0)
187 >                        fprintf(stderr,
188 >                        "%s: (%s): warning - bad status from \"%s\"\n",
189 >                                        progname, fname, buf);
190          } else
191                  printf("\n%s\n", buf);
192   }
# Line 192 | Line 203 | cvobject(              /* convert an object */
203          int     i, n;
204          register int    j;
205  
206 <        if (fscanf(fin, "%s %s %s", buf, typ, nam) != 3)
206 >        if (fgetword(buf, sizeof(buf), fin) == NULL ||
207 >                        fgetword(typ, sizeof(typ), fin) == NULL ||
208 >                        fgetword(nam, sizeof(nam), fin) == NULL)
209                  goto readerr;
210          if (!strcmp(typ, "polygon"))
211                  for (j = 0; j < nmarkers; j++)
# Line 200 | Line 213 | cvobject(              /* convert an object */
213                                  replace(fname, &marker[j], nam, fin);
214                                  return;
215                          }
216 <        printf("\n%s %s %s\n", buf, typ, nam);
216 >        putchar('\n'); fputword(buf, stdout);
217 >        printf(" %s ", typ);
218 >        fputword(nam, stdout); putchar('\n');
219          if (!strcmp(typ, "alias")) {            /* alias special case */
220 <                if (fscanf(fin, "%s", buf) != 1)
220 >                if (fgetword(buf, sizeof(buf), fin) == NULL)
221                          goto readerr;
222 <                printf("\t%s\n", buf);
222 >                putchar('\t'); fputword(buf, stdout); putchar('\n');
223                  return;
224          }
225          for (i = 0; i < 3; i++) {               /* pass along arguments */
# Line 240 | Line 255 | replace(               /* replace marker */
255          char    buf[256];
256  
257          buf[0] = '\0';                  /* bug fix thanks to schorsch */
258 <        if (m->doxform) {
259 <                sprintf(buf, "xform -e -n %s", mark);
258 >        if (m->usetype == USE_XFORM) {
259 >                sprintf(buf, "xform -n %s", mark);
260                  if (m->modout != NULL)
261                          sprintf(buf+strlen(buf), " -m %s", m->modout);
262                  if (buildxf(buf+strlen(buf), m->mscale, fin) < 0)
# Line 255 | Line 270 | replace(               /* replace marker */
270          } else {
271                  if ((n = buildxf(buf, m->mscale, fin)) < 0)
272                          goto badxf;
273 <                printf("\n%s instance %s\n",
274 <                                m->modout==NULL?"void":m->modout, mark);
273 >                printf("\n%s %s %s\n",
274 >                                m->modout==NULL?"void":m->modout,
275 >                                m->usetype==USE_INSTANCE?"instance":"mesh",
276 >                                mark);
277                  printf("%d %s%s\n0\n0\n", n+1, m->objname, buf);
278          }
279          return;
# Line 375 | Line 392 | addrot(                /* compute rotation (x,y,z) => (xp,yp,zp) */
392          int     n;
393          double  theta;
394  
395 +        if (yp[2]*yp[2] + zp[2]*zp[2] < 2.*FTINY*FTINY) {
396 +                /* Special case for X' along Z-axis */
397 +                theta = -atan2(yp[0], yp[1]);
398 +                sprintf(xf, " -ry %f -rz %f",
399 +                                xp[2] < 0.0 ? 90.0 : -90.0,
400 +                                theta*(180./PI));
401 +                return(4);
402 +        }
403          n = 0;
404          theta = atan2(yp[2], zp[2]);
405 <        if (!FEQ(theta,0.0)) {
405 >        if (!FABSEQ(theta,0.0)) {
406                  sprintf(xf, " -rx %f", theta*(180./PI));
407                  while (*xf) ++xf;
408                  n += 2;
409          }
410 <        theta = asin(-xp[2]);
411 <        if (!FEQ(theta,0.0)) {
410 >        theta = Asin(-xp[2]);
411 >        if (!FABSEQ(theta,0.0)) {
412                  sprintf(xf, " -ry %f", theta*(180./PI));
413                  while (*xf) ++xf;
414                  n += 2;
415          }
416          theta = atan2(xp[1], xp[0]);
417 <        if (!FEQ(theta,0.0)) {
417 >        if (!FABSEQ(theta,0.0)) {
418                  sprintf(xf, " -rz %f", theta*(180./PI));
419                  /* while (*xf) ++xf; */
420                  n += 2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines