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.2 by greg, Fri Jul 8 16:10:06 1994 UTC vs.
Revision 2.11 by greg, Thu Apr 13 15:33:48 1995 UTC

# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include <stdio.h>
12 + #include <math.h>
13   #include <string.h>
14   #include "fvect.h"
15   #include "object.h"
16   #include "color.h"
17   #include "lookup.h"
18  
19 + #define PI      3.14159265358979323846
20 +
21 + #define C_1SIDEDTHICK   0.005
22 +
23   int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
24 < int     o_instance(), o_source(), o_illum();
25 < int     o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light();
24 > int     o_instance(), o_illum();
25 > int     o_plastic(), o_metal(), o_glass(), o_dielectric(),
26 >        o_mirror(), o_trans(), o_light();
27  
28   extern void     free();
29   extern char     *malloc();
# Line 33 | Line 39 | double unit_mult = 1.;                         /* units multiplier */
39  
40   #define hasmult         (unit_mult < .999 || unit_mult > 1.001)
41  
42 + /*
43 + * Stuff for tracking and reusing vertices:
44 + */
45  
46 + char    VKFMT[] = "%+16.9e %+16.9e %+16.9e";
47 + #define VKLEN           64
48 +
49 + #define mkvkey(k,v)     sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2])
50 +
51 + #define NVERTS          256
52 +
53 + long    vclock;         /* incremented at each vertex request */
54 +
55 + struct vert {
56 +        long    lused;          /* when last used (0 if unassigned) */
57 +        FVECT   p;              /* track point position only */
58 + } vert[NVERTS];         /* our vertex cache */
59 +
60 + LUTAB   vertab = LU_SINIT(free,NULL);   /* our vertex lookup table */
61 +
62 +
63   main(argc, argv)
64   int     argc;
65   char    **argv;
# Line 60 | Line 86 | char   **argv;
86                                  goto unkopt;
87                          }
88                          break;
89 +                default:
90 +                        goto unkopt;
91                  }
92          init();
93          if (i >= argc)
# Line 166 | Line 194 | FUNARGS        *fa;
194                          fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id);
195                          exit(1);
196                  }
197 <        } else if (lu_find(&rmats, mod)->data != NULL)  /* make alias */
198 <                newmat(id, mod);
197 >        } else {                                        /* unsupported */
198 >                o_unsupported(mod, typ, id, fa);
199 >                if (lu_find(&rmats, mod)->data != NULL) /* make alias */
200 >                        newmat(id, mod);
201 >        }
202   }
203  
204  
# Line 244 | Line 275 | char   *id;
275  
276   init()                  /* initialize dispatch table and output */
277   {
278 +        lu_init(&vertab, NVERTS);
279          lu_init(&rdispatch, 22);
280          add2dispatch("polygon", o_face);
281          add2dispatch("cone", o_cone);
# Line 259 | Line 291 | init()                 /* initialize dispatch table and output */
291          add2dispatch("metal", o_metal);
292          add2dispatch("metal2", o_metal);
293          add2dispatch("glass", o_glass);
294 +        add2dispatch("dielectric", o_dielectric);
295          add2dispatch("trans", o_trans);
296          add2dispatch("trans2", o_trans);
297          add2dispatch("mirror", o_mirror);
# Line 266 | Line 299 | init()                 /* initialize dispatch table and output */
299          add2dispatch("spotlight", o_light);
300          add2dispatch("glow", o_light);
301          add2dispatch("illum", o_illum);
302 <        puts("# The following was converted from Radiance scene input");
302 >        puts("# The following was converted from RADIANCE scene input");
303          if (hasmult)
304                  printf("xf -s %.4e\n", unit_mult);
305          printf("o %s\n", curobj);
# Line 278 | Line 311 | uninit()                       /* mark end of MGF file */
311          puts("o");
312          if (hasmult)
313                  puts("xf");
314 <        puts("# End of data converted from Radiance scene input");
314 >        puts("# End of data converted from RADIANCE scene input");
315          lu_done(&rdispatch);
316          lu_done(&rmats);
317 +        lu_done(&vertab);
318   }
319  
320  
321 + clrverts()                      /* clear vertex table */
322 + {
323 +        register int    i;
324 +
325 +        lu_done(&vertab);
326 +        for (i = 0; i < NVERTS; i++)
327 +                vert[i].lused = 0;
328 +        lu_init(&vertab, NVERTS);
329 + }
330 +
331 +
332   add2dispatch(name, func)        /* add function to dispatch table */
333   char    *name;
334   int     (*func)();
# Line 301 | Line 346 | int    (*func)();
346   }
347  
348  
304 /*
305 * Stuff for tracking and reusing vertices:
306 */
307
308 char    VKFMT[] = "%+1.9e %+1.9e %+1.9e";
309 #define VKLEN           64
310
311 #define mkvkey(k,v)     sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2])
312
313 #define NVERTS          256
314
315 long    clock;          /* incremented at each vertex request */
316
317 struct vert {
318        long    lused;          /* when last used (0 if unassigned) */
319        FVECT   p;              /* track point position only */
320 } vert[NVERTS];
321
322 LUTAB   vertab = LU_SINIT(free,NULL);   /* our vertex lookup table */
323
324
349   char *
350   getvertid(vname, vp)            /* get/set vertex ID for this point */
351   char    *vname;
352   FVECT   vp;
353   {
354 <        char    vkey[VKLEN];
354 >        static char     vkey[VKLEN];
355          register LUENT  *lp;
356          register int    i, vndx;
357  
358 <        if (!vertab.tsiz && !lu_init(&vertab, NVERTS))
335 <                goto memerr;
336 <        clock++;                        /* increment counter */
358 >        vclock++;                       /* increment counter */
359          mkvkey(vkey, vp);
360          if ((lp = lu_find(&vertab, vkey)) == NULL)
361                  goto memerr;
# Line 353 | Line 375 | FVECT  vp;
375                          mkvkey(vkey, vert[vndx].p);
376                          lu_delete(&vertab, vkey);
377                  }
378 <                vert[vndx].lused = clock;                       /* assign it */
357 <                VCOPY(vert[vndx].p, vp);
378 >                VCOPY(vert[vndx].p, vp);                        /* assign it */
379                  printf("v v%d =\n\tp %.15g %.15g %.15g\n",      /* print it */
380                                  vndx, vp[0], vp[1], vp[2]);
381                  lp->data = (char *)&vert[vndx];                 /* set it */
382          } else
383                  vndx = (struct vert *)lp->data - vert;
384 +        vert[vndx].lused = vclock;              /* record this use */
385          sprintf(vname, "v%d", vndx);
386          return(vname);
387   memerr:
# Line 369 | Line 391 | memerr:
391  
392  
393   int
394 + o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */
395 + char    *mod, *typ, *id;
396 + FUNARGS *fa;
397 + {
398 +        register int    i;
399 +
400 +        fputs("\n# Unsupported RADIANCE primitive:\n", stdout);
401 +        printf("# %s %s %s", mod, typ, id);
402 +        printf("\n# %d", fa->nsargs);
403 +        for (i = 0; i < fa->nsargs; i++)
404 +                printf(" %s", fa->sarg[i]);
405 + #ifdef IARGS
406 +        printf("\n# %d", fa->niargs);
407 +        for (i = 0; i < fa->niargs; i++)
408 +                printf(" %ld", fa->iarg[i]);
409 + #else
410 +        fputs("\n# 0", stdout);
411 + #endif
412 +        printf("\n# %d", fa->nfargs);
413 +        for (i = 0; i < fa->nfargs; i++)
414 +                printf(" %g", fa->farg[i]);
415 +        fputs("\n\n", stdout);
416 +        return(0);
417 + }
418 +
419 +
420 + int
421   o_face(mod, typ, id, fa)                /* print out a polygon */
422   char    *mod, *typ, *id;
423   FUNARGS *fa;
# Line 512 | Line 561 | FUNARGS        *fa;
561                  fputs(fa->sarg[i], stdout);
562          }
563          putchar('\n');
564 +        clrverts();                     /* vertex id's no longer reliable */
565          return(0);
566   }
567  
568  
569   int
520 o_source(mod, typ, id, fa)      /* convert a source */
521 char    *mod, *typ, *id;
522 FUNARGS *fa;
523 {
524        return(0);              /* there is no MGF equivalent! */
525 }
526
527
528 int
570   o_illum(mod, typ, id, fa)       /* convert an illum material */
571   char    *mod, *typ, *id;
572   FUNARGS *fa;
# Line 609 | Line 650 | register FUNARGS       *fa;
650          newmat(id, NULL);
651          if (fa->nfargs == 4)
652                  nrfr = fa->farg[3];
653 +        printf("\tir %f 0\n", nrfr);
654          F = (1. - nrfr)/(1. + nrfr);            /* use normal incidence */
655          F *= F;
656          for (i = 0; i < 3; i++) {
# Line 634 | Line 676 | register FUNARGS       *fa;
676  
677  
678   int
679 + o_dielectric(mod, typ, id, fa)  /* convert a dielectric material */
680 + char    *mod, *typ, *id;
681 + register FUNARGS        *fa;
682 + {
683 +        COLOR   cxyz, trgb;
684 +        double  F, d;
685 +        register int    i;
686 +
687 +        if (fa->nfargs != 5)
688 +                return(-1);
689 +        newmat(id, NULL);
690 +        F = (1. - fa->farg[3])/(1. + fa->farg[3]);      /* normal incidence */
691 +        F *= F;
692 +        for (i = 0; i < 3; i++)
693 +                trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult);
694 +        printf("\tir %f 0\n", fa->farg[3]);     /* put index of refraction */
695 +        printf("\tsides 1\n");
696 +        puts("\tc");                            /* put reflected component */
697 +        printf("\trs %.4f 0\n", F);
698 +        rgb_cie(cxyz, trgb);                    /* put transmitted component */
699 +        puts("\tc");
700 +        d = cxyz[0] + cxyz[1] + cxyz[2];
701 +        if (d > FTINY)
702 +                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
703 +        printf("\tts %.4f 0\n", cxyz[1]);
704 +        return(0);
705 + }
706 +
707 +
708 + int
709   o_mirror(mod, typ, id, fa)      /* convert a mirror material */
710   char    *mod, *typ, *id;
711   register FUNARGS        *fa;
# Line 715 | Line 787 | register FUNARGS       *fa;
787          puts("\tc");
788          if (d > FTINY)
789                  printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
790 <        printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY);
790 >        printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY));
791          return(0);
792   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines