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.15 by gwlarson, Wed Oct 14 14:48:04 1998 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines