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

Comparing ray/src/cv/rad2mgf.c (file contents):
Revision 2.16 by greg, Sat Feb 22 02:07:23 2003 UTC vs.
Revision 2.24 by greg, Wed Dec 28 18:35:42 2005 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   * Convert Radiance scene description to MGF
6   */
7  
8 #include "standard.h"
8   #include <ctype.h>
9   #include <string.h>
10 + #include <stdio.h>
11 +
12 + #include "platform.h"
13 + #include "rtmath.h"
14 + #include "rtio.h"
15 + #include "rtprocess.h"
16   #include "object.h"
17   #include "color.h"
18   #include "lookup.h"
19  
20   #define C_1SIDEDTHICK   0.005
21  
17 int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
18 int     o_instance(), o_illum();
19 int     o_plastic(), o_metal(), o_glass(), o_dielectric(),
20        o_mirror(), o_trans(), o_light();
22  
23   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
24  
# Line 50 | Line 51 | struct vert {
51  
52   LUTAB   vertab = LU_SINIT(free,NULL);   /* our vertex lookup table */
53  
54 + void rad2mgf(char *inp);
55 + void cvtprim(char *inp, char *mod, char *typ, char *id, FUNARGS *fa);
56 + void newmat(char *id, char *alias);
57 + void setmat(char *id);
58 + void setobj(char *id);
59 + void init(void);
60 + void uninit(void);
61 + void clrverts(void);
62 + void unspace(char *s);
63 + void add2dispatch(char *name, int (*func)());
64 + char *getvertid(char *vname, FVECT vp);
65 + int o_unsupported(char *mod, char *typ, char *id, FUNARGS *fa);
66 + int o_face(char *mod, char *typ, char *id, FUNARGS *fa);
67 + int o_cone(char *mod, char *typ, char *id, FUNARGS *fa);
68 + int o_sphere(char *mod, char *typ, char *id, FUNARGS *fa);
69 + int o_cylinder(char *mod, char *typ, char *id, FUNARGS *fa);
70 + int o_ring(char *mod, char *typ, char *id, FUNARGS *fa);
71 + int o_instance(char *mod, char *typ, char *id, FUNARGS *fa);
72 + int o_illum(char *mod, char *typ, char *id, FUNARGS *fa);
73 + int o_plastic(char *mod, char *typ, char *id, FUNARGS *fa);
74 + int o_metal(char *mod, char *typ, char *id, FUNARGS *fa);
75 + int o_glass(char *mod, char *typ, char *id, FUNARGS *fa);
76 + int o_dielectric(char *mod, char *typ, char *id, FUNARGS *fa);
77 + int o_mirror(char *mod, char *typ, char *id, FUNARGS *fa);
78 + int o_trans(char *mod, char *typ, char *id, FUNARGS *fa);
79 + int o_light(char *mod, char *typ, char *id, FUNARGS *fa);
80  
81 < main(argc, argv)
82 < int     argc;
83 < char    **argv;
81 >
82 > int
83 > main(
84 >        int     argc,
85 >        char    **argv
86 > )
87   {
88          int     i;
89  
# Line 94 | Line 124 | unkopt:
124   }
125  
126  
127 < rad2mgf(inp)            /* convert a Radiance file to MGF */
128 < char    *inp;
127 > void
128 > rad2mgf(                /* convert a Radiance file to MGF */
129 >        char    *inp
130 > )
131   {
132 < #define mod     buf
101 < #define typ     (buf+128)
102 < #define id      (buf+256)
103 < #define alias   (buf+384)
104 <        char    buf[512];
132 >        char  mod[128], typ[32], id[128], alias[128];
133          FUNARGS fa;
134          register FILE   *fp;
135          register int    c;
# Line 140 | Line 168 | char   *inp;
168                          break;
169                  default:                /* Radiance primitive */
170                          ungetc(c, fp);
171 <                        if (fscanf(fp, "%s %s %s", mod, typ, id) != 3) {
171 >                        if (fgetword(mod, sizeof(mod), fp) == NULL ||
172 >                                        fgetword(typ, sizeof(typ), fp) == NULL ||
173 >                                        fgetword(id, sizeof(id), fp) == NULL) {
174                                  fputs(inp, stderr);
175                                  fputs(": unexpected EOF\n", stderr);
176                                  exit(1);
177                          }
178 +                        unspace(mod);
179 +                        unspace(id);
180                          if (!strcmp(typ, "alias")) {
181                                  strcpy(alias, "EOF");
182 <                                fscanf(fp, "%s", alias);
182 >                                fgetword(alias, sizeof(alias), fp);
183 >                                unspace(alias);
184                                  newmat(id, alias);
185                          } else {
186                                  if (!readfargs(&fa, fp)) {
# Line 166 | Line 199 | char   *inp;
199                  pclose(fp);
200          else
201                  fclose(fp);
169 #undef mod
170 #undef typ
171 #undef id
172 #undef alias
202   }
203  
204  
205 < cvtprim(inp, mod, typ, id, fa)  /* process Radiance primitive */
206 < char    *inp, *mod, *typ, *id;
207 < FUNARGS *fa;
205 > void
206 > unspace(        /* replace spaces with underscores in s */
207 >        char *s
208 > )
209   {
210 +        while (*s) {
211 +                if (isspace(*s))
212 +                        *s = '_';
213 +                ++s;
214 +        }
215 + }
216 +
217 +
218 + void
219 + cvtprim(        /* process Radiance primitive */
220 +        char    *inp,
221 +        char    *mod,
222 +        char    *typ,
223 +        char    *id,
224 +        FUNARGS *fa
225 + )
226 + {
227          int     (*df)();
228  
229          df = (int (*)())lu_find(&rdispatch, typ)->data;
230          if (df != NULL) {                               /* convert */
231                  if ((*df)(mod, typ, id, fa) < 0) {
232 <                        fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id);
232 >                        fprintf(stderr, "%s: bad %s \"%s\"\n", "rad2mgf", typ, id);
233                          exit(1);
234                  }
235          } else {                                        /* unsupported */
# Line 193 | Line 240 | FUNARGS        *fa;
240   }
241  
242  
243 < newmat(id, alias)               /* add a modifier to the alias list */
244 < char    *id;
245 < char    *alias;
243 > void
244 > newmat(         /* add a modifier to the alias list */
245 >        char    *id,
246 >        char    *alias
247 > )
248   {
249          register LUENT  *lp, *lpa;
250  
# Line 229 | Line 278 | memerr:
278   }
279  
280  
281 < setmat(id)                      /* set material to this one */
282 < char    *id;
281 > void
282 > setmat(                 /* set material to this one */
283 >        char    *id
284 > )
285   {
286          if (!strcmp(id, curmat))        /* already set? */
287                  return;
# Line 241 | Line 292 | char   *id;
292   }
293  
294  
295 < setobj(id)                      /* set object name to this one */
296 < char    *id;
295 > void
296 > setobj(                 /* set object name to this one */
297 >        char    *id
298 > )
299   {
300          register char   *cp, *cp2;
301          char    *end = NULL;
# Line 260 | Line 313 | char   *id;
313                  *cp2++ = 'O';
314          }
315          for (cp = id; cp < end; *cp2++ = *cp++) {
316 <                if (*cp < '!' | *cp > '~')      /* limit to visible chars */
316 >                if ((*cp < '!') | (*cp > '~'))  /* limit to visible chars */
317                          *cp = '?';
318                  diff += *cp != *cp2;
319          }
# Line 272 | Line 325 | char   *id;
325   }
326  
327  
328 < init()                  /* initialize dispatch table and output */
328 > void
329 > init(void)                      /* initialize dispatch table and output */
330   {
331          lu_init(&vertab, NVERTS);
332          lu_init(&rdispatch, 22);
# Line 285 | Line 339 | init()                 /* initialize dispatch table and output */
339          add2dispatch("tube", o_cylinder);
340          add2dispatch("ring", o_ring);
341          add2dispatch("instance", o_instance);
342 +        add2dispatch("mesh", o_instance);
343          add2dispatch("plastic", o_plastic);
344          add2dispatch("plastic2", o_plastic);
345          add2dispatch("metal", o_metal);
# Line 305 | Line 360 | init()                 /* initialize dispatch table and output */
360   }
361  
362  
363 < uninit()                        /* mark end of MGF file */
363 > void
364 > uninit(void)                    /* mark end of MGF file */
365   {
366          puts("o");
367          if (hasmult)
# Line 317 | Line 373 | uninit()                       /* mark end of MGF file */
373   }
374  
375  
376 < clrverts()                      /* clear vertex table */
376 > void
377 > clrverts(void)                  /* clear vertex table */
378   {
379          register int    i;
380  
# Line 328 | Line 385 | clrverts()                     /* clear vertex table */
385   }
386  
387  
388 < add2dispatch(name, func)        /* add function to dispatch table */
389 < char    *name;
390 < int     (*func)();
388 > void
389 > add2dispatch(   /* add function to dispatch table */
390 >        char    *name,
391 >        int     (*func)()
392 > )
393   {
394          register LUENT  *lp;
395  
# Line 346 | Line 405 | int    (*func)();
405  
406  
407   char *
408 < getvertid(vname, vp)            /* get/set vertex ID for this point */
409 < char    *vname;
410 < FVECT   vp;
408 > getvertid(              /* get/set vertex ID for this point */
409 >        char    *vname,
410 >        FVECT   vp
411 > )
412   {
413          static char     vkey[VKLEN];
414          register LUENT  *lp;
# Line 390 | Line 450 | memerr:
450  
451  
452   int
453 < o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */
454 < char    *mod, *typ, *id;
455 < FUNARGS *fa;
453 > o_unsupported(          /* mark unsupported primitive */
454 >        char    *mod,
455 >        char    *typ,
456 >        char    *id,
457 >        FUNARGS *fa
458 > )
459   {
460          register int    i;
461  
# Line 417 | Line 480 | FUNARGS        *fa;
480  
481  
482   int
483 < o_face(mod, typ, id, fa)                /* print out a polygon */
484 < char    *mod, *typ, *id;
485 < FUNARGS *fa;
483 > o_face(         /* print out a polygon */
484 >        char    *mod,
485 >        char    *typ,
486 >        char    *id,
487 >        FUNARGS *fa
488 > )
489   {
490          char    entbuf[2048], *linestart;
491          register char   *cp;
492          register int    i;
493  
494 <        if (fa->nfargs < 9 | fa->nfargs % 3)
494 >        if ((fa->nfargs < 9) | (fa->nfargs % 3))
495                  return(-1);
496          setmat(mod);
497          setobj(id);
# Line 448 | Line 514 | FUNARGS        *fa;
514  
515  
516   int
517 < o_cone(mod, typ, id, fa)        /* print out a cone */
518 < char    *mod, *typ, *id;
519 < register FUNARGS        *fa;
517 > o_cone( /* print out a cone */
518 >        char    *mod,
519 >        char    *typ,
520 >        char    *id,
521 >        register FUNARGS        *fa
522 > )
523   {
524          char    v1[6], v2[6];
525  
# Line 471 | Line 540 | register FUNARGS       *fa;
540  
541  
542   int
543 < o_sphere(mod, typ, id, fa)      /* print out a sphere */
544 < char    *mod, *typ, *id;
545 < register FUNARGS        *fa;
543 > o_sphere(       /* print out a sphere */
544 >        char    *mod,
545 >        char    *typ,
546 >        char    *id,
547 >        register FUNARGS        *fa
548 > )
549   {
550          char    cent[6];
551  
# Line 488 | Line 560 | register FUNARGS       *fa;
560  
561  
562   int
563 < o_cylinder(mod, typ, id, fa)    /* print out a cylinder */
564 < char    *mod, *typ, *id;
565 < register FUNARGS        *fa;
563 > o_cylinder(     /* print out a cylinder */
564 >        char    *mod,
565 >        char    *typ,
566 >        char    *id,
567 >        register FUNARGS        *fa
568 > )
569   {
570          char    v1[6], v2[6];
571  
# Line 507 | Line 582 | register FUNARGS       *fa;
582  
583  
584   int
585 < o_ring(mod, typ, id, fa)        /* print out a ring */
586 < char    *mod, *typ, *id;
587 < register FUNARGS        *fa;
585 > o_ring( /* print out a ring */
586 >        char    *mod,
587 >        char    *typ,
588 >        char    *id,
589 >        register FUNARGS        *fa
590 > )
591   {
592          if (fa->nfargs != 8)
593                  return(-1);
# Line 530 | Line 608 | register FUNARGS       *fa;
608  
609  
610   int
611 < o_instance(mod, typ, id, fa)    /* convert an instance */
612 < char    *mod, *typ, *id;
613 < FUNARGS *fa;
611 > o_instance(     /* convert an instance (or mesh) */
612 >        char    *mod,
613 >        char    *typ,
614 >        char    *id,
615 >        FUNARGS *fa
616 > )
617   {
618          register int    i;
619          register char   *cp;
# Line 571 | Line 652 | FUNARGS        *fa;
652  
653  
654   int
655 < o_illum(mod, typ, id, fa)       /* convert an illum material */
656 < char    *mod, *typ, *id;
657 < FUNARGS *fa;
655 > o_illum(        /* convert an illum material */
656 >        char    *mod,
657 >        char    *typ,
658 >        char    *id,
659 >        FUNARGS *fa
660 > )
661   {
662          if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) {
663                  newmat(id, fa->sarg[0]);        /* just create alias */
# Line 587 | Line 671 | FUNARGS        *fa;
671  
672  
673   int
674 < o_plastic(mod, typ, id, fa)     /* convert a plastic material */
675 < char    *mod, *typ, *id;
676 < register FUNARGS        *fa;
674 > o_plastic(      /* convert a plastic material */
675 >        char    *mod,
676 >        char    *typ,
677 >        char    *id,
678 >        register FUNARGS        *fa
679 > )
680   {
681          COLOR   cxyz, rrgb;
682          double  d;
# Line 615 | Line 702 | register FUNARGS       *fa;
702  
703  
704   int
705 < o_metal(mod, typ, id, fa)       /* convert a metal material */
706 < char    *mod, *typ, *id;
707 < register FUNARGS        *fa;
705 > o_metal(        /* convert a metal material */
706 >        char    *mod,
707 >        char    *typ,
708 >        char    *id,
709 >        register FUNARGS        *fa
710 > )
711   {
712          COLOR   cxyz, rrgb;
713          double  d;
# Line 641 | Line 731 | register FUNARGS       *fa;
731  
732  
733   int
734 < o_glass(mod, typ, id, fa)       /* convert a glass material */
735 < char    *mod, *typ, *id;
736 < register FUNARGS        *fa;
734 > o_glass(        /* convert a glass material */
735 >        char    *mod,
736 >        char    *typ,
737 >        char    *id,
738 >        register FUNARGS        *fa
739 > )
740   {
741          COLOR   cxyz, rrgb, trgb;
742          double  nrfr = 1.52, F, d;
# Line 680 | Line 773 | register FUNARGS       *fa;
773  
774  
775   int
776 < o_dielectric(mod, typ, id, fa)  /* convert a dielectric material */
777 < char    *mod, *typ, *id;
778 < register FUNARGS        *fa;
776 > o_dielectric(   /* convert a dielectric material */
777 >        char    *mod,
778 >        char    *typ,
779 >        char    *id,
780 >        register FUNARGS        *fa
781 > )
782   {
783          COLOR   cxyz, trgb;
784          double  F, d;
# Line 710 | Line 806 | register FUNARGS       *fa;
806  
807  
808   int
809 < o_mirror(mod, typ, id, fa)      /* convert a mirror material */
810 < char    *mod, *typ, *id;
811 < register FUNARGS        *fa;
809 > o_mirror(       /* convert a mirror material */
810 >        char    *mod,
811 >        char    *typ,
812 >        char    *id,
813 >        register FUNARGS        *fa
814 > )
815   {
816          COLOR   cxyz, rrgb;
817          double  d;
# Line 736 | Line 835 | register FUNARGS       *fa;
835  
836  
837   int
838 < o_trans(mod, typ, id, fa)       /* convert a trans material */
839 < char    *mod, *typ, *id;
840 < register FUNARGS        *fa;
838 > o_trans(        /* convert a trans material */
839 >        char    *mod,
840 >        char    *typ,
841 >        char    *id,
842 >        register FUNARGS        *fa
843 > )
844   {
845          COLOR   cxyz, rrgb;
846          double  rough, trans, tspec, d;
# Line 775 | Line 877 | register FUNARGS       *fa;
877  
878  
879   int
880 < o_light(mod, typ, id, fa)               /* convert a light type */
881 < char    *mod, *typ, *id;
882 < register FUNARGS        *fa;
880 > o_light(                /* convert a light type */
881 >        char    *mod,
882 >        char    *typ,
883 >        char    *id,
884 >        register FUNARGS        *fa
885 > )
886   {
887          COLOR   cxyz, rrgb;
888          double  d;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines