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.2 by greg, Thu Sep 5 15:09:08 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 49 | Line 51 | or \"ring\".  These may be abbreviated as a single let
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 < by multiplying the input wattage by 15 for incandescent fixtures or 40\n\
54 > by multiplying the input wattage by 14 for incandescent fixtures or 70\n\
55   for fluorescent fixtures." },
56   };
57  
# 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 182 | Line 193 | compute()                      /* compute lamp radiance */
193   }
194  
195  
196 < getd(dp)                        /* get a positive double from stdin */
196 > getd(name, dp, help)            /* get a positive double from stdin */
197 > char    *name;
198   double  *dp;
199 + char    *help;
200   {
201          char    buf[32];
202 <
202 > again:
203 >        printf("%s [%g]: ", name, *dp);
204          if (gets(buf) == NULL)
205                  return(0);
206 +        if (buf[0] == '?') {
207 +                puts(help);
208 +                goto again;
209 +        }
210          if ((buf[0] < '0' || buf[0] > '9') && buf[0] != '.')
211                  return(0);
212          *dp = atof(buf);
# Line 196 | Line 214 | double *dp;
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 <        printf("Enter area of polygon: ");
221 <        if (!getd(&projarea))
222 <                return(0);
223 <        projarea *= unit2meter*unit2meter;
224 <        projarea *= PI;
220 >        static double   parea = 1.0;
221 >
222 >        getd("Polygon area", &parea,
223 >                "Enter the total radiating area of the polygon.");
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 <        double  radius;
232 >        static double   radius = 1.0;
233  
234 <        printf("Enter sphere radius: ");
235 <        if (!getd(&radius))
236 <                return(0);
217 <        radius *= unit2meter;
218 <        projarea = 4.*PI*PI*radius*radius;
234 >        getd("Sphere radius", &radius,
235 >                "Enter the distance from the sphere's center to its surface.");
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 <        double  length, radius;
244 >        static double   length = 1.0, radius = 0.1;
245  
246 <        printf("Enter cylinder length: ");
247 <        if (!getd(&length))
248 <                return(0);
249 <        length *= unit2meter;
250 <        printf("Enter cylinder radius: ");
232 <        if (!getd(&radius))
233 <                return(0);
234 <        radius *= unit2meter;
235 <        projarea = PI*PI*2.*PI*radius*length;
246 >        getd("Cylinder length", &length,
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 >        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 <        double  radius;
258 >        static double   radius = 1.0;
259  
260 <        printf("Enter disk radius: ");
261 <        if (!getd(&radius))
262 <                return(0);
263 <        radius *= unit2meter;
248 <        projarea = PI*PI*radius*radius;
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 >        area = PI*unit2meter*unit2meter * radius*radius;
264          return(1);
265   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines