6 #define MIN_VALUE_OR -10.
7 #define MAX_DIF_NEXT_OR 15.
8 #define MIN_VALUE_NEXT_OR 0.
9 #define THR_CONT_ANAP 1
18 GridStats::GridStats()
22 GridStats::~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;
30 void 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;
46 Anaprop<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);
56 void 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);
65 void 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;
128 float bin_low = volume[el_inf].get(i, k);
130 if (el_up >= volume.size() || k >= volume[el_up].beam_size){
132 bin_high = volume[el_up].get(i, k);
135 bin_high = volume[el_up].get(i, k);
140 if(bin_high == fondo_scala && SD[el_inf].
get(i,k)<= conf_texture_threshold && SD[el_inf].
get(i,k) > 0.01)
143 MAX_DIF_NEXT=DBZ::BYTEtoDB(255);
144 MAX_DIF=DBZ::BYTEtoDB(255);
145 MIN_VALUE=fondo_scala;
146 MIN_VALUE_NEXT= fondo_scala;
152 MAX_DIF_NEXT=MAX_DIF_NEXT_OR;
153 MIN_VALUE=MIN_VALUE_OR;
154 MIN_VALUE_NEXT=MIN_VALUE_NEXT_OR;
158 if (cont_anap> THR_CONT_ANAP ||count_first_elev < 80 )
159 test_an=(bin_low > fondo_scala && bin_high >= fondo_scala );
161 test_an=(bin_low > fondo_scala && bin_high > fondo_scala );
162 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));
164 double loc_conf_text_thre ;
165 if (k <= 20 ) loc_conf_text_thre = 20. ;
166 else loc_conf_text_thre= conf_texture_threshold ;
175 MAX_DIF_USED = MAX_DIF_NEXT;
176 MIN_VALUE_USED = MIN_VALUE_NEXT;
181 MAX_DIF_USED = MAX_DIF;
182 MIN_VALUE_USED = MIN_VALUE;
188 bin_low-bin_high >= MAX_DIF_USED
191 bin_high <= MIN_VALUE_USED
193 bin_low > MIN_VALUE + 5
198 SD[el_inf].
get(i,k) > loc_conf_text_thre
213 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){
214 for(
unsigned l=0; l<el_up; l++){
215 volume[l].set(i, k, bin_high);
217 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)) ;
219 for(
unsigned l=0; l<el_up; l++){
220 volume[l].set(i, k, fondo_scala);
222 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)) ;
226 cont_anap=cont_anap+1;
227 grid_stats.incr_anap(i, k);
230 dato_corrotto(i, k)=ANAP_YES;
231 elev_fin(i, k) = el_up;
233 if (el_up > first_level_static(i, k)) grid_stats.incr_elev(i, k);
235 beam_blocking(i, k)=0;
241 for (
unsigned ii=0; ii<7; ii++){
242 int iaz_prox = (i + ii - 3 + volume.beam_count) % volume.beam_count;
243 if( SD[el_inf].get(iaz_prox,k) < loc_conf_text_thre && SD[el_inf].get(iaz_prox,k) > 0.01) count_low++;
244 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++;
246 if ( !(SD[el_inf].
get(i,k) < 1.3*loc_conf_text_thre && SD[el_inf].
get(i,k) > 0.01 && count_low >=5)) {
247 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)){
248 bin_low = fondo_scala;
249 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)) ;
250 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)) ;
254 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)) ;
257 elev_fin(i, k) = el_up;
259 if (el_up > first_level_static(i, k)) grid_stats.incr_elev(i, k);
261 beam_blocking(i, k)=0;
265 if (do_beamblocking && do_bloccorr)
267 bin_low = DBZ::beam_blocking_correction(bin_low, beam_blocking(i, k));
268 grid_stats.incr_bloc(i, k, beam_blocking(i, k));
271 for(
unsigned l=0; l<=el_inf; l++)
272 volume[l].set(i, k, bin_low);
273 sprintf(buf3,
" - fin %6.2f - TA-NO_AN",volume[0].
get(i,k)) ;
277 dato_corrotto(i, k)=ANAP_OK;
278 elev_fin(i, k) = el_inf;
280 if (el_inf > first_level_static(i, k)) grid_stats.incr_elev(i, k);
285 else if (bin_low < fondo_scala)
287 for(
unsigned l=0; l<el_up; l++)
289 if (volume[l].beam_size > k && volume[el_up].beam_size > k)
290 volume[l].set(i, k, bin_high);
291 else if (volume[l].beam_size > k )
292 volume[l].set(i, k, fondo_scala);
299 if (bin_high<fondo_scala) dato_corrotto(i, k)=ANAP_NODAT;
301 if (cont_anap< THR_CONT_ANAP )
302 test_an1=(bin_high>=fondo_scala);
304 test_an1=(bin_high>fondo_scala);
306 if (test_an1) dato_corrotto(i, k)=ANAP_NOCONTROL;
307 if (bin_high==fondo_scala) dato_corrotto(i, k)=ANAP_OK;
311 beam_blocking(i, k)=0;
315 else if (bin_low == fondo_scala || bin_high <= fondo_scala)
319 for (
unsigned ii=0; ii<7; ii++){
320 int iaz = (i + ii - 3 + volume.beam_count) % volume.beam_count;
321 if( SD[el_inf].get(iaz,k) < loc_conf_text_thre && SD[el_inf].get(iaz,k) > 0.01) count++;
323 if ( !(SD[el_inf].
get(i,k) < loc_conf_text_thre && SD[el_inf].
get(i,k) >0.01 && count >=5 ))
324 bin_low = fondo_scala;
326 for(
unsigned l=0; l<=el_inf; l++)
328 if (volume[l].beam_size > k)
329 volume[l].set(i, k, bin_low);
331 sprintf(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)) ;
335 dato_corrotto(i, k)=ANAP_OK;
336 elev_fin(i, k) = el_inf;
339 if (el_inf > first_level_static(i, k)) grid_stats.incr_elev(i, k);
345 quota(i, k)=(
unsigned short)PolarScanBase::sample_height(
346 elev_fin.elevation_at_elev_preci(i, k),
347 (k + 0.5) * volume[0].cell_size);
356 void Anaprop<T>::remove_without_SD(
358 PolarScan<unsigned char>& beam_blocking,
359 const PolarScan<unsigned char>& first_level,
360 const PolarScan<unsigned char>& first_level_static,
361 const Volume<double>& SD)
363 const double fondo_scala = volume[0].undetect;
364 LOG_WARN(
"Anaprop remove without SD");
367 for(
unsigned i=0; i<volume[0].beam_count; i++)
372 bool do_test_AP =
true;
373 double MAX_DIF=MAX_DIF_OR;
374 double MAX_DIF_NEXT=MAX_DIF_NEXT_OR;
375 double MIN_VALUE=MIN_VALUE_OR;
376 double MIN_VALUE_NEXT=MIN_VALUE_NEXT_OR;
378 double MIN_VALUE_USED, MAX_DIF_USED;
380 bool flag_anap =
false;
381 unsigned cont_anap=0;
382 unsigned count_first_elev=0;
385 for(
unsigned k=0; k<volume[0].beam_size; k++)
388 grid_stats.incr_tot(i, k);
390 int loc_el_inf = first_level(i, k) < volume.size() ? first_level(i,k) : volume.size()-1;
391 while ( k >= volume[loc_el_inf].beam_size)
395 if (loc_el_inf < 0)
throw std::runtime_error(
"loc_el_inf < 0");
400 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)){
405 const unsigned el_inf = loc_el_inf;
406 if (el_inf == 0) count_first_elev++;
408 elev_fin(i, k) = el_inf;
412 unsigned el_up = el_inf +1;
416 float bin_low = volume[el_inf].get(i, k);
418 if (el_up >= volume.size() || k >= volume[el_up].beam_size){
420 bin_high = volume[el_up].get(i, k);
423 bin_high = volume[el_up].get(i, k);
427 if(bin_high == fondo_scala && SD[el_inf].
get(i,k)<= conf_texture_threshold && SD[el_inf].
get(i,k) > 0.01)
430 MAX_DIF_NEXT=DBZ::BYTEtoDB(255);
431 MAX_DIF=DBZ::BYTEtoDB(255);
432 MIN_VALUE=fondo_scala;
433 MIN_VALUE_NEXT= fondo_scala;
439 MAX_DIF_NEXT=MAX_DIF_NEXT_OR;
440 MIN_VALUE=MIN_VALUE_OR;
441 MIN_VALUE_NEXT=MIN_VALUE_NEXT_OR;
445 if (cont_anap> THR_CONT_ANAP ||count_first_elev < 80 )
446 test_an=(bin_low > fondo_scala && bin_high >= fondo_scala );
448 test_an=(bin_low > fondo_scala && bin_high > fondo_scala );
457 MAX_DIF_USED = MAX_DIF_NEXT;
458 MIN_VALUE_USED = MIN_VALUE_NEXT;
463 MAX_DIF_USED = MAX_DIF;
464 MIN_VALUE_USED = MIN_VALUE;
468 ( bin_low-bin_high >= MAX_DIF_USED
471 bin_high <= MIN_VALUE_USED
473 bin_low > MIN_VALUE + 5
479 if(k < volume[el_up].beam_size ){
480 for(
unsigned l=0; l<el_up; l++){
481 volume[l].set(i, k, bin_high);
485 for(
unsigned l=0; l<el_up; l++){
486 volume[l].set(i, k, fondo_scala);
492 cont_anap=cont_anap+1;
493 grid_stats.incr_anap(i, k);
496 dato_corrotto(i, k)=ANAP_YES;
497 elev_fin(i, k) = el_up;
499 if (el_up > first_level_static(i, k)) grid_stats.incr_elev(i, k);
501 beam_blocking(i, k)=0;
507 if (do_beamblocking && do_bloccorr)
509 bin_low = DBZ::beam_blocking_correction(bin_low, beam_blocking(i, k));
510 grid_stats.incr_bloc(i, k, beam_blocking(i, k));
513 for(
unsigned l=0; l<=el_inf; l++)
514 volume[l].set(i, k, bin_low);
519 dato_corrotto(i, k)=ANAP_OK;
520 elev_fin(i, k) = el_inf;
522 if (el_inf > first_level_static(i, k)) grid_stats.incr_elev(i, k);
527 else if (bin_low < fondo_scala)
529 for(
unsigned l=0; l<el_up; l++)
531 if (volume[l].beam_size > k && volume[el_up].beam_size > k)
532 volume[l].set(i, k, bin_high);
533 else if (volume[l].beam_size > k )
534 volume[l].set(i, k, fondo_scala);
541 if (bin_high<fondo_scala) dato_corrotto(i, k)=ANAP_NODAT;
543 if (cont_anap< THR_CONT_ANAP )
544 test_an1=(bin_high>=fondo_scala);
546 test_an1=(bin_high>fondo_scala);
548 if (test_an1) dato_corrotto(i, k)=ANAP_NOCONTROL;
549 if (bin_high==fondo_scala) dato_corrotto(i, k)=ANAP_OK;
553 beam_blocking(i, k)=0;
557 else if (bin_low == fondo_scala || bin_high <= fondo_scala)
561 for (
unsigned ii=0; ii<7; ii++){
562 int iaz = (i + ii - 3 + volume.beam_count) % volume.beam_count;
563 if( SD[el_inf].get(iaz,k) < conf_texture_threshold && SD[el_inf].get(iaz,k) > 0.01) count++;
565 if ( !(SD[el_inf].
get(i,k) < conf_texture_threshold && SD[el_inf].
get(i,k) >0.01 && count >=5 ))
566 bin_low = fondo_scala;
568 for(
unsigned l=0; l<=el_inf; l++)
570 if (volume[l].beam_size > k)
571 volume[l].set(i, k, bin_low);
577 dato_corrotto(i, k)=ANAP_OK;
578 elev_fin(i, k) = el_inf;
581 if (el_inf > first_level_static(i, k)) grid_stats.incr_elev(i, k);
587 quota(i, k)=(
unsigned short)PolarScanBase::sample_height(
588 elev_fin.elevation_at_elev_preci(i, k),
589 (k + 0.5) * volume[0].cell_size);
595 template class Anaprop<double>;