ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/lampcolor.c
(Generate patch)

Comparing ray/src/cv/lampcolor.c (file contents):
Revision 1.6 by greg, Thu Sep 12 13:36:43 1991 UTC vs.
Revision 2.8 by greg, Sat Jun 21 15:05:01 2003 UTC

# Line 1 | Line 1
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 < #define PI      3.14159265358979323846
12 > #include "standard.h"
13 > #include "color.h"
14  
15 extern char     *gets(), *strcpy();
16 extern double   atof();
17 extern float    *matchlamp();
18
15                                  /* lamp parameters */
16   #define LTYPE           0
17   #define LUNIT           1
# Line 23 | Line 19 | extern float   *matchlamp();
19   #define LOUTP           3
20   #define NPARAMS         4
21  
22 < int     typecheck(), unitcheck(), geomcheck(), outpcheck();
22 > static int typecheck(char *s);
23 > static int unitcheck(char *s);
24 > static int geomcheck(char *s);
25 > static int outpcheck(char *s);
26 > static void compute(void);
27 > static int getpolygon(void), getsphere(void), getcylinder(void), getring(void);
28  
29 +
30   float   *lampcolor;             /* the lamp color (RGB) */
31   double  unit2meter;             /* conversion from units to meters */
32 < double  projarea;               /* projected area for this geometry */
32 > double  area;                   /* radiating area for this geometry */
33   double  lumens;                 /* total lamp lumens */
34  
35   struct {
# Line 36 | Line 38 | struct {
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\
# Line 93 | Line 95 | char   *argv[];
95   }
96  
97  
98 < typecheck(s)                    /* check lamp type */
99 < char    *s;
98 > static int
99 > typecheck(                      /* check lamp type */
100 > char    *s
101 > )
102   {
103          lampcolor = matchlamp(s);
104          return(lampcolor != NULL);
105   }
106  
107  
108 < unitcheck(s)                    /* compute conversion to meters */
109 < char    *s;
108 > static int
109 > unitcheck(                      /* compute conversion to meters */
110 > char    *s
111 > )
112   {
113          int     len = strlen(s);
114  
# Line 132 | Line 138 | char   *s;
138   }
139  
140  
141 < geomcheck(s)                    /* check/set lamp geometry */
142 < char    *s;
141 > static int
142 > geomcheck(                      /* check/set lamp geometry */
143 > char    *s
144 > )
145   {
146          int     len = strlen(s);
147  
# Line 159 | Line 167 | char   *s;
167   }
168  
169  
170 < outpcheck(s)                    /* check lumen output value */
171 < register char   *s;
170 > static int
171 > outpcheck(                      /* check lumen output value */
172 > register char   *s
173 > )
174   {
175          if ((*s < '0' || *s > '9') && *s != '.')
176                  return(0);
# Line 169 | Line 179 | register char  *s;
179   }
180  
181  
182 < compute()                       /* compute lamp radiance */
182 > static void
183 > compute(void)                   /* compute lamp radiance */
184   {
185          double  whiteval;
186  
187 <        whiteval = lumens/470./projarea;
187 >        whiteval = lumens/area/(WHTEFFICACY*PI);
188  
189          printf("Lamp color (RGB) = %f %f %f\n",
190                          lampcolor[0]*whiteval,
# Line 203 | Line 214 | again:
214   }
215  
216  
217 < getpolygon()                    /* get projected area for a polygon */
217 > static int
218 > getpolygon(void)                        /* get projected area for a polygon */
219   {
220 <        static double   area = 1.0;
220 >        static double   parea = 1.0;
221  
222 <        getd("Polygon area", &area,
222 >        getd("Polygon area", &parea,
223                  "Enter the total radiating area of the polygon.");
224 <        projarea = PI*unit2meter*unit2meter * area;
224 >        area = unit2meter*unit2meter * parea;
225          return(1);
226   }
227  
228  
229 < getsphere()                     /* get projected area for a sphere */
229 > static int
230 > getsphere(void)                 /* get projected area for a sphere */
231   {
232          static double   radius = 1.0;
233  
234          getd("Sphere radius", &radius,
235                  "Enter the distance from the sphere's center to its surface.");
236 <        projarea = 4.*PI*PI*unit2meter*unit2meter * radius*radius;
236 >        area = 4.*PI*unit2meter*unit2meter * radius*radius;
237          return(1);
238   }
239  
240  
241 < getcylinder()                   /* get projected area for a cylinder */
241 > static int
242 > getcylinder(void)                       /* get projected area for a cylinder */
243   {
244          static double   length = 1.0, radius = 0.1;
245  
# Line 233 | Line 247 | getcylinder()                  /* get projected area for a cylinder *
247                  "Enter the length of the cylinder.");
248          getd("Cylinder radius", &radius,
249                  "Enter the distance from the cylinder's axis to its surface.");
250 <        projarea = PI*PI*2.*PI*unit2meter*unit2meter * radius*length;
250 >        area = 2.*PI*unit2meter*unit2meter * radius*length;
251          return(1);
252   }
253  
254  
255 < getring()                       /* get projected area for a ring */
255 > static int
256 > getring(void)                   /* get projected area for a ring */
257   {
258          static double   radius = 1.0;
259  
260          getd("Disk radius", &radius,
261   "Enter the distance from the ring's center to its outer edge.\n\
262   The inner radius must be zero.");
263 <        projarea = PI*PI*unit2meter*unit2meter * radius*radius;
263 >        area = PI*unit2meter*unit2meter * radius*radius;
264          return(1);
265   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines