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.21 by schorsch, Mon Oct 27 10:26:45 2003 UTC vs.
Revision 2.23 by schorsch, Sat Nov 15 17:54:06 2003 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   * Convert Radiance scene description to MGF
6   */
7  
8 #include "platform.h"
9 #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"
# Line 18 | Line 19 | static const char      RCSid[] = "$Id$";
19  
20   #define C_1SIDEDTHICK   0.005
21  
21 int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
22 int     o_instance(), o_illum();
23 int     o_plastic(), o_metal(), o_glass(), o_dielectric(),
24        o_mirror(), o_trans(), o_light();
22  
23   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
24  
# Line 54 | Line 51 | struct vert {
51  
52   LUTAB   vertab = LU_SINIT(free,NULL);   /* our vertex lookup table */
53  
54 + static void rad2mgf(char *inp);
55 + static void cvtprim(char *inp, char *mod, char *typ, char *id, FUNARGS *fa);
56 + static void newmat(char *id, char *alias);
57 + static void setmat(char *id);
58 + static void setobj(char *id);
59 + static void init(void);
60 + static void uninit(void);
61 + static void clrverts(void);
62 + static void add2dispatch(char *name, int (*func)());
63 + static char *getvertid(char *vname, FVECT vp);
64 + static int o_unsupported(char *mod, char *typ, char *id, FUNARGS *fa);
65 + static int o_face(char *mod, char *typ, char *id, FUNARGS *fa);
66 + static int o_cone(char *mod, char *typ, char *id, FUNARGS *fa);
67 + static int o_sphere(char *mod, char *typ, char *id, FUNARGS *fa);
68 + static int o_cylinder(char *mod, char *typ, char *id, FUNARGS *fa);
69 + static int o_ring(char *mod, char *typ, char *id, FUNARGS *fa);
70 + static int o_instance(char *mod, char *typ, char *id, FUNARGS *fa);
71 + static int o_illum(char *mod, char *typ, char *id, FUNARGS *fa);
72 + static int o_plastic(char *mod, char *typ, char *id, FUNARGS *fa);
73 + static int o_metal(char *mod, char *typ, char *id, FUNARGS *fa);
74 + static int o_glass(char *mod, char *typ, char *id, FUNARGS *fa);
75 + static int o_dielectric(char *mod, char *typ, char *id, FUNARGS *fa);
76 + static int o_mirror(char *mod, char *typ, char *id, FUNARGS *fa);
77 + static int o_trans(char *mod, char *typ, char *id, FUNARGS *fa);
78 + static int o_light(char *mod, char *typ, char *id, FUNARGS *fa);
79  
80 < main(argc, argv)
81 < int     argc;
82 < char    **argv;
80 >
81 > int
82 > main(
83 >        int     argc,
84 >        char    **argv
85 > )
86   {
87          int     i;
88  
# Line 98 | Line 123 | unkopt:
123   }
124  
125  
126 < rad2mgf(inp)            /* convert a Radiance file to MGF */
127 < char    *inp;
126 > void
127 > rad2mgf(                /* convert a Radiance file to MGF */
128 >        char    *inp
129 > )
130   {
131   #define mod     buf
132   #define typ     (buf+128)
# Line 177 | Line 204 | char   *inp;
204   }
205  
206  
207 < cvtprim(inp, mod, typ, id, fa)  /* process Radiance primitive */
208 < char    *inp, *mod, *typ, *id;
209 < FUNARGS *fa;
207 > void
208 > cvtprim(        /* process Radiance primitive */
209 >        char    *inp,
210 >        char    *mod,
211 >        char    *typ,
212 >        char    *id,
213 >        FUNARGS *fa
214 > )
215   {
216          int     (*df)();
217  
218          df = (int (*)())lu_find(&rdispatch, typ)->data;
219          if (df != NULL) {                               /* convert */
220                  if ((*df)(mod, typ, id, fa) < 0) {
221 <                        fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id);
221 >                        fprintf(stderr, "%s: bad %s \"%s\"\n", "rat2mgf", typ, id);
222                          exit(1);
223                  }
224          } else {                                        /* unsupported */
# Line 197 | Line 229 | FUNARGS        *fa;
229   }
230  
231  
232 < newmat(id, alias)               /* add a modifier to the alias list */
233 < char    *id;
234 < char    *alias;
232 > void
233 > newmat(         /* add a modifier to the alias list */
234 >        char    *id,
235 >        char    *alias
236 > )
237   {
238          register LUENT  *lp, *lpa;
239  
# Line 233 | Line 267 | memerr:
267   }
268  
269  
270 < setmat(id)                      /* set material to this one */
271 < char    *id;
270 > void
271 > setmat(                 /* set material to this one */
272 >        char    *id
273 > )
274   {
275          if (!strcmp(id, curmat))        /* already set? */
276                  return;
# Line 245 | Line 281 | char   *id;
281   }
282  
283  
284 < setobj(id)                      /* set object name to this one */
285 < char    *id;
284 > void
285 > setobj(                 /* set object name to this one */
286 >        char    *id
287 > )
288   {
289          register char   *cp, *cp2;
290          char    *end = NULL;
# Line 276 | Line 314 | char   *id;
314   }
315  
316  
317 < init()                  /* initialize dispatch table and output */
317 > void
318 > init(void)                      /* initialize dispatch table and output */
319   {
320          lu_init(&vertab, NVERTS);
321          lu_init(&rdispatch, 22);
# Line 310 | Line 349 | init()                 /* initialize dispatch table and output */
349   }
350  
351  
352 < uninit()                        /* mark end of MGF file */
352 > void
353 > uninit(void)                    /* mark end of MGF file */
354   {
355          puts("o");
356          if (hasmult)
# Line 322 | Line 362 | uninit()                       /* mark end of MGF file */
362   }
363  
364  
365 < clrverts()                      /* clear vertex table */
365 > void
366 > clrverts(void)                  /* clear vertex table */
367   {
368          register int    i;
369  
# Line 333 | Line 374 | clrverts()                     /* clear vertex table */
374   }
375  
376  
377 < add2dispatch(name, func)        /* add function to dispatch table */
378 < char    *name;
379 < int     (*func)();
377 > void
378 > add2dispatch(   /* add function to dispatch table */
379 >        char    *name,
380 >        int     (*func)()
381 > )
382   {
383          register LUENT  *lp;
384  
# Line 351 | Line 394 | int    (*func)();
394  
395  
396   char *
397 < getvertid(vname, vp)            /* get/set vertex ID for this point */
398 < char    *vname;
399 < FVECT   vp;
397 > getvertid(              /* get/set vertex ID for this point */
398 >        char    *vname,
399 >        FVECT   vp
400 > )
401   {
402          static char     vkey[VKLEN];
403          register LUENT  *lp;
# Line 395 | Line 439 | memerr:
439  
440  
441   int
442 < o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */
443 < char    *mod, *typ, *id;
444 < FUNARGS *fa;
442 > o_unsupported(          /* mark unsupported primitive */
443 >        char    *mod,
444 >        char    *typ,
445 >        char    *id,
446 >        FUNARGS *fa
447 > )
448   {
449          register int    i;
450  
# Line 422 | Line 469 | FUNARGS        *fa;
469  
470  
471   int
472 < o_face(mod, typ, id, fa)                /* print out a polygon */
473 < char    *mod, *typ, *id;
474 < FUNARGS *fa;
472 > o_face(         /* print out a polygon */
473 >        char    *mod,
474 >        char    *typ,
475 >        char    *id,
476 >        FUNARGS *fa
477 > )
478   {
479          char    entbuf[2048], *linestart;
480          register char   *cp;
# Line 453 | Line 503 | FUNARGS        *fa;
503  
504  
505   int
506 < o_cone(mod, typ, id, fa)        /* print out a cone */
507 < char    *mod, *typ, *id;
508 < register FUNARGS        *fa;
506 > o_cone( /* print out a cone */
507 >        char    *mod,
508 >        char    *typ,
509 >        char    *id,
510 >        register FUNARGS        *fa
511 > )
512   {
513          char    v1[6], v2[6];
514  
# Line 476 | Line 529 | register FUNARGS       *fa;
529  
530  
531   int
532 < o_sphere(mod, typ, id, fa)      /* print out a sphere */
533 < char    *mod, *typ, *id;
534 < register FUNARGS        *fa;
532 > o_sphere(       /* print out a sphere */
533 >        char    *mod,
534 >        char    *typ,
535 >        char    *id,
536 >        register FUNARGS        *fa
537 > )
538   {
539          char    cent[6];
540  
# Line 493 | Line 549 | register FUNARGS       *fa;
549  
550  
551   int
552 < o_cylinder(mod, typ, id, fa)    /* print out a cylinder */
553 < char    *mod, *typ, *id;
554 < register FUNARGS        *fa;
552 > o_cylinder(     /* print out a cylinder */
553 >        char    *mod,
554 >        char    *typ,
555 >        char    *id,
556 >        register FUNARGS        *fa
557 > )
558   {
559          char    v1[6], v2[6];
560  
# Line 512 | Line 571 | register FUNARGS       *fa;
571  
572  
573   int
574 < o_ring(mod, typ, id, fa)        /* print out a ring */
575 < char    *mod, *typ, *id;
576 < register FUNARGS        *fa;
574 > o_ring( /* print out a ring */
575 >        char    *mod,
576 >        char    *typ,
577 >        char    *id,
578 >        register FUNARGS        *fa
579 > )
580   {
581          if (fa->nfargs != 8)
582                  return(-1);
# Line 535 | Line 597 | register FUNARGS       *fa;
597  
598  
599   int
600 < o_instance(mod, typ, id, fa)    /* convert an instance (or mesh) */
601 < char    *mod, *typ, *id;
602 < FUNARGS *fa;
600 > o_instance(     /* convert an instance (or mesh) */
601 >        char    *mod,
602 >        char    *typ,
603 >        char    *id,
604 >        FUNARGS *fa
605 > )
606   {
607          register int    i;
608          register char   *cp;
# Line 576 | Line 641 | FUNARGS        *fa;
641  
642  
643   int
644 < o_illum(mod, typ, id, fa)       /* convert an illum material */
645 < char    *mod, *typ, *id;
646 < FUNARGS *fa;
644 > o_illum(        /* convert an illum material */
645 >        char    *mod,
646 >        char    *typ,
647 >        char    *id,
648 >        FUNARGS *fa
649 > )
650   {
651          if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) {
652                  newmat(id, fa->sarg[0]);        /* just create alias */
# Line 592 | Line 660 | FUNARGS        *fa;
660  
661  
662   int
663 < o_plastic(mod, typ, id, fa)     /* convert a plastic material */
664 < char    *mod, *typ, *id;
665 < register FUNARGS        *fa;
663 > o_plastic(      /* convert a plastic material */
664 >        char    *mod,
665 >        char    *typ,
666 >        char    *id,
667 >        register FUNARGS        *fa
668 > )
669   {
670          COLOR   cxyz, rrgb;
671          double  d;
# Line 620 | Line 691 | register FUNARGS       *fa;
691  
692  
693   int
694 < o_metal(mod, typ, id, fa)       /* convert a metal material */
695 < char    *mod, *typ, *id;
696 < register FUNARGS        *fa;
694 > o_metal(        /* convert a metal material */
695 >        char    *mod,
696 >        char    *typ,
697 >        char    *id,
698 >        register FUNARGS        *fa
699 > )
700   {
701          COLOR   cxyz, rrgb;
702          double  d;
# Line 646 | Line 720 | register FUNARGS       *fa;
720  
721  
722   int
723 < o_glass(mod, typ, id, fa)       /* convert a glass material */
724 < char    *mod, *typ, *id;
725 < register FUNARGS        *fa;
723 > o_glass(        /* convert a glass material */
724 >        char    *mod,
725 >        char    *typ,
726 >        char    *id,
727 >        register FUNARGS        *fa
728 > )
729   {
730          COLOR   cxyz, rrgb, trgb;
731          double  nrfr = 1.52, F, d;
# Line 685 | Line 762 | register FUNARGS       *fa;
762  
763  
764   int
765 < o_dielectric(mod, typ, id, fa)  /* convert a dielectric material */
766 < char    *mod, *typ, *id;
767 < register FUNARGS        *fa;
765 > o_dielectric(   /* convert a dielectric material */
766 >        char    *mod,
767 >        char    *typ,
768 >        char    *id,
769 >        register FUNARGS        *fa
770 > )
771   {
772          COLOR   cxyz, trgb;
773          double  F, d;
# Line 715 | Line 795 | register FUNARGS       *fa;
795  
796  
797   int
798 < o_mirror(mod, typ, id, fa)      /* convert a mirror material */
799 < char    *mod, *typ, *id;
800 < register FUNARGS        *fa;
798 > o_mirror(       /* convert a mirror material */
799 >        char    *mod,
800 >        char    *typ,
801 >        char    *id,
802 >        register FUNARGS        *fa
803 > )
804   {
805          COLOR   cxyz, rrgb;
806          double  d;
# Line 741 | Line 824 | register FUNARGS       *fa;
824  
825  
826   int
827 < o_trans(mod, typ, id, fa)       /* convert a trans material */
828 < char    *mod, *typ, *id;
829 < register FUNARGS        *fa;
827 > o_trans(        /* convert a trans material */
828 >        char    *mod,
829 >        char    *typ,
830 >        char    *id,
831 >        register FUNARGS        *fa
832 > )
833   {
834          COLOR   cxyz, rrgb;
835          double  rough, trans, tspec, d;
# Line 780 | Line 866 | register FUNARGS       *fa;
866  
867  
868   int
869 < o_light(mod, typ, id, fa)               /* convert a light type */
870 < char    *mod, *typ, *id;
871 < register FUNARGS        *fa;
869 > o_light(                /* convert a light type */
870 >        char    *mod,
871 >        char    *typ,
872 >        char    *id,
873 >        register FUNARGS        *fa
874 > )
875   {
876          COLOR   cxyz, rrgb;
877          double  d;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines