1 |
|
#ifndef lint |
2 |
|
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
< |
/* EVALGLARE V1.31 |
4 |
> |
/* EVALGLARE V2.00 |
5 |
|
* Evalglare Software License, Version 2.0 |
6 |
|
* |
7 |
|
* Copyright (c) 1995 - 2016 Fraunhofer ISE, EPFL. |
312 |
|
*/ |
313 |
|
/* evalglare.c, v1.31 2016/08/02 bug removal: default output did not calculate the amout of glare sources before and therefore no_glaresources was set to zero causing dgi,ugr being set to zero as well. Now renumbering of the glare sources and calculation of the amount of glare sources is done for all output versions. |
314 |
|
*/ |
315 |
+ |
/* evalglare.c, v2.00 2016/11/15 add of a second fast calculation mode for annual calculations, activted by -2. Output: dgp,ugr |
316 |
+ |
*/ |
317 |
+ |
/* evalglare.c, v2.01 2016/11/16 change of -2 option (now -2 dir_illum). External provision of the direct illuminance necessary, since the sun interpolation of daysim is causing problems in calculation of the background luminance. |
318 |
+ |
*/ |
319 |
+ |
/* evalglare.c, v2.02 2017/02/28 change of warning message, when invalid exposure setting is found. Reason: tab removal is not in all cases the right measure - it depends which tool caused the invalid exposure entry */ |
320 |
+ |
|
321 |
+ |
/* evalglare.c, v2.03 2017/08/12 ad of -O option - disk replacement by providing luminance, not documented |
322 |
+ |
remove some minor memory leakages, clean up initialization by C. Reetz |
323 |
+ |
*/ |
324 |
+ |
|
325 |
+ |
|
326 |
+ |
|
327 |
+ |
#ifndef EVALGLARE |
328 |
|
#define EVALGLARE |
329 |
+ |
#endif |
330 |
|
#define PROGNAME "evalglare" |
331 |
< |
#define VERSION "1.31 release 02.08.2016 by EPFL, J.Wienold" |
331 |
> |
#define VERSION "2.03 release 12.08.2017 by EPFL, J.Wienold" |
332 |
|
#define RELEASENAME PROGNAME " " VERSION |
333 |
|
|
334 |
|
|
1215 |
|
} |
1216 |
|
} |
1217 |
|
ugr = 8 * log10(0.25 / lum_backg * sum_glare); |
1218 |
< |
|
1218 |
> |
if (sum_glare==0) { |
1219 |
> |
ugr=0.0; |
1220 |
> |
} |
1221 |
> |
if (lum_backg<=0) { |
1222 |
> |
ugr=-99.0; |
1223 |
> |
} |
1224 |
> |
|
1225 |
|
return ugr; |
1226 |
|
|
1227 |
|
} |
1396 |
|
i_split, posindex_2, task_lum, checkfile, rval, i, i_max, x, y,x2,y2,x_zone,y_zone, i_z1, i_z2, |
1397 |
|
igs, actual_igs, lastpixelwas_gs, icol, xt, yt, change,checkpixels, before_igs, sgs, splithigh,uniform_gs,x_max, y_max,y_mid, |
1398 |
|
detail_out, posindex_picture, non_cos_lb, rx, ry, rmx,rmy,apply_disability,band_calc,band_color,masking,i_mask,no_glaresources,force; |
1399 |
< |
double lum_total_max,age_corr_factor,age,dgp_ext,dgp,low_light_corr,omega_cos_contr, setvalue, lum_ideal, E_v_contr, sigma,om,delta_E, |
1399 |
> |
double LUM_replace,lum_total_max,age_corr_factor,age,dgp_ext,dgp,low_light_corr,omega_cos_contr, setvalue, lum_ideal, E_v_contr, sigma,om,delta_E, |
1400 |
|
E_vl_ext, lum_max, new_lum_max, r_center, ugp, ugr_exp, dgi_mod,lum_a, pgsv,E_v_mask,pgsv_sat,angle_disk,dist,n_corner_px,zero_corner_px, |
1401 |
< |
search_pix, a1, a2, a3, a4, a5, c3, c1, c2, r_split, max_angle,r_actual,lum_actual, |
1401 |
> |
search_pix, a1, a2, a3, a4, a5, c3, c1, c2, r_split, max_angle,r_actual,lum_actual,dir_ill, |
1402 |
|
omegat, sang, E_v, E_v2, E_v_dir, avlum, act_lum, ang, angle_z1, angle_z2,per_95_band,per_75_band,pos, |
1403 |
|
l_max, lum_backg, lum_backg_cos, omega_sources, lum_sources,per_75_mask,per_95_mask,per_75_z1,per_95_z1,per_75_z2,per_95_z2, |
1404 |
|
lum, lum_source,teta,Lveil_cie,Lveil_cie_sum,disability_thresh,u_r,u_g,u_b,band_angle,band_avlum, |
1410 |
|
float lum_task, lum_thres, dgi, vcp, cgi, ugr, limit, dgr, |
1411 |
|
abs_max, Lveil; |
1412 |
|
char maskfile[500],file_out[500], file_out2[500], version[500]; |
1413 |
< |
char *cline; |
1413 |
> |
char *cline = NULL; |
1414 |
|
VIEW userview = STDVIEW; |
1415 |
|
int gotuserview = 0; |
1416 |
< |
struct muc_rvar* s_mask; |
1416 |
> |
struct muc_rvar* s_mask = NULL; |
1417 |
> |
struct muc_rvar* s_band = NULL; |
1418 |
> |
struct muc_rvar* s_z1 = NULL; |
1419 |
> |
struct muc_rvar* s_z2 = NULL; |
1420 |
> |
struct muc_rvar* s_noposweight = NULL; |
1421 |
> |
struct muc_rvar* s_posweight = NULL; |
1422 |
> |
struct muc_rvar* s_posweight2 = NULL; |
1423 |
> |
|
1424 |
> |
// initializing variables .... |
1425 |
> |
Lveil = lum_backg_cos = 0; |
1426 |
> |
dgi = ugr = ugp = ugr_exp = dgi_mod = cgi = dgr = vcp = 0.0; |
1427 |
> |
lum_task = lum_thres = limit = 0; |
1428 |
|
s_mask = muc_rvar_create(); |
1429 |
< |
muc_rvar_set_dim(s_mask, 1); |
1429 |
> |
muc_rvar_set_dim(s_mask, 1); |
1430 |
|
muc_rvar_clear(s_mask); |
1400 |
– |
struct muc_rvar* s_band; |
1431 |
|
s_band = muc_rvar_create(); |
1432 |
< |
muc_rvar_set_dim(s_band, 1); |
1432 |
> |
muc_rvar_set_dim(s_band, 1); |
1433 |
|
muc_rvar_clear(s_band); |
1404 |
– |
struct muc_rvar* s_z1; |
1434 |
|
s_z1 = muc_rvar_create(); |
1435 |
< |
muc_rvar_set_dim(s_z1, 1); |
1435 |
> |
muc_rvar_set_dim(s_z1, 1); |
1436 |
|
muc_rvar_clear(s_z1); |
1437 |
|
|
1409 |
– |
struct muc_rvar* s_z2; |
1438 |
|
s_z2 = muc_rvar_create(); |
1439 |
< |
muc_rvar_set_dim(s_z2, 1); |
1439 |
> |
muc_rvar_set_dim(s_z2, 1); |
1440 |
|
muc_rvar_clear(s_z2); |
1441 |
|
|
1414 |
– |
struct muc_rvar* s_noposweight; |
1442 |
|
s_noposweight = muc_rvar_create(); |
1443 |
< |
muc_rvar_set_dim(s_noposweight, 1); |
1443 |
> |
muc_rvar_set_dim(s_noposweight, 1); |
1444 |
|
muc_rvar_clear(s_noposweight); |
1445 |
|
|
1419 |
– |
struct muc_rvar* s_posweight; |
1446 |
|
s_posweight = muc_rvar_create(); |
1447 |
< |
muc_rvar_set_dim(s_posweight, 1); |
1447 |
> |
muc_rvar_set_dim(s_posweight, 1); |
1448 |
|
muc_rvar_clear(s_posweight); |
1449 |
|
|
1424 |
– |
struct muc_rvar* s_posweight2; |
1450 |
|
s_posweight2 = muc_rvar_create(); |
1451 |
< |
muc_rvar_set_dim(s_posweight2, 1); |
1451 |
> |
muc_rvar_set_dim(s_posweight2, 1); |
1452 |
|
muc_rvar_clear(s_posweight2); |
1453 |
|
|
1454 |
|
/*set required user view parameters to invalid values*/ |
1455 |
+ |
dir_ill=0.0; |
1456 |
|
delta_E=0.0; |
1457 |
|
no_glaresources=0; |
1458 |
|
n_corner_px=0; |
1555 |
|
omega_mask=0.0; |
1556 |
|
i_mask=0; |
1557 |
|
actual_igs=0; |
1558 |
+ |
LUM_replace=0; |
1559 |
|
/* command line for output picture*/ |
1560 |
|
|
1561 |
|
cline = (char *) malloc(CLINEMAX+1); |
1694 |
|
strcpy(file_out2, argv[++i]); |
1695 |
|
/* printf("max lum set to %f\n",new_lum_max);*/ |
1696 |
|
break; |
1697 |
+ |
case 'O': |
1698 |
+ |
img_corr = 1; |
1699 |
+ |
set_lum_max2 = 3; |
1700 |
+ |
x_disk = atoi(argv[++i]); |
1701 |
+ |
y_disk = atoi(argv[++i]); |
1702 |
+ |
angle_disk = atof(argv[++i]); |
1703 |
+ |
LUM_replace = atof(argv[++i]); |
1704 |
+ |
strcpy(file_out2, argv[++i]); |
1705 |
+ |
/* printf("max lum set to %f\n",new_lum_max);*/ |
1706 |
+ |
break; |
1707 |
|
|
1708 |
+ |
|
1709 |
|
case 'n': |
1710 |
|
non_cos_lb = 0; |
1711 |
|
break; |
1777 |
|
case '1': |
1778 |
|
output = 1; |
1779 |
|
break; |
1780 |
+ |
case '2': |
1781 |
+ |
output = 2; |
1782 |
+ |
dir_ill = atof(argv[++i]); |
1783 |
+ |
break; |
1784 |
|
|
1785 |
|
case 'v': |
1786 |
|
if (argv[i][2] == '\0') { |
1812 |
|
|
1813 |
|
/*fast calculation, if gendgp_profile is used: No Vertical illuminance calculation, only dgp is calculated*/ |
1814 |
|
|
1815 |
< |
if (output == 1 && ext_vill == 1) { |
1815 |
> |
if (output == 1 && ext_vill == 1 ) { |
1816 |
|
calcfast=1; |
1817 |
|
} |
1818 |
+ |
|
1819 |
+ |
if (output == 2 && ext_vill == 1 ) { |
1820 |
+ |
calcfast=2; |
1821 |
+ |
} |
1822 |
+ |
|
1823 |
|
/*masking and zoning cannot be applied at the same time*/ |
1824 |
|
|
1825 |
|
if (masking ==1 && zones >0) { |
2108 |
|
lum_pos_mean= lum_pos_mean/sang; |
2109 |
|
lum_pos2_mean= lum_pos2_mean/sang; |
2110 |
|
|
2111 |
< |
if (set_lum_max2 >= 1 && E_v_contr > 0 && (E_vl_ext - E_v) > 0) { |
2111 |
> |
// XXX: sure this works? I'd suggest parenthesis. |
2112 |
> |
if ((set_lum_max2 >= 1 && E_v_contr > 0 && (E_vl_ext - E_v) > 0) || set_lum_max2==3) { |
2113 |
|
|
2114 |
+ |
if (set_lum_max2<3){ |
2115 |
|
lum_ideal = (E_vl_ext - E_v + E_v_contr) / omega_cos_contr; |
2116 |
|
if (set_lum_max2 == 2 && lum_ideal >= 2e9) { |
2117 |
|
printf("warning! luminance of replacement pixels would be larger than 2e9 cd/m2. Value set to 2e9cd/m2!\n") ; |
2122 |
|
} |
2123 |
|
printf("change luminance values!! lum_ideal,setvalue,E_vl_ext,E_v,E_v_contr %f %f %f %f %f\n", |
2124 |
|
lum_ideal, setvalue, E_vl_ext, E_v, E_v_contr); |
2125 |
+ |
}else{setvalue=LUM_replace; |
2126 |
+ |
} |
2127 |
|
|
2128 |
|
|
2129 |
|
for (x = 0; x < pict_get_xsize(p); x++) |
2143 |
|
pict_get_color(p, x, y)[BLU] = |
2144 |
|
setvalue / 179.0; |
2145 |
|
|
2146 |
< |
}else{ if(set_lum_max2 ==2 ) { |
2146 |
> |
}else{ if(set_lum_max2 >1 ) { |
2147 |
|
r_actual =acos(DOT(pict_get_cached_dir(p, x_disk, y_disk), pict_get_cached_dir(p, x, y))) * 2; |
2148 |
|
if (x_disk == x && y_disk==y ) r_actual=0.0; |
2149 |
|
|
2156 |
|
pict_get_color(p, x, y)[BLU] = |
2157 |
|
setvalue / 179.0; |
2158 |
|
|
2159 |
< |
} |
2109 |
< |
|
2110 |
< |
|
2159 |
> |
} |
2160 |
|
} |
2161 |
|
} |
2162 |
|
} |
2272 |
|
/* pict_write(p,"firstscan.pic"); */ |
2273 |
|
|
2274 |
|
|
2275 |
< |
if (calcfast == 1 || search_pix <= 1.0) { |
2275 |
> |
|
2276 |
> |
|
2277 |
> |
if (calcfast ==1 || search_pix <= 1.0 || calcfast == 2 ) { |
2278 |
|
skip_second_scan=1; |
2279 |
|
} |
2280 |
+ |
|
2281 |
|
|
2282 |
|
/* second glare source scan: combine glare sources facing each other */ |
2283 |
|
change = 1; |
2452 |
|
|
2453 |
|
/* calculation of direct vertical illuminance for CGI and for disability glare, coloring glare sources*/ |
2454 |
|
|
2455 |
< |
if (calcfast == 0) { |
2455 |
> |
if (calcfast == 0 || calcfast == 2) { |
2456 |
|
for (x = 0; x < pict_get_xsize(p); x++) |
2457 |
|
for (y = 0; y < pict_get_ysize(p); y++) { |
2458 |
|
if (pict_get_hangle(p, x, y, p->view.vdir, p->view.vup, &ang)) { |
2876 |
|
if (E_vl_ext < 1000) { |
2877 |
|
low_light_corr=1.0*exp(0.024*E_vl_ext-4)/(1+exp(0.024*E_vl_ext-4)); } else {low_light_corr=1.0 ;} |
2878 |
|
dgp =low_light_corr*dgp; |
2879 |
< |
dgp =age_corr_factor*dgp; |
2880 |
< |
printf("%f\n", dgp); |
2879 |
> |
|
2880 |
> |
if (calcfast == 2) { |
2881 |
> |
|
2882 |
> |
lum_backg_cos=(E_vl_ext-dir_ill)/3.1415927; |
2883 |
> |
ugr = get_ugr(p, lum_backg_cos, igs, posindex_2); |
2884 |
> |
printf("%f %f \n", dgp,ugr); |
2885 |
> |
}else{ |
2886 |
> |
printf("%f\n", dgp); |
2887 |
> |
} |
2888 |
|
} |
2889 |
|
|
2890 |
|
|
2921 |
|
} |
2922 |
|
|
2923 |
|
|
2924 |
< |
|
2924 |
> |
pict_free(p); |
2925 |
> |
pict_free(pm); |
2926 |
> |
muc_rvar_free(s_mask); |
2927 |
> |
muc_rvar_free(s_band); |
2928 |
> |
muc_rvar_free(s_z1); |
2929 |
> |
muc_rvar_free(s_z2); |
2930 |
> |
muc_rvar_free(s_noposweight); |
2931 |
> |
muc_rvar_free(s_posweight); |
2932 |
> |
muc_rvar_free(s_posweight2); |
2933 |
> |
free(cline); |
2934 |
|
return EXIT_SUCCESS; |
2867 |
– |
exit(0); |
2935 |
|
|
2936 |
|
userr: |
2937 |
|
fprintf(stderr, |
2938 |
|
"Usage: %s [-s][-d][-c picture][-t xpos ypos angle] [-T xpos ypos angle] [-b fact] [-r angle] [-y] [-Y lum] [-i Ev] [-I Ev ymax ymin] [-v] picfile\n", |
2939 |
|
progname); |
2940 |
< |
exit(1); |
2940 |
> |
pict_free(p); |
2941 |
> |
pict_free(pm); |
2942 |
> |
muc_rvar_free(s_mask); |
2943 |
> |
muc_rvar_free(s_band); |
2944 |
> |
muc_rvar_free(s_z1); |
2945 |
> |
muc_rvar_free(s_z2); |
2946 |
> |
muc_rvar_free(s_noposweight); |
2947 |
> |
muc_rvar_free(s_posweight); |
2948 |
> |
muc_rvar_free(s_posweight2); |
2949 |
> |
free(cline); |
2950 |
> |
return 1; |
2951 |
|
} |
2952 |
|
|
2953 |
|
|