Back to index

radiance  4R0+20100331
Defines | Functions | Variables
lampcolor.c File Reference
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "rtmath.h"
#include "rtio.h"
#include "color.h"

Go to the source code of this file.

Defines

#define LTYPE   0
#define LUNIT   1
#define LGEOM   2
#define LOUTP   3
#define NPARAMS   4

Functions

static int typecheck (char *s)
static int unitcheck (char *s)
static int geomcheck (char *s)
static int outpcheck (char *s)
static void compute (void)
static int getpolygon (void)
static int getsphere (void)
static int getcylinder (void)
static int getring (void)
static int getd (char *name, double *dp, char *help)
int main (int argc, char *argv[])
static int outpcheck (register char *s)

Variables

static const char RCSid [] = "$Id: lampcolor.c,v 2.10 2004/03/18 05:22:00 greg Exp $"
float * lampcolor
double unit2meter
double area
double lumens
struct {
char * name
char value [64]
int(* check )()
char * help
param [NPARAMS]

Define Documentation

#define LGEOM   2

Definition at line 19 of file lampcolor.c.

#define LOUTP   3

Definition at line 20 of file lampcolor.c.

#define LTYPE   0

Definition at line 17 of file lampcolor.c.

#define LUNIT   1

Definition at line 18 of file lampcolor.c.

#define NPARAMS   4

Definition at line 21 of file lampcolor.c.


Function Documentation

static void compute ( void  ) [static]

Definition at line 187 of file lampcolor.c.

{
       double whiteval;

       whiteval = lumens/area/(WHTEFFICACY*PI);

       printf("Lamp color (RGB) = %f %f %f\n",
                     lampcolor[0]*whiteval,
                     lampcolor[1]*whiteval,
                     lampcolor[2]*whiteval);
}

Here is the caller graph for this function:

static int geomcheck ( char *  s) [static]

Definition at line 146 of file lampcolor.c.

{
       int    len = strlen(s);

       switch (*s) {
       case 'p':
              if (strncmp(s, "polygonal", len))
                     return(0);
              return(getpolygon());
       case 's':
              if (strncmp(s, "sphere", len) && strncmp(s, "spherical", len))
                     return(0);
              return(getsphere());
       case 'c':
              if (strncmp(s,"cylinder",len) && strncmp(s,"cylindrical",len))
                     return(0);
              return(getcylinder());
       case 'r':
              if (strncmp(s, "ring", len) && strncmp(s, "disk", len))
                     return(0);
              return(getring());
       }
       return(0);
}

Here is the call graph for this function:

static int getcylinder ( void  )

Definition at line 248 of file lampcolor.c.

{
       static double length = 1.0, radius = 0.1;

       getd("Cylinder length", &length,
              "Enter the length of the cylinder.");
       getd("Cylinder radius", &radius,
              "Enter the distance from the cylinder's axis to its surface.");
       area = 2.*PI*unit2meter*unit2meter * radius*length;
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int getd ( char *  name,
double *  dp,
char *  help 
) [static]

Definition at line 201 of file lampcolor.c.

{
       char   buf[32];
again:
       printf("%s [%g]: ", name, *dp);
       if (fgets(buf, sizeof(buf), stdin) == NULL)
              return(0);
       if (buf[0] == '?') {
              puts(help);
              goto again;
       }
       if ((buf[0] < '0' || buf[0] > '9') && buf[0] != '.')
              return(0);
       *dp = atof(buf);
       return(1);
}

Here is the caller graph for this function:

static int getpolygon ( void  ) [static]

Definition at line 224 of file lampcolor.c.

{
       static double parea = 1.0;

       getd("Polygon area", &parea,
              "Enter the total radiating area of the polygon.");
       area = unit2meter*unit2meter * parea;
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int getring ( void  )

Definition at line 262 of file lampcolor.c.

{
       static double radius = 1.0;

       getd("Disk radius", &radius,
"Enter the distance from the ring's center to its outer edge.\n\
The inner radius must be zero.");
       area = PI*unit2meter*unit2meter * radius*radius;
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int getsphere ( void  )

Definition at line 236 of file lampcolor.c.

{
       static double radius = 1.0;

       getd("Sphere radius", &radius,
              "Enter the distance from the sphere's center to its surface.");
       area = 4.*PI*unit2meter*unit2meter * radius*radius;
       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 62 of file lampcolor.c.

{
       char   *lamptab = "lamp.tab";
       char   buf[64];
       int    i;

       if (argc > 1) lamptab = argv[1];
       if (loadlamps(lamptab) == 0) {
              fprintf(stderr, "%s: no such lamp table\n", lamptab);
              exit(1);
       }
       printf("Program to compute lamp radiance.  Enter '?' for help.\n");
       for ( ; ; ) {
              i = 0;
              while (i < NPARAMS) {
                     printf("Enter %s [%s]: ", param[i].name,
                                   param[i].value);
                     if (fgetline(buf, sizeof(buf), stdin) == NULL)
                            exit(0);
                     if (buf[0] == '?') {
                            puts(param[i].help);
                            continue;
                     }
                     if (buf[0])
                            strcpy(param[i].value, buf);
                     if (!(*param[i].check)(param[i].value)) {
                            fprintf(stderr, "%s: bad value for %s\n",
                                          param[i].value, param[i].name);
                            continue;
                     }
                     i++;
              }
              compute();
       }
}

Here is the call graph for this function:

static int outpcheck ( char *  s) [static]
static int outpcheck ( register char *  s) [static]

Definition at line 175 of file lampcolor.c.

{
       if ((*s < '0' || *s > '9') && *s != '.')
              return(0);
       lumens = atof(s);
       return(1);
}
static int typecheck ( char *  s) [static]

Definition at line 103 of file lampcolor.c.

{
       lampcolor = matchlamp(s);
       return(lampcolor != NULL);
}

Here is the call graph for this function:

static int unitcheck ( char *  s) [static]

Definition at line 113 of file lampcolor.c.

{
       int    len = strlen(s);

       switch (*s) {
       case 'm':
              if (strncmp(s, "meters", len))
                     return(0);
              unit2meter = 1.0;
              return(1);
       case 'c':
              if (strncmp(s, "centimeters", len) && strncmp(s, "cms", len))
                     return(0);
              unit2meter = 0.01;
              return(1);
       case 'f':
              if (strncmp(s, "foot", len) && strncmp(s, "feet", len))
                     return(0);
              unit2meter = 0.3048;
              return(1);
       case 'i':
              if (strncmp(s, "inches", len))
                     return(0);
              unit2meter = 0.0254;
              return(1);
       }
       return(0);
}

Variable Documentation

double area

Definition at line 34 of file lampcolor.c.

float* lampcolor

Definition at line 32 of file lampcolor.c.

double lumens

Definition at line 35 of file lampcolor.c.

struct { ... } param[NPARAMS]
const char RCSid[] = "$Id: lampcolor.c,v 2.10 2004/03/18 05:22:00 greg Exp $" [static]

Definition at line 2 of file lampcolor.c.

double unit2meter

Definition at line 33 of file lampcolor.c.