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.17 by schorsch, Sun Jun 8 12:03:09 2003 UTC vs.
Revision 2.25 by greg, Wed Dec 28 18:39:07 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  
20 int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
21 int     o_instance(), o_illum();
22 int     o_plastic(), o_metal(), o_glass(), o_dielectric(),
23        o_mirror(), o_trans(), o_light();
22  
23   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
24  
# Line 53 | 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 97 | 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
133 < #define typ     (buf+128)
105 < #define id      (buf+256)
106 < #define alias   (buf+384)
107 <        char    buf[512];
132 >        char  buf[512];
133 >        char  mod[128], typ[32], id[128], alias[128];
134          FUNARGS fa;
135          register FILE   *fp;
136          register int    c;
# Line 143 | Line 169 | char   *inp;
169                          break;
170                  default:                /* Radiance primitive */
171                          ungetc(c, fp);
172 <                        if (fscanf(fp, "%s %s %s", mod, typ, id) != 3) {
172 >                        if (fgetword(mod, sizeof(mod), fp) == NULL ||
173 >                                        fgetword(typ, sizeof(typ), fp) == NULL ||
174 >                                        fgetword(id, sizeof(id), fp) == NULL) {
175                                  fputs(inp, stderr);
176                                  fputs(": unexpected EOF\n", stderr);
177                                  exit(1);
178                          }
179 +                        unspace(mod);
180 +                        unspace(id);
181                          if (!strcmp(typ, "alias")) {
182                                  strcpy(alias, "EOF");
183 <                                fscanf(fp, "%s", alias);
183 >                                fgetword(alias, sizeof(alias), fp);
184 >                                unspace(alias);
185                                  newmat(id, alias);
186                          } else {
187                                  if (!readfargs(&fa, fp)) {
# Line 169 | Line 200 | char   *inp;
200                  pclose(fp);
201          else
202                  fclose(fp);
172 #undef mod
173 #undef typ
174 #undef id
175 #undef alias
203   }
204  
205  
206 < cvtprim(inp, mod, typ, id, fa)  /* process Radiance primitive */
207 < char    *inp, *mod, *typ, *id;
208 < FUNARGS *fa;
206 > void
207 > unspace(        /* replace spaces with underscores in s */
208 >        char *s
209 > )
210   {
211 +        while (*s) {
212 +                if (isspace(*s))
213 +                        *s = '_';
214 +                ++s;
215 +        }
216 + }
217 +
218 +
219 + void
220 + cvtprim(        /* process Radiance primitive */
221 +        char    *inp,
222 +        char    *mod,
223 +        char    *typ,
224 +        char    *id,
225 +        FUNARGS *fa
226 + )
227 + {
228          int     (*df)();
229  
230          df = (int (*)())lu_find(&rdispatch, typ)->data;
231          if (df != NULL) {                               /* convert */
232                  if ((*df)(mod, typ, id, fa) < 0) {
233 <                        fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id);
233 >                        fprintf(stderr, "%s: bad %s \"%s\"\n", "rad2mgf", typ, id);
234                          exit(1);
235                  }
236          } else {                                        /* unsupported */
# Line 196 | Line 241 | FUNARGS        *fa;
241   }
242  
243  
244 < newmat(id, alias)               /* add a modifier to the alias list */
245 < char    *id;
246 < char    *alias;
244 > void
245 > newmat(         /* add a modifier to the alias list */
246 >        char    *id,
247 >        char    *alias
248 > )
249   {
250          register LUENT  *lp, *lpa;
251  
# Line 232 | Line 279 | memerr:
279   }
280  
281  
282 < setmat(id)                      /* set material to this one */
283 < char    *id;
282 > void
283 > setmat(                 /* set material to this one */
284 >        char    *id
285 > )
286   {
287          if (!strcmp(id, curmat))        /* already set? */
288                  return;
# Line 244 | Line 293 | char   *id;
293   }
294  
295  
296 < setobj(id)                      /* set object name to this one */
297 < char    *id;
296 > void
297 > setobj(                 /* set object name to this one */
298 >        char    *id
299 > )
300   {
301          register char   *cp, *cp2;
302          char    *end = NULL;
# Line 263 | Line 314 | char   *id;
314                  *cp2++ = 'O';
315          }
316          for (cp = id; cp < end; *cp2++ = *cp++) {
317 <                if (*cp < '!' | *cp > '~')      /* limit to visible chars */
317 >                if ((*cp < '!') | (*cp > '~'))  /* limit to visible chars */
318                          *cp = '?';
319                  diff += *cp != *cp2;
320          }
# Line 275 | Line 326 | char   *id;
326   }
327  
328  
329 < init()                  /* initialize dispatch table and output */
329 > void
330 > init(void)                      /* initialize dispatch table and output */
331   {
332          lu_init(&vertab, NVERTS);
333          lu_init(&rdispatch, 22);
# Line 288 | Line 340 | init()                 /* initialize dispatch table and output */
340          add2dispatch("tube", o_cylinder);
341          add2dispatch("ring", o_ring);
342          add2dispatch("instance", o_instance);
343 +        add2dispatch("mesh", o_instance);
344          add2dispatch("plastic", o_plastic);
345          add2dispatch("plastic2", o_plastic);
346          add2dispatch("metal", o_metal);
# Line 308 | Line 361 | init()                 /* initialize dispatch table and output */
361   }
362  
363  
364 < uninit()                        /* mark end of MGF file */
364 > void
365 > uninit(void)                    /* mark end of MGF file */
366   {
367          puts("o");
368          if (hasmult)
# Line 320 | Line 374 | uninit()                       /* mark end of MGF file */
374   }
375  
376  
377 < clrverts()                      /* clear vertex table */
377 > void
378 > clrverts(void)                  /* clear vertex table */
379   {
380          register int    i;
381  
# Line 331 | Line 386 | clrverts()                     /* clear vertex table */
386   }
387  
388  
389 < add2dispatch(name, func)        /* add function to dispatch table */
390 < char    *name;
391 < int     (*func)();
389 > void
390 > add2dispatch(   /* add function to dispatch table */
391 >        char    *name,
392 >        int     (*func)()
393 > )
394   {
395          register LUENT  *lp;
396  
# Line 349 | Line 406 | int    (*func)();
406  
407  
408   char *
409 < getvertid(vname, vp)            /* get/set vertex ID for this point */
410 < char    *vname;
411 < FVECT   vp;
409 > getvertid(              /* get/set vertex ID for this point */
410 >        char    *vname,
411 >        FVECT   vp
412 > )
413   {
414          static char     vkey[VKLEN];
415          register LUENT  *lp;
# Line 393 | Line 451 | memerr:
451  
452  
453   int
454 < o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */
455 < char    *mod, *typ, *id;
456 < FUNARGS *fa;
454 > o_unsupported(          /* mark unsupported primitive */
455 >        char    *mod,
456 >        char    *typ,
457 >        char    *id,
458 >        FUNARGS *fa
459 > )
460   {
461          register int    i;
462  
# Line 420 | Line 481 | FUNARGS        *fa;
481  
482  
483   int
484 < o_face(mod, typ, id, fa)                /* print out a polygon */
485 < char    *mod, *typ, *id;
486 < FUNARGS *fa;
484 > o_face(         /* print out a polygon */
485 >        char    *mod,
486 >        char    *typ,
487 >        char    *id,
488 >        FUNARGS *fa
489 > )
490   {
491          char    entbuf[2048], *linestart;
492          register char   *cp;
493          register int    i;
494  
495 <        if (fa->nfargs < 9 | fa->nfargs % 3)
495 >        if ((fa->nfargs < 9) | (fa->nfargs % 3))
496                  return(-1);
497          setmat(mod);
498          setobj(id);
# Line 451 | Line 515 | FUNARGS        *fa;
515  
516  
517   int
518 < o_cone(mod, typ, id, fa)        /* print out a cone */
519 < char    *mod, *typ, *id;
520 < register FUNARGS        *fa;
518 > o_cone( /* print out a cone */
519 >        char    *mod,
520 >        char    *typ,
521 >        char    *id,
522 >        register FUNARGS        *fa
523 > )
524   {
525          char    v1[6], v2[6];
526  
# Line 474 | Line 541 | register FUNARGS       *fa;
541  
542  
543   int
544 < o_sphere(mod, typ, id, fa)      /* print out a sphere */
545 < char    *mod, *typ, *id;
546 < register FUNARGS        *fa;
544 > o_sphere(       /* print out a sphere */
545 >        char    *mod,
546 >        char    *typ,
547 >        char    *id,
548 >        register FUNARGS        *fa
549 > )
550   {
551          char    cent[6];
552  
# Line 491 | Line 561 | register FUNARGS       *fa;
561  
562  
563   int
564 < o_cylinder(mod, typ, id, fa)    /* print out a cylinder */
565 < char    *mod, *typ, *id;
566 < register FUNARGS        *fa;
564 > o_cylinder(     /* print out a cylinder */
565 >        char    *mod,
566 >        char    *typ,
567 >        char    *id,
568 >        register FUNARGS        *fa
569 > )
570   {
571          char    v1[6], v2[6];
572  
# Line 510 | Line 583 | register FUNARGS       *fa;
583  
584  
585   int
586 < o_ring(mod, typ, id, fa)        /* print out a ring */
587 < char    *mod, *typ, *id;
588 < register FUNARGS        *fa;
586 > o_ring( /* print out a ring */
587 >        char    *mod,
588 >        char    *typ,
589 >        char    *id,
590 >        register FUNARGS        *fa
591 > )
592   {
593          if (fa->nfargs != 8)
594                  return(-1);
# Line 533 | Line 609 | register FUNARGS       *fa;
609  
610  
611   int
612 < o_instance(mod, typ, id, fa)    /* convert an instance */
613 < char    *mod, *typ, *id;
614 < FUNARGS *fa;
612 > o_instance(     /* convert an instance (or mesh) */
613 >        char    *mod,
614 >        char    *typ,
615 >        char    *id,
616 >        FUNARGS *fa
617 > )
618   {
619          register int    i;
620          register char   *cp;
# Line 574 | Line 653 | FUNARGS        *fa;
653  
654  
655   int
656 < o_illum(mod, typ, id, fa)       /* convert an illum material */
657 < char    *mod, *typ, *id;
658 < FUNARGS *fa;
656 > o_illum(        /* convert an illum material */
657 >        char    *mod,
658 >        char    *typ,
659 >        char    *id,
660 >        FUNARGS *fa
661 > )
662   {
663          if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) {
664                  newmat(id, fa->sarg[0]);        /* just create alias */
# Line 590 | Line 672 | FUNARGS        *fa;
672  
673  
674   int
675 < o_plastic(mod, typ, id, fa)     /* convert a plastic material */
676 < char    *mod, *typ, *id;
677 < register FUNARGS        *fa;
675 > o_plastic(      /* convert a plastic material */
676 >        char    *mod,
677 >        char    *typ,
678 >        char    *id,
679 >        register FUNARGS        *fa
680 > )
681   {
682          COLOR   cxyz, rrgb;
683          double  d;
# Line 618 | Line 703 | register FUNARGS       *fa;
703  
704  
705   int
706 < o_metal(mod, typ, id, fa)       /* convert a metal material */
707 < char    *mod, *typ, *id;
708 < register FUNARGS        *fa;
706 > o_metal(        /* convert a metal material */
707 >        char    *mod,
708 >        char    *typ,
709 >        char    *id,
710 >        register FUNARGS        *fa
711 > )
712   {
713          COLOR   cxyz, rrgb;
714          double  d;
# Line 644 | Line 732 | register FUNARGS       *fa;
732  
733  
734   int
735 < o_glass(mod, typ, id, fa)       /* convert a glass material */
736 < char    *mod, *typ, *id;
737 < register FUNARGS        *fa;
735 > o_glass(        /* convert a glass material */
736 >        char    *mod,
737 >        char    *typ,
738 >        char    *id,
739 >        register FUNARGS        *fa
740 > )
741   {
742          COLOR   cxyz, rrgb, trgb;
743          double  nrfr = 1.52, F, d;
# Line 683 | Line 774 | register FUNARGS       *fa;
774  
775  
776   int
777 < o_dielectric(mod, typ, id, fa)  /* convert a dielectric material */
778 < char    *mod, *typ, *id;
779 < register FUNARGS        *fa;
777 > o_dielectric(   /* convert a dielectric material */
778 >        char    *mod,
779 >        char    *typ,
780 >        char    *id,
781 >        register FUNARGS        *fa
782 > )
783   {
784          COLOR   cxyz, trgb;
785          double  F, d;
# Line 713 | Line 807 | register FUNARGS       *fa;
807  
808  
809   int
810 < o_mirror(mod, typ, id, fa)      /* convert a mirror material */
811 < char    *mod, *typ, *id;
812 < register FUNARGS        *fa;
810 > o_mirror(       /* convert a mirror material */
811 >        char    *mod,
812 >        char    *typ,
813 >        char    *id,
814 >        register FUNARGS        *fa
815 > )
816   {
817          COLOR   cxyz, rrgb;
818          double  d;
# Line 739 | Line 836 | register FUNARGS       *fa;
836  
837  
838   int
839 < o_trans(mod, typ, id, fa)       /* convert a trans material */
840 < char    *mod, *typ, *id;
841 < register FUNARGS        *fa;
839 > o_trans(        /* convert a trans material */
840 >        char    *mod,
841 >        char    *typ,
842 >        char    *id,
843 >        register FUNARGS        *fa
844 > )
845   {
846          COLOR   cxyz, rrgb;
847          double  rough, trans, tspec, d;
# Line 778 | Line 878 | register FUNARGS       *fa;
878  
879  
880   int
881 < o_light(mod, typ, id, fa)               /* convert a light type */
882 < char    *mod, *typ, *id;
883 < register FUNARGS        *fa;
881 > o_light(                /* convert a light type */
882 >        char    *mod,
883 >        char    *typ,
884 >        char    *id,
885 >        register FUNARGS        *fa
886 > )
887   {
888          COLOR   cxyz, rrgb;
889          double  d;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines