1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Program to convert lamp color from table and compute radiance. |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <string.h> |
10 |
+ |
#include <math.h> |
11 |
|
|
12 |
+ |
#include "rtmath.h" |
13 |
+ |
#include "rtio.h" |
14 |
|
#include "color.h" |
15 |
|
|
15 |
– |
#define PI 3.14159265358979323846 |
16 |
– |
|
17 |
– |
extern char *gets(), *strcpy(); |
18 |
– |
#ifndef atof |
19 |
– |
extern double atof(); |
20 |
– |
#endif |
21 |
– |
extern float *matchlamp(); |
22 |
– |
|
16 |
|
/* lamp parameters */ |
17 |
|
#define LTYPE 0 |
18 |
|
#define LUNIT 1 |
20 |
|
#define LOUTP 3 |
21 |
|
#define NPARAMS 4 |
22 |
|
|
23 |
< |
int typecheck(), unitcheck(), geomcheck(), outpcheck(); |
23 |
> |
static int typecheck(char *s); |
24 |
> |
static int unitcheck(char *s); |
25 |
> |
static int geomcheck(char *s); |
26 |
> |
static int outpcheck(char *s); |
27 |
> |
static void compute(void); |
28 |
> |
static int getpolygon(void), getsphere(void), getcylinder(void), getring(void); |
29 |
> |
static int getd(char *name, double *dp, char *help); |
30 |
|
|
31 |
+ |
|
32 |
|
float *lampcolor; /* the lamp color (RGB) */ |
33 |
|
double unit2meter; /* conversion from units to meters */ |
34 |
|
double area; /* radiating area for this geometry */ |
40 |
|
int (*check)(); |
41 |
|
char *help; |
42 |
|
} param[NPARAMS] = { |
43 |
< |
{ "lamp type", "white", typecheck, |
43 |
> |
{ "lamp type", "WHITE", typecheck, |
44 |
|
"The lamp type is a string which corresponds to one of the types registered\n\ |
45 |
< |
in the lamp table file. A value of \"white\" means an uncolored source,\n\ |
45 |
> |
in the lamp table file. A value of \"WHITE\" means an uncolored source,\n\ |
46 |
|
which may be preferable because it results in a color balanced image." }, |
47 |
|
{ "length unit", "meter", unitcheck, |
48 |
|
"Unit must be one of: \"meter\", \"centimeter\", \"foot\", or \"inch\".\n\ |
58 |
|
}; |
59 |
|
|
60 |
|
|
61 |
< |
main(argc, argv) |
62 |
< |
int argc; |
63 |
< |
char *argv[]; |
61 |
> |
int |
62 |
> |
main( |
63 |
> |
int argc, |
64 |
> |
char *argv[] |
65 |
> |
) |
66 |
|
{ |
67 |
|
char *lamptab = "lamp.tab"; |
68 |
|
char buf[64]; |
79 |
|
while (i < NPARAMS) { |
80 |
|
printf("Enter %s [%s]: ", param[i].name, |
81 |
|
param[i].value); |
82 |
< |
if (gets(buf) == NULL) |
82 |
> |
if (fgetline(buf, sizeof(buf), stdin) == NULL) |
83 |
|
exit(0); |
84 |
|
if (buf[0] == '?') { |
85 |
|
puts(param[i].help); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
< |
typecheck(s) /* check lamp type */ |
103 |
< |
char *s; |
102 |
> |
static int |
103 |
> |
typecheck( /* check lamp type */ |
104 |
> |
char *s |
105 |
> |
) |
106 |
|
{ |
107 |
|
lampcolor = matchlamp(s); |
108 |
|
return(lampcolor != NULL); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
< |
unitcheck(s) /* compute conversion to meters */ |
113 |
< |
char *s; |
112 |
> |
static int |
113 |
> |
unitcheck( /* compute conversion to meters */ |
114 |
> |
char *s |
115 |
> |
) |
116 |
|
{ |
117 |
|
int len = strlen(s); |
118 |
|
|
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
< |
geomcheck(s) /* check/set lamp geometry */ |
146 |
< |
char *s; |
145 |
> |
static int |
146 |
> |
geomcheck( /* check/set lamp geometry */ |
147 |
> |
char *s |
148 |
> |
) |
149 |
|
{ |
150 |
|
int len = strlen(s); |
151 |
|
|
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
< |
outpcheck(s) /* check lumen output value */ |
175 |
< |
register char *s; |
174 |
> |
static int |
175 |
> |
outpcheck( /* check lumen output value */ |
176 |
> |
register char *s |
177 |
> |
) |
178 |
|
{ |
179 |
|
if ((*s < '0' || *s > '9') && *s != '.') |
180 |
|
return(0); |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
< |
compute() /* compute lamp radiance */ |
186 |
> |
static void |
187 |
> |
compute(void) /* compute lamp radiance */ |
188 |
|
{ |
189 |
|
double whiteval; |
190 |
|
|
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
< |
getd(name, dp, help) /* get a positive double from stdin */ |
201 |
< |
char *name; |
202 |
< |
double *dp; |
203 |
< |
char *help; |
200 |
> |
static int |
201 |
> |
getd( /* get a positive double from stdin */ |
202 |
> |
char *name, |
203 |
> |
double *dp, |
204 |
> |
char *help |
205 |
> |
) |
206 |
|
{ |
207 |
|
char buf[32]; |
208 |
|
again: |
209 |
|
printf("%s [%g]: ", name, *dp); |
210 |
< |
if (gets(buf) == NULL) |
210 |
> |
if (fgets(buf, sizeof(buf), stdin) == NULL) |
211 |
|
return(0); |
212 |
|
if (buf[0] == '?') { |
213 |
|
puts(help); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
< |
getpolygon() /* get projected area for a polygon */ |
223 |
> |
static int |
224 |
> |
getpolygon(void) /* get projected area for a polygon */ |
225 |
|
{ |
226 |
|
static double parea = 1.0; |
227 |
|
|
232 |
|
} |
233 |
|
|
234 |
|
|
235 |
< |
getsphere() /* get projected area for a sphere */ |
235 |
> |
static int |
236 |
> |
getsphere(void) /* get projected area for a sphere */ |
237 |
|
{ |
238 |
|
static double radius = 1.0; |
239 |
|
|
244 |
|
} |
245 |
|
|
246 |
|
|
247 |
< |
getcylinder() /* get projected area for a cylinder */ |
247 |
> |
static int |
248 |
> |
getcylinder(void) /* get projected area for a cylinder */ |
249 |
|
{ |
250 |
|
static double length = 1.0, radius = 0.1; |
251 |
|
|
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
< |
getring() /* get projected area for a ring */ |
261 |
> |
static int |
262 |
> |
getring(void) /* get projected area for a ring */ |
263 |
|
{ |
264 |
|
static double radius = 1.0; |
265 |
|
|