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.10 by greg, Thu Mar 18 05:22:00 2004 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 "rtmath.h"
13 > #include "rtio.h"
14 > #include "color.h"
15  
15 extern char     *gets(), *strcpy();
16 extern double   atof();
17 extern float    *matchlamp();
18
16                                  /* lamp parameters */
17   #define LTYPE           0
18   #define LUNIT           1
# Line 23 | Line 20 | extern float   *matchlamp();
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  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 54 | Line 58 | for fluorescent fixtures." },
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];
# Line 73 | Line 79 | char   *argv[];
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);
# Line 93 | Line 99 | char   *argv[];
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  
# Line 132 | Line 142 | char   *s;
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  
# Line 159 | Line 171 | char   *s;
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);
# Line 169 | Line 183 | register char  *s;
183   }
184  
185  
186 < compute()                       /* compute lamp radiance */
186 > static void
187 > compute(void)                   /* compute lamp radiance */
188   {
189          double  whiteval;
190  
191 <        whiteval = lumens/470./projarea;
191 >        whiteval = lumens/area/(WHTEFFICACY*PI);
192  
193          printf("Lamp color (RGB) = %f %f %f\n",
194                          lampcolor[0]*whiteval,
# Line 182 | Line 197 | compute()                      /* compute lamp radiance */
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);
# Line 203 | Line 220 | again:
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   area = 1.0;
226 >        static double   parea = 1.0;
227  
228 <        getd("Polygon area", &area,
228 >        getd("Polygon area", &parea,
229                  "Enter the total radiating area of the polygon.");
230 <        projarea = PI*unit2meter*unit2meter * area;
230 >        area = unit2meter*unit2meter * parea;
231          return(1);
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  
240          getd("Sphere radius", &radius,
241                  "Enter the distance from the sphere's center to its surface.");
242 <        projarea = 4.*PI*PI*unit2meter*unit2meter * radius*radius;
242 >        area = 4.*PI*unit2meter*unit2meter * radius*radius;
243          return(1);
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  
# Line 233 | Line 253 | getcylinder()                  /* get projected area for a cylinder *
253                  "Enter the length of the cylinder.");
254          getd("Cylinder radius", &radius,
255                  "Enter the distance from the cylinder's axis to its surface.");
256 <        projarea = PI*PI*2.*PI*unit2meter*unit2meter * radius*length;
256 >        area = 2.*PI*unit2meter*unit2meter * radius*length;
257          return(1);
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  
266          getd("Disk radius", &radius,
267   "Enter the distance from the ring's center to its outer edge.\n\
268   The inner radius must be zero.");
269 <        projarea = PI*PI*unit2meter*unit2meter * radius*radius;
269 >        area = PI*unit2meter*unit2meter * radius*radius;
270          return(1);
271   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines