Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
nff2rad.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "rtmath.h"

Go to the source code of this file.

Classes

struct  t_color_entry

Defines

#define VecCopy(a, b)   (b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];
#define NCOLORS   (738)
#define LESS_THAN   -1
#define GREATER_THAN   1
#define EQUAL_TO   0

Typedefs

typedef double Flt
typedef Flt Vec [3]
typedef Vec Point
typedef Vec Color
typedef struct t_color_entry ColorEntry

Functions

void init (void)
void nff2rad (void)
void comment (void)
void view (void)
void light (void)
void background (void)
void fill (void)
void cone (void)
void sphere (void)
void poly (void)
int LookupColorByName (char *name, Vec color)
int BinarySearch (char *name, int l, int h, ColorEntry array[])
int main (int argc, char *argv[])

Variables

static const char RCSid [] = "$Id: nff2rad.c,v 2.7 2003/11/15 17:54:06 schorsch Exp $"
char * viewfile = NULL
char * progname
ColorEntry Colors []

Class Documentation

struct t_color_entry

Definition at line 83 of file nff2rad.c.

Class Members
Vec ce_color
char * ce_name

Define Documentation

#define EQUAL_TO   0

Definition at line 90 of file nff2rad.c.

#define GREATER_THAN   1

Definition at line 89 of file nff2rad.c.

#define LESS_THAN   -1

Definition at line 88 of file nff2rad.c.

#define NCOLORS   (738)

Definition at line 81 of file nff2rad.c.

#define VecCopy (   a,
 
)    (b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];

Definition at line 80 of file nff2rad.c.


Typedef Documentation

typedef Vec Color

Definition at line 78 of file nff2rad.c.

typedef struct t_color_entry ColorEntry
typedef double Flt

Definition at line 75 of file nff2rad.c.

typedef Vec Point

Definition at line 77 of file nff2rad.c.

typedef Flt Vec[3]

Definition at line 76 of file nff2rad.c.


Function Documentation

void background ( void  )

Definition at line 348 of file nff2rad.c.

{
       float  r, g, b;
       char colname[50];
       double cvec[3];

       if (scanf("%s", colname) != 1) {
           fprintf(stderr,"%s: background syntax error\n",progname);exit(1);
       }
        if(LookupColorByName(colname,cvec)==1){
           r=cvec[0];g=cvec[1];b=cvec[2];
       }else{
           if(sscanf(colname,"%f",&r)!=1 ||
              scanf("%f %f", &g, &b) !=2) {
              fprintf(stderr, "%s: background syntax error\n", progname);
              exit(1);
           }
       }
       printf("\nvoid glow backg_color\n");
       printf("0\n0\n4 %g %g %g 0\n", r, g, b);
       printf("\nbackg_color source background\n");
       printf("0\n0\n4 0 0 1 360\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

int BinarySearch ( char *  name,
int  l,
int  h,
ColorEntry  array[] 
)

Definition at line 1387 of file nff2rad.c.

{
       int m, rc ;
       if (l > h)
              return(-1) ;
       
       m = (l + h) / 2 ;

       rc = strcmp(name, array[m].ce_name) ;
       if (rc == 0)
              return m ;
       else if (rc < 0)
              return BinarySearch(name, l, m-1, array) ;
       else
              return BinarySearch(name, m + 1, h, array) ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void comment ( void  )

Definition at line 210 of file nff2rad.c.

{
       register int  c;
       
       putchar('#');
       while ((c = getchar()) != EOF) {
              putchar(c);
              if (c == '\n')
                     break;
       }
}

Here is the caller graph for this function:

void cone ( void  )

Definition at line 462 of file nff2rad.c.

{
       static int    ncs = 0;
       int    invert;
       float  x0, y0, z0, x1, y1, z1, r0, r1;
       
       if (scanf("%f %f %f %f %f %f %f %f", &x0, &y0, &z0, &r0,
                     &x1, &y1, &z1, &r1) != 8) {
              fprintf(stderr, "%s: cylinder or cone syntax error\n",
                            progname);
              exit(1);
       }
       if ( (invert = r0 < 0.) ) {
              r0 = -r0;
              r1 = -r1;
       }
       if (r0-r1 < .001 && r1-r0 < .001) {       /* cylinder */
              printf("\nfill %s c%d \n", invert?"tube":"cylinder", ++ncs);
              printf("0\n0\n7\n");
              printf("\t%g\t%g\t%g\n", x0, y0, z0);
              printf("\t%g\t%g\t%g\n", x1, y1, z1);
              printf("\t%g\n", r0);
       } else {                           /* cone */
              printf("\nfill %s c%d \n", invert?"cup":"cone", ++ncs);
              printf("0\n0\n8\n");
              printf("\t%g\t%g\t%g\n", x0, y0, z0);
              printf("\t%g\t%g\t%g\n", x1, y1, z1);
              printf("\t%g\t%g\n", r0, r1);
       }
}

Here is the caller graph for this function:

void fill ( void  )

Definition at line 396 of file nff2rad.c.

{
       float  r, g, b, d, s, p, t, n;
       char colname[50];
       double cvec[3];

       if (scanf("%s", colname) != 1) {
           fprintf(stderr,"%s: fill syntax error\n",progname);exit(1);
       }
        if(LookupColorByName(colname,cvec)==1){
           r=cvec[0];g=cvec[1];b=cvec[2];
       }else{
           if(sscanf(colname,"%f",&r)!=1 ||
              scanf("%f %f", &g, &b) !=2) {
              fprintf(stderr, "%s: fill syntax error\n", progname);
              exit(1);
           }
       }
       if (scanf("%f %f %f %f %f", &d, &s, &p, &t, &n) != 5) {
              fprintf(stderr, "%s: fill material syntax error\n", progname);
              exit(1);
       }
       if (p > 1.)
              p = 1./p;
       if (t > .001) {             /* has transmission */
              if (n > 1.1) {              /* has index of refraction */
                     printf("\nvoid dielectric fill\n");
                     printf("0\n0\n5 %g %g %g %g 0\n", r, g, b, n);
              } else {             /* transmits w/o refraction */
                     printf("\nvoid trans fill\n");
                     printf("0\n0\n7 %g %g %g %g 0 %g 1\n",
                                   r*d, g*d, b*d, s, t);
              }
       } else {             /* no transmission */
              printf("\nvoid plastic fill\n");
              printf("0\n0\n5 %g %g %g %g %g\n", r*d, g*d, b*d, s, p);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void init ( void  )
void light ( void  )

Definition at line 318 of file nff2rad.c.

{
       static int    nlights = 0;
       register int  c;
       float  x, y, z;

       if (scanf("%f %f %f",&x, &y, &z) != 3) {
           fprintf(stderr, "%s: light source syntax error\n", progname);
           exit(1);
       }
       while ((c = getchar()) != EOF && c != '\n')
              ;
       printf("\nlight sphere l%d \n", ++nlights);
       printf("0\n0\n4 %g %g %g .01\n", x, y, z);
}

Here is the caller graph for this function:

int LookupColorByName ( char *  name,
Vec  color 
)

Definition at line 1370 of file nff2rad.c.

{
       int rc ;
       rc = BinarySearch(name, 0, NCOLORS - 1 , Colors) ;
       if (rc < 0) {
              return(0) ;
       }

       VecCopy(Colors[rc].ce_color, color) ;
       return 1 ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 111 of file nff2rad.c.

{
       int    i;
       
       progname = argv[0];
       for (i = 1; i < argc; i++)
              if (argc-i > 1 && !strcmp(argv[i], "-vf"))
                     viewfile = argv[++i];
              else if (!strncmp(argv[i], "-h",2))
                     goto userr;
              else
                     break;
       if (argc-i > 1)
              goto userr;
       if (argc-i == 1 && freopen(argv[i], "r", stdin) == NULL) {
              perror(argv[i]);
              exit(1);
       }
       init();
       nff2rad();
       exit(0);
userr:
       fprintf(stderr, "Usage: %s [-vf viewfile] [input]\n", progname);
       exit(1);
}

Here is the call graph for this function:

void nff2rad ( void  )

Definition at line 153 of file nff2rad.c.

{
       register int  c;
       
       while ((c = getchar()) != EOF)
              switch (c) {
              case ' ':                   /* white space */
              case '\t':
              case '\n':
              case '\f':
              case '\r':
                     continue;
              case '#':                   /* comment */
                     comment();
                     break;
              case 'v':                   /* view point */
                     view();
                     break;
              case 'l':                   /* light source */
                     light();
                     break;
              case 'b':                   /* background color */
                     background();
                     break;
              case 'f':                   /* fill material */
                     fill();
                     break;
              case 'c':                   /* cylinder or cone */
                     cone();
                     break;
              case 's':                   /* sphere */
                     sphere();
                     break;
              case 'p':                   /* polygon or patch */
                     poly();
                     break;
              default:                    /* unknown */
                     fprintf(stderr, "%c: unknown NFF primitive\n", c);
                     exit(1);
              }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void poly ( void  )

Definition at line 564 of file nff2rad.c.

{
       static int    npolys = 0;
       int    ispatch;
       int    nverts;
       float  x, y, z;
       
       ispatch = getchar();
       if (ispatch != 'p') {
              ungetc(ispatch, stdin);
              ispatch = 0;
       }
       if (scanf("%d", &nverts) != 1)
              goto fmterr;
       printf("\nfill polygon p%d \n", ++npolys);
       printf("0\n0\n%d\n", 3*nverts);
       while (nverts-- > 0) {
              if (scanf("%f %f %f", &x, &y, &z) != 3)
                     goto fmterr;
              if (ispatch)
                     scanf("%*f %*f %*f");
              printf("\t%g\t%g\t%g\n", x, y, z);
       }
       return;
fmterr:
       fprintf(stderr, "%s: polygon or patch syntax error\n", progname);
       exit(1);
}

Here is the caller graph for this function:

void sphere ( void  )

Definition at line 508 of file nff2rad.c.

{
       static int    nspheres = 0;
       float  x, y, z, r;
       
       if (scanf("%f %f %f %f", &x, &y, &z, &r) != 4) {
              fprintf(stderr, "%s: sphere syntax error\n", progname);
              exit(1);
       }
       if (r < 0.) {
              printf("\nfill bubble s%d \n", ++nspheres);
              printf("0\n0\n4 %g %g %g %g\n", x, y, z, -r);
       } else {
              printf("\nfill sphere s%d \n", ++nspheres);
              printf("0\n0\n4 %g %g %g %g\n", x, y, z, r);
       }
}

Here is the caller graph for this function:

void view ( void  )

Definition at line 268 of file nff2rad.c.

{
       static FILE   *fp = NULL;
       float  from[3], at[3], up[3], angle;
       
       if (scanf(" from %f %f %f", &from[0], &from[1], &from[2]) != 3)
              goto fmterr;
       if (scanf(" at %f %f %f", &at[0], &at[1], &at[2]) != 3)
              goto fmterr;
       if (scanf(" up %f %f %f", &up[0], &up[1], &up[2]) != 3)
              goto fmterr;
       if (scanf(" angle %f", &angle) != 1)
              goto fmterr;
       scanf(" hither %*f");
       scanf(" resolution %*d %*d");
       if (viewfile != NULL) {
              if (fp == NULL && (fp = fopen(viewfile, "a")) == NULL) {
                     perror(viewfile);
                     exit(1);
              }
              fprintf(fp,
       "VIEW= -vp %g %g %g -vd %g %g %g -vu %g %g %g -vh %g -vv %g\n",
                            from[0], from[1], from[2],
                            at[0]-from[0], at[1]-from[1], at[2]-from[2],
                            up[0], up[1], up[2],
                            angle, angle);
       }
       return;
fmterr:
       fprintf(stderr, "%s: view syntax error\n", progname);
       exit(1);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 628 of file nff2rad.c.

char* progname

Definition at line 94 of file nff2rad.c.

const char RCSid[] = "$Id: nff2rad.c,v 2.7 2003/11/15 17:54:06 schorsch Exp $" [static]

Definition at line 2 of file nff2rad.c.

char* viewfile = NULL

Definition at line 92 of file nff2rad.c.