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> |
8 |
> |
#include <math.h> |
9 |
|
|
10 |
+ |
#include "rtmath.h" |
11 |
+ |
#include "rtio.h" |
12 |
|
#include "color.h" |
13 |
|
|
15 |
– |
#define PI 3.14159265358979323846 |
16 |
– |
|
17 |
– |
extern char *gets(), *strcpy(); |
18 |
– |
extern double atof(); |
19 |
– |
extern float *matchlamp(); |
20 |
– |
|
14 |
|
/* lamp parameters */ |
15 |
|
#define LTYPE 0 |
16 |
|
#define LUNIT 1 |
18 |
|
#define LOUTP 3 |
19 |
|
#define NPARAMS 4 |
20 |
|
|
21 |
< |
int typecheck(), unitcheck(), geomcheck(), outpcheck(); |
21 |
> |
static int typecheck(char *s); |
22 |
> |
static int unitcheck(char *s); |
23 |
> |
static int geomcheck(char *s); |
24 |
> |
static int outpcheck(char *s); |
25 |
> |
static void compute(void); |
26 |
> |
static int getpolygon(void), getsphere(void), getcylinder(void), getring(void); |
27 |
> |
static int getd(char *name, double *dp, char *help); |
28 |
|
|
29 |
+ |
|
30 |
|
float *lampcolor; /* the lamp color (RGB) */ |
31 |
|
double unit2meter; /* conversion from units to meters */ |
32 |
|
double area; /* radiating area for this geometry */ |
38 |
|
int (*check)(); |
39 |
|
char *help; |
40 |
|
} param[NPARAMS] = { |
41 |
< |
{ "lamp type", "white", typecheck, |
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\ |
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\ |
56 |
|
}; |
57 |
|
|
58 |
|
|
59 |
< |
main(argc, argv) |
60 |
< |
int argc; |
61 |
< |
char *argv[]; |
59 |
> |
int |
60 |
> |
main( |
61 |
> |
int argc, |
62 |
> |
char *argv[] |
63 |
> |
) |
64 |
|
{ |
65 |
|
char *lamptab = "lamp.tab"; |
66 |
|
char buf[64]; |
77 |
|
while (i < NPARAMS) { |
78 |
|
printf("Enter %s [%s]: ", param[i].name, |
79 |
|
param[i].value); |
80 |
< |
if (gets(buf) == NULL) |
80 |
> |
if (fgetline(buf, sizeof(buf), stdin) == NULL) |
81 |
|
exit(0); |
82 |
|
if (buf[0] == '?') { |
83 |
|
puts(param[i].help); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
< |
typecheck(s) /* check lamp type */ |
101 |
< |
char *s; |
100 |
> |
static int |
101 |
> |
typecheck( /* check lamp type */ |
102 |
> |
char *s |
103 |
> |
) |
104 |
|
{ |
105 |
|
lampcolor = matchlamp(s); |
106 |
|
return(lampcolor != NULL); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
< |
unitcheck(s) /* compute conversion to meters */ |
111 |
< |
char *s; |
110 |
> |
static int |
111 |
> |
unitcheck( /* compute conversion to meters */ |
112 |
> |
char *s |
113 |
> |
) |
114 |
|
{ |
115 |
|
int len = strlen(s); |
116 |
|
|
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
< |
geomcheck(s) /* check/set lamp geometry */ |
144 |
< |
char *s; |
143 |
> |
static int |
144 |
> |
geomcheck( /* check/set lamp geometry */ |
145 |
> |
char *s |
146 |
> |
) |
147 |
|
{ |
148 |
|
int len = strlen(s); |
149 |
|
|
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
< |
outpcheck(s) /* check lumen output value */ |
173 |
< |
register char *s; |
172 |
> |
static int |
173 |
> |
outpcheck( /* check lumen output value */ |
174 |
> |
register char *s |
175 |
> |
) |
176 |
|
{ |
177 |
|
if ((*s < '0' || *s > '9') && *s != '.') |
178 |
|
return(0); |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
< |
compute() /* compute lamp radiance */ |
184 |
> |
static void |
185 |
> |
compute(void) /* compute lamp radiance */ |
186 |
|
{ |
187 |
|
double whiteval; |
188 |
|
|
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
< |
getd(name, dp, help) /* get a positive double from stdin */ |
199 |
< |
char *name; |
200 |
< |
double *dp; |
201 |
< |
char *help; |
198 |
> |
static int |
199 |
> |
getd( /* get a positive double from stdin */ |
200 |
> |
char *name, |
201 |
> |
double *dp, |
202 |
> |
char *help |
203 |
> |
) |
204 |
|
{ |
205 |
|
char buf[32]; |
206 |
|
again: |
207 |
|
printf("%s [%g]: ", name, *dp); |
208 |
< |
if (gets(buf) == NULL) |
208 |
> |
if (fgets(buf, sizeof(buf), stdin) == NULL) |
209 |
|
return(0); |
210 |
|
if (buf[0] == '?') { |
211 |
|
puts(help); |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
< |
getpolygon() /* get projected area for a polygon */ |
221 |
> |
static int |
222 |
> |
getpolygon(void) /* get projected area for a polygon */ |
223 |
|
{ |
224 |
|
static double parea = 1.0; |
225 |
|
|
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
< |
getsphere() /* get projected area for a sphere */ |
233 |
> |
static int |
234 |
> |
getsphere(void) /* get projected area for a sphere */ |
235 |
|
{ |
236 |
|
static double radius = 1.0; |
237 |
|
|
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
< |
getcylinder() /* get projected area for a cylinder */ |
245 |
> |
static int |
246 |
> |
getcylinder(void) /* get projected area for a cylinder */ |
247 |
|
{ |
248 |
|
static double length = 1.0, radius = 0.1; |
249 |
|
|
256 |
|
} |
257 |
|
|
258 |
|
|
259 |
< |
getring() /* get projected area for a ring */ |
259 |
> |
static int |
260 |
> |
getring(void) /* get projected area for a ring */ |
261 |
|
{ |
262 |
|
static double radius = 1.0; |
263 |
|
|