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.18 by schorsch, Sun Jul 27 22:12:02 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 284 | Line 293 | init()                 /* initialize dispatch table and output */
293          add2dispatch("metal", o_metal);
294          add2dispatch("metal2", o_metal);
295          add2dispatch("glass", o_glass);
296 +        add2dispatch("dielectric", o_dielectric);
297          add2dispatch("trans", o_trans);
298          add2dispatch("trans2", o_trans);
299          add2dispatch("mirror", o_mirror);
# Line 291 | Line 301 | init()                 /* initialize dispatch table and output */
301          add2dispatch("spotlight", o_light);
302          add2dispatch("glow", o_light);
303          add2dispatch("illum", o_illum);
304 <        puts("# The following was converted from Radiance scene input");
304 >        puts("# The following was converted from RADIANCE scene input");
305          if (hasmult)
306                  printf("xf -s %.4e\n", unit_mult);
307          printf("o %s\n", curobj);
# Line 303 | Line 313 | uninit()                       /* mark end of MGF file */
313          puts("o");
314          if (hasmult)
315                  puts("xf");
316 <        puts("# End of data converted from Radiance scene input");
316 >        puts("# End of data converted from RADIANCE scene input");
317          lu_done(&rdispatch);
318          lu_done(&rmats);
319          lu_done(&vertab);
# Line 343 | Line 353 | getvertid(vname, vp)           /* get/set vertex ID for this po
353   char    *vname;
354   FVECT   vp;
355   {
356 <        char    vkey[VKLEN];
356 >        static char     vkey[VKLEN];
357          register LUENT  *lp;
358          register int    i, vndx;
359  
# Line 383 | Line 393 | memerr:
393  
394  
395   int
396 + o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */
397 + char    *mod, *typ, *id;
398 + FUNARGS *fa;
399 + {
400 +        register int    i;
401 +
402 +        fputs("\n# Unsupported RADIANCE primitive:\n", stdout);
403 +        printf("# %s %s %s", mod, typ, id);
404 +        printf("\n# %d", fa->nsargs);
405 +        for (i = 0; i < fa->nsargs; i++)
406 +                printf(" %s", fa->sarg[i]);
407 + #ifdef IARGS
408 +        printf("\n# %d", fa->niargs);
409 +        for (i = 0; i < fa->niargs; i++)
410 +                printf(" %ld", fa->iarg[i]);
411 + #else
412 +        fputs("\n# 0", stdout);
413 + #endif
414 +        printf("\n# %d", fa->nfargs);
415 +        for (i = 0; i < fa->nfargs; i++)
416 +                printf(" %g", fa->farg[i]);
417 +        fputs("\n\n", stdout);
418 +        return(0);
419 + }
420 +
421 +
422 + int
423   o_face(mod, typ, id, fa)                /* print out a polygon */
424   char    *mod, *typ, *id;
425   FUNARGS *fa;
426   {
427 <        char    entbuf[512];
427 >        char    entbuf[2048], *linestart;
428          register char   *cp;
429          register int    i;
430  
431 <        if (fa->nfargs < 9 | fa->nfargs % 3)
431 >        if ((fa->nfargs < 9) | (fa->nfargs % 3))
432                  return(-1);
433          setmat(mod);
434          setobj(id);
435 <        cp = entbuf;
435 >        cp = linestart = entbuf;
436          *cp++ = 'f';
437          for (i = 0; i < fa->nfargs; i += 3) {
438                  *cp++ = ' ';
439 +                if (cp - linestart > 72) {
440 +                        *cp++ = '\\'; *cp++ = '\n';
441 +                        linestart = cp;
442 +                        *cp++ = ' '; *cp++ = ' ';
443 +                }
444                  getvertid(cp, fa->farg + i);
445                  while (*cp)
446                          cp++;
# Line 532 | Line 574 | FUNARGS        *fa;
574  
575  
576   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
577   o_illum(mod, typ, id, fa)       /* convert an illum material */
578   char    *mod, *typ, *id;
579   FUNARGS *fa;
# Line 624 | Line 657 | register FUNARGS       *fa;
657          newmat(id, NULL);
658          if (fa->nfargs == 4)
659                  nrfr = fa->farg[3];
660 +        printf("\tir %f 0\n", nrfr);
661          F = (1. - nrfr)/(1. + nrfr);            /* use normal incidence */
662          F *= F;
663          for (i = 0; i < 3; i++) {
# Line 638 | Line 672 | register FUNARGS       *fa;
672          if (d > FTINY)
673                  printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
674          printf("\trs %.4f 0\n", cxyz[1]);
675 +        rgb_cie(cxyz, trgb);                    /* put transmitted component */
676 +        puts("\tc");
677 +        d = cxyz[0] + cxyz[1] + cxyz[2];
678 +        if (d > FTINY)
679 +                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
680 +        printf("\tts %.4f 0\n", cxyz[1]);
681 +        return(0);
682 + }
683 +
684 +
685 + int
686 + o_dielectric(mod, typ, id, fa)  /* convert a dielectric material */
687 + char    *mod, *typ, *id;
688 + register FUNARGS        *fa;
689 + {
690 +        COLOR   cxyz, trgb;
691 +        double  F, d;
692 +        register int    i;
693 +
694 +        if (fa->nfargs != 5)
695 +                return(-1);
696 +        newmat(id, NULL);
697 +        F = (1. - fa->farg[3])/(1. + fa->farg[3]);      /* normal incidence */
698 +        F *= F;
699 +        for (i = 0; i < 3; i++)
700 +                trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult);
701 +        printf("\tir %f 0\n", fa->farg[3]);     /* put index of refraction */
702 +        printf("\tsides 1\n");
703 +        puts("\tc");                            /* put reflected component */
704 +        printf("\trs %.4f 0\n", F);
705          rgb_cie(cxyz, trgb);                    /* put transmitted component */
706          puts("\tc");
707          d = cxyz[0] + cxyz[1] + cxyz[2];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines