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.7 by schorsch, Sun Jun 8 12:03:09 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 + #include "standard.h"
13 + #include "color.h"
14 +
15   #define PI      3.14159265358979323846
16  
15 extern char     *gets(), *strcpy();
16 extern double   atof();
17 extern float    *matchlamp();
18
17                                  /* lamp parameters */
18   #define LTYPE           0
19   #define LUNIT           1
# Line 23 | Line 21 | extern float   *matchlamp();
21   #define LOUTP           3
22   #define NPARAMS         4
23  
24 < int     typecheck(), unitcheck(), geomcheck(), outpcheck();
24 > static int typecheck(char *s);
25 > static int unitcheck(char *s);
26 > static int geomcheck(char *s);
27 > static int outpcheck(char *s);
28 > static void compute(void);
29 > static int getpolygon(void), getsphere(void), getcylinder(void), getring(void);
30  
31 +
32   float   *lampcolor;             /* the lamp color (RGB) */
33   double  unit2meter;             /* conversion from units to meters */
34 < double  projarea;               /* projected area for this geometry */
34 > double  area;                   /* radiating area for this geometry */
35   double  lumens;                 /* total lamp lumens */
36  
37   struct {
# Line 36 | Line 40 | struct {
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\
# Line 49 | Line 53 | or \"ring\".  These may be abbreviated as a single let
53          { "total lamp lumens", "0", outpcheck,
54   "This is the overall light output of the lamp and its fixture.  If you do\n\
55   not know this value explicitly, you can compute the approximate lumens\n\
56 < by multiplying the input wattage by 15 for incandescent fixtures or 40\n\
56 > by multiplying the input wattage by 14 for incandescent fixtures or 70\n\
57   for fluorescent fixtures." },
58   };
59  
# Line 93 | Line 97 | char   *argv[];
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  
# Line 132 | Line 140 | char   *s;
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  
# Line 159 | Line 169 | char   *s;
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);
# Line 169 | Line 181 | register char  *s;
181   }
182  
183  
184 < compute()                       /* compute lamp radiance */
184 > static void
185 > compute(void)                   /* compute lamp radiance */
186   {
187          double  whiteval;
188  
189 <        whiteval = lumens/470./projarea;
189 >        whiteval = lumens/area/(WHTEFFICACY*PI);
190  
191          printf("Lamp color (RGB) = %f %f %f\n",
192                          lampcolor[0]*whiteval,
# Line 182 | Line 195 | compute()                      /* compute lamp radiance */
195   }
196  
197  
198 < getd(dp)                        /* get a positive double from stdin */
198 > getd(name, dp, help)            /* get a positive double from stdin */
199 > char    *name;
200   double  *dp;
201 + char    *help;
202   {
203          char    buf[32];
204 <
204 > again:
205 >        printf("%s [%g]: ", name, *dp);
206          if (gets(buf) == NULL)
207                  return(0);
208 +        if (buf[0] == '?') {
209 +                puts(help);
210 +                goto again;
211 +        }
212          if ((buf[0] < '0' || buf[0] > '9') && buf[0] != '.')
213                  return(0);
214          *dp = atof(buf);
# Line 196 | Line 216 | double *dp;
216   }
217  
218  
219 < getpolygon()                    /* get projected area for a polygon */
219 > static int
220 > getpolygon(void)                        /* get projected area for a polygon */
221   {
222 <        printf("Enter area of polygon: ");
223 <        if (!getd(&projarea))
224 <                return(0);
225 <        projarea *= unit2meter*unit2meter;
226 <        projarea *= PI;
222 >        static double   parea = 1.0;
223 >
224 >        getd("Polygon area", &parea,
225 >                "Enter the total radiating area of the polygon.");
226 >        area = unit2meter*unit2meter * parea;
227          return(1);
228   }
229  
230  
231 < getsphere()                     /* get projected area for a sphere */
231 > static int
232 > getsphere(void)                 /* get projected area for a sphere */
233   {
234 <        double  radius;
234 >        static double   radius = 1.0;
235  
236 <        printf("Enter sphere radius: ");
237 <        if (!getd(&radius))
238 <                return(0);
217 <        radius *= unit2meter;
218 <        projarea = 4.*PI*PI*radius*radius;
236 >        getd("Sphere radius", &radius,
237 >                "Enter the distance from the sphere's center to its surface.");
238 >        area = 4.*PI*unit2meter*unit2meter * radius*radius;
239          return(1);
240   }
241  
242  
243 < getcylinder()                   /* get projected area for a cylinder */
243 > static int
244 > getcylinder(void)                       /* get projected area for a cylinder */
245   {
246 <        double  length, radius;
246 >        static double   length = 1.0, radius = 0.1;
247  
248 <        printf("Enter cylinder length: ");
249 <        if (!getd(&length))
250 <                return(0);
251 <        length *= unit2meter;
252 <        printf("Enter cylinder radius: ");
232 <        if (!getd(&radius))
233 <                return(0);
234 <        radius *= unit2meter;
235 <        projarea = PI*PI*2.*PI*radius*length;
248 >        getd("Cylinder length", &length,
249 >                "Enter the length of the cylinder.");
250 >        getd("Cylinder radius", &radius,
251 >                "Enter the distance from the cylinder's axis to its surface.");
252 >        area = 2.*PI*unit2meter*unit2meter * radius*length;
253          return(1);
254   }
255  
256  
257 < getring()                       /* get projected area for a ring */
257 > static int
258 > getring(void)                   /* get projected area for a ring */
259   {
260 <        double  radius;
260 >        static double   radius = 1.0;
261  
262 <        printf("Enter disk radius: ");
263 <        if (!getd(&radius))
264 <                return(0);
265 <        radius *= unit2meter;
248 <        projarea = PI*PI*radius*radius;
262 >        getd("Disk radius", &radius,
263 > "Enter the distance from the ring's center to its outer edge.\n\
264 > The inner radius must be zero.");
265 >        area = PI*unit2meter*unit2meter * radius*radius;
266          return(1);
267   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines