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.8 by greg, Mon Dec 12 12:09:28 1994 UTC vs.
Revision 2.19 by greg, Sat Aug 16 15:54:30 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 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  
8 < #include <stdio.h>
8 > #include "standard.h"
9 > #include <ctype.h>
10   #include <string.h>
11 < #include "fvect.h"
11 > #include <stdio.h>
12 >
13 > #include "platform.h"
14   #include "object.h"
15   #include "color.h"
16   #include "lookup.h"
17  
18 < #define PI      3.14159265358979323846
18 > #define C_1SIDEDTHICK   0.005
19  
20   int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
21 < int     o_instance(), o_source(), o_illum();
22 < int     o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light();
21 > int     o_instance(), o_illum();
22 > int     o_plastic(), o_metal(), o_glass(), o_dielectric(),
23 >        o_mirror(), o_trans(), o_light();
24  
24 extern void     free();
25 extern char     *malloc();
26
25   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
26  
27   LUTAB   rdispatch = LU_SINIT(NULL,NULL);        /* function dispatch table */
# Line 39 | Line 37 | double unit_mult = 1.;                         /* units multiplier */
37   * Stuff for tracking and reusing vertices:
38   */
39  
40 < char    VKFMT[] = "%+1.9e %+1.9e %+1.9e";
40 > char    VKFMT[] = "%+16.9e %+16.9e %+16.9e";
41   #define VKLEN           64
42  
43   #define mkvkey(k,v)     sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2])
# Line 190 | Line 188 | FUNARGS        *fa;
188                          fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id);
189                          exit(1);
190                  }
191 <        } else if (lu_find(&rmats, mod)->data != NULL)  /* make alias */
192 <                newmat(id, mod);
191 >        } else {                                        /* unsupported */
192 >                o_unsupported(mod, typ, id, fa);
193 >                if (lu_find(&rmats, mod)->data != NULL) /* make alias */
194 >                        newmat(id, mod);
195 >        }
196   }
197  
198  
# Line 256 | Line 257 | char   *id;
257          if (end == NULL)
258                  end = cp;
259                                  /* copy to current object */
260 <        for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++)
260 >        cp2 = curobj;
261 >        if (!isalpha(*id)) {    /* start with letter */
262 >                diff = *cp2 != 'O';
263 >                *cp2++ = 'O';
264 >        }
265 >        for (cp = id; cp < end; *cp2++ = *cp++) {
266 >                if ((*cp < '!') | (*cp > '~'))  /* limit to visible chars */
267 >                        *cp = '?';
268                  diff += *cp != *cp2;
269 +        }
270          if (!diff && !*cp2)
271                  return;
272          *cp2 = '\0';
# Line 279 | Line 288 | init()                 /* initialize dispatch table and output */
288          add2dispatch("tube", o_cylinder);
289          add2dispatch("ring", o_ring);
290          add2dispatch("instance", o_instance);
291 +        add2dispatch("mesh", o_instance);
292          add2dispatch("plastic", o_plastic);
293          add2dispatch("plastic2", o_plastic);
294          add2dispatch("metal", o_metal);
295          add2dispatch("metal2", o_metal);
296          add2dispatch("glass", o_glass);
297 +        add2dispatch("dielectric", o_dielectric);
298          add2dispatch("trans", o_trans);
299          add2dispatch("trans2", o_trans);
300          add2dispatch("mirror", o_mirror);
# Line 291 | Line 302 | init()                 /* initialize dispatch table and output */
302          add2dispatch("spotlight", o_light);
303          add2dispatch("glow", o_light);
304          add2dispatch("illum", o_illum);
305 <        puts("# The following was converted from Radiance scene input");
305 >        puts("# The following was converted from RADIANCE scene input");
306          if (hasmult)
307                  printf("xf -s %.4e\n", unit_mult);
308          printf("o %s\n", curobj);
# Line 303 | Line 314 | uninit()                       /* mark end of MGF file */
314          puts("o");
315          if (hasmult)
316                  puts("xf");
317 <        puts("# End of data converted from Radiance scene input");
317 >        puts("# End of data converted from RADIANCE scene input");
318          lu_done(&rdispatch);
319          lu_done(&rmats);
320          lu_done(&vertab);
# Line 343 | Line 354 | getvertid(vname, vp)           /* get/set vertex ID for this po
354   char    *vname;
355   FVECT   vp;
356   {
357 <        char    vkey[VKLEN];
357 >        static char     vkey[VKLEN];
358          register LUENT  *lp;
359          register int    i, vndx;
360  
# Line 383 | Line 394 | memerr:
394  
395  
396   int
397 + o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */
398 + char    *mod, *typ, *id;
399 + FUNARGS *fa;
400 + {
401 +        register int    i;
402 +
403 +        fputs("\n# Unsupported RADIANCE primitive:\n", stdout);
404 +        printf("# %s %s %s", mod, typ, id);
405 +        printf("\n# %d", fa->nsargs);
406 +        for (i = 0; i < fa->nsargs; i++)
407 +                printf(" %s", fa->sarg[i]);
408 + #ifdef IARGS
409 +        printf("\n# %d", fa->niargs);
410 +        for (i = 0; i < fa->niargs; i++)
411 +                printf(" %ld", fa->iarg[i]);
412 + #else
413 +        fputs("\n# 0", stdout);
414 + #endif
415 +        printf("\n# %d", fa->nfargs);
416 +        for (i = 0; i < fa->nfargs; i++)
417 +                printf(" %g", fa->farg[i]);
418 +        fputs("\n\n", stdout);
419 +        return(0);
420 + }
421 +
422 +
423 + int
424   o_face(mod, typ, id, fa)                /* print out a polygon */
425   char    *mod, *typ, *id;
426   FUNARGS *fa;
427   {
428 <        char    entbuf[512];
428 >        char    entbuf[2048], *linestart;
429          register char   *cp;
430          register int    i;
431  
432 <        if (fa->nfargs < 9 | fa->nfargs % 3)
432 >        if ((fa->nfargs < 9) | (fa->nfargs % 3))
433                  return(-1);
434          setmat(mod);
435          setobj(id);
436 <        cp = entbuf;
436 >        cp = linestart = entbuf;
437          *cp++ = 'f';
438          for (i = 0; i < fa->nfargs; i += 3) {
439                  *cp++ = ' ';
440 +                if (cp - linestart > 72) {
441 +                        *cp++ = '\\'; *cp++ = '\n';
442 +                        linestart = cp;
443 +                        *cp++ = ' '; *cp++ = ' ';
444 +                }
445                  getvertid(cp, fa->farg + i);
446                  while (*cp)
447                          cp++;
# Line 491 | Line 534 | register FUNARGS       *fa;
534  
535  
536   int
537 < o_instance(mod, typ, id, fa)    /* convert an instance */
537 > o_instance(mod, typ, id, fa)    /* convert an instance (or mesh) */
538   char    *mod, *typ, *id;
539   FUNARGS *fa;
540   {
# Line 532 | Line 575 | FUNARGS        *fa;
575  
576  
577   int
535 o_source(mod, typ, id, fa)      /* convert a source */
536 char    *mod, *typ, *id;
537 FUNARGS *fa;
538 {
539        return(0);              /* there is no MGF equivalent! */
540 }
541
542
543 int
578   o_illum(mod, typ, id, fa)       /* convert an illum material */
579   char    *mod, *typ, *id;
580   FUNARGS *fa;
# Line 624 | Line 658 | register FUNARGS       *fa;
658          newmat(id, NULL);
659          if (fa->nfargs == 4)
660                  nrfr = fa->farg[3];
661 +        printf("\tir %f 0\n", nrfr);
662          F = (1. - nrfr)/(1. + nrfr);            /* use normal incidence */
663          F *= F;
664          for (i = 0; i < 3; i++) {
# Line 638 | Line 673 | register FUNARGS       *fa;
673          if (d > FTINY)
674                  printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
675          printf("\trs %.4f 0\n", cxyz[1]);
676 +        rgb_cie(cxyz, trgb);                    /* put transmitted component */
677 +        puts("\tc");
678 +        d = cxyz[0] + cxyz[1] + cxyz[2];
679 +        if (d > FTINY)
680 +                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
681 +        printf("\tts %.4f 0\n", cxyz[1]);
682 +        return(0);
683 + }
684 +
685 +
686 + int
687 + o_dielectric(mod, typ, id, fa)  /* convert a dielectric material */
688 + char    *mod, *typ, *id;
689 + register FUNARGS        *fa;
690 + {
691 +        COLOR   cxyz, trgb;
692 +        double  F, d;
693 +        register int    i;
694 +
695 +        if (fa->nfargs != 5)
696 +                return(-1);
697 +        newmat(id, NULL);
698 +        F = (1. - fa->farg[3])/(1. + fa->farg[3]);      /* normal incidence */
699 +        F *= F;
700 +        for (i = 0; i < 3; i++)
701 +                trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult);
702 +        printf("\tir %f 0\n", fa->farg[3]);     /* put index of refraction */
703 +        printf("\tsides 1\n");
704 +        puts("\tc");                            /* put reflected component */
705 +        printf("\trs %.4f 0\n", F);
706          rgb_cie(cxyz, trgb);                    /* put transmitted component */
707          puts("\tc");
708          d = cxyz[0] + cxyz[1] + cxyz[2];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines