6#define MIN_VALUE_OR -10.
7#define MAX_DIF_NEXT_OR 15.
8#define MIN_VALUE_NEXT_OR 0.
22GridStats::~GridStats()
24 if (stat_anap)
delete[] stat_anap;
25 if (stat_tot)
delete[] stat_tot;
26 if (stat_bloc)
delete[] stat_bloc;
27 if (stat_elev)
delete[] stat_elev;
30void GridStats::init(
const Volume<double>& volume)
32 size_az = volume[0].beam_count / step_stat_az + 1;
33 size_beam = volume[0].beam_size / step_stat_range + 1;
34 stat_anap =
new unsigned[size_az * size_beam];
35 stat_tot =
new unsigned[size_az * size_beam];
36 stat_bloc =
new unsigned[size_az * size_beam];
37 stat_elev =
new unsigned[size_az * size_beam];
39 for (
unsigned i = 0; i < size_az * size_beam; ++i)
40 stat_anap[i] = stat_tot[i] = stat_bloc[i] = stat_elev[i] = 0;
46Anaprop<T>::Anaprop(
const Volume<T>& volume)
47 : elev_fin(volume), dato_corrotto(volume.beam_count, volume.max_beam_size(), 0),
48 quota(volume.beam_count, volume.max_beam_size(), 0)
50 logging_category = log4c_category_get(
"radar.anaprop");
51 LOG_WARN(
"Anaprop init");
52 grid_stats.init(volume);
56void Anaprop<T>::init_elev_fin_static(
const Volume<T>& volume,
const PolarScan<unsigned char>& first_level_static)
58 for(
unsigned i=0; i < volume[0].beam_count; ++i)
59 for(
unsigned k=0; k < volume[0].beam_size; ++k)
61 elev_fin(i, k) = first_level_static(i, k);
65void Anaprop<T>::remove(
67 PolarScan<unsigned char>& beam_blocking,
68 const PolarScan<unsigned char>& first_level,
69 const PolarScan<unsigned char>& first_level_static,
70 const Volume<double>& SD)
72 const double fondo_scala = volume[0].undetect;
73 unsigned NUM_AZ_X_PPI=volume[0].beam_count;
76 for (
unsigned i = 0; i < volume.beam_count; ++i)
81 bool do_test_AP =
true;
82 double MAX_DIF=MAX_DIF_OR;
83 double MAX_DIF_NEXT=MAX_DIF_NEXT_OR;
84 double MIN_VALUE=MIN_VALUE_OR;
85 double MIN_VALUE_NEXT=MIN_VALUE_NEXT_OR;
87 double MIN_VALUE_USED, MAX_DIF_USED;
89 bool flag_anap =
false;
91 unsigned count_first_elev=0;
94 for(
unsigned k=0; k<volume[0].beam_size; k++)
97 char buf1 [256], buf2[256], buf3[256];
98 unsigned count_low =0;
99 unsigned count_high=0;
102 grid_stats.incr_tot(i, k);
105 int loc_el_inf = first_level(i, k) < volume.size() ? first_level(i,k) : volume.size()-1;
107 while ( k >= volume[loc_el_inf].beam_size)
111 if (loc_el_inf < 0)
throw std::runtime_error(
"loc_el_inf < 0");
113 while (loc_el_inf > 0 && SD[loc_el_inf-1].get(i,k) < conf_texture_threshold && SD[loc_el_inf-1].get(i,k)>=0.01 && volume[loc_el_inf-1].get(i,k) > volume[loc_el_inf].get(i,k)){
117 const unsigned el_inf = loc_el_inf;
118 if (el_inf == 0) count_first_elev++;
120 elev_fin(i, k) = el_inf;
124 unsigned el_up = el_inf +1;
129 float bin_low = volume[el_inf].get(i, k);
131 if (el_up >= volume.size() || k >= volume[el_up].beam_size){
133 bin_high = volume[el_up].get(i, k);
136 bin_high = volume[el_up].get(i, k);
142 if(bin_high == fondo_scala && SD[el_inf].get(i,k)<= conf_texture_threshold && SD[el_inf].get(i,k) > 0.01)
145 MAX_DIF_NEXT=DBZ::BYTEtoDB(255);
146 MAX_DIF=DBZ::BYTEtoDB(255);
147 MIN_VALUE=fondo_scala;
148 MIN_VALUE_NEXT= fondo_scala;
154 MAX_DIF_NEXT=MAX_DIF_NEXT_OR;
155 MIN_VALUE=MIN_VALUE_OR;
156 MIN_VALUE_NEXT=MIN_VALUE_NEXT_OR;
160 if (cont_anap> THR_CONT_ANAP ||count_first_elev < 80 )
161 test_an=(bin_low > fondo_scala && bin_high >= fondo_scala );
163 test_an=(bin_low > fondo_scala && bin_high > fondo_scala );
164 sprintf(buf1,
"b@(%3d,%3d) - el_inf %2d - el_up %2d -low %6.2f - up %6.2f - cont %3d %1d %1d %6.2f %6.2f %6.2f %6.2f -- %6.2f %6.2f ",i,k,el_inf,el_up,bin_low,bin_high, cont_anap,test_an, flag_anap, MAX_DIF, MIN_VALUE, MAX_DIF_NEXT, MIN_VALUE_NEXT, SD[el_inf].get(i,k),SD[el_up].get((i),k));
166 double loc_conf_text_thre ;
167 if (k <= 20 ) loc_conf_text_thre = 20. ;
168 else loc_conf_text_thre= conf_texture_threshold ;
177 MAX_DIF_USED = MAX_DIF_NEXT;
178 MIN_VALUE_USED = MIN_VALUE_NEXT;
183 MAX_DIF_USED = MAX_DIF;
184 MIN_VALUE_USED = MIN_VALUE;
190 bin_low-bin_high >= MAX_DIF_USED
193 bin_high <= MIN_VALUE_USED
195 bin_low > MIN_VALUE + 5
200 SD[el_inf].get(i,k) > loc_conf_text_thre
215 if(k < volume[el_up].beam_size && SD[el_up].get(i,k) <= loc_conf_text_thre && SD[el_up].get(i,k) >= 0.01){
216 for(
unsigned l=0; l<el_up; l++){
217 volume[l].set(i, k, bin_high);
219 sprintf(buf2,
" tex_th %4.1f cl %4d cu %4d - fin %6.2f - TA-AN",loc_conf_text_thre, count_low, count_high, volume[0].get(i,k)) ;
221 for(
unsigned l=0; l<el_up; l++){
222 volume[l].set(i, k, fondo_scala);
224 if (k < volume[el_up].beam_size) sprintf(buf2,
" tex_th %4.1f cl %4d cu %4d - fin %6.2f - TA-AN set to fondo_scala",loc_conf_text_thre,count_low, count_high, volume[0].get(i,k)) ;
228 cont_anap=cont_anap+1;
229 grid_stats.incr_anap(i, k);
232 dato_corrotto(i, k)=ANAP_YES;
233 elev_fin(i, k) = el_up;
235 if (el_up > first_level_static(i, k)) grid_stats.incr_elev(i, k);
237 beam_blocking(i, k)=0;
243 for (
unsigned ii=0; ii<7; ii++){
244 int iaz_prox = (i + ii - 3 + volume.beam_count) % volume.beam_count;
245 if( SD[el_inf].get(iaz_prox,k) < loc_conf_text_thre && SD[el_inf].get(iaz_prox,k) > 0.01) count_low++;
246 if( k < SD[el_up].beam_size && SD[el_up].get(iaz_prox,k) < 1.7*loc_conf_text_thre&& SD[el_up].get(iaz_prox,k) > 0.01) count_high++;
248 if ( !(SD[el_inf].get(i,k) < 1.3*loc_conf_text_thre && SD[el_inf].get(i,k) > 0.01 && count_low >=5)) {
249 if ( k >= SD[el_up].beam_size || !(SD[el_up].get(i,k) < 1.7* loc_conf_text_thre && SD[el_up].get(i,k) > 0.01 && count_high >=3)){
250 bin_low = fondo_scala;
251 if ( k < SD[el_up].beam_size ) sprintf(buf2,
" tex_th %4.1f cl %4d cu %4d - fin %6.2f - TA-NO_AN low = fondo",loc_conf_text_thre,count_low, count_high, volume[0].get(i,k)) ;
252 else sprintf(buf2,
" tex_th %4.1f cl %4d cu %4d - fin %6.2f - TA-NO_AN low = fondo",loc_conf_text_thre,count_low, count_high, volume[0].get(i,k)) ;
256 sprintf(buf2,
" tex_th %4.1f cl %4d cu %4d - fin %6.2f - TA-NO_AN low = high",loc_conf_text_thre,count_low, count_high, volume[0].get(i,k)) ;
259 elev_fin(i, k) = el_up;
261 if (el_up > first_level_static(i, k)) grid_stats.incr_elev(i, k);
263 beam_blocking(i, k)=0;
267 if (do_beamblocking && do_bloccorr)
269 bin_low = DBZ::beam_blocking_correction(bin_low, beam_blocking(i, k));
270 grid_stats.incr_bloc(i, k, beam_blocking(i, k));
273 for(
unsigned l=0; l<=el_inf; l++)
274 volume[l].set(i, k, bin_low);
275sprintf(buf3,
" - fin %6.2f - TA-NO_AN",volume[0].get(i,k)) ;
279 dato_corrotto(i, k)=ANAP_OK;
280 elev_fin(i, k) = el_inf;
282 if (el_inf > first_level_static(i, k)) grid_stats.incr_elev(i, k);
287 else if (bin_low < fondo_scala)
289 for(
unsigned l=0; l<el_up; l++)
291 if (volume[l].beam_size > k && volume[el_up].beam_size > k)
292 volume[l].set(i, k, bin_high);
293 else if (volume[l].beam_size > k )
294 volume[l].set(i, k, fondo_scala);
301 if (bin_high<fondo_scala) dato_corrotto(i, k)=ANAP_NODAT;
303 if (cont_anap< THR_CONT_ANAP )
304 test_an1=(bin_high>=fondo_scala);
306 test_an1=(bin_high>fondo_scala);
308 if (test_an1) dato_corrotto(i, k)=ANAP_NOCONTROL;
309 if (bin_high==fondo_scala) dato_corrotto(i, k)=ANAP_OK;
313 beam_blocking(i, k)=0;
317 else if (bin_low == fondo_scala || bin_high <= fondo_scala)
321 for (
unsigned ii=0; ii<7; ii++){
322 int iaz = (i + ii - 3 + volume.beam_count) % volume.beam_count;
323 if( SD[el_inf].get(iaz,k) < loc_conf_text_thre && SD[el_inf].get(iaz,k) > 0.01) count++;
325 if ( !(SD[el_inf].get(i,k) < loc_conf_text_thre && SD[el_inf].get(i,k) >0.01 && count >=5 ))
326 bin_low = fondo_scala;
328 for(
unsigned l=0; l<=el_inf; l++)
330 if (volume[l].beam_size > k)
331 volume[l].set(i, k, bin_low);
333sprintf(buf2,
" tex_th %4.1f cl %4d cu %4d - fin %6.2f - NO_TA low = fondo",loc_conf_text_thre,count_low, count_high, volume[0].get(i,k)) ;
337 dato_corrotto(i, k)=ANAP_OK;
338 elev_fin(i, k) = el_inf;
341 if (el_inf > first_level_static(i, k)) grid_stats.incr_elev(i, k);
347 quota(i, k)=(
unsigned short)PolarScanBase::sample_height(
348 elev_fin.elevation_at_elev_preci(i, k),
349 (k + 0.5) * volume[0].cell_size);
358void Anaprop<T>::remove_without_SD(
360 PolarScan<unsigned char>& beam_blocking,
361 const PolarScan<unsigned char>& first_level,
362 const PolarScan<unsigned char>& first_level_static,
363 const Volume<double>& SD)
365 const double fondo_scala = volume[0].undetect;
366LOG_WARN(
"Anaprop remove without SD");
369 for(
unsigned i=0; i<volume[0].beam_count; i++)
374 bool do_test_AP =
true;
375 double MAX_DIF=MAX_DIF_OR;
376 double MAX_DIF_NEXT=MAX_DIF_NEXT_OR;
377 double MIN_VALUE=MIN_VALUE_OR;
378 double MIN_VALUE_NEXT=MIN_VALUE_NEXT_OR;
380 double MIN_VALUE_USED, MAX_DIF_USED;
382 bool flag_anap =
false;
383 unsigned cont_anap=0;
384 unsigned count_first_elev=0;
387 for(
unsigned k=0; k<volume[0].beam_size; k++)
390 grid_stats.incr_tot(i, k);
392 int loc_el_inf = first_level(i, k) < volume.size() ? first_level(i,k) : volume.size()-1;
394 while ( k >= volume[loc_el_inf].beam_size)
398 if (loc_el_inf < 0)
throw std::runtime_error(
"loc_el_inf < 0");
404 while (loc_el_inf > 0 && SD[loc_el_inf-1].get(i,k) < conf_texture_threshold && SD[loc_el_inf-1].get(i,k)>=0.01 && volume[loc_el_inf-1].get(i,k) > volume[loc_el_inf].get(i,k)){
409 const unsigned el_inf = loc_el_inf;
410 if (el_inf == 0) count_first_elev++;
412 elev_fin(i, k) = el_inf;
416 unsigned el_up = el_inf +1;
420 float bin_low = volume[el_inf].get(i, k);
422 if (el_up >= volume.size() || k >= volume[el_up].beam_size){
425 bin_high = volume[el_up].get(i, k);
428 bin_high = volume[el_up].get(i, k);
432 if(bin_high == fondo_scala && SD[el_inf].get(i,k)<= conf_texture_threshold && SD[el_inf].get(i,k) > 0.01)
435 MAX_DIF_NEXT=DBZ::BYTEtoDB(255);
436 MAX_DIF=DBZ::BYTEtoDB(255);
437 MIN_VALUE=fondo_scala;
438 MIN_VALUE_NEXT= fondo_scala;
444 MAX_DIF_NEXT=MAX_DIF_NEXT_OR;
445 MIN_VALUE=MIN_VALUE_OR;
446 MIN_VALUE_NEXT=MIN_VALUE_NEXT_OR;
450 if (cont_anap> THR_CONT_ANAP ||count_first_elev < 80 )
451 test_an=(bin_low > fondo_scala && bin_high >= fondo_scala );
453 test_an=(bin_low > fondo_scala && bin_high > fondo_scala );
462 MAX_DIF_USED = MAX_DIF_NEXT;
463 MIN_VALUE_USED = MIN_VALUE_NEXT;
468 MAX_DIF_USED = MAX_DIF;
469 MIN_VALUE_USED = MIN_VALUE;
473 ( bin_low-bin_high >= MAX_DIF_USED
476 bin_high <= MIN_VALUE_USED
478 bin_low > MIN_VALUE + 5
484 if(k < volume[el_up].beam_size ){
485 for(
unsigned l=0; l<el_up; l++){
486 volume[l].set(i, k, bin_high);
490 for(
unsigned l=0; l<el_up; l++){
491 volume[l].set(i, k, fondo_scala);
497 cont_anap=cont_anap+1;
498 grid_stats.incr_anap(i, k);
501 dato_corrotto(i, k)=ANAP_YES;
502 elev_fin(i, k) = el_up;
504 if (el_up > first_level_static(i, k)) grid_stats.incr_elev(i, k);
506 beam_blocking(i, k)=0;
512 if (do_beamblocking && do_bloccorr)
514 bin_low = DBZ::beam_blocking_correction(bin_low, beam_blocking(i, k));
515 grid_stats.incr_bloc(i, k, beam_blocking(i, k));
518 for(
unsigned l=0; l<=el_inf; l++)
519 volume[l].set(i, k, bin_low);
524 dato_corrotto(i, k)=ANAP_OK;
525 elev_fin(i, k) = el_inf;
527 if (el_inf > first_level_static(i, k)) grid_stats.incr_elev(i, k);
532 else if (bin_low < fondo_scala)
534 for(
unsigned l=0; l<el_up; l++)
536 if (volume[l].beam_size > k && volume[el_up].beam_size > k)
537 volume[l].set(i, k, bin_high);
538 else if (volume[l].beam_size > k )
539 volume[l].set(i, k, fondo_scala);
546 if (bin_high<fondo_scala) dato_corrotto(i, k)=ANAP_NODAT;
548 if (cont_anap< THR_CONT_ANAP )
549 test_an1=(bin_high>=fondo_scala);
551 test_an1=(bin_high>fondo_scala);
553 if (test_an1) dato_corrotto(i, k)=ANAP_NOCONTROL;
554 if (bin_high==fondo_scala) dato_corrotto(i, k)=ANAP_OK;
558 beam_blocking(i, k)=0;
562 else if (bin_low == fondo_scala || bin_high <= fondo_scala)
566 for (
unsigned ii=0; ii<7; ii++){
567 int iaz = (i + ii - 3 + volume.beam_count) % volume.beam_count;
568 if( SD[el_inf].get(iaz,k) < conf_texture_threshold && SD[el_inf].get(iaz,k) > 0.01) count++;
570 if ( !(SD[el_inf].get(i,k) < conf_texture_threshold && SD[el_inf].get(i,k) >0.01 && count >=5 ))
571 bin_low = fondo_scala;
573 for(
unsigned l=0; l<=el_inf; l++)
575 if (volume[l].beam_size > k)
576 volume[l].set(i, k, bin_low);
582 dato_corrotto(i, k)=ANAP_OK;
583 elev_fin(i, k) = el_inf;
586 if (el_inf > first_level_static(i, k)) grid_stats.incr_elev(i, k);
592 quota(i, k)=(
unsigned short)PolarScanBase::sample_height(
593 elev_fin.elevation_at_elev_preci(i, k),
594 (k + 0.5) * volume[0].cell_size);
600template class Anaprop<double>;