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.6 by greg, Sat Feb 22 02:07:23 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  
10 + #include <math.h>
11 +
12 + #include "color.h"
13 +
14   #define PI      3.14159265358979323846
15  
16   extern char     *gets(), *strcpy();
16 extern double   atof();
17   extern float    *matchlamp();
18  
19                                  /* lamp parameters */
# Line 27 | Line 27 | int    typecheck(), unitcheck(), geomcheck(), outpcheck()
27  
28   float   *lampcolor;             /* the lamp color (RGB) */
29   double  unit2meter;             /* conversion from units to meters */
30 < double  projarea;               /* projected area for this geometry */
30 > double  area;                   /* radiating area for this geometry */
31   double  lumens;                 /* total lamp lumens */
32  
33   struct {
# Line 36 | Line 36 | struct {
36          int     (*check)();
37          char    *help;
38   } param[NPARAMS] = {
39 <        { "lamp type", "white", typecheck,
39 >        { "lamp type", "WHITE", typecheck,
40   "The lamp type is a string which corresponds to one of the types registered\n\
41 < in the lamp table file.  A value of \"white\" means an uncolored source,\n\
41 > in the lamp table file.  A value of \"WHITE\" means an uncolored source,\n\
42   which may be preferable because it results in a color balanced image." },
43          { "length unit", "meter", unitcheck,
44   "Unit must be one of:  \"meter\", \"centimeter\", \"foot\", or \"inch\".\n\
# Line 49 | Line 49 | or \"ring\".  These may be abbreviated as a single let
49          { "total lamp lumens", "0", outpcheck,
50   "This is the overall light output of the lamp and its fixture.  If you do\n\
51   not know this value explicitly, you can compute the approximate lumens\n\
52 < by multiplying the input wattage by 15 for incandescent fixtures or 40\n\
52 > by multiplying the input wattage by 14 for incandescent fixtures or 70\n\
53   for fluorescent fixtures." },
54   };
55  
# Line 173 | Line 173 | compute()                      /* compute lamp radiance */
173   {
174          double  whiteval;
175  
176 <        whiteval = lumens/470./projarea;
176 >        whiteval = lumens/area/(WHTEFFICACY*PI);
177  
178          printf("Lamp color (RGB) = %f %f %f\n",
179                          lampcolor[0]*whiteval,
# Line 182 | Line 182 | compute()                      /* compute lamp radiance */
182   }
183  
184  
185 < getd(dp)                        /* get a positive double from stdin */
185 > getd(name, dp, help)            /* get a positive double from stdin */
186 > char    *name;
187   double  *dp;
188 + char    *help;
189   {
190          char    buf[32];
191 <
191 > again:
192 >        printf("%s [%g]: ", name, *dp);
193          if (gets(buf) == NULL)
194                  return(0);
195 +        if (buf[0] == '?') {
196 +                puts(help);
197 +                goto again;
198 +        }
199          if ((buf[0] < '0' || buf[0] > '9') && buf[0] != '.')
200                  return(0);
201          *dp = atof(buf);
# Line 198 | Line 205 | double *dp;
205  
206   getpolygon()                    /* get projected area for a polygon */
207   {
208 <        printf("Enter area of polygon: ");
209 <        if (!getd(&projarea))
210 <                return(0);
211 <        projarea *= unit2meter*unit2meter;
212 <        projarea *= PI;
208 >        static double   parea = 1.0;
209 >
210 >        getd("Polygon area", &parea,
211 >                "Enter the total radiating area of the polygon.");
212 >        area = unit2meter*unit2meter * parea;
213          return(1);
214   }
215  
216  
217   getsphere()                     /* get projected area for a sphere */
218   {
219 <        double  radius;
219 >        static double   radius = 1.0;
220  
221 <        printf("Enter sphere radius: ");
222 <        if (!getd(&radius))
223 <                return(0);
217 <        radius *= unit2meter;
218 <        projarea = 4.*PI*PI*radius*radius;
221 >        getd("Sphere radius", &radius,
222 >                "Enter the distance from the sphere's center to its surface.");
223 >        area = 4.*PI*unit2meter*unit2meter * radius*radius;
224          return(1);
225   }
226  
227  
228   getcylinder()                   /* get projected area for a cylinder */
229   {
230 <        double  length, radius;
230 >        static double   length = 1.0, radius = 0.1;
231  
232 <        printf("Enter cylinder length: ");
233 <        if (!getd(&length))
234 <                return(0);
235 <        length *= unit2meter;
236 <        printf("Enter cylinder radius: ");
232 <        if (!getd(&radius))
233 <                return(0);
234 <        radius *= unit2meter;
235 <        projarea = PI*PI*2.*PI*radius*length;
232 >        getd("Cylinder length", &length,
233 >                "Enter the length of the cylinder.");
234 >        getd("Cylinder radius", &radius,
235 >                "Enter the distance from the cylinder's axis to its surface.");
236 >        area = 2.*PI*unit2meter*unit2meter * radius*length;
237          return(1);
238   }
239  
240  
241   getring()                       /* get projected area for a ring */
242   {
243 <        double  radius;
243 >        static double   radius = 1.0;
244  
245 <        printf("Enter disk radius: ");
246 <        if (!getd(&radius))
247 <                return(0);
248 <        radius *= unit2meter;
248 <        projarea = PI*PI*radius*radius;
245 >        getd("Disk radius", &radius,
246 > "Enter the distance from the ring's center to its outer edge.\n\
247 > The inner radius must be zero.");
248 >        area = PI*unit2meter*unit2meter * radius*radius;
249          return(1);
250   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines