Back to index

radiance  4R0+20100331
Defines | Functions | Variables
geom2mgf.c File Reference
#include <stdio.h>

Go to the source code of this file.

Defines

#define PI   3.14159265358979323846
#define WHTEFFICACY   179.0 /* lumens/watt conversion factor */
#define FEQ(a, b)   ((a)-(b) < 1e-4 && (a)-(b) > -1e-4)

Functions

 main (int argc, char **argv)
 translate (char *fname)
 doquad (char *fn, FILE *fp)
 dosphere (char *fn, FILE *fp)
 domat (char *fn, FILE *fp)

Variables

static const char RCSid [] = "$Id: geom2mgf.c,v 1.2 2003/02/28 20:11:29 greg Exp $"

Define Documentation

#define FEQ (   a,
 
)    ((a)-(b) < 1e-4 && (a)-(b) > -1e-4)

Definition at line 11 of file geom2mgf.c.

#define PI   3.14159265358979323846

Definition at line 8 of file geom2mgf.c.

#define WHTEFFICACY   179.0 /* lumens/watt conversion factor */

Definition at line 9 of file geom2mgf.c.


Function Documentation

domat ( char *  fn,
FILE *  fp 
)

Definition at line 103 of file geom2mgf.c.

{
       static short  curtype = 0;
       static double curv1, curv2;
       double d1, d2;
       double f;

nextchar:
       switch(getc(fp)) {
       case ' ':
       case '\t':
       case '\n':
       case '\f':
       case '\r':
              goto nextchar;
       case 'd':                   /* diffuse reflector */
              if (fscanf(fp, "%lf", &d1) != 1)
                     break;
              if (curtype == 'd' && FEQ(d1, curv1))
                     return;
              curtype = 'd';
              curv1 = d1;
              printf("m\n\tc\n");
              printf("\trd %.4f\n", d1);
              return;
       case 's':                   /* specular reflector */
              if (fscanf(fp, "%lf", &d1) != 1)
                     break;
              if (curtype == 's' && FEQ(d1, curv1))
                     return;
              curtype = 's';
              curv1 = d1;
              printf("m\n\tc\n");
              printf("\trs %.4f 0\n", d1);
              return;
       case 't':                   /* dielectric */
              if (fscanf(fp, "%lf", &d1) != 1)
                     break;
              if (curtype == 't' && FEQ(d1, curv1))
                     return;
              curtype = 't';
              curv1 = d1;
              printf("m\n\tc\n");
              printf("\tsides 1\n\tir %.3f 0\n", d1);
              f = (1.0 - d1)/(1.0 + d1);
              f *= f;
              printf("\trs %.4f 0\n", f);
              printf("\tts %.4f 0\n", 1.0-f);
              return;
       case 'l':                   /* light source */
              if (fscanf(fp, "%lf %lf", &d1, &d2) != 2)
                     break;
              if (curtype == 'l' && FEQ(d1, curv1) && FEQ(d2, curv2))
                     return;
              curtype = 'l';
              curv1 = d1;
              curv2 = d2;
              printf("m\n\tc\n");
              printf("\tsides 1\n\trd %.4f\n\ted %.2f\n",
                            d1, PI*WHTEFFICACY*d2);
              return;
       }
       fprintf(stderr, "%s: material format error\n", fn);
       exit(1);
}

Here is the caller graph for this function:

doquad ( char *  fn,
FILE *  fp 
)

Definition at line 64 of file geom2mgf.c.

{
       double vert[3];
       register int  i;

       for (i = 0; i < 4; i++) {
              if (fscanf(fp, "%lf %lf %lf", &vert[0],
                            &vert[1], &vert[2]) != 3) {
                     fprintf(stderr, "%s: bad quad\n", fn);
                     exit(1);
              }
              printf("v qv%d =\n\tp %.9g %.9g %.9g\n",
                            i, vert[0], vert[1], vert[2]);
       }
       domat(fn, fp);
       printf("f qv0 qv1 qv2 qv3\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

dosphere ( char *  fn,
FILE *  fp 
)

Definition at line 85 of file geom2mgf.c.

{
       double cent[3], radius;

       if (fscanf(fp, "%lf %lf %lf %lf", &cent[0], &cent[1],
                     &cent[2], &radius) != 4) {
              fprintf(stderr, "%s: bad sphere\n", fn);
              exit(1);
       }
       printf("v sc = \n\tp %.9g %.9g %.9g\n",
                     cent[0], cent[1], cent[2]);
       domat(fn, fp);
       printf("sph sc %.9g\n", radius);
}

Here is the call graph for this function:

Here is the caller graph for this function:

main ( int  argc,
char **  argv 
)

Definition at line 14 of file geom2mgf.c.

{
       int    i;

       if (argc == 1)
              translate(NULL);
       else
              for (i = 1; i < argc; i++)
                     translate(argv[i]);
       exit(0);
}

Here is the call graph for this function:

translate ( char *  fname)

Definition at line 29 of file geom2mgf.c.

{
       FILE   *fp;
       register int  c;

       if (fname == NULL) {
              fname = "<stdin>";
              fp = stdin;
       } else if ((fp = fopen(fname, "r")) == NULL) {
              perror(fname);
              exit(1);
       }
       while ((c = getc(fp)) != EOF)
              switch (c) {
              case ' ':            /* white space */
              case '\t':
              case '\n':
              case '\f':
              case '\r':
                     break;
              case 'q':            /* quad */
                     doquad(fname, fp);
                     break;
              case 's':            /* sphere */
                     dosphere(fname, fp);
                     break;
              default:             /* illegal */
                     fprintf(stderr, "%s: illegal character (%d)\n",
                                   fname, c);
                     exit(1);
              }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: geom2mgf.c,v 1.2 2003/02/28 20:11:29 greg Exp $" [static]

Definition at line 2 of file geom2mgf.c.