--- ray/src/cv/lampcolor.c 1991/09/12 13:26:16 1.5 +++ ray/src/cv/lampcolor.c 2003/06/21 15:05:01 2.8 @@ -1,21 +1,17 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: lampcolor.c,v 2.8 2003/06/21 15:05:01 greg Exp $"; #endif - /* * Program to convert lamp color from table and compute radiance. */ #include +#include +#include -#define PI 3.14159265358979323846 +#include "standard.h" +#include "color.h" -extern char *gets(), *strcpy(); -extern double atof(); -extern float *matchlamp(); - /* lamp parameters */ #define LTYPE 0 #define LUNIT 1 @@ -23,11 +19,17 @@ extern float *matchlamp(); #define LOUTP 3 #define NPARAMS 4 -int typecheck(), unitcheck(), geomcheck(), outpcheck(); +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), getsphere(void), getcylinder(void), getring(void); + float *lampcolor; /* the lamp color (RGB) */ double unit2meter; /* conversion from units to meters */ -double projarea; /* projected area for this geometry */ +double area; /* radiating area for this geometry */ double lumens; /* total lamp lumens */ struct { @@ -36,9 +38,9 @@ struct { int (*check)(); char *help; } param[NPARAMS] = { - { "lamp type", "white", typecheck, + { "lamp type", "WHITE", typecheck, "The lamp type is a string which corresponds to one of the types registered\n\ -in the lamp table file. A value of \"white\" means an uncolored source,\n\ +in the lamp table file. A value of \"WHITE\" means an uncolored source,\n\ which may be preferable because it results in a color balanced image." }, { "length unit", "meter", unitcheck, "Unit must be one of: \"meter\", \"centimeter\", \"foot\", or \"inch\".\n\ @@ -93,16 +95,20 @@ char *argv[]; } -typecheck(s) /* check lamp type */ -char *s; +static int +typecheck( /* check lamp type */ +char *s +) { lampcolor = matchlamp(s); return(lampcolor != NULL); } -unitcheck(s) /* compute conversion to meters */ -char *s; +static int +unitcheck( /* compute conversion to meters */ +char *s +) { int len = strlen(s); @@ -132,8 +138,10 @@ char *s; } -geomcheck(s) /* check/set lamp geometry */ -char *s; +static int +geomcheck( /* check/set lamp geometry */ +char *s +) { int len = strlen(s); @@ -159,8 +167,10 @@ char *s; } -outpcheck(s) /* check lumen output value */ -register char *s; +static int +outpcheck( /* check lumen output value */ +register char *s +) { if ((*s < '0' || *s > '9') && *s != '.') return(0); @@ -169,11 +179,12 @@ register char *s; } -compute() /* compute lamp radiance */ +static void +compute(void) /* compute lamp radiance */ { double whiteval; - whiteval = lumens/470./projarea; + whiteval = lumens/area/(WHTEFFICACY*PI); printf("Lamp color (RGB) = %f %f %f\n", lampcolor[0]*whiteval, @@ -182,13 +193,20 @@ compute() /* compute lamp radiance */ } -getd(dp) /* get a positive double from stdin */ +getd(name, dp, help) /* get a positive double from stdin */ +char *name; double *dp; +char *help; { char buf[32]; - +again: + printf("%s [%g]: ", name, *dp); if (gets(buf) == NULL) return(0); + if (buf[0] == '?') { + puts(help); + goto again; + } if ((buf[0] < '0' || buf[0] > '9') && buf[0] != '.') return(0); *dp = atof(buf); @@ -196,47 +214,52 @@ double *dp; } -getpolygon() /* get projected area for a polygon */ +static int +getpolygon(void) /* get projected area for a polygon */ { - static double area = 1.0; + static double parea = 1.0; - printf("Polygon area [%g]: ", area); - getd(&area); - projarea = PI*unit2meter*unit2meter * area; + getd("Polygon area", &parea, + "Enter the total radiating area of the polygon."); + area = unit2meter*unit2meter * parea; return(1); } -getsphere() /* get projected area for a sphere */ +static int +getsphere(void) /* get projected area for a sphere */ { static double radius = 1.0; - printf("Sphere radius [%g]: ", radius); - getd(&radius); - projarea = 4.*PI*PI*unit2meter*unit2meter * radius*radius; + getd("Sphere radius", &radius, + "Enter the distance from the sphere's center to its surface."); + area = 4.*PI*unit2meter*unit2meter * radius*radius; return(1); } -getcylinder() /* get projected area for a cylinder */ +static int +getcylinder(void) /* get projected area for a cylinder */ { static double length = 1.0, radius = 0.1; - printf("Cylinder length [%g]: ", length); - getd(&length); - printf("Cylinder radius [%g]: ", radius); - getd(&radius); - projarea = PI*PI*2.*PI*unit2meter*unit2meter * radius*length; + 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); } -getring() /* get projected area for a ring */ +static int +getring(void) /* get projected area for a ring */ { static double radius = 1.0; - printf("Disk radius [%g]: ", radius); - getd(&radius); - projarea = PI*PI*unit2meter*unit2meter * radius*radius; + 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); }