--- ray/src/cv/ies2rad.c 1990/12/11 08:45:48 1.1 +++ ray/src/cv/ies2rad.c 1992/09/08 10:06:29 2.4 @@ -1,4 +1,4 @@ -/* Copyright (c) 1990 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -12,6 +12,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include +#include "color.h" +#include "paths.h" #define PI 3.14159265358979323846 /* floating comparisons */ @@ -34,7 +36,6 @@ static char SCCSid[] = "$SunId$ LBL"; /* string lengths */ #define MAXLINE 132 #define MAXWORD 76 -#define MAXPATH 128 /* file types */ #define T_RAD ".rad" #define T_DST ".dat" @@ -48,26 +49,27 @@ static char SCCSid[] = "$SunId$ LBL"; #define F_M .3048 /* feet to meters */ -#define abspath(p) ((p)[0] == '/' || (p)[0] == '.') +#define abspath(p) (ISDIRSEP((p)[0]) || (p)[0] == '.') +static char default_name[] = "default"; + char *libdir = NULL; /* library directory location */ char *prefdir = NULL; /* subdirectory */ char *lampdat = "lamp.tab"; /* lamp data file */ double meters2out = 1.0; /* conversion from meters to output */ char *lamptype = NULL; /* selected lamp type */ -float *lampcolor = NULL; /* pointer to lamp color */ +char *deflamp = NULL; /* default lamp type */ float defcolor[3] = {1.,1.,1.}; /* default lamp color */ +float *lampcolor = defcolor; /* pointer to current lamp color */ double multiplier = 1.0; /* multiplier for all light sources */ char units[64] = "meters"; /* output units */ -double minaspect = 0.0; /* minimum allowed aspect ratio */ -int maxemitters = 1; /* maximum emitters per hemisphere */ double illumrad = 0.0; /* radius for illum sphere */ typedef struct { int type; /* RECT, DISK, SPHERE */ double w, l, h; /* width, length, height */ - double area; /* effective radiating area */ + double area; /* max. projected area */ } SHAPE; /* a source shape */ int gargc; /* global argc (minus filenames) */ @@ -75,7 +77,6 @@ char **gargv; /* global argv */ extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), *filename(), *libname(), *fullname(), *malloc(); -extern double atof(); extern float *matchlamp(); @@ -153,22 +154,17 @@ char *argv[]; case 'o': /* output file name */ outfile = argv[++i]; break; - case 's': /* square emitters */ - minaspect = .6; - if (argv[i][2] == '/') { - maxemitters = atoi(argv[i]+3); - if (maxemitters < 1) - goto badopt; - } - break; case 'i': /* illum */ illumrad = atof(argv[++i]); if (illumrad < MINDIM) illumrad = MINDIM; break; - case 't': /* select lamp type */ + case 't': /* override lamp type */ lamptype = argv[++i]; break; + case 'u': /* default lamp type */ + deflamp = argv[++i]; + break; case 'c': /* default lamp color */ defcolor[0] = atof(argv[++i]); defcolor[1] = atof(argv[++i]); @@ -185,14 +181,7 @@ char *argv[]; } gargc = i; gargv = argv; - /* get lamp data */ - if ((status = loadlamps(lampdat)) < 0) - exit(1); - if (status == 0 || (lamptype != NULL && - (lampcolor = matchlamp(lamptype)) == NULL)) { - lampcolor = defcolor; - fprintf(stderr, "%s: warning - no lamp data\n", argv[0]); - } + initlamps(); /* get lamp data (if needed) */ /* convert ies file(s) */ if (outfile != NULL) { if (i == argc) @@ -219,6 +208,46 @@ char *argv[]; } +initlamps() /* set up lamps */ +{ + float *lcol; + int status; + + if (lamptype != NULL && !strcmp(lamptype, default_name) && + deflamp == NULL) + return; /* no need for data */ + /* else load file */ + if ((status = loadlamps(lampdat)) < 0) + exit(1); + if (status == 0) { + fprintf(stderr, "%s: warning - no lamp data\n", lampdat); + lamptype = default_name; + return; + } + if (deflamp != NULL) { /* match default type */ + if ((lcol = matchlamp(deflamp)) == NULL) + fprintf(stderr, + "%s: warning - unknown default lamp type\n", + deflamp); + else + copycolor(defcolor, lcol); + } + if (lamptype != NULL) { /* match selected type */ + if (strcmp(lamptype, default_name)) { + if ((lcol = matchlamp(lamptype)) == NULL) { + fprintf(stderr, + "%s: warning - unknown lamp type\n", + lamptype); + lamptype = default_name; + } else + copycolor(defcolor, lcol); + } + freelamps(); /* all done with data */ + } + /* else keep lamp data */ +} + + char * stradd(dst, src, sep) /* add a string at dst */ register char *dst, *src; @@ -245,7 +274,7 @@ char *path, *fname, *suffix; else if (abspath(fname)) strcpy(stradd(path, fname, 0), suffix); else - libname(stradd(path, libdir, '/'), fname, suffix); + libname(stradd(path, libdir, DIRSEP), fname, suffix); return(path); } @@ -258,7 +287,7 @@ char *path, *fname, *suffix; if (abspath(fname)) strcpy(stradd(path, fname, 0), suffix); else - strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix); + strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix); return(path); } @@ -271,7 +300,7 @@ register char *path; register char *cp; for (cp = path; *path; path++) - if (*path == '/') + if (ISDIRSEP(*path)) cp = path+1; return(cp); } @@ -284,7 +313,7 @@ char *path; register char *p1, *p2; for (p1 = p2 = path; *p2; p2++) - if (*p2 == '/') + if (ISDIRSEP(*p2)) p1 = p2; *p1 = '\0'; return(path); @@ -418,10 +447,10 @@ char *dir, *tltspec, *dfltname, *tltid; datin = in; strcpy(tltname, dfltname); } else { - if (tltspec[0] == '/') + if (ISDIRSEP(tltspec[0])) strcpy(buf, tltspec); else - strcpy(stradd(buf, dir, '/'), tltspec); + strcpy(stradd(buf, dir, DIRSEP), tltspec); if ((datin = fopen(buf, "r")) == NULL) { perror(buf); return(-1); @@ -511,7 +540,7 @@ char *mod, *name; perror(buf); return(-1); } - if (cvdata(in, datout, 2, nangles, 1./683., bounds) != 0) { + if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { fprintf(stderr, "dosource: bad distribution data\n"); fclose(datout); unlink(fullname(buf,name,T_DST)); @@ -656,11 +685,9 @@ double width, length, height; shp->area = shp->w * shp->l; break; case DISK: + case SPHERE: shp->area = PI/4. * shp->w * shp->w; break; - case SPHERE: - shp->area = PI * shp->w * shp->w; - break; } return(0); } @@ -769,7 +796,7 @@ FILE *in, *out; int ndim, npts[]; double mult, lim[][2]; { - register double *pt[4]; + double *pt[4]; register int i, j; double val; int total;