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.4 by greg, Sat Jul 9 09:42:48 1994 UTC vs.
Revision 2.17 by schorsch, Sun Jun 8 12:03:09 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 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  
22 extern void     free();
23 extern char     *malloc();
24
25   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
26  
27   LUTAB   rdispatch = LU_SINIT(NULL,NULL);        /* function dispatch table */
# Line 37 | 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])
44  
45   #define NVERTS          256
46  
47 < long    clock;          /* incremented at each vertex request */
47 > long    vclock;         /* incremented at each vertex request */
48  
49   struct vert {
50          long    lused;          /* when last used (0 if unassigned) */
# Line 80 | Line 80 | char   **argv;
80                                  goto unkopt;
81                          }
82                          break;
83 +                default:
84 +                        goto unkopt;
85                  }
86          init();
87          if (i >= argc)
# Line 186 | 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 252 | 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 280 | 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 287 | 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 299 | 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);
320   }
321  
322  
323 + clrverts()                      /* clear vertex table */
324 + {
325 +        register int    i;
326 +
327 +        lu_done(&vertab);
328 +        for (i = 0; i < NVERTS; i++)
329 +                vert[i].lused = 0;
330 +        lu_init(&vertab, NVERTS);
331 + }
332 +
333 +
334   add2dispatch(name, func)        /* add function to dispatch table */
335   char    *name;
336   int     (*func)();
# Line 328 | 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  
360 <        clock++;                        /* increment counter */
360 >        vclock++;                       /* increment counter */
361          mkvkey(vkey, vp);
362          if ((lp = lu_find(&vertab, vkey)) == NULL)
363                  goto memerr;
# Line 358 | Line 383 | FVECT  vp;
383                  lp->data = (char *)&vert[vndx];                 /* set it */
384          } else
385                  vndx = (struct vert *)lp->data - vert;
386 <        vert[vndx].lused = clock;               /* record this use */
386 >        vert[vndx].lused = vclock;              /* record this use */
387          sprintf(vname, "v%d", vndx);
388          return(vname);
389   memerr:
# Line 368 | 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  
# Line 380 | Line 432 | FUNARGS        *fa;
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 511 | Line 568 | FUNARGS        *fa;
568                  fputs(fa->sarg[i], stdout);
569          }
570          putchar('\n');
571 +        clrverts();                     /* vertex id's no longer reliable */
572          return(0);
573   }
574  
575  
576   int
519 o_source(mod, typ, id, fa)      /* convert a source */
520 char    *mod, *typ, *id;
521 FUNARGS *fa;
522 {
523        return(0);              /* there is no MGF equivalent! */
524 }
525
526
527 int
577   o_illum(mod, typ, id, fa)       /* convert an illum material */
578   char    *mod, *typ, *id;
579   FUNARGS *fa;
# Line 608 | 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 633 | Line 683 | register FUNARGS       *fa;
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];
708 +        if (d > FTINY)
709 +                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
710 +        printf("\tts %.4f 0\n", cxyz[1]);
711 +        return(0);
712 + }
713 +
714 +
715 + int
716   o_mirror(mod, typ, id, fa)      /* convert a mirror material */
717   char    *mod, *typ, *id;
718   register FUNARGS        *fa;
# Line 714 | Line 794 | register FUNARGS       *fa;
794          puts("\tc");
795          if (d > FTINY)
796                  printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
797 <        printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY);
797 >        printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY));
798          return(0);
799   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines