ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/lampcolor.c
Revision: 2.1
Committed: Tue Nov 12 17:02:10 1991 UTC (32 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.9: +0 -0 lines
Log Message:
updated revision number for release 2.0

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1991 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8 greg 1.2 * Program to convert lamp color from table and compute radiance.
9 greg 1.1 */
10    
11     #include <stdio.h>
12    
13 greg 1.8 #include "color.h"
14    
15 greg 1.2 #define PI 3.14159265358979323846
16    
17     extern char *gets(), *strcpy();
18     extern double atof();
19 greg 1.1 extern float *matchlamp();
20    
21 greg 1.2 /* lamp parameters */
22     #define LTYPE 0
23     #define LUNIT 1
24     #define LGEOM 2
25     #define LOUTP 3
26     #define NPARAMS 4
27 greg 1.1
28 greg 1.2 int typecheck(), unitcheck(), geomcheck(), outpcheck();
29    
30     float *lampcolor; /* the lamp color (RGB) */
31     double unit2meter; /* conversion from units to meters */
32 greg 1.7 double area; /* radiating area for this geometry */
33 greg 1.2 double lumens; /* total lamp lumens */
34    
35     struct {
36     char *name;
37     char value[64];
38     int (*check)();
39     char *help;
40     } param[NPARAMS] = {
41     { "lamp type", "white", typecheck,
42     "The lamp type is a string which corresponds to one of the types registered\n\
43     in the lamp table file. A value of \"white\" means an uncolored source,\n\
44     which may be preferable because it results in a color balanced image." },
45     { "length unit", "meter", unitcheck,
46     "Unit must be one of: \"meter\", \"centimeter\", \"foot\", or \"inch\".\n\
47     These may be abbreviated as a single letter." },
48     { "lamp geometry", "polygon", geomcheck,
49     "The lamp geometry must be one of: \"polygon\", \"sphere\", \"cylinder\"\n\
50     or \"ring\". These may be abbreviated as a single letter." },
51     { "total lamp lumens", "0", outpcheck,
52     "This is the overall light output of the lamp and its fixture. If you do\n\
53     not know this value explicitly, you can compute the approximate lumens\n\
54 greg 1.3 by multiplying the input wattage by 14 for incandescent fixtures or 70\n\
55 greg 1.2 for fluorescent fixtures." },
56     };
57    
58    
59 greg 1.1 main(argc, argv)
60     int argc;
61     char *argv[];
62     {
63     char *lamptab = "lamp.tab";
64 greg 1.2 char buf[64];
65     int i;
66 greg 1.1
67     if (argc > 1) lamptab = argv[1];
68     if (loadlamps(lamptab) == 0) {
69 greg 1.2 fprintf(stderr, "%s: no such lamp table\n", lamptab);
70 greg 1.1 exit(1);
71     }
72 greg 1.2 printf("Program to compute lamp radiance. Enter '?' for help.\n");
73 greg 1.1 for ( ; ; ) {
74 greg 1.2 i = 0;
75     while (i < NPARAMS) {
76     printf("Enter %s [%s]: ", param[i].name,
77     param[i].value);
78     if (gets(buf) == NULL)
79     exit(0);
80     if (buf[0] == '?') {
81     puts(param[i].help);
82     continue;
83     }
84     if (buf[0])
85     strcpy(param[i].value, buf);
86     if (!(*param[i].check)(param[i].value)) {
87     fprintf(stderr, "%s: bad value for %s\n",
88     param[i].value, param[i].name);
89     continue;
90     }
91     i++;
92     }
93     compute();
94 greg 1.1 }
95 greg 1.2 }
96    
97    
98     typecheck(s) /* check lamp type */
99     char *s;
100     {
101     lampcolor = matchlamp(s);
102     return(lampcolor != NULL);
103     }
104    
105    
106     unitcheck(s) /* compute conversion to meters */
107     char *s;
108     {
109     int len = strlen(s);
110    
111     switch (*s) {
112     case 'm':
113     if (strncmp(s, "meters", len))
114     return(0);
115     unit2meter = 1.0;
116     return(1);
117     case 'c':
118     if (strncmp(s, "centimeters", len) && strncmp(s, "cms", len))
119     return(0);
120     unit2meter = 0.01;
121     return(1);
122     case 'f':
123     if (strncmp(s, "foot", len) && strncmp(s, "feet", len))
124     return(0);
125     unit2meter = 0.3048;
126     return(1);
127     case 'i':
128     if (strncmp(s, "inches", len))
129     return(0);
130     unit2meter = 0.0254;
131     return(1);
132     }
133     return(0);
134     }
135    
136    
137     geomcheck(s) /* check/set lamp geometry */
138     char *s;
139     {
140     int len = strlen(s);
141    
142     switch (*s) {
143     case 'p':
144     if (strncmp(s, "polygonal", len))
145     return(0);
146     return(getpolygon());
147     case 's':
148     if (strncmp(s, "sphere", len) && strncmp(s, "spherical", len))
149     return(0);
150     return(getsphere());
151     case 'c':
152     if (strncmp(s,"cylinder",len) && strncmp(s,"cylindrical",len))
153     return(0);
154     return(getcylinder());
155     case 'r':
156     if (strncmp(s, "ring", len) && strncmp(s, "disk", len))
157     return(0);
158     return(getring());
159     }
160     return(0);
161     }
162    
163    
164     outpcheck(s) /* check lumen output value */
165     register char *s;
166     {
167     if ((*s < '0' || *s > '9') && *s != '.')
168     return(0);
169     lumens = atof(s);
170     return(1);
171     }
172    
173    
174     compute() /* compute lamp radiance */
175     {
176     double whiteval;
177    
178 greg 1.8 whiteval = lumens/area/(WHTEFFICACY*PI);
179 greg 1.2
180     printf("Lamp color (RGB) = %f %f %f\n",
181     lampcolor[0]*whiteval,
182     lampcolor[1]*whiteval,
183     lampcolor[2]*whiteval);
184     }
185    
186    
187 greg 1.6 getd(name, dp, help) /* get a positive double from stdin */
188     char *name;
189 greg 1.2 double *dp;
190 greg 1.6 char *help;
191 greg 1.2 {
192     char buf[32];
193 greg 1.6 again:
194     printf("%s [%g]: ", name, *dp);
195 greg 1.2 if (gets(buf) == NULL)
196     return(0);
197 greg 1.6 if (buf[0] == '?') {
198     puts(help);
199     goto again;
200     }
201 greg 1.2 if ((buf[0] < '0' || buf[0] > '9') && buf[0] != '.')
202     return(0);
203     *dp = atof(buf);
204     return(1);
205     }
206    
207    
208     getpolygon() /* get projected area for a polygon */
209     {
210 greg 1.9 static double parea = 1.0;
211 greg 1.5
212 greg 1.9 getd("Polygon area", &parea,
213 greg 1.6 "Enter the total radiating area of the polygon.");
214 greg 1.9 area = unit2meter*unit2meter * parea;
215 greg 1.2 return(1);
216     }
217    
218    
219     getsphere() /* get projected area for a sphere */
220     {
221 greg 1.5 static double radius = 1.0;
222 greg 1.2
223 greg 1.6 getd("Sphere radius", &radius,
224     "Enter the distance from the sphere's center to its surface.");
225 greg 1.7 area = 4.*PI*unit2meter*unit2meter * radius*radius;
226 greg 1.2 return(1);
227     }
228    
229    
230     getcylinder() /* get projected area for a cylinder */
231     {
232 greg 1.5 static double length = 1.0, radius = 0.1;
233 greg 1.2
234 greg 1.6 getd("Cylinder length", &length,
235     "Enter the length of the cylinder.");
236     getd("Cylinder radius", &radius,
237     "Enter the distance from the cylinder's axis to its surface.");
238 greg 1.7 area = 2.*PI*unit2meter*unit2meter * radius*length;
239 greg 1.2 return(1);
240     }
241    
242    
243     getring() /* get projected area for a ring */
244     {
245 greg 1.5 static double radius = 1.0;
246 greg 1.2
247 greg 1.6 getd("Disk radius", &radius,
248     "Enter the distance from the ring's center to its outer edge.\n\
249     The inner radius must be zero.");
250 greg 1.7 area = PI*unit2meter*unit2meter * radius*radius;
251 greg 1.2 return(1);
252 greg 1.1 }