ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/lampcolor.c
Revision: 1.5
Committed: Thu Sep 12 13:26:16 1991 UTC (33 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +19 -27 lines
Log Message:
added defaults to geometries

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