%dimensione stanza
dim_stanza_x=10000;
dim_stanza_y=10000;

%Ricotrisco dati per ogni telecamera

T1P=[a{1}' b{1}' c{1}' num_pixel_centri{1}' x_f_as(1)*ones(length(a{1}),1) y_f_as(1)*ones(length(a{1}),1)];
T2P=[a{2}' b{2}' c{2}' num_pixel_centri{2}' x_f_as(2)*ones(length(a{2}),1) y_f_as(2)*ones(length(a{2}),1)];
T3P=[a{3}' b{3}' c{3}' num_pixel_centri{3}' x_f_as(3)*ones(length(a{3}),1) y_f_as(3)*ones(length(a{3}),1)];
T4P=[a{4}' b{4}' c{4}' num_pixel_centri{4}' x_f_as(4)*ones(length(a{4}),1) y_f_as(4)*ones(length(a{4}),1)];
T5P=[a{5}' b{5}' c{5}' num_pixel_centri{5}' x_f_as(5)*ones(length(a{5}),1) y_f_as(5)*ones(length(a{5}),1)];
T6P=[a{6}' b{6}' c{6}' num_pixel_centri{6}' x_f_as(6)*ones(length(a{6}),1) y_f_as(6)*ones(length(a{6}),1)];
T7P=[a{7}' b{7}' c{7}' num_pixel_centri{7}' x_f_as(7)*ones(length(a{7}),1) y_f_as(7)*ones(length(a{7}),1)];
T8P=[a{8}' b{8}' c{8}' num_pixel_centri{8}' x_f_as(8)*ones(length(a{8}),1) y_f_as(8)*ones(length(a{8}),1)];
T9P=[a{9}' b{9}' c{9}' num_pixel_centri{9}' x_f_as(9)*ones(length(a{9}),1) y_f_as(9)*ones(length(a{9}),1)];
T10P=[a{10}' b{10}' c{10}' num_pixel_centri{10}' x_f_as(10)*ones(length(a{10}),1) y_f_as(10)*ones(length(a{10}),1)];
T11P=[a{11}' b{11}' c{11}' num_pixel_centri{11}' x_f_as(11)*ones(length(a{11}),1) y_f_as(11)*ones(length(a{11}),1)];
T12P=[a{12}' b{12}' c{12}' num_pixel_centri{12}' x_f_as(12)*ones(length(a{12}),1) y_f_as(12)*ones(length(a{12}),1)];
T13P=[a{13}' b{13}' c{13}' num_pixel_centri{13}' x_f_as(13)*ones(length(a{13}),1) y_f_as(13)*ones(length(a{13}),1)];
T14P=[a{14}' b{14}' c{14}' num_pixel_centri{14}' x_f_as(14)*ones(length(a{14}),1) y_f_as(14)*ones(length(a{14}),1)];
T15P=[a{15}' b{15}' c{15}' num_pixel_centri{15}' x_f_as(15)*ones(length(a{15}),1) y_f_as(15)*ones(length(a{15}),1)];
T16P=[a{16}' b{16}' c{16}' num_pixel_centri{16}' x_f_as(16)*ones(length(a{16}),1) y_f_as(16)*ones(length(a{16}),1)];


%%Inizializzo raggi

R11Pa3=cell(1,2);
R21Pa3=cell(1,2);
R31Pa3=cell(1,2);
R41Pa3=cell(1,2);
R51Pa3=cell(1,2);
R61Pa3=cell(1,2);
R71Pa3=cell(1,2);
R81Pa3=cell(1,2);

%Inizializzo i punti ricostruiti

tmpP11a3=cell(1,4);
tmpP11a3{1}=[-1 -1 -1];
tmpP11a3{2}=[1 1 1 1 1 1];
tmpP11a3{3}=[1 1 1 1 1 1];
tmpP11a3{4}=[1 1 1 1 1 1];


P11Pa3=cell(1,2);
P11Pa3{1}=tmpP11a3;
P11Pa3{2}=tmpP11a3;

%Associo le telecamere ricordando che al primo passo nn vi sono
%ricostruzioni

R11Pa3{1}=T1P;
R11Pa3{2}=T2P;
R21Pa3{1}=T3P;
R21Pa3{2}=T4P;
R31Pa3{1}=T5P;
R31Pa3{2}=T6P;
R41Pa3{1}=T7P;
R41Pa3{2}=T8P;
R51Pa3{1}=T9P;
R51Pa3{2}=T10P;
R61Pa3{1}=T11P;
R61Pa3{2}=T12P;
R71Pa3{1}=T13P;
R71Pa3{2}=T14P;
R81Pa3{1}=T15P;
R81Pa3{2}=T16P;

%secondo passo dell'albero
tic
[R12Pa3 P12Pa3]=associa3_pes(R11Pa3, R21Pa3, P11Pa3, P11Pa3,epsilon,dim_stanza_x,dim_stanza_y,d_max);
t4=toc; %valuto i tempi
set(S.tP1R4,'string',t4,'visible','on')
tic
[R22Pa3 P22Pa3]=associa3_pes(R31Pa3, R41Pa3, P11Pa3, P11Pa3,epsilon,dim_stanza_x,dim_stanza_y,d_max);
t3=toc;
set(S.tP1R3,'string',t3,'visible','on')
tic
[R32Pa3 P32Pa3]=associa3_pes(R51Pa3, R61Pa3, P11Pa3, P11Pa3,epsilon,dim_stanza_x,dim_stanza_y,d_max);
t2=toc;
set(S.tP1R2,'string',t2,'visible','on')
tic
[R42Pa3 P42Pa3]=associa3_pes(R71Pa3, R81Pa3, P11Pa3, P11Pa3,epsilon,dim_stanza_x,dim_stanza_y,d_max);
t1=toc;
set(S.tP1R1,'string',t1,'visible','on')

tmp=max([t1 t2 t3 t4])

%terzo passo dell'albero

tic
[R13Pa3 P13Pa3]=associa3_pes(R12Pa3, R22Pa3, P12Pa3, P22Pa3,epsilon,dim_stanza_x,dim_stanza_y,d_max);
t2=toc;
set(S.tP2R2,'string',t2,'visible','on')
tic
[R23Pa3 P23Pa3]=associa3_pes(R32Pa3, R42Pa3, P32Pa3, P42Pa3,epsilon,dim_stanza_x,dim_stanza_y,d_max);
t3=toc;
set(S.tP2R1,'string',t3,'visible','on')

tmp=tmp+max([t2 t3]);

%quarto passo dell'albero

tic
[R14Pa3 P14Pa3]=associa3_pes(R13Pa3, R23Pa3, P13Pa3, P23Pa3,epsilon,dim_stanza_x,dim_stanza_y,d_max); 
tmpo=toc;
set(S.tP3R1,'string',tmpo,'visible','on')
tmp=tmp+tmpo;
set(S.Ttot,'string',tmp,'visible','on') %Calcolo anche massimo tempo esecuzione considerando un approccio distribuito
