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.5 by greg, Mon Aug 15 16:29:22 1994 UTC vs.
Revision 2.16 by greg, Sat Feb 22 02:07:23 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>
13 #include "fvect.h"
11   #include "object.h"
12   #include "color.h"
13   #include "lookup.h"
14  
15 + #define C_1SIDEDTHICK   0.005
16 +
17   int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
18 < int     o_instance(), o_source(), o_illum();
19 < int     o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light();
18 > int     o_instance(), o_illum();
19 > int     o_plastic(), o_metal(), o_glass(), o_dielectric(),
20 >        o_mirror(), o_trans(), o_light();
21  
22 extern void     free();
23 extern char     *malloc();
24
22   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
23  
24   LUTAB   rdispatch = LU_SINIT(NULL,NULL);        /* function dispatch table */
# Line 37 | Line 34 | double unit_mult = 1.;                         /* units multiplier */
34   * Stuff for tracking and reusing vertices:
35   */
36  
37 < char    VKFMT[] = "%+1.9e %+1.9e %+1.9e";
37 > char    VKFMT[] = "%+16.9e %+16.9e %+16.9e";
38   #define VKLEN           64
39  
40   #define mkvkey(k,v)     sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2])
41  
42   #define NVERTS          256
43  
44 < long    clock;          /* incremented at each vertex request */
44 > long    vclock;         /* incremented at each vertex request */
45  
46   struct vert {
47          long    lused;          /* when last used (0 if unassigned) */
# Line 80 | Line 77 | char   **argv;
77                                  goto unkopt;
78                          }
79                          break;
80 +                default:
81 +                        goto unkopt;
82                  }
83          init();
84          if (i >= argc)
# Line 186 | Line 185 | FUNARGS        *fa;
185                          fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id);
186                          exit(1);
187                  }
188 <        } else if (lu_find(&rmats, mod)->data != NULL)  /* make alias */
189 <                newmat(id, mod);
188 >        } else {                                        /* unsupported */
189 >                o_unsupported(mod, typ, id, fa);
190 >                if (lu_find(&rmats, mod)->data != NULL) /* make alias */
191 >                        newmat(id, mod);
192 >        }
193   }
194  
195  
# Line 252 | Line 254 | char   *id;
254          if (end == NULL)
255                  end = cp;
256                                  /* copy to current object */
257 <        for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++)
257 >        cp2 = curobj;
258 >        if (!isalpha(*id)) {    /* start with letter */
259 >                diff = *cp2 != 'O';
260 >                *cp2++ = 'O';
261 >        }
262 >        for (cp = id; cp < end; *cp2++ = *cp++) {
263 >                if (*cp < '!' | *cp > '~')      /* limit to visible chars */
264 >                        *cp = '?';
265                  diff += *cp != *cp2;
266 +        }
267          if (!diff && !*cp2)
268                  return;
269          *cp2 = '\0';
# Line 280 | Line 290 | init()                 /* initialize dispatch table and output */
290          add2dispatch("metal", o_metal);
291          add2dispatch("metal2", o_metal);
292          add2dispatch("glass", o_glass);
293 +        add2dispatch("dielectric", o_dielectric);
294          add2dispatch("trans", o_trans);
295          add2dispatch("trans2", o_trans);
296          add2dispatch("mirror", o_mirror);
# Line 287 | Line 298 | init()                 /* initialize dispatch table and output */
298          add2dispatch("spotlight", o_light);
299          add2dispatch("glow", o_light);
300          add2dispatch("illum", o_illum);
301 <        puts("# The following was converted from Radiance scene input");
301 >        puts("# The following was converted from RADIANCE scene input");
302          if (hasmult)
303                  printf("xf -s %.4e\n", unit_mult);
304          printf("o %s\n", curobj);
# Line 299 | Line 310 | uninit()                       /* mark end of MGF file */
310          puts("o");
311          if (hasmult)
312                  puts("xf");
313 <        puts("# End of data converted from Radiance scene input");
313 >        puts("# End of data converted from RADIANCE scene input");
314          lu_done(&rdispatch);
315          lu_done(&rmats);
316          lu_done(&vertab);
# Line 339 | Line 350 | getvertid(vname, vp)           /* get/set vertex ID for this po
350   char    *vname;
351   FVECT   vp;
352   {
353 <        char    vkey[VKLEN];
353 >        static char     vkey[VKLEN];
354          register LUENT  *lp;
355          register int    i, vndx;
356  
357 <        clock++;                        /* increment counter */
357 >        vclock++;                       /* increment counter */
358          mkvkey(vkey, vp);
359          if ((lp = lu_find(&vertab, vkey)) == NULL)
360                  goto memerr;
# Line 369 | Line 380 | FVECT  vp;
380                  lp->data = (char *)&vert[vndx];                 /* set it */
381          } else
382                  vndx = (struct vert *)lp->data - vert;
383 <        vert[vndx].lused = clock;               /* record this use */
383 >        vert[vndx].lused = vclock;              /* record this use */
384          sprintf(vname, "v%d", vndx);
385          return(vname);
386   memerr:
# Line 379 | Line 390 | memerr:
390  
391  
392   int
393 + o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */
394 + char    *mod, *typ, *id;
395 + FUNARGS *fa;
396 + {
397 +        register int    i;
398 +
399 +        fputs("\n# Unsupported RADIANCE primitive:\n", stdout);
400 +        printf("# %s %s %s", mod, typ, id);
401 +        printf("\n# %d", fa->nsargs);
402 +        for (i = 0; i < fa->nsargs; i++)
403 +                printf(" %s", fa->sarg[i]);
404 + #ifdef IARGS
405 +        printf("\n# %d", fa->niargs);
406 +        for (i = 0; i < fa->niargs; i++)
407 +                printf(" %ld", fa->iarg[i]);
408 + #else
409 +        fputs("\n# 0", stdout);
410 + #endif
411 +        printf("\n# %d", fa->nfargs);
412 +        for (i = 0; i < fa->nfargs; i++)
413 +                printf(" %g", fa->farg[i]);
414 +        fputs("\n\n", stdout);
415 +        return(0);
416 + }
417 +
418 +
419 + int
420   o_face(mod, typ, id, fa)                /* print out a polygon */
421   char    *mod, *typ, *id;
422   FUNARGS *fa;
423   {
424 <        char    entbuf[512];
424 >        char    entbuf[2048], *linestart;
425          register char   *cp;
426          register int    i;
427  
# Line 391 | Line 429 | FUNARGS        *fa;
429                  return(-1);
430          setmat(mod);
431          setobj(id);
432 <        cp = entbuf;
432 >        cp = linestart = entbuf;
433          *cp++ = 'f';
434          for (i = 0; i < fa->nfargs; i += 3) {
435                  *cp++ = ' ';
436 +                if (cp - linestart > 72) {
437 +                        *cp++ = '\\'; *cp++ = '\n';
438 +                        linestart = cp;
439 +                        *cp++ = ' '; *cp++ = ' ';
440 +                }
441                  getvertid(cp, fa->farg + i);
442                  while (*cp)
443                          cp++;
# Line 528 | Line 571 | FUNARGS        *fa;
571  
572  
573   int
531 o_source(mod, typ, id, fa)      /* convert a source */
532 char    *mod, *typ, *id;
533 FUNARGS *fa;
534 {
535        return(0);              /* there is no MGF equivalent! */
536 }
537
538
539 int
574   o_illum(mod, typ, id, fa)       /* convert an illum material */
575   char    *mod, *typ, *id;
576   FUNARGS *fa;
# Line 620 | Line 654 | register FUNARGS       *fa;
654          newmat(id, NULL);
655          if (fa->nfargs == 4)
656                  nrfr = fa->farg[3];
657 +        printf("\tir %f 0\n", nrfr);
658          F = (1. - nrfr)/(1. + nrfr);            /* use normal incidence */
659          F *= F;
660          for (i = 0; i < 3; i++) {
# Line 645 | Line 680 | register FUNARGS       *fa;
680  
681  
682   int
683 + o_dielectric(mod, typ, id, fa)  /* convert a dielectric material */
684 + char    *mod, *typ, *id;
685 + register FUNARGS        *fa;
686 + {
687 +        COLOR   cxyz, trgb;
688 +        double  F, d;
689 +        register int    i;
690 +
691 +        if (fa->nfargs != 5)
692 +                return(-1);
693 +        newmat(id, NULL);
694 +        F = (1. - fa->farg[3])/(1. + fa->farg[3]);      /* normal incidence */
695 +        F *= F;
696 +        for (i = 0; i < 3; i++)
697 +                trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult);
698 +        printf("\tir %f 0\n", fa->farg[3]);     /* put index of refraction */
699 +        printf("\tsides 1\n");
700 +        puts("\tc");                            /* put reflected component */
701 +        printf("\trs %.4f 0\n", F);
702 +        rgb_cie(cxyz, trgb);                    /* put transmitted component */
703 +        puts("\tc");
704 +        d = cxyz[0] + cxyz[1] + cxyz[2];
705 +        if (d > FTINY)
706 +                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
707 +        printf("\tts %.4f 0\n", cxyz[1]);
708 +        return(0);
709 + }
710 +
711 +
712 + int
713   o_mirror(mod, typ, id, fa)      /* convert a mirror material */
714   char    *mod, *typ, *id;
715   register FUNARGS        *fa;
# Line 726 | Line 791 | register FUNARGS       *fa;
791          puts("\tc");
792          if (d > FTINY)
793                  printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
794 <        printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY);
794 >        printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY));
795          return(0);
796   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines