ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/evalglare.c
(Generate patch)

Comparing ray/src/util/evalglare.c (file contents):
Revision 2.2 by greg, Tue Aug 18 15:02:53 2015 UTC vs.
Revision 2.6 by greg, Thu May 18 02:25:27 2017 UTC

# Line 1 | Line 1
1   #ifndef lint
2   static const char RCSid[] = "$Id$";
3   #endif
4 < /* EVALGLARE V1.17
5 < * Evalglare Software License, Version 1.0
4 > /* EVALGLARE V2.00
5 > * Evalglare Software License, Version 2.0
6   *
7 < * Copyright (c) 1995 - 2015 Fraunhofer ISE, EPFL.
7 > * Copyright (c) 1995 - 2016 Fraunhofer ISE, EPFL.
8   * All rights reserved.
9   *
10   *
# Line 23 | Line 23 | static const char RCSid[] = "$Id$";
23   * 3. The end-user documentation included with the redistribution,
24   *           if any, must include the following acknowledgments:
25   *             "This product includes the evalglare software,
26 <                developed at Fraunhofer ISE by J. Wienold" and
26 >                developed at Fraunhofer ISE and EPFL by J. Wienold" and
27   *             "This product includes Radiance software
28   *                 (http://radsite.lbl.gov/)
29   *                 developed by the Lawrence Berkeley National Laboratory
# Line 31 | Line 31 | static const char RCSid[] = "$Id$";
31   *       Alternately, this acknowledgment may appear in the software itself,
32   *       if and wherever such third-party acknowledgments normally appear.
33   *
34 < * 4. The names "Evalglare," and "Fraunhofer ISE" must
34 > * 4. The names "Evalglare," "EPFL" and "Fraunhofer ISE" must
35   *       not be used to endorse or promote products derived from this
36   *       software without prior written permission. For written
37   *       permission, please contact [email protected]
38   *
39   * 5. Products derived from this software may not be called "evalglare",
40   *       nor may "evalglare" appear in their name, without prior written
41 < *       permission of Fraunhofer ISE.
41 > *       permission of EPFL.
42   *
43   * Redistribution and use in source and binary forms, WITH
44   * modification, are permitted provided that the following conditions
# Line 48 | Line 48 | static const char RCSid[] = "$Id$";
48   * conditions 1.-5. apply
49   *
50   * 6. In order to ensure scientific correctness, any modification in source code imply fulfilling all following comditions:
51 < *     a) A written permission from Fraunhofer ISE. For written permission, please contact [email protected].
51 > *     a) A written permission from EPFL. For written permission, please contact [email protected].
52   *     b) The permission can be applied via email and must contain the applied changes in source code and at least two example calculations,
53   *        comparing the results of the modified version and the current version of evalglare.
54   *     b) Any redistribution of a modified version of evalglare must contain following note:
# Line 278 | Line 278 | static const char RCSid[] = "$Id$";
278     remove of age factor due to non proven statistical evidence
279     */
280  
281 < #define EVALGLARE
281 > /* evalglare.c, v1.18 2015/11/10 add masking, UDP, PSGV, DGI_mod, UGR_exp and zoning. For zoning and band luminance, a statistical package from C. Reetz was added in order to derive median, std_dev, percentiles.
282 > memory leakage was checked and is o.k.
283 >   */
284  
285 + /* evalglare.c, v1.19 2015/12/04 sorting subroutines in statistical package changed by. C. Reetz, adding Position index weighted Luminance evaluation (mean and median of entire image, only in detailed output available)
286 +   */
287 + /* evalglare.c, v1.20 2015/12/21 removing -ansi gcc-option in makefile for the standalone version, adding DGR as output since VCP equation seems not to match with original publication
288 +   */
289 + /* evalglare.c, v1.21 2016/03/15 add a new pixel-overflow-correction option -N
290 +   */
291 + /* evalglare.c, v1.22 2016/03/22 fixed problem using -N option and angular distance calculation, when actual pixel equals disk-center (arccos returned nan)
292 +   */
293 + /* evalglare.c, v1.23 2016/04/18 fixed problem making black corners for -vth fish-eye images
294 +   */
295 + /* evalglare.c, v1.24 2016/04/26 significant speed improvement for 2nd glare source scan: for other glare sources will not be searched any more, when the 8 surrounding pixels have the same glare source number! Smaller speed improvement in the first glare source scan: remembering if pixel before was also a glare source, then no search for surrounding glare sources is applied.
296 + changed masking threshold to 0.05 cd/m2
297 +   */
298 + /* evalglare.c, v1.25 2016/04/27 removed the change on the first glare source scan: in few cases glare sources are not merged together in the same way as before. Although the difference is marginal, this algorithm was removed in order to be consistent to the existing results.
299 +   */
300 + /* evalglare.c, v1.26 2016/04/28 removed the bug Lb getting nan in case all glare source pixels are above the peak extraction limit.
301 + The calculation of the average source lumiance and solid angle was adapted to be more robust for extreme cases.
302 + In case no glare source is found, the values of the glare metrics, relying only on glare sources, is set to zero (100 for VCP) to avoid nan and -inf in the output.
303 + Changed glare section output when 0 glare source are found to have the same amount of columns than when glare sources are found
304 +   */
305 + /* evalglare.c, v1.27 2016/06/13 include a warning, if -vtv is in the header. Check, if the corners are black AND -vtv is used ->stopping (stopping can be avoided by using the forcing option -f ). Check, if an invalid exposure is in the header -> stopping in any case.
306 +   */
307 + /* evalglare.c, v1.28 2016/07/08 small code changes in the section of calculating the E_glare (disability) for each glare source.
308 +   */
309 + /* evalglare.c, v1.29 2016/07/12 change threshold for the black corner to 2cd/m2.
310 +   */
311 + /* evalglare.c, v1.30 2016/07/28 change zonal output: If just one zone is specified, only one zone shows up in the output (bug removal).
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 + #define EVALGLARE
322   #define PROGNAME "evalglare"
323 < #define VERSION "1.17 release 15.07.2015 by EPFL, J.Wienold"
323 > #define VERSION "2.02 release 28.02.2017 by EPFL, J.Wienold"
324   #define RELEASENAME PROGNAME " " VERSION
325  
326 < #include "rtio.h"
288 < #include "platform.h"
326 >
327   #include "pictool.h"
328 + #include "rtio.h"
329   #include <math.h>
330   #include <string.h>
331 + #include "platform.h"
332 + #include "muc_randvar.h"
333 +
334   char *progname;
335  
336   /* subroutine to add a pixel to a glare source */
# Line 564 | Line 606 | double get_task_lum(pict * p, int x, int y, float r, i
606          return av_lum;
607   }
608  
567 /* subroutine for calculation of band luminance */
568 double get_band_lum(pict * p, float r, int task_color)
569 {
570        int x_min, x_max, y_min, y_max, ix, iy, y_mid;
571        double r_actual, av_lum, omega_sum, act_lum;
609  
610  
574        x_max = pict_get_xsize(p) - 1;
575        y_max = pict_get_ysize(p) - 1;
576        x_min = 0;
577        y_min = 0;
578        y_mid = rint(y_max/2);
611  
612  
581
582        av_lum = 0.0;
583        omega_sum = 0.0;
584
585        for (iy = y_min; iy <= y_max; iy++) {
586                for (ix = x_min; ix <= x_max; ix++) {
587
588 /*                      if (DOT(pict_get_cached_dir(p,ix,iy),p->view.vdir) < 0.0)
589                                continue;*/
590                        r_actual =
591                                acos(DOT(pict_get_cached_dir(p, ix, y_mid),
592                                                 pict_get_cached_dir(p, ix, iy))) ;
593                        act_lum = luminance(pict_get_color(p, ix, iy));
594
595                        if ((r_actual <= r) || (iy == y_mid) ) {
596                                act_lum = luminance(pict_get_color(p, ix, iy));
597                                av_lum += pict_get_omega(p, ix, iy) * act_lum;
598                                omega_sum += pict_get_omega(p, ix, iy);
599                                if (task_color == 1) {
600                                        pict_get_color(p, ix, iy)[RED] = 0.0;
601                                        pict_get_color(p, ix, iy)[GRN] = act_lum / WHTEFFICACY / CIE_gf;
602                                        pict_get_color(p, ix, iy)[BLU] = 0.0;
603                                }
604                        }
605                }
606        }
607
608        av_lum = av_lum / omega_sum;
609 /*    printf("average luminance of band %f \n",av_lum);*/
610 /*      printf("solid angle of band %f \n",omega_sum);*/
611        return av_lum;
612 }
613
614
615
616
617
613   /* subroutine for coloring the glare sources
614       red is used only for explicit call of the subroutine with acol=0  , e.g. for disability glare
615       -1: set to grey*/
# Line 626 | Line 621 | int setglcolor(pict * p, int x, int y, int acol, int u
621          l=u_r+u_g+u_b ;
622          
623          pcol[RED][0] = 1.0 / CIE_rf;
624 <        pcol[GRN][0] = 0.;
625 <        pcol[BLU][0] = 0.;
624 >        pcol[GRN][0] = 0.0 / CIE_gf;
625 >        pcol[BLU][0] = 0.0 / CIE_bf;
626  
627 <        pcol[RED][1] = 0.;
627 >        pcol[RED][1] = 0.0 / CIE_rf;
628          pcol[GRN][1] = 1.0 / CIE_gf;
629 <        pcol[BLU][1] = 0.;
629 >        pcol[BLU][1] = 0.0 / CIE_bf;
630  
631 <        pcol[RED][2] = 0.;
632 <        pcol[GRN][2] = 0.;
633 <        pcol[BLU][2] = 1 / CIE_bf;
631 >        pcol[RED][2] = 0.15 / CIE_rf;
632 >        pcol[GRN][2] = 0.15 / CIE_gf;
633 >        pcol[BLU][2] = 0.7 / CIE_bf;
634  
635 <        pcol[RED][3] = 1.0 / (1.0 - CIE_bf);
636 <        pcol[GRN][3] = 1.0 / (1.0 - CIE_bf);
637 <        pcol[BLU][3] = 0.;
635 >        pcol[RED][3] = .5 / CIE_rf;
636 >        pcol[GRN][3] = .5 / CIE_gf;
637 >        pcol[BLU][3] = 0.0 / CIE_bf;
638  
639 <        pcol[RED][4] = 1.0 / (1.0 - CIE_gf);
640 <        pcol[GRN][4] = 0.;
641 <        pcol[BLU][4] = 1.0 / (1.0 - CIE_gf);
639 >        pcol[RED][4] = .5 / CIE_rf;
640 >        pcol[GRN][4] = .0 / CIE_gf;
641 >        pcol[BLU][4] = .5 / CIE_bf ;
642  
643 <        pcol[RED][5] = 0.;
644 <        pcol[GRN][5] = 1.0 / (1.0 - CIE_rf);
645 <        pcol[BLU][5] = 1.0 / (1.0 - CIE_rf);
643 >        pcol[RED][5] = .0 / CIE_rf;
644 >        pcol[GRN][5] = .5 / CIE_gf;
645 >        pcol[BLU][5] = .5 / CIE_bf;
646  
647 <        pcol[RED][6] = 0.;
648 <        pcol[GRN][6] = 1.0 / (1.0 - CIE_rf);
649 <        pcol[BLU][6] = 1.0 / (1.0 - CIE_rf);
647 >        pcol[RED][6] = 0.333 / CIE_rf;
648 >        pcol[GRN][6] = 0.333 / CIE_gf;
649 >        pcol[BLU][6] = 0.333 / CIE_bf;
650  
651  
652          pcol[RED][999] = 1.0 / WHTEFFICACY;
# Line 662 | Line 657 | int setglcolor(pict * p, int x, int y, int acol, int u
657          pcol[RED][998] = u_r /(l* CIE_rf) ;
658          pcol[GRN][998] = u_g /(l* CIE_gf);
659          pcol[BLU][998] = u_b /(l* CIE_bf);
660 < /*        printf("CIE_rf,CIE_gf,CIE_bf,l=%f %f %f %f\n",CIE_rf,CIE_gf,CIE_bf,l);*/
660 > /*        printf("CIE_rf,CIE_gf,CIE_bf,l=%f %f %f %f %f\n",CIE_rf,CIE_gf,CIE_bf,l,WHTEFFICACY); */
661          icol = acol ;
662          if ( acol == -1) {icol=999;
663                                    }else{if (acol>0){icol = acol % 5 +1;
# Line 675 | Line 670 | int setglcolor(pict * p, int x, int y, int acol, int u
670          pict_get_color(p, x, y)[RED] = pcol[RED][icol] * act_lum / WHTEFFICACY;
671          pict_get_color(p, x, y)[GRN] = pcol[GRN][icol] * act_lum / WHTEFFICACY;
672          pict_get_color(p, x, y)[BLU] = pcol[BLU][icol] * act_lum / WHTEFFICACY;
673 <
673 > /*        printf("x,y,lum_before,lum_after,diff %i %i %f %f %f\n",x,y, act_lum,luminance(pict_get_color(p, x, y)), act_lum-luminance(pict_get_color(p, x, y))); */
674          return icol;
675   }
676  
# Line 727 | Line 722 | void add_secondary_gs(pict * p, int x, int y, float r,
722  
723   /* color pixel of gs */
724  
725 <                icol = setglcolor(p, x, y, act_gs, uniform_gs, u_r, u_g , u_b);
725 > /*              icol = setglcolor(p, x, y, act_gs, uniform_gs, u_r, u_g , u_b); */
726  
727          }
728   }
# Line 767 | Line 762 | void split_pixel_from_gs(pict * p, int x, int y, int n
762  
763   /* color pixel of new gs */
764  
765 <        icol = setglcolor(p, x, y, new_gsn, uniform_gs, u_r, u_g , u_b);
765 > /*      icol = setglcolor(p, x, y, new_gsn, uniform_gs, u_r, u_g , u_b); */
766 >        
767  
772
768   }
769  
770   /* subroutine for the calculation of the position index */
# Line 800 | Line 795 | float get_posindex(pict * p, float x, float y, int pos
795          tau = tau * deg;
796          sigma = sigma * deg;
797  
798 +        if (postype == 1) {
799 + /* KIM  model */        
800 +        posindex = exp ((sigma-(-0.000009*tau*tau*tau+0.0014*tau*tau+0.0866*tau+21.633))/(-0.000009*tau*tau*tau+0.0013*tau*tau+0.0853*tau+8.772));
801 +        }else{
802 + /* Guth model, equation from IES lighting handbook */
803          posindex =
804                  exp((35.2 - 0.31889 * tau -
805                           1.22 * exp(-2 * tau / 9)) / 1000 * sigma + (21 +
# Line 821 | Line 821 | float get_posindex(pict * p, float x, float y, int pos
821  
822                  posindex = 1 + fact * r;
823          }
824 <        if (posindex > 16)
824 >                if (posindex > 16)
825                  posindex = 16;
826 + }
827  
828          return posindex;
829  
# Line 1035 | Line 1036 | return;
1036  
1037   }
1038  
1039 < /* subroutine for the calculation of the daylight glare index */
1039 > /* subroutine for the calculation of the daylight glare index DGI*/
1040  
1041  
1042   float get_dgi(pict * p, float lum_backg, int igs, int posindex_2)
# Line 1062 | Line 1063 | float get_dgi(pict * p, float lum_backg, int igs, int
1063          return dgi;
1064  
1065   }
1066 + /* subroutine for the calculation of the modified daylight glare index DGI_mod (Fisekis2003)
1067 +   several glare sources are taken into account and summed up, original equation has no summary
1068 + */
1069  
1070 +
1071 + float get_dgi_mod(pict * p, float lum_a, int igs, int posindex_2)
1072 + {
1073 +        float dgi_mod, sum_glare, omega_s;
1074 +        int i;
1075 +
1076 +
1077 +        sum_glare = 0;
1078 +        omega_s = 0;
1079 +
1080 +        for (i = 0; i <= igs; i++) {
1081 +
1082 +                if (pict_get_npix(p, i) > 0) {
1083 +                        omega_s =
1084 +                                pict_get_av_omega(p, i) / get_posindex(p,pict_get_av_posx(p,i), pict_get_av_posy(p,i),posindex_2) /
1085 +                                get_posindex(p, pict_get_av_posx(p, i), pict_get_av_posy(p, i), posindex_2);
1086 +                        sum_glare += 0.478 * pow(pict_get_av_lum(p, i), 1.6) * pow(omega_s,0.8) / (pow(lum_a,0.85) + 0.07 * pow(pict_get_av_omega(p, i),0.5) * pict_get_av_lum(p, i));
1087 +                    /*    printf("i,sum_glare %i %f\n",i,sum_glare); */
1088 +                }
1089 +        }
1090 +        dgi_mod = 10 * log10(sum_glare);
1091 +
1092 +        return dgi_mod;
1093 +
1094 + }
1095 +
1096   /* subroutine for the calculation of the daylight glare probability */
1097   double
1098   get_dgp(pict * p, double E_v, int igs, double a1, double a2, double a3,
# Line 1103 | Line 1133 | get_dgp(pict * p, double E_v, int igs, double a1, doub
1133   }
1134  
1135   /* subroutine for the calculation of the visual comfort probability */
1136 < float get_vcp(pict * p, double lum_a, int igs, int posindex_2)
1136 > float get_dgr(pict * p, double lum_a, int igs, int posindex_2)
1137   {
1138 <        float vcp;
1139 <        double sum_glare, dgr;
1138 >        float dgr;
1139 >        double sum_glare;
1140          int i, i_glare;
1141  
1142  
# Line 1132 | Line 1162 | float get_vcp(pict * p, double lum_a, int igs, int pos
1162          }
1163          dgr = pow(sum_glare, pow(i_glare, -0.0914));
1164  
1165 +
1166 +
1167 +        return dgr;
1168 +
1169 + }
1170 +
1171 + float get_vcp(float dgr )
1172 + {
1173 +        float vcp;
1174 +
1175          vcp = 50 * erf((6.347 - 1.3227 * log(dgr)) / 1.414213562373) + 50;
1176          if (dgr > 750) {
1177                  vcp = 0;
# Line 1139 | Line 1179 | float get_vcp(pict * p, double lum_a, int igs, int pos
1179          if (dgr < 20) {
1180                  vcp = 100;
1181          }
1142
1143
1182          return vcp;
1183  
1184   }
1185  
1186 +
1187   /* subroutine for the calculation of the unified glare rating */
1188   float get_ugr(pict * p, double lum_backg, int igs, int posindex_2)
1189   {
# Line 1168 | Line 1207 | float get_ugr(pict * p, double lum_backg, int igs, int
1207                  }
1208          }
1209          ugr = 8 * log10(0.25 / lum_backg * sum_glare);
1210 <
1210 >        if (sum_glare==0) {
1211 >        ugr=0.0;
1212 >        }
1213 >        if (lum_backg<=0) {
1214 >        ugr=-99.0;
1215 >        }
1216 >        
1217          return ugr;
1218  
1219   }
1220 + /* subroutine for the calculation of the experimental unified glare rating (Fisekis 2003)*/
1221 + float get_ugr_exp(pict * p, double lum_backg, double lum_a, int igs, int posindex_2)
1222 + {
1223 +        float ugr_exp;
1224 +        double sum_glare;
1225 +        int i, i_glare;
1226  
1227  
1228 +        sum_glare = 0;
1229 +        i_glare = 0;
1230 +        for (i = 0; i <= igs; i++) {
1231 +
1232 +                if (pict_get_npix(p, i) > 0) {
1233 +                        i_glare = i_glare + 1;
1234 +                        sum_glare +=
1235 +                                pow(1 /get_posindex(p, pict_get_av_posx(p, i), pict_get_av_posy(p, i), posindex_2),2) *pict_get_av_lum(p, i)* pict_get_av_omega(p, i);
1236 +
1237 +                }
1238 +        }
1239 +        ugr_exp =8 * log10(lum_a) + 8 * log10(sum_glare/lum_backg);
1240 +
1241 +        return ugr_exp;
1242 +
1243 + }
1244 + /* subroutine for the calculation of the unified glare probability (Hirning 2014)*/
1245 + float get_ugp(pict * p, double lum_backg, int igs, int posindex_2)
1246 + {
1247 +        float ugp;
1248 +        double sum_glare;
1249 +        int i, i_glare;
1250 +
1251 +
1252 +        sum_glare = 0;
1253 +        i_glare = 0;
1254 +        for (i = 0; i <= igs; i++) {
1255 +
1256 +                if (pict_get_npix(p, i) > 0) {
1257 +                        i_glare = i_glare + 1;
1258 +                        sum_glare +=
1259 +                                pow(pict_get_av_lum(p, i) /
1260 +                                        get_posindex(p, pict_get_av_posx(p, i),
1261 +                                                                 pict_get_av_posy(p, i), posindex_2),
1262 +                                        2) * pict_get_av_omega(p, i);
1263 +
1264 +                }
1265 +        }
1266 +        ugp = 0.26 * log10(0.25 / lum_backg * sum_glare);
1267 +
1268 +        return ugp;
1269 +
1270 + }
1271 +
1272 +
1273   /* subroutine for the calculation of the disability glare according to Poynter */
1274   float get_disability(pict * p, double lum_backg, int igs)
1275   {
# Line 1221 | Line 1317 | float get_disability(pict * p, double lum_backg, int i
1317  
1318   /* subroutine for the calculation of the cie glare index */
1319  
1320 < float
1225 < get_cgi(pict * p, double E_v, double E_v_dir, int igs, int posindex_2)
1320 > float get_cgi(pict * p, double E_v, double E_v_dir, int igs, int posindex_2)
1321   {
1322          float cgi;
1323          double sum_glare;
# Line 1246 | Line 1341 | get_cgi(pict * p, double E_v, double E_v_dir, int igs,
1341          cgi = 8 * log10((2 * (1 + E_v_dir / 500) / E_v) * sum_glare);
1342  
1343          return cgi;
1344 + }      
1345  
1346 + /* subroutine for the calculation of the PGSV; is only applied, when masking is done, since it refers only to the window. Important: masking area must be the window! */
1347 + float get_pgsv(double E_v, double E_mask,double omega_mask,double lum_mask_av)
1348 + {
1349 +        float pgsv;
1350 +        double Lb;
1351 +
1352 +        Lb = (E_v-E_mask)/1.414213562373;
1353 +
1354 +        pgsv =3.2*log10(lum_mask_av)-0.64*log10(omega_mask)+(0.79*log10(omega_mask)-0.61)*log10(Lb)-8.2 ;
1355 +
1356 +
1357 +        return pgsv;
1358   }
1359  
1360 + /* subroutine for the calculation of the PGSV_saturation; is only applied, when masking is done, since it refers only to the window. Important: masking area must be the window! */
1361 + float get_pgsv_sat(double E_v)
1362 + {
1363 +        float pgsv_sat;
1364  
1365 +        pgsv_sat =3.3-(0.57+3.3)/pow((1+E_v/1.414213562373/1250),1.7);
1366 +
1367 +
1368 +        return pgsv_sat;
1369 + }
1370 +
1371 +
1372 +
1373 +
1374   #ifdef  EVALGLARE
1375  
1376  
# Line 1261 | Line 1382 | int main(int argc, char **argv)
1382   {
1383          #define CLINEMAX 4095 /* memory allocated for command line string */
1384          pict *p = pict_create();
1385 <        int     skip_second_scan,calcfast,age_corr,cut_view,cut_view_type,calc_vill, output, detail_out2, y1, fill, yfillmax, yfillmin,
1386 <                ext_vill, set_lum_max, set_lum_max2, task_color, i_splitstart,
1387 <                i_split, posindex_2, task_lum, checkfile, rval, i, i_max, x, y,x2,y2,
1388 <                igs, actual_igs, icol, xt, yt, change, before_igs, sgs, splithigh,uniform_gs,
1389 <                detail_out, posindex_picture, non_cos_lb, rx, ry, rmx, rmy,apply_disability,band_calc,band_color;
1390 <        double  lum_total_max,age_corr_factor,age,dgp_ext,dgp,low_light_corr,omega_cos_contr, setvalue, lum_ideal, E_v_contr, sigma,
1391 <                E_vl_ext, lum_max, new_lum_max, r_center,
1392 <                search_pix, a1, a2, a3, a4, a5, c3, c1, c2, r_split, max_angle,
1393 <                omegat, sang, E_v, E_v2, E_v_dir, avlum, act_lum, ang,
1394 <                l_max, lum_backg, lum_backg_cos, omega_sources, lum_sources,
1395 <                lum, lum_source,teta,Lveil_cie,Lveil_cie_sum,disability_thresh,u_r,u_g,u_b,band_angle,band_avlum;
1396 <        float lum_task, lum_thres, dgi,  vcp, cgi, ugr, limit,
1385 >        pict *pm = pict_create();
1386 >        int     skip_second_scan,calcfast,age_corr,cut_view,cut_view_type,calc_vill, output, detail_out2, x1,y1, fill, yfillmax, yfillmin,
1387 >                ext_vill, set_lum_max, set_lum_max2, img_corr,x_disk,y_disk,task_color, i_splitstart,zones,act_gsn,splitgs,
1388 >                i_split, posindex_2, task_lum, checkfile, rval, i, i_max, x, y,x2,y2,x_zone,y_zone, i_z1, i_z2,
1389 >                igs, actual_igs, lastpixelwas_gs, icol, xt, yt, change,checkpixels, before_igs, sgs, splithigh,uniform_gs,x_max, y_max,y_mid,
1390 >                detail_out, posindex_picture, non_cos_lb, rx, ry, rmx,rmy,apply_disability,band_calc,band_color,masking,i_mask,no_glaresources,force;
1391 >        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,
1392 >                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,
1393 >                search_pix, a1, a2, a3, a4, a5, c3, c1, c2, r_split, max_angle,r_actual,lum_actual,dir_ill,
1394 >                omegat, sang, E_v, E_v2, E_v_dir, avlum, act_lum, ang, angle_z1, angle_z2,per_95_band,per_75_band,pos,
1395 >                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,
1396 >                lum, lum_source,teta,Lveil_cie,Lveil_cie_sum,disability_thresh,u_r,u_g,u_b,band_angle,band_avlum,
1397 >                lum_mask[1],lum_mask_av,lum_mask_std[1],lum_mask_median[1],omega_mask,bbox[2],
1398 >                lum_band[1],lum_band_av,lum_band_std[1],lum_band_median[1],omega_band,bbox_band[2],
1399 >                lum_z1[1],lum_z1_av,lum_z1_std[1],lum_z1_median[1],omega_z1,bbox_z1[2],
1400 >                lum_z2[1],lum_z2_av,lum_z2_std[1],lum_z2_median[1],omega_z2,bbox_z2[2],
1401 >                lum_pos[1],lum_nopos_median[1],lum_pos_median[1],lum_pos2_median[1],lum_pos_mean,lum_pos2_mean;
1402 >        float lum_task, lum_thres, dgi,  vcp, cgi, ugr, limit, dgr,
1403                  abs_max, Lveil;
1404 <        char file_out[500], file_out2[500], version[500];
1404 >        char maskfile[500],file_out[500], file_out2[500], version[500];
1405          char *cline;
1406          VIEW userview = STDVIEW;
1407          int gotuserview = 0;
1408 +        struct muc_rvar* s_mask;
1409 +        s_mask = muc_rvar_create();
1410 +        muc_rvar_set_dim(s_mask, 1);
1411 +        muc_rvar_clear(s_mask);
1412 +        struct muc_rvar* s_band;
1413 +        s_band = muc_rvar_create();
1414 +        muc_rvar_set_dim(s_band, 1);
1415 +        muc_rvar_clear(s_band);
1416 +        struct muc_rvar* s_z1;
1417 +        s_z1 = muc_rvar_create();
1418 +        muc_rvar_set_dim(s_z1, 1);
1419 +        muc_rvar_clear(s_z1);
1420  
1421 +        struct muc_rvar* s_z2;
1422 +        s_z2 = muc_rvar_create();
1423 +        muc_rvar_set_dim(s_z2, 1);
1424 +        muc_rvar_clear(s_z2);
1425 +
1426 +        struct muc_rvar* s_noposweight;
1427 +        s_noposweight = muc_rvar_create();
1428 +        muc_rvar_set_dim(s_noposweight, 1);
1429 +        muc_rvar_clear(s_noposweight);
1430 +
1431 +        struct muc_rvar* s_posweight;
1432 +        s_posweight = muc_rvar_create();
1433 +        muc_rvar_set_dim(s_posweight, 1);
1434 +        muc_rvar_clear(s_posweight);
1435 +
1436 +        struct muc_rvar* s_posweight2;
1437 +        s_posweight2 = muc_rvar_create();
1438 +        muc_rvar_set_dim(s_posweight2, 1);
1439 +        muc_rvar_clear(s_posweight2);
1440 +
1441          /*set required user view parameters to invalid values*/
1442 <        uniform_gs = 0;
1442 >        dir_ill=0.0;
1443 >        delta_E=0.0;
1444 >        no_glaresources=0;
1445 >        n_corner_px=0;
1446 >        zero_corner_px=0;
1447 >        force=0;
1448 >        dist=0.0;
1449 >        u_r=0.33333;
1450 >        u_g=0.33333;
1451 >        u_b=0.33333;
1452 >        band_angle=0;
1453 >        angle_z1=0;
1454 >        angle_z2=0;
1455 >        x_zone=0;
1456 >        y_zone=0;
1457 >        per_75_z2=0;
1458 >        per_95_z2=0;
1459 >        lum_pos_mean=0;
1460 >        lum_pos2_mean=0;
1461 >        lum_band_av = 0.0;
1462 >        omega_band = 0.0;
1463 >        pgsv = 0.0 ;
1464 >        pgsv_sat = 0.0 ;
1465 >        E_v_mask = 0.0;
1466 >        lum_z1_av = 0.0;
1467 >        omega_z1 = 0.0;
1468 >        lum_z2_av = 0.0;
1469 >        omega_z2 = 0.0 ;
1470 >        i_z1 = 0;
1471 >        i_z2 = 0;        
1472 >        zones = 0;
1473 >        lum_z2_av = 0.0;
1474 >        uniform_gs = 0;
1475          apply_disability = 0;
1476          disability_thresh = 0;
1477          Lveil_cie_sum=0.0;
# Line 1300 | Line 1491 | int main(int argc, char **argv)
1491          omegat = 0.0;
1492          yt = 0;
1493          xt = 0;
1494 +        x_disk=0;
1495 +        y_disk=0;
1496 +        angle_disk=0;
1497          yfillmin = 0;
1498          yfillmax = 0;
1499          cut_view = 0;
# Line 1332 | Line 1526 | int main(int argc, char **argv)
1526          limit = 50000.0;
1527          set_lum_max = 0;
1528          set_lum_max2 = 0;
1529 +        img_corr=0;
1530          abs_max = 0;
1531          progname = argv[0];
1532          E_v_contr = 0.0;
1533 <        strcpy(version, "1.15 release 05.02.2015 by J.Wienold");
1533 >        strcpy(version, "1.19 release 09.12.2015 by J.Wienold");
1534          low_light_corr=1.0;
1535          output = 0;
1536          calc_vill = 0;
1537          band_avlum = -99;
1538          band_calc = 0;
1539 +        masking = 0;
1540 +        lum_mask[0]=0.0;
1541 +        lum_mask_av=0.0;
1542 +        omega_mask=0.0;
1543 +        i_mask=0;
1544 +        actual_igs=0;
1545   /* command line for output picture*/
1546  
1547          cline = (char *) malloc(CLINEMAX+1);
# Line 1382 | Line 1583 | int main(int argc, char **argv)
1583                          printf("age factor not supported any more \n");
1584                          exit(1);
1585                          break;
1586 +                case 'A':
1587 +                        masking = 1;
1588 +                        detail_out = 1;
1589 +                        strcpy(maskfile, argv[++i]);
1590 +                        pict_read(pm,maskfile );
1591 +
1592 +                        break;
1593                  case 'b':
1594                          lum_thres = atof(argv[++i]);
1595                          break;
# Line 1401 | Line 1609 | int main(int argc, char **argv)
1609                  case 's':
1610                          sgs = 1;
1611                          break;
1612 +                case 'f':
1613 +                        force = 1;
1614 +                        break;
1615                  case 'k':
1616                          apply_disability = 1;
1617                          disability_thresh = atof(argv[++i]);
# Line 1409 | Line 1620 | int main(int argc, char **argv)
1620                  case 'p':
1621                          posindex_picture = 1;
1622                          break;
1623 +                case 'P':
1624 +                        posindex_2 = atoi(argv[++i]);
1625 +                        break;
1626 +                        
1627  
1628                  case 'y':
1629                          splithigh = 1;
# Line 1439 | Line 1654 | int main(int argc, char **argv)
1654                          detail_out2 = 1;
1655                          break;
1656                  case 'm':
1657 +                        img_corr = 1;
1658                          set_lum_max = 1;
1659                          lum_max = atof(argv[++i]);
1660                          new_lum_max = atof(argv[++i]);
# Line 1447 | Line 1663 | int main(int argc, char **argv)
1663                          break;
1664  
1665                  case 'M':
1666 +                        img_corr = 1;
1667                          set_lum_max2 = 1;
1668                          lum_max = atof(argv[++i]);
1669                          E_vl_ext = atof(argv[++i]);
1670                          strcpy(file_out2, argv[++i]);
1671   /*                      printf("max lum set to %f\n",new_lum_max);*/
1672                          break;
1673 +                case 'N':
1674 +                        img_corr = 1;
1675 +                        set_lum_max2 = 2;
1676 +                        x_disk = atoi(argv[++i]);
1677 +                        y_disk = atoi(argv[++i]);
1678 +                        angle_disk = atof(argv[++i]);
1679 +                        E_vl_ext = atof(argv[++i]);
1680 +                        strcpy(file_out2, argv[++i]);
1681 + /*                      printf("max lum set to %f\n",new_lum_max);*/
1682 +                        break;
1683 +
1684                  case 'n':
1685                          non_cos_lb = 0;
1686                          break;
# Line 1472 | Line 1700 | int main(int argc, char **argv)
1700                          omegat = atof(argv[++i]);
1701                          task_color = 1;
1702                          break;
1703 +                case 'l':
1704 +                        zones = 1;
1705 +                        x_zone = atoi(argv[++i]);
1706 +                        y_zone = atoi(argv[++i]);
1707 +                        angle_z1 = atof(argv[++i]);
1708 +                        angle_z2 = -1;
1709 +                        break;
1710 +                case 'L':
1711 +                        zones = 2;
1712 +                        x_zone = atoi(argv[++i]);
1713 +                        y_zone = atoi(argv[++i]);
1714 +                        angle_z1 = atof(argv[++i]);
1715 +                        angle_z2 = atof(argv[++i]);
1716 +                        break;
1717 +                        
1718 +                        
1719                  case 'B':
1720                          band_calc = 1;
1721                          band_angle = atof(argv[++i]);
# Line 1508 | Line 1752 | int main(int argc, char **argv)
1752                  case '1':
1753                          output = 1;
1754                          break;
1755 +                case '2':
1756 +                        output = 2;
1757 +                        dir_ill = atof(argv[++i]);
1758 +                        break;
1759  
1760                  case 'v':
1761                          if (argv[i][2] == '\0') {
# Line 1539 | Line 1787 | int main(int argc, char **argv)
1787  
1788   /*fast calculation, if gendgp_profile is used: No Vertical illuminance calculation, only dgp is calculated*/
1789  
1790 < if (output == 1 && ext_vill == 1) {
1790 > if (output == 1 && ext_vill == 1 ) {
1791                         calcfast=1;
1792                         }
1793 +                      
1794 + if (output == 2 && ext_vill == 1 ) {
1795 +                       calcfast=2;
1796 +                       }
1797 +                      
1798 + /*masking and zoning cannot be applied at the same time*/
1799  
1800 + if (masking ==1 && zones >0) {
1801 +               fprintf(stderr,  " masking and zoning cannot be activated at the same time!\n");
1802 +               exit(1);
1803 + }
1804 +
1805   /* read picture file */
1806          if (i == argc) {
1807                  SET_FILE_BINARY(stdin);
# Line 1576 | Line 1835 | if (output == 1 && ext_vill == 1) {
1835                  return EXIT_FAILURE;
1836          }
1837  
1838 +
1839 +
1840   /*                fprintf(stderr,"Picture read!");*/
1841  
1842   /* command line for output picture*/
1843  
1844          pict_set_comment(p, cline);
1845  
1846 + /* several checks */
1847          if (p->view.type == VT_PAR) {
1848 <                fprintf(stderr, "wrong view type! must not be parallel ! \n");
1848 >                fprintf(stderr, "error: wrong view type! must not be parallel ! \n");
1849                  exit(1);
1850          }
1851  
1852 +        if (p->view.type == VT_PER) {
1853 +                fprintf(stderr, "warning: image has perspective view type specified in header ! \n");
1854 +        }
1855  
1856 +        if (masking == 1) {
1857 +
1858 +                if (!pict_get_xsize(p)==pict_get_xsize(pm) || !pict_get_ysize(p)==pict_get_ysize(pm)) {
1859 +                fprintf(stderr, "error: masking image has other resolution than main image ! \n");
1860 +                fprintf(stderr, "size must be identical \n");
1861 +                printf("resolution main image : %dx%d\n",pict_get_xsize(p),pict_get_ysize(p));
1862 +                printf("resolution masking image : %dx%d\n",pict_get_xsize(pm),pict_get_ysize(pm));
1863 +                exit(1);
1864 +                
1865 +                }
1866 +
1867 +        }
1868 + /*      printf("resolution: %dx%d\n",pict_get_xsize(p),pict_get_ysize(p)); */
1869 +
1870   /* Check size of search radius */
1871          rmx = (pict_get_xsize(p) / 2);
1872          rmy = (pict_get_ysize(p) / 2);
# Line 1632 | Line 1911 | if (output == 1 && ext_vill == 1) {
1911          avlum = 0.0;
1912          pict_new_gli(p);
1913          igs = 0;
1914 +        pict_get_z1_gsn(p,igs) = 0;
1915 +        pict_get_z2_gsn(p,igs) = 0;
1916  
1917 +
1918   /* cut out GUTH field of view and exit without glare evaluation */
1919   if (cut_view==2) {
1920          if (cut_view_type==1) {
# Line 1699 | Line 1981 | if (cut_view==2) {
1981          if (calcfast == 0) {
1982          for (x = 0; x < pict_get_xsize(p); x++)
1983                  for (y = 0; y < pict_get_ysize(p); y++) {
1984 +                   lum = luminance(pict_get_color(p, x, y));              
1985 +                   dist=sqrt((x-rmx)*(x-rmx)+(y-rmy)*(y-rmy));
1986 +                  if (dist>((rmx+rmy)/2)) {
1987 +                     n_corner_px=n_corner_px+1;
1988 +                     if (lum<7.0) {
1989 +                         zero_corner_px=zero_corner_px+1;
1990 +                         }
1991 +                     }
1992 +                
1993 +                
1994                          if (pict_get_hangle(p, x, y, p->view.vdir, p->view.vup, &ang)) {
1995                                  if (pict_is_validpixel(p, x, y)) {
1704                                        lum = luminance(pict_get_color(p, x, y));
1996                                          if (fill == 1 && y >= yfillmax) {
1997                                                  y1 = y - 1;
1998                                                  lum = luminance(pict_get_color(p, x, y1));
# Line 1714 | Line 2005 | if (cut_view==2) {
2005                                                  abs_max = lum;
2006                                          }
2007   /* set luminance restriction, if -m is set */
2008 <                                        if (set_lum_max == 1 && lum >= lum_max) {
2009 <                                                pict_get_color(p, x, y)[RED] = new_lum_max / 179.0;
2010 <                                                pict_get_color(p, x, y)[GRN] = new_lum_max / 179.0;
2011 <                                                pict_get_color(p, x, y)[BLU] = new_lum_max / 179.0;
2012 < /*                                    printf("old lum, new lum %f %f \n",lum,luminance(pict_get_color(p,x,y))); */
2013 <                                                lum = luminance(pict_get_color(p, x, y));
2008 >                                        if (img_corr == 1 ) {
2009 >                                                if (set_lum_max == 1 && lum >= lum_max) {
2010 >                                                        pict_get_color(p, x, y)[RED] = new_lum_max / 179.0;
2011 >                                                        pict_get_color(p, x, y)[GRN] = new_lum_max / 179.0;
2012 >                                                        pict_get_color(p, x, y)[BLU] = new_lum_max / 179.0;
2013 > /*                                                      printf("old lum, new lum %f %f \n",lum,luminance(pict_get_color(p,x,y))); */
2014 >                                                        lum = luminance(pict_get_color(p, x, y));
2015 >                                                        }
2016 >                                                if (set_lum_max2 == 1 && lum >= lum_max) {
2017  
2018 <                                        }
2019 <                                        if (set_lum_max2 == 1 && lum >= lum_max) {
2018 >                                                        E_v_contr +=DOT(p->view.vdir,pict_get_cached_dir(p, x,y)) * pict_get_omega(p,x,y)* lum;
2019 >                                                        omega_cos_contr +=DOT(p->view.vdir,pict_get_cached_dir(p, x,y)) * pict_get_omega(p,x,y)* 1;
2020 >                                                        }
2021 >                                                if (set_lum_max2 == 2 ) {
2022 >                                                        r_actual =acos(DOT(pict_get_cached_dir(p, x_disk, y_disk), pict_get_cached_dir(p, x, y))) * 2;
2023 >                                                        if (x_disk == x && y_disk==y ) r_actual=0.0;
2024  
2025 <                                                E_v_contr +=
2026 <                                                        DOT(p->view.vdir,
2027 <                                                                pict_get_cached_dir(p, x,
2028 <                                                                                                        y)) * pict_get_omega(p,
2029 <                                                                                                                                                 x,
2030 <                                                                                                                                                 y)
2031 <                                                        * lum;
2032 <                                                omega_cos_contr +=
2033 <                                                        DOT(p->view.vdir,
2034 <                                                                pict_get_cached_dir(p, x,
1737 <                                                                                                        y)) * pict_get_omega(p,
1738 <                                                                                                                                                 x,
1739 <                                                                                                                                                 y)
1740 <                                                        * 1;
2025 >                                                        act_lum = luminance(pict_get_color(p, x, y));
2026 >
2027 >                                                       if (r_actual <= angle_disk) {
2028 >                                                              E_v_contr +=DOT(p->view.vdir,pict_get_cached_dir(p, x,y)) * pict_get_omega(p,x,y)* lum;
2029 >                                                              omega_cos_contr += DOT(p->view.vdir,pict_get_cached_dir(p, x,y)) * pict_get_omega(p,x,y)* 1;
2030 >                                                                }
2031 >
2032 >                                                
2033 >                                                
2034 >                                                        }
2035                                          }
2036 +                                        om = pict_get_omega(p, x, y);
2037 +                                        sang += om;
2038 +                                        E_v += DOT(p->view.vdir, pict_get_cached_dir(p, x,y)) * om *lum;
2039 +                                        avlum += om * lum;
2040 +                                        pos=get_posindex(p, x, y,posindex_2);
2041  
2042 +                                        lum_pos[0]=lum;
2043 +                                        muc_rvar_add_sample(s_noposweight,lum_pos);
2044 +                                        lum_pos[0]=lum/pos;
2045 +                                        lum_pos_mean+=lum_pos[0]*om;
2046 +                                        muc_rvar_add_sample(s_posweight, lum_pos);
2047 +                                        lum_pos[0]=lum_pos[0]/pos;
2048 +                                        lum_pos2_mean+=lum_pos[0]*om;
2049 +                                        muc_rvar_add_sample(s_posweight2,lum_pos);
2050  
2051 <                                        sang += pict_get_omega(p, x, y);
2052 <                                        E_v +=
1746 <                                                DOT(p->view.vdir,
1747 <                                                        pict_get_cached_dir(p, x,
1748 <                                                                                                y)) * pict_get_omega(p, x,
1749 <                                                                                                                                         y) *
1750 <                                                lum;
1751 <                                        avlum +=
1752 <                                                pict_get_omega(p, x,
1753 <                                                                           y) * luminance(pict_get_color(p, x,
1754 <                                                                                                                                         y));
2051 >
2052 >
2053                                  } else {
2054                                          pict_get_color(p, x, y)[RED] = 0.0;
2055                                          pict_get_color(p, x, y)[GRN] = 0.0;
2056                                          pict_get_color(p, x, y)[BLU] = 0.0;
2057  
2058                                  }
2059 <                        }
2059 >                        }else {
2060 >                                        pict_get_color(p, x, y)[RED] = 0.0;
2061 >                                        pict_get_color(p, x, y)[GRN] = 0.0;
2062 >                                        pict_get_color(p, x, y)[BLU] = 0.0;
2063 >
2064 >                                }
2065                  }
2066  
2067 <        if (set_lum_max2 == 1 && E_v_contr > 0 && (E_vl_ext - E_v) > 0) {
2067 > /* check if image has black corners AND a perspective view */
2068  
2069 +       if (zero_corner_px/n_corner_px > 0.70 && (p->view.type == VT_PER) ) {
2070 +       printf (" corner pixels are to  %f %% black! \n",zero_corner_px/n_corner_px*100);
2071 +                printf("error! The image has black corners AND header contains a perspective view type definition !!!\n") ;
2072 +                
2073 +                if (force==0) {
2074 +                                printf("stopping...!!!!\n") ;
2075 +
2076 +                      exit(1);
2077 +                 }
2078 +       }
2079 +
2080 +
2081 +
2082 +
2083 +        lum_pos_mean= lum_pos_mean/sang;
2084 +        lum_pos2_mean= lum_pos2_mean/sang;
2085 +
2086 +        if (set_lum_max2 >= 1 && E_v_contr > 0 && (E_vl_ext - E_v) > 0) {
2087 +
2088                  lum_ideal = (E_vl_ext - E_v + E_v_contr) / omega_cos_contr;
2089 +                if (set_lum_max2 == 2 && lum_ideal >= 2e9) {
2090 +                printf("warning! luminance of replacement pixels would be larger than 2e9 cd/m2. Value set to 2e9cd/m2!\n") ;
2091 +                }
2092 +
2093                  if (lum_ideal > 0 && lum_ideal < setvalue) {
2094                          setvalue = lum_ideal;
2095                  }
2096 <                printf
1771 <                        ("change luminance values!! lum_ideal,setvalue,E_vl_ext,E_v,E_v_contr %f  %f %f %f %f\n",
2096 >                printf("change luminance values!! lum_ideal,setvalue,E_vl_ext,E_v,E_v_contr %f  %f %f %f %f\n",
2097                           lum_ideal, setvalue, E_vl_ext, E_v, E_v_contr);
2098  
2099 <
2099 >            
2100                  for (x = 0; x < pict_get_xsize(p); x++)
2101                          for (y = 0; y < pict_get_ysize(p); y++) {
2102                                  if (pict_get_hangle
2103                                          (p, x, y, p->view.vdir, p->view.vup, &ang)) {
2104                                          if (pict_is_validpixel(p, x, y)) {
2105                                                  lum = luminance(pict_get_color(p, x, y));
2106 +                                                
2107 +                                                
2108                                                  if (set_lum_max2 == 1 && lum >= lum_max) {
2109  
2110                                                          pict_get_color(p, x, y)[RED] =
# Line 1787 | Line 2114 | if (cut_view==2) {
2114                                                          pict_get_color(p, x, y)[BLU] =
2115                                                                  setvalue / 179.0;
2116  
2117 +                                                }else{ if(set_lum_max2 ==2 ) {
2118 +                                                        r_actual =acos(DOT(pict_get_cached_dir(p, x_disk, y_disk), pict_get_cached_dir(p, x, y))) * 2;
2119 +                                                        if (x_disk == x && y_disk==y ) r_actual=0.0;
2120 +
2121 +                                                       if (r_actual <= angle_disk) {
2122 +                                                      
2123 +                                                        pict_get_color(p, x, y)[RED] =
2124 +                                                                setvalue / 179.0;
2125 +                                                        pict_get_color(p, x, y)[GRN] =
2126 +                                                                setvalue / 179.0;
2127 +                                                        pict_get_color(p, x, y)[BLU] =
2128 +                                                                setvalue / 179.0;
2129 +                                                      
2130 +                                                       }
2131 +                                                                
2132 +                                                
2133                                                  }
2134 +                                                }
2135                                          }
2136                                  }
2137                          }
2138 +                        
2139  
2140                  pict_write(p, file_out2);
2141 <
2141 >        exit(1);
2142          }
2143          if (set_lum_max == 1) {
2144                  pict_write(p, file_out2);
# Line 1853 | Line 2198 | if (cut_view==1) {
2198                  lum_source = lum_thres;
2199          }
2200  
2201 <        /*     printf("Ev, avlum, Omega_tot%f %f %f \n",E_v, avlum, sang); */
2201 > /*     printf("Ev, avlum, Omega_tot%f %f %f \n",E_v, avlum, sang); */
2202  
2203   /* first glare source scan: find primary glare sources */
2204 <        for (x = 0; x < pict_get_xsize(p); x++)
2204 >        for (x = 0; x < pict_get_xsize(p); x++) {
2205 > /*                lastpixelwas_gs=0; */
2206                  for (y = 0; y < pict_get_ysize(p); y++) {
2207                          if (pict_get_hangle(p, x, y, p->view.vdir, p->view.vup, &ang)) {
2208                                  if (pict_is_validpixel(p, x, y)) {
# Line 1865 | Line 2211 | if (cut_view==1) {
2211                                                  if (act_lum >lum_total_max) {
2212                                                                               lum_total_max=act_lum;
2213                                                                                 }
2214 <                                                
2215 <                                                actual_igs =
2216 <                                                        find_near_pgs(p, x, y, max_angle, 0, igs, 1);
2214 > /* speed improvement first scan: when last pixel was glare source, then use this glare source number instead of searching.
2215 >   has been deactivated with v1.25
2216 >                      
2217 >                                                if (lastpixelwas_gs==0 || search_pix <= 1.0 ) { */
2218 >                                                actual_igs = find_near_pgs(p, x, y, max_angle, 0, igs, 1);
2219 > /*  }*/
2220                                                  if (actual_igs == 0) {
2221                                                          igs = igs + 1;
2222                                                          pict_new_gli(p);
2223                                                          pict_get_lum_min(p, igs) = HUGE_VAL;
2224                                                          pict_get_Eglare(p,igs) = 0.0;
2225                                                          pict_get_Dglare(p,igs) = 0.0;
2226 +                                                        pict_get_z1_gsn(p,igs) = 0;
2227 +                                                        pict_get_z2_gsn(p,igs) = 0;
2228                                                          actual_igs = igs;
2229 +                                                        
2230                                                  }
2231 <                                                icol = setglcolor(p, x, y, actual_igs, uniform_gs, u_r, u_g , u_b);
2231 > /* no coloring any more here            icol = setglcolor(p, x, y, actual_igs, uniform_gs, u_r, u_g , u_b); */
2232                                                  pict_get_gsn(p, x, y) = actual_igs;
2233                                                  pict_get_pgs(p, x, y) = 1;
2234                                                  add_pixel_to_gs(p, x, y, actual_igs);
2235 + /*                                                lastpixelwas_gs=actual_igs; */
2236  
2237                                          } else {
2238                                                  pict_get_pgs(p, x, y) = 0;
2239 + /*                                               lastpixelwas_gs=0;*/
2240                                          }
2241                                  }
2242                          }
2243 <                }
2243 >                }
2244 >             }
2245   /*      pict_write(p,"firstscan.pic");   */
2246  
2247 < if (calcfast == 1 ) {
2247 >
2248 >
2249 >
2250 > if (calcfast ==1 || search_pix <= 1.0 || calcfast == 2 ) {
2251     skip_second_scan=1;
2252     }
2253 +  
2254  
2255   /* second glare source scan: combine glare sources facing each other */
2256          change = 1;
2257 +        i = 0;
2258          while (change == 1 && skip_second_scan==0) {
2259                  change = 0;
2260 <                for (x = 0; x < pict_get_xsize(p); x++)
2260 >                i = i+1;
2261 >                for (x = 0; x < pict_get_xsize(p); x++) {
2262                          for (y = 0; y < pict_get_ysize(p); y++) {
1902                                before_igs = pict_get_gsn(p, x, y);
2263                                  if (pict_get_hangle
2264                                          (p, x, y, p->view.vdir, p->view.vup, &ang)) {
2265 <                                        if (pict_is_validpixel(p, x, y) && before_igs > 0) {
2265 >                                        checkpixels=1;
2266 >                                        before_igs = pict_get_gsn(p, x, y);
2267 >
2268 > /* speed improvement: search for other nearby glare sources only, when at least one adjacend pixel has another glare source number  */
2269 >                                        if (x >1 && x<pict_get_xsize(p)-2 && y >1 && y<pict_get_ysize(p)-2 )   {
2270 >                                                x1=x-1;
2271 >                                                x2=x+1;
2272 >                                                y1=y-1;
2273 >                                                y2=y+1;
2274 >                                            if (before_igs == pict_get_gsn(p, x1, y) && before_igs == pict_get_gsn(p, x2, y) && before_igs == pict_get_gsn(p, x, y1) && before_igs == pict_get_gsn(p, x, y2) && before_igs == pict_get_gsn(p, x1, y1) && before_igs == pict_get_gsn(p, x2, y1) && before_igs == pict_get_gsn(p, x1, y2) && before_igs == pict_get_gsn(p, x2, y2) ) {
2275 >                                            checkpixels = 0;
2276 >                                             actual_igs = before_igs;
2277 >                                             }  }
2278 >
2279 >
2280 >                                        if (pict_is_validpixel(p, x, y) && before_igs > 0 && checkpixels==1) {
2281                                                  actual_igs =
2282                                                          find_near_pgs(p, x, y, max_angle, before_igs,
2283                                                                                    igs, 1);
# Line 1911 | Line 2286 | if (calcfast == 1 ) {
2286                                                  }
2287                                                  if (before_igs > 0) {
2288                                                          actual_igs = pict_get_gsn(p, x, y);
2289 <                                                        icol = setglcolor(p, x, y, actual_igs, uniform_gs, u_r, u_g , u_b);
2289 >                                                /*      icol = setglcolor(p, x, y, actual_igs, uniform_gs, u_r, u_g , u_b); */
2290                                                  }
2291  
2292                                          }
2293                                  }
2294                          }
2295   /*      pict_write(p,"secondscan.pic");*/
2296 +        }}
2297  
1922        }
1923
2298   /*smoothing: add secondary glare sources */
2299          i_max = igs;
2300          if (sgs == 1) {
# Line 1977 | Line 2351 | if (calcfast == 1 ) {
2351                                                                          if (i_splitstart == (igs + 1)) {
2352                                                                                  igs = igs + 1;
2353                                                                                  pict_new_gli(p);
2354 +                                                                                pict_get_z1_gsn(p,igs) = 0;
2355 +                                                                                pict_get_z2_gsn(p,igs) = 0;
2356 +
2357                                                                                  pict_get_Eglare(p,igs) = 0.0;
2358                                                                                  pict_get_Dglare(p,igs) = 0.0;
2359                                                                                  pict_get_lum_min(p, igs) =
# Line 1990 | Line 2367 | if (calcfast == 1 ) {
2367                                                                          if (i_split == 0) {
2368                                                                                  igs = igs + 1;
2369                                                                                  pict_new_gli(p);
2370 +                                                                                pict_get_z1_gsn(p,igs) = 0;
2371 +                                                                                pict_get_z2_gsn(p,igs) = 0;
2372 +
2373                                                                                  pict_get_Eglare(p,igs) = 0.0;
2374                                                                                  pict_get_Dglare(p,igs) = 0.0;
2375                                                                                  pict_get_lum_min(p, igs) =
# Line 2026 | Line 2406 | if (calcfast == 1 ) {
2406                                                                                  if (before_igs > 0) {
2407                                                                                          actual_igs =
2408                                                                                                  pict_get_gsn(p, x, y);
2409 <                                                                                        icol =
2409 > /*                                                                                     icol =
2410                                                                                                  setglcolor(p, x, y,
2411 <                                                                                                                   actual_igs, uniform_gs, u_r, u_g , u_b);
2411 >                                                                                                                   actual_igs, uniform_gs, u_r, u_g , u_b);*/
2412                                                                                  }
2413  
2414                                                                          }
# Line 2043 | Line 2423 | if (calcfast == 1 ) {
2423                  }
2424          }
2425  
2426 < /* calculation of direct vertical illuminance for CGI and for disability glare*/
2426 > /* calculation of direct vertical illuminance for CGI and for disability glare, coloring glare sources*/
2427  
2428 <
2049 <        if (calcfast == 0) {
2428 >        if (calcfast == 0 || calcfast == 2) {
2429          for (x = 0; x < pict_get_xsize(p); x++)
2430                  for (y = 0; y < pict_get_ysize(p); y++) {
2431                          if (pict_get_hangle(p, x, y, p->view.vdir, p->view.vup, &ang)) {
2432                                  if (pict_is_validpixel(p, x, y)) {
2433                                          if (pict_get_gsn(p, x, y) > 0) {
2434 <                                                pict_get_Eglare(p,pict_get_gsn(p, x, y)) +=
2435 <                                                        DOT(p->view.vdir, pict_get_cached_dir(p, x, y))
2436 <                                                        * pict_get_omega(p, x, y)
2437 <                                                        * luminance(pict_get_color(p, x, y));
2438 <                                                E_v_dir +=
2060 <                                                        DOT(p->view.vdir, pict_get_cached_dir(p, x, y))
2061 <                                                        * pict_get_omega(p, x, y)
2062 <                                                        * luminance(pict_get_color(p, x, y));
2434 >                                                actual_igs = pict_get_gsn(p, x, y);
2435 >                                                delta_E=DOT(p->view.vdir, pict_get_cached_dir(p, x, y))* pict_get_omega(p, x, y)* luminance(pict_get_color(p, x, y));
2436 >                                                pict_get_Eglare(p,actual_igs ) = pict_get_Eglare(p,actual_igs ) + delta_E;
2437 >                                                E_v_dir = E_v_dir + delta_E;
2438 >                                                setglcolor(p, x, y, actual_igs, uniform_gs, u_r, u_g , u_b);
2439                                          }
2440                                  }
2441                          }
2442                  }
2443          lum_backg_cos = (E_v - E_v_dir) / 3.1415927;
2444 <        lum_backg = lum_backg_cos;
2444 >
2445           }
2446 < /* calc of band luminance if applied */
2446 > /* calc of band luminance distribution if applied */
2447          if (band_calc == 1) {
2448 <        band_avlum=get_band_lum( p, band_angle, band_color);
2449 <        }
2448 >                x_max = pict_get_xsize(p) - 1;
2449 >                y_max = pict_get_ysize(p) - 1;
2450 >                y_mid = (int)(y_max/2);
2451 >                for (x = 0; x <= x_max; x++)
2452 >                for (y = 0; y <= y_max; y++) {
2453 >                        if (pict_get_hangle(p, x, y, p->view.vdir, p->view.vup, &ang)) {
2454 >                                if (pict_is_validpixel(p, x, y)) {
2455  
2456 +                        r_actual = acos(DOT(pict_get_cached_dir(p, x, y_mid), pict_get_cached_dir(p, x, y))) ;
2457 +                        act_lum = luminance(pict_get_color(p, x, y));
2458 +
2459 +                        if ((r_actual <= band_angle) || (y == y_mid) ) {
2460 +                                lum_band[0]=luminance(pict_get_color(p, x, y));
2461 +                                muc_rvar_add_sample(s_band, lum_band);
2462 +                                act_lum = luminance(pict_get_color(p, x, y));
2463 +                                lum_band_av += pict_get_omega(p, x, y) * act_lum;
2464 +                                omega_band += pict_get_omega(p, x, y);
2465 +                                if (band_color == 1) {
2466 +                                        pict_get_color(p, x, y)[RED] = 0.0;
2467 +                                        pict_get_color(p, x, y)[GRN] = act_lum / WHTEFFICACY / CIE_gf;
2468 +                                        pict_get_color(p, x, y)[BLU] = 0.0;
2469 +                                }
2470 +                        }
2471 +                }}}
2472 +                lum_band_av=lum_band_av/omega_band;
2473 +                muc_rvar_get_vx(s_band,lum_band_std);
2474 +                muc_rvar_get_percentile(s_band,lum_band_median,0.75);
2475 +                per_75_band=lum_band_median[0];
2476 +                muc_rvar_get_percentile(s_band,lum_band_median,0.95);
2477 +                per_95_band=lum_band_median[0];
2478 +                muc_rvar_get_median(s_band,lum_band_median);
2479 +                muc_rvar_get_bounding_box(s_band,bbox_band);
2480 +        
2481 +                printf ("band:band_omega,band_av_lum,band_median_lum,band_std_lum,band_perc_75,band_perc_95,band_lum_min,band_lum_max: %f %f %f %f %f %f %f %f\n",omega_band,lum_band_av,lum_band_median[0],sqrt(lum_band_std[0]),per_75_band,per_95_band,bbox_band[0],bbox_band[1] );
2482 + /*      av_lum = av_lum / omega_sum; */
2483 + /*    printf("average luminance of band %f \n",av_lum);*/
2484 + /*      printf("solid angle of band %f \n",omega_sum);*/
2485 +        }
2486 +
2487   /*printf("total number of glare sources: %i\n",igs); */
2488          lum_sources = 0;
2489          omega_sources = 0;
2490 +        i=0;
2491          for (x = 0; x <= igs; x++) {
2492 +        if (pict_get_npix(p, x) > 0) {
2493                  lum_sources += pict_get_av_lum(p, x) * pict_get_av_omega(p, x);
2494                  omega_sources += pict_get_av_omega(p, x);
2495 +                i=i+1;
2496 +        }}
2497 +      
2498 +        if (sang == omega_sources) {
2499 +               lum_backg =avlum;
2500 +        } else {
2501 +               lum_backg =(sang * avlum - lum_sources) / (sang - omega_sources);
2502          }
2503 <        if (non_cos_lb == 1) {
2504 <                lum_backg =
2505 <                        (sang * avlum - lum_sources) / (sang - omega_sources);
2503 >
2504 >
2505 >        if (i == 0) {
2506 >               lum_sources =0.0;
2507 >        } else { lum_sources=lum_sources/omega_sources;
2508          }
2509 +
2510 +
2511 +
2512 +        if (non_cos_lb == 0) {
2513 +                        lum_backg = lum_backg_cos;
2514 +        }
2515 +
2516 + /* file writing NOT here
2517 +        if (checkfile == 1) {
2518 +                pict_write(p, file_out);
2519 +        }
2520 + */
2521 +
2522   /* print detailed output */
2523 +        
2524 +        
2525 +
2526 + /* masking */
2527 +
2528 +        if ( masking == 1 ) {
2529 +        
2530 +        
2531 +                for (x = 0; x < pict_get_xsize(p); x++)
2532 +                for (y = 0; y < pict_get_ysize(p); y++) {
2533 +                        if (pict_get_hangle(p, x, y, p->view.vdir, p->view.vup, &ang)) {
2534 +                                if (pict_is_validpixel(p, x, y)) {
2535 +                                        if (luminance(pict_get_color(pm, x, y))>0.1) {
2536 + /*                                         printf ("hallo %i %i %f \n",x,y,luminance(pict_get_color(pm, x, y)));*/
2537 +                                                  i_mask=i_mask+1;
2538 +                                                  lum_mask[0]=luminance(pict_get_color(p, x, y));
2539 +                                                 /* printf ("%f \n",lum_mask[0]);*/
2540 +                                                  muc_rvar_add_sample(s_mask, lum_mask);
2541 +                                                  omega_mask += pict_get_omega(p, x, y);
2542 +                                                  lum_mask_av += pict_get_omega(p, x, y)* luminance(pict_get_color(p, x, y));
2543 +                                                  E_v_mask +=DOT(p->view.vdir, pict_get_cached_dir(p, x, y))*pict_get_omega(p, x, y)* luminance(pict_get_color(p, x, y));
2544 +
2545 +                                                  pict_get_color(pm, x, y)[RED] = luminance(pict_get_color(p, x, y))/179.0;
2546 +                                                  pict_get_color(pm, x, y)[GRN] = luminance(pict_get_color(p, x, y))/179.0;
2547 +                                                  pict_get_color(pm, x, y)[BLU] = luminance(pict_get_color(p, x, y))/179.0;
2548 +  
2549 +                                           } else {
2550 +                                           pict_get_color(p, x, y)[RED] = 0.0 ;
2551 +                                           pict_get_color(p, x, y)[GRN] = 0.0 ;
2552 +                                           pict_get_color(p, x, y)[BLU] = 0.0 ;
2553 +                                           }
2554 +                                }
2555 +                        }
2556 +                }
2557 + /* Average luminance in masking area (weighted by solid angle) */
2558 +                lum_mask_av=lum_mask_av/omega_mask;
2559 +                muc_rvar_get_vx(s_mask,lum_mask_std);
2560 +                muc_rvar_get_percentile(s_mask,lum_mask_median,0.75);
2561 +                per_75_mask=lum_mask_median[0];
2562 +                muc_rvar_get_percentile(s_mask,lum_mask_median,0.95);
2563 +                per_95_mask=lum_mask_median[0];
2564 +                muc_rvar_get_median(s_mask,lum_mask_median);
2565 +                muc_rvar_get_bounding_box(s_mask,bbox);
2566 + /* PSGV only why masking of window is applied! */
2567 +                 pgsv = get_pgsv(E_v, E_v_mask, omega_mask, lum_mask_av);
2568 +                 pgsv_sat =get_pgsv_sat(E_v);
2569 +
2570          if (detail_out == 1) {
2571 +
2572 +                printf ("masking:no_pixels,omega,av_lum,median_lum,std_lum,perc_75,perc_95,lum_min,lum_max,pgsv,pgsv_sat: %i %f %f %f %f %f %f %f %f %f %f\n",i_mask,omega_mask,lum_mask_av,lum_mask_median[0],sqrt(lum_mask_std[0]),per_75_mask,per_95_mask,bbox[0],bbox[1],pgsv,pgsv_sat );
2573 +
2574 +        }      
2575 +                
2576 +        }
2577 +
2578 + /* zones */
2579 +
2580 +        if ( zones > 0 ) {
2581 +        
2582 +                for (x = 0; x < pict_get_xsize(p); x++)
2583 +                for (y = 0; y < pict_get_ysize(p); y++) {
2584 +                        if (pict_get_hangle(p, x, y, p->view.vdir, p->view.vup, &ang)) {
2585 +                                if (pict_is_validpixel(p, x, y)) {
2586 +
2587 +
2588 +                                 r_actual =acos(DOT(pict_get_cached_dir(p, x, y), pict_get_cached_dir(p, x_zone, y_zone))) * 2;
2589 +                                 lum_actual = luminance(pict_get_color(p, x, y));
2590 +                                 act_gsn=pict_get_gsn(p, x, y);
2591 +                            /*     printf("1act_gsn,pict_get_z1_gsn,pict_get_z2_gsn %i %f %f \n",act_gsn,pict_get_z1_gsn(p,act_gsn),pict_get_z2_gsn(p,act_gsn));*/
2592 +                                
2593 + /*zone1 */
2594 +                        if (r_actual <= angle_z1) {
2595 +                                                  i_z1=i_z1+1;
2596 +                                                  lum_z1[0]=lum_actual;
2597 +                                                  muc_rvar_add_sample(s_z1, lum_z1);
2598 +                                                  omega_z1 += pict_get_omega(p, x, y);
2599 +                                                  lum_z1_av += pict_get_omega(p, x, y)* lum_actual;
2600 +                                                  setglcolor(p,x,y,1,1 , 0.66, 0.01 ,0.33);
2601 + /*check if separation gsn already exist */
2602 +
2603 +                                                   if (act_gsn > 0){
2604 +                                                   if (pict_get_z1_gsn(p,act_gsn) == 0) {
2605 +                                                                                          pict_new_gli(p);
2606 +                                                                                          igs = igs + 1;
2607 +                                                                                          pict_get_z1_gsn(p,act_gsn) = igs*1.000;
2608 +                                                                                          pict_get_z1_gsn(p,igs) = -1.0;
2609 +                                                                                          pict_get_z2_gsn(p,igs) = -1.0;
2610 +                                                                                          splitgs=(int)(pict_get_z1_gsn(p,act_gsn));
2611 + /*                                                                                        printf ("Glare source %i gets glare source %i in zone 1 : %i %f %f \n",act_gsn,igs,splitgs,pict_get_z1_gsn(p,act_gsn),pict_get_z1_gsn(p,igs)); */
2612 +                                                                                         }
2613 +                                                    splitgs=(int)(pict_get_z1_gsn(p,act_gsn));
2614 +                                        /*          printf("splitgs%i \n",splitgs);       */              
2615 +                                                    split_pixel_from_gs(p, x, y, splitgs, uniform_gs, u_r, u_g , u_b);
2616 +                                                }                                
2617 +                                                  }
2618 + /*zone2 */
2619 +
2620 +                        if (r_actual > angle_z1 && r_actual<= angle_z2 ) {
2621 +
2622 +                                                  i_z2=i_z2+1;
2623 +                                                  lum_z2[0]=lum_actual;
2624 +                                                  muc_rvar_add_sample(s_z2, lum_z2);
2625 +                                                  omega_z2 +=   pict_get_omega(p, x, y);
2626 +                                                  lum_z2_av += pict_get_omega(p, x, y)* lum_actual;
2627 +                                                  setglcolor(p,x,y,1,1 , 0.65, 0.33 ,0.02);
2628 + /*                                                printf("zone 2 x y act_gsn pict_get_z1_gsn(p,act_gsn) pict_get_z2_gsn(p,act_gsn): %i %i %f 1:%f 2:%f \n",x,y,act_gsn,pict_get_z1_gsn(p,act_gsn),pict_get_z2_gsn(p,act_gsn));
2629 + */                                                if (act_gsn > 0){
2630 +                                                   if (pict_get_z2_gsn(p,act_gsn) == 0) {
2631 +                                                                                          pict_new_gli(p);
2632 +                                                                                          igs = igs + 1;
2633 +                                                                                          pict_get_z2_gsn(p,act_gsn) = igs*1.000;
2634 +                                                                                          pict_get_z1_gsn(p,igs) = -2.0;
2635 +                                                                                          pict_get_z2_gsn(p,igs) = -2.0;
2636 + /*                                                                                         printf ("Glare source %i gets glare source %i in zone 2 \n",act_gsn,igs ); */
2637 +                                                                                         }
2638 +                                                splitgs=(int)(pict_get_z2_gsn(p,act_gsn));
2639 + /*                                              printf("splitgs %i \n",splitgs);*/                              
2640 +                                                    split_pixel_from_gs(p, x, y, splitgs, uniform_gs, u_r, u_g , u_b);
2641 +                                           }
2642 +                                }
2643 +
2644 +                        }
2645 +                } }
2646 + /* Average luminance in zones (weighted by solid angle), calculate percentiles, median min and max in zones  */
2647 +               if (zones == 2 ) {
2648 +                lum_z2_av=lum_z2_av/omega_z2;
2649 +                muc_rvar_get_vx(s_z2,lum_z2_std);
2650 +                muc_rvar_get_percentile(s_z2,lum_z2_median,0.75);
2651 +                per_75_z2=lum_z2_median[0];
2652 +                muc_rvar_get_percentile(s_z2,lum_z2_median,0.95);
2653 +                per_95_z2=lum_z2_median[0];
2654 +                muc_rvar_get_median(s_z2,lum_z2_median);
2655 +                muc_rvar_get_bounding_box(s_z2,bbox_z2);
2656 +                }
2657 +                lum_z1_av=lum_z1_av/omega_z1;
2658 +                muc_rvar_get_vx(s_z1,lum_z1_std);
2659 +                muc_rvar_get_percentile(s_z1,lum_z1_median,0.75);
2660 +                per_75_z1=lum_z1_median[0];
2661 +                muc_rvar_get_percentile(s_z1,lum_z1_median,0.95);
2662 +                per_95_z1=lum_z1_median[0];
2663 +                muc_rvar_get_median(s_z1,lum_z1_median);
2664 +                muc_rvar_get_bounding_box(s_z1,bbox_z1);
2665 +        if (detail_out == 1) {
2666 +
2667 +                printf ("zoning:z1_omega,z1_av_lum,z1_median_lum,z1_std_lum,z1_perc_75,z1_perc_95,z1_lum_min,z1_lum_max: %f %f %f %f %f %f %f %f\n",omega_z1,lum_z1_av,lum_z1_median[0],sqrt(lum_z1_std[0]),per_75_z1,per_95_z1,bbox_z1[0],bbox_z1[1] );
2668 +
2669 +               if (zones == 2 ) {
2670 +
2671 +                printf ("zoning:z2_omega,z2_av_lum,z2_median_lum,z2_std_lum,z2_perc_75,z2_perc_95,z2_lum_min,z2_lum_max:  %f %f %f %f %f %f %f %f\n",omega_z2,lum_z2_av,lum_z2_median[0],sqrt(lum_z2_std[0]),per_75_z2,per_95_z2,bbox_z2[0],bbox_z2[1] );
2672 + } }            
2673 +                
2674 +        }
2675 +
2676                  i = 0;
2677                  for (x = 0; x <= igs; x++) {
2678   /* resorting glare source numbers */
# Line 2092 | Line 2680 | if (calcfast == 1 ) {
2680                                  i = i + 1;
2681                          }
2682                  }
2683 +                no_glaresources=i;
2684  
2685 + /* glare sources */
2686 +        if (detail_out == 1) {
2687  
2097
2688                  printf
2689 <                        ("%i No pixels x-pos y-pos L_s Omega_s Posindx L_b L_t E_vert Edir Max_Lum Sigma xdir ydir zdir Eglare_cie Lveil_cie \n",
2689 >                        ("%i No pixels x-pos y-pos L_s Omega_s Posindx L_b L_t E_vert Edir Max_Lum Sigma xdir ydir zdir Eglare_cie Lveil_cie teta glare_zone\n",
2690                           i);
2691                  if (i == 0) {
2692 <                        printf("%i %f %f %f %f %.10f %f %f %f %f %f %f\n", i, 0.0, 0.0,
2693 <                                   0.0, 0.0, 0.0, 0.0, lum_backg, lum_task, E_v, E_v_dir,
2104 <                                   abs_max);
2692 >                        printf("%i %f %f %f %f %.10f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", i, 0.0, 0.0,
2693 >                                   0.0, 0.0, 0.0, 0.0, lum_backg, lum_task, E_v, E_v_dir,abs_max,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
2694  
2695                  } else {
2696                          i = 0;
# Line 2121 | Line 2710 | if (calcfast == 1 ) {
2710                                                                       Lveil_cie =0 ;
2711                                                                     }
2712                                          Lveil_cie_sum =  Lveil_cie_sum + Lveil_cie;
2713 <                                        printf("%i %f %f %f %f %.10f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",
2713 >                                        if (pict_get_z1_gsn(p,x)<0) {
2714 >                                        act_gsn=(int)(-pict_get_z1_gsn(p,x));
2715 >                                        }else{
2716 >                                        act_gsn=0;
2717 >                                        }
2718 >                                        printf("%i %f %f %f %f %.10f %f %f %f %f %f %f %f %f %f %f %f %f %f %i \n",
2719                                                     i, pict_get_npix(p, x), pict_get_av_posx(p, x),
2720                                                     pict_get_ysize(p) - pict_get_av_posy(p, x),
2721                                                     pict_get_av_lum(p, x), pict_get_av_omega(p, x),
# Line 2129 | Line 2723 | if (calcfast == 1 ) {
2723                                                                                  pict_get_av_posy(p, x),
2724                                                                                  posindex_2), lum_backg, lum_task,
2725                                                     E_v, E_v_dir, abs_max, sigma * 180 / 3.1415927
2726 <                                                   ,pict_get_cached_dir(p, x2,y2)[0],pict_get_cached_dir(p, x2,y2)[1],pict_get_cached_dir(p, x2,y2)[2],pict_get_Eglare(p,x),Lveil_cie,teta
2133 <                                                  
2134 <                                                   );
2726 >                                                   ,pict_get_cached_dir(p, x2,y2)[0],pict_get_cached_dir(p, x2,y2)[1],pict_get_cached_dir(p, x2,y2)[2],pict_get_Eglare(p,x),Lveil_cie,teta,act_gsn );
2727                                  }
2728                          }
2729                  }
# Line 2171 | Line 2763 | if (calcfast == 1 ) {
2763          }
2764  
2765   if (calcfast == 0) {
2766 +        lum_a= E_v2/3.1415927;
2767          dgi = get_dgi(p, lum_backg, igs, posindex_2);
2768          ugr = get_ugr(p, lum_backg, igs, posindex_2);
2769 +        ugp = get_ugp (p,lum_backg, igs, posindex_2);
2770 +        ugr_exp = get_ugr_exp (p,lum_backg_cos,lum_a, igs, posindex_2);
2771 +        dgi_mod = get_dgi_mod(p, lum_a, igs, posindex_2);
2772          cgi = get_cgi(p, E_v, E_v_dir, igs, posindex_2);
2773 <        vcp = get_vcp(p, avlum, igs, posindex_2);
2773 >        dgr = get_dgr(p, avlum, igs, posindex_2);
2774 >        vcp = get_vcp(dgr);
2775          Lveil = get_disability(p, avlum, igs);
2776 +        if (no_glaresources == 0) {
2777 +                dgi = 0.0;
2778 +                ugr = 0.0;
2779 +                ugp = 0.0;
2780 +                ugr_exp = 0.0;
2781 +                dgi_mod = 0.0;
2782 +                cgi = 0.0;
2783 +                dgr = 0.0;
2784 +                vcp = 100.0;
2785 +        }
2786   }
2787   /* check dgp range */
2788          if (dgp <= 0.2) {
# Line 2201 | Line 2808 | if (calcfast == 0) {
2808                                  dgp =low_light_corr*dgp;
2809                                  dgp =age_corr_factor*dgp;
2810                          }
2811 +                muc_rvar_get_median(s_noposweight,lum_nopos_median);
2812 +                muc_rvar_get_median(s_posweight,lum_pos_median);
2813 +                muc_rvar_get_median(s_posweight2,lum_pos2_median);
2814 +
2815  
2816 +
2817 +        
2818                          printf
2819 <                                ("dgp,av_lum,E_v,lum_backg,E_v_dir,dgi,ugr,vcp,cgi,lum_sources,omega_sources,Lveil,Lveil_cie,band_avlum: %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n",
2819 >                                ("dgp,av_lum,E_v,lum_backg,E_v_dir,dgi,ugr,vcp,cgi,lum_sources,omega_sources,Lveil,Lveil_cie,dgr,ugp,ugr_exp,dgi_mod,av_lum_pos,av_lum_pos2,med_lum,med_lum_pos,med_lum_pos2: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",
2820                                   dgp, avlum, E_v, lum_backg, E_v_dir, dgi, ugr, vcp, cgi,
2821 <                                 lum_sources / omega_sources, omega_sources, Lveil,Lveil_cie_sum,band_avlum);
2821 >                                 lum_sources, omega_sources, Lveil,Lveil_cie_sum,dgr,ugp,ugr_exp,dgi_mod,lum_pos_mean,lum_pos2_mean/sang,lum_nopos_median[0],lum_pos_median[0],lum_pos2_median[0]);
2822                  } else {
2823                          if (detail_out2 == 1) {
2824  
# Line 2236 | Line 2849 | if (calcfast == 0) {
2849                                  if (E_vl_ext < 1000) {
2850                                  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 ;}
2851                                  dgp =low_light_corr*dgp;
2852 <                                dgp =age_corr_factor*dgp;
2853 <                printf("%f\n", dgp);
2852 >
2853 >                     if (calcfast == 2) {
2854 >                    
2855 >                         lum_backg_cos=(E_vl_ext-dir_ill)/3.1415927;
2856 >                         ugr = get_ugr(p, lum_backg_cos, igs, posindex_2);
2857 >                         printf("%f %f \n", dgp,ugr);
2858 >                     }else{      
2859 >                         printf("%f\n", dgp);
2860 >                }
2861          }
2862  
2863  
# Line 2268 | Line 2888 | has to be re-written from scratch....
2888  
2889   /*output  */
2890          if (checkfile == 1) {
2891 +                        
2892 +        
2893                  pict_write(p, file_out);
2894          }
2895  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines