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.12 by greg, Wed May 10 19:46:05 1995 UTC vs.
Revision 2.23 by schorsch, Sat Nov 15 17:54:06 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 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   * Convert Radiance scene description to MGF
6   */
7  
11 #include <stdio.h>
12 #include <math.h>
8   #include <ctype.h>
9   #include <string.h>
10 < #include "fvect.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 PI      3.14159265358979323846
21
20   #define C_1SIDEDTHICK   0.005
21  
24 int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
25 int     o_instance(), o_illum();
26 int     o_plastic(), o_metal(), o_glass(), o_dielectric(),
27        o_mirror(), o_trans(), o_light();
22  
29 extern void     free();
30 extern char     *malloc();
31
23   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
24  
25   LUTAB   rdispatch = LU_SINIT(NULL,NULL);        /* function dispatch table */
# Line 60 | 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 104 | 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 183 | 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 203 | 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 239 | 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 251 | 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 270 | Line 302 | char   *id;
302                  *cp2++ = 'O';
303          }
304          for (cp = id; cp < end; *cp2++ = *cp++) {
305 <                if (*cp < '!' | *cp > '~')      /* limit to visible chars */
305 >                if ((*cp < '!') | (*cp > '~'))  /* limit to visible chars */
306                          *cp = '?';
307                  diff += *cp != *cp2;
308          }
# Line 282 | 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 295 | Line 328 | init()                 /* initialize dispatch table and output */
328          add2dispatch("tube", o_cylinder);
329          add2dispatch("ring", o_ring);
330          add2dispatch("instance", o_instance);
331 +        add2dispatch("mesh", o_instance);
332          add2dispatch("plastic", o_plastic);
333          add2dispatch("plastic2", o_plastic);
334          add2dispatch("metal", o_metal);
# Line 315 | 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 327 | 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 338 | 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 356 | 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 400 | 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 427 | 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[512];
479 >        char    entbuf[2048], *linestart;
480          register char   *cp;
481          register int    i;
482  
483 <        if (fa->nfargs < 9 | fa->nfargs % 3)
483 >        if ((fa->nfargs < 9) | (fa->nfargs % 3))
484                  return(-1);
485          setmat(mod);
486          setobj(id);
487 <        cp = entbuf;
487 >        cp = linestart = entbuf;
488          *cp++ = 'f';
489          for (i = 0; i < fa->nfargs; i += 3) {
490                  *cp++ = ' ';
491 +                if (cp - linestart > 72) {
492 +                        *cp++ = '\\'; *cp++ = '\n';
493 +                        linestart = cp;
494 +                        *cp++ = ' '; *cp++ = ' ';
495 +                }
496                  getvertid(cp, fa->farg + i);
497                  while (*cp)
498                          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 */
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