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.3 by greg, Mon Aug 2 14:29:31 1993 UTC vs.
Revision 2.11 by greg, Thu Jan 29 22:20:31 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id";
3   #endif
6
4   /*
5   * Replace markers in Radiance scene description with objects or instances.
6   *
7   *      Created:        17 Feb 1991     Greg Ward
8   */
9  
10 < #include <stdio.h>
10 > #include <stdlib.h>
11   #include <ctype.h>
12   #include <math.h>
13 + #include <stdio.h>
14  
15 + #include "platform.h"
16 + #include "rtio.h"
17 + #include "rtprocess.h"
18   #include "fvect.h"
19  
20   #ifdef  M_PI
21 < #define  PI             M_PI
21 > #define  PI             ((double)M_PI)
22   #else
23   #define  PI             3.14159265358979323846
24   #endif
# Line 27 | Line 28 | static char SCCSid[] = "$SunId$ LBL";
28   #define  MAXVERT        6       /* maximum number of vertices for markers */
29   #define  MAXMARK        32      /* maximum number of markers */
30  
31 < #ifdef  DCL_ATOF
32 < extern double  atof();
33 < #endif
31 > #define  USE_XFORM      1       /* use !xform inline command */
32 > #define  USE_INSTANCE   2       /* use instance primitive */
33 > #define  USE_MESH       3       /* use mesh primitive */
34  
35   typedef struct {
36          short   beg, end;               /* beginning and ending vertex */
# Line 41 | Line 42 | struct mrkr {
42          double  mscale;                 /* scale by this to get unit */
43          char    *modin;                 /* input modifier indicating marker */
44          char    *objname;               /* output object file or octree */
45 <        int     doxform;                /* true if xform, false if instance */
45 >        int     usetype;                /* one of USE_* above */
46   }  marker[MAXMARK];             /* array of markers */
47   int     nmarkers = 0;           /* number of markers */
48  
# Line 49 | Line 50 | int    expand;                 /* expand commands? */
50  
51   char    *progname;
52  
53 + static void convert(char *name, FILE *fin);
54 + static void cvcomm(char *fname, FILE *fin);
55 + static void cvobject(char *fname, FILE *fin);
56 + static void replace(char *fname, struct mrkr *m, char *mark, FILE *fin);
57 + static int edgecmp(const void *e1, const void *e2);
58 + static int buildxf(char *xf, double markscale, FILE *fin);
59 + static int addrot(char *xf, FVECT xp, FVECT yp, FVECT zp);
60  
61 < main(argc, argv)
62 < int     argc;
63 < char    *argv[];
61 >
62 > int
63 > main(
64 >        int     argc,
65 >        char    *argv[]
66 > )
67   {
68          FILE    *fp;
69          int     i, j;
# Line 63 | Line 74 | char   *argv[];
74                  do {
75                          switch (argv[i][1]) {
76                          case 'i':
77 <                                marker[nmarkers].doxform = 0;
77 >                                marker[nmarkers].usetype = USE_INSTANCE;
78                                  marker[nmarkers].objname = argv[++i];
79                                  break;
80 +                        case 'I':
81 +                                marker[nmarkers].usetype = USE_MESH;
82 +                                marker[nmarkers].objname = argv[++i];
83 +                                break;
84                          case 'x':
85 <                                marker[nmarkers].doxform = 1;
85 >                                marker[nmarkers].usetype = USE_XFORM;
86                                  marker[nmarkers].objname = argv[++i];
87                                  break;
88                          case 'e':
# Line 112 | Line 127 | char   *argv[];
127                          convert(argv[i], fp);
128                          fclose(fp);
129                  }
130 <        exit(0);
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 <        exit(1);
135 >        return 1;
136   }
137  
138  
139 < convert(name, fin)              /* replace marks in a stream */
140 < char    *name;
141 < register FILE   *fin;
139 > void
140 > convert(                /* replace marks in a stream */
141 >        char    *name,
142 >        register FILE   *fin
143 > )
144   {
145          register int    c;
146  
# Line 148 | Line 165 | register FILE  *fin;
165   }
166  
167  
168 < cvcomm(fname, fin)              /* convert a command */
169 < char    *fname;
170 < FILE    *fin;
168 > void
169 > cvcomm(         /* convert a command */
170 >        char    *fname,
171 >        FILE    *fin
172 > )
173   {
174 <        FILE    *pin, *popen();
174 >        FILE    *pin;
175          char    buf[512], *fgetline();
176  
177          fgetline(buf, sizeof(buf), fin);
# Line 170 | Line 189 | FILE   *fin;
189   }
190  
191  
192 < cvobject(fname, fin)            /* convert an object */
193 < char    *fname;
194 < FILE    *fin;
192 > void
193 > cvobject(               /* convert an object */
194 >        char    *fname,
195 >        FILE    *fin
196 > )
197   {
198 +        extern char     *fgetword();
199          char    buf[128], typ[16], nam[128];
200          int     i, n;
201          register int    j;
# Line 198 | Line 220 | FILE   *fin;
220                          goto readerr;
221                  printf("%d", n);
222                  for (j = 0; j < n; j++) {
223 <                        if (fscanf(fin, "%s", buf) != 1)
223 >                        if (fgetword(buf, sizeof(buf), fin) == NULL)
224                                  goto readerr;
225                          if (j%3 == 0)
226                                  putchar('\n');
227 <                        printf("\t%s", buf);
227 >                        putchar('\t');
228 >                        fputword(buf, stdout);
229                  }
230                  putchar('\n');
231          }
# Line 213 | Line 236 | readerr:
236   }
237  
238  
239 < replace(fname, m, mark, fin)            /* replace marker */
240 < char    *fname;
241 < register struct mrkr    *m;
242 < char    *mark;
243 < FILE    *fin;
239 > void
240 > replace(                /* replace marker */
241 >        char    *fname,
242 >        register struct mrkr    *m,
243 >        char    *mark,
244 >        FILE    *fin
245 > )
246   {
247          int     n;
248          char    buf[256];
249  
250 <        if (m->doxform) {
251 <                sprintf(buf, "xform -e -n %s", mark);
250 >        buf[0] = '\0';                  /* bug fix thanks to schorsch */
251 >        if (m->usetype == USE_XFORM) {
252 >                sprintf(buf, "xform -n %s", mark);
253                  if (m->modout != NULL)
254                          sprintf(buf+strlen(buf), " -m %s", m->modout);
255                  if (buildxf(buf+strlen(buf), m->mscale, fin) < 0)
# Line 237 | Line 263 | FILE   *fin;
263          } else {
264                  if ((n = buildxf(buf, m->mscale, fin)) < 0)
265                          goto badxf;
266 <                printf("\n%s instance %s\n",
267 <                                m->modout==NULL?"void":m->modout, mark);
266 >                printf("\n%s %s %s\n",
267 >                                m->modout==NULL?"void":m->modout,
268 >                                m->usetype==USE_INSTANCE?"instance":"mesh",
269 >                                mark);
270                  printf("%d %s%s\n0\n0\n", n+1, m->objname, buf);
271          }
272          return;
# Line 249 | Line 277 | badxf:
277   }
278  
279  
280 < edgecmp(e1, e2)                 /* compare two edges, descending order */
281 < EDGE    *e1, *e2;
280 > int
281 > edgecmp(                        /* compare two edges, descending order */
282 >        const void *e1,
283 >        const void *e2
284 > )
285   {
286 <        if (e1->len2 > e2->len2)
286 >        if (((EDGE*)e1)->len2 > ((EDGE*)e2)->len2)
287                  return(-1);
288 <        if (e1->len2 < e2->len2)
288 >        if (((EDGE*)e1)->len2 < ((EDGE*)e2)->len2)
289                  return(1);
290          return(0);
291   }
292  
293  
294   int
295 < buildxf(xf, markscale, fin)             /* build transform for marker */
296 < char    *xf;
297 < double  markscale;
298 < FILE    *fin;
295 > buildxf(                /* build transform for marker */
296 >        register char   *xf,
297 >        double  markscale,
298 >        FILE    *fin
299 > )
300   {
301          static FVECT    vlist[MAXVERT];
302          static EDGE     elist[MAXVERT];
# Line 329 | Line 361 | FILE   *fin;
361          if (markscale > 0.0) {          /* add scale factor */
362                  sprintf(xf, " -s %f", xlen*markscale);
363                  n += 2;
364 <                xf += strlen(xf);
364 >                while (*xf) ++xf;
365          }
366                                          /* add rotation */
367          n += addrot(xf, xvec, yvec, zvec);
368 <        xf += strlen(xf);
368 >        while (*xf) ++xf;
369                                          /* add translation */
370          n += 4;
371          sprintf(xf, " -t %f %f %f", vlist[elist[1].beg][0],
# Line 342 | Line 374 | FILE   *fin;
374   }
375  
376  
377 < addrot(xf, xp, yp, zp)          /* compute rotation (x,y,z) => (xp,yp,zp) */
378 < char    *xf;
379 < FVECT   xp, yp, zp;
377 > int
378 > addrot(         /* compute rotation (x,y,z) => (xp,yp,zp) */
379 >        register char   *xf,
380 >        FVECT xp,
381 >        FVECT yp,
382 >        FVECT zp
383 > )
384   {
385          int     n;
386          double  theta;
# Line 353 | Line 389 | FVECT  xp, yp, zp;
389          theta = atan2(yp[2], zp[2]);
390          if (!FEQ(theta,0.0)) {
391                  sprintf(xf, " -rx %f", theta*(180./PI));
392 <                xf += strlen(xf);
392 >                while (*xf) ++xf;
393                  n += 2;
394          }
395          theta = asin(-xp[2]);
396          if (!FEQ(theta,0.0)) {
397                  sprintf(xf, " -ry %f", theta*(180./PI));
398 <                xf += strlen(xf);
398 >                while (*xf) ++xf;
399                  n += 2;
400          }
401          theta = atan2(xp[1], xp[0]);
402          if (!FEQ(theta,0.0)) {
403                  sprintf(xf, " -rz %f", theta*(180./PI));
404 <                /* xf += strlen(xf); */
404 >                /* while (*xf) ++xf; */
405                  n += 2;
406          }
407          return(n);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines