function H = drawEnvironment
% H = drawEnvironment
%  Crea la struttura grafica per 8 cams e 9 aree.
%  Restituisce la variabile struct dei puntatori agli elementi utili:
%     H.view(1..8) :  handlers delle aree di copertura
%      H.cam(1..8) :  handlers delle cams
%     H.historybox :  handler dell'history-textbox
%        H.poolbox :  handler del pool-textbox
%      H.bar(1..4) :  handlers dei contatori di task

close all;

% Create figure
figure('Tag','figura','Units','normalized','Position',[.1 .1 .8 .5],...
    'NumberTitle','off','Name','TaskViewer','Color',[0.75 0.75 0.75],...
    'menubar','none');

% Create cam axes
axes('Parent',gcf,'Tag','assi','Position',[0 0 0.5 1],...
    'ZTickLabel','','ZTick',zeros(1,0),'YTickLabel','','YTick',zeros(1,0),...
    'XTickLabel','','XTick',zeros(1,0),'TickDir','in',...
    'PlotBoxAspectRatio',[1 1 1],'MinorGridLineStyle','none',...
    'GridLineStyle','none','FontUnits','normalized','FontSize',0.03876,...
    'DataAspectRatio',[1 1 2],'CLim',[0 1],'CameraViewAngle',6.609,...
    'CameraUpVector',[0 1 0],'CameraTarget',[0.5 0.5 0],...
    'CameraPosition',[0.5 0.5 17.32],'ALim',[0 1]);
xlim([0 1]); ylim([0 1]); hold('all');

% Create wall
rectangle('Parent',gca,'Tag','muro','Position',[-0.01 -0.01 1.02 1.02],...
    'EdgeColor',[0.75 0.75 0.75],'FaceColor',[0.75 0.75 0.75]);
rectangle('Parent',gca,'Tag','muro','Position',[.1 .1 .8 .8],...
    'EdgeColor',[0 0 0],'FaceColor',[1 1 1]);
rectangle('Parent',gca,'Tag','muro','Position',[0.3 0.3 0.1 0.4],...
    'EdgeColor',[0 0 0],'FaceColor',[0.75 0.75 0.75]);
rectangle('Parent',gca,'Tag','muro','Position',[0.6 0.3 0.1 0.4],...
    'EdgeColor',[0 0 0],'FaceColor',[0.75 0.75 0.75]);

% Create view patch
H.view(1) = patch([.4 .4 .31 .31 .69 .69 .59 .59],[.31 .7 .7 .89 .89 .71 .71 .31],...
    [1 1 1],'EdgeColor',[1 1 1],'Parent',gca,'CDataMapping','direct',...
    'AlphaDataMapping','none','FaceAlpha',0.2,'LineStyle',':','Tag','view1');
H.view(2) = patch([.31 .31 .41 .41 .6 .6 .69 .69],[.11 .29 .29 .69 .69 .3 .3 .11],...
    [1 1 1],'EdgeColor',[1 1 1],'Parent',gca,'CDataMapping','direct',...
    'AlphaDataMapping','none','FaceAlpha',0.2,'LineStyle',':','Tag','view2');
H.view(3) = patch([.1 .1 .69 .69 .29 .29],[.31 .9 .9 .71 .71 .31],[1 1 1],...
    'EdgeColor',[1 1 1],'Parent',gca,'CDataMapping','direct',...
    'AlphaDataMapping','none','FaceAlpha',0.2,'LineStyle',':','Tag','view3');
H.view(4) = patch([.31 .31 .9 .9 .71 .71],[.71 .9 .9 .31 .31 .71],[1 1 1],...
    'EdgeColor',[1 1 1],'Parent',gca,'CDataMapping','direct',...
    'AlphaDataMapping','none','FaceAlpha',0.2,'LineStyle',':','Tag','view4');
H.view(5) = patch([.31 .31 .71 .71 .9 .9],[.1 .29 .29 .69 .69 .1],[1 1 1],...
    'EdgeColor',[1 1 1],'Parent',gca,'CDataMapping','direct',...
    'AlphaDataMapping','none','FaceAlpha',0.2,'LineStyle',':','Tag','view5');
H.view(6) = patch([.1 .1 .29 .29 .69 .69],[.1 .69 .69 .29 .29 .1],[1 1 1],...
    'EdgeColor',[1 1 1],'Parent',gca,'CDataMapping','direct',...
    'AlphaDataMapping','none','FaceAlpha',0.2,'LineStyle',':','Tag','view6');
H.view(7) = patch([.11 .11 .3 .3],[.11 .89 .89 .11],[1 1 1],'EdgeColor',[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none',...
    'FaceAlpha',0.2,'LineStyle',':','Tag','view7');
H.view(8) = patch([.7 .7 .89 .89],[.11 .89 .89 .11],[1 1 1],'EdgeColor',[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none',...
    'FaceAlpha',0.2,'LineStyle',':','Tag','view8');

% Create cam patch
H.cam(1) = patch([0.3771 0.4166 0.4182 0.4265 0.4328 0.4213 0.4229 0.3834],...
    [0.6666 0.6729 0.6630 0.6744 0.6349 0.6433 0.6334 0.6271],[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none','Tag','cam1');
H.cam(2) = patch([0.6229 0.5834 0.5818 0.5735 0.5672 0.5787 0.5771 0.6166],...
    [0.3334 0.3271 0.3370 0.3256 0.3651 0.3567 0.3666 0.3729],[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none','Tag','cam2');
H.cam(3) = patch([0.1000 0.1283 0.1212 0.1354 0.1071 0.1071 0.1000 0.0717],...
    [0.9283 0.9000 0.8929 0.8929 0.8646 0.8788 0.8717 0.9000],[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none','Tag','cam3');
H.cam(4) = patch([0.9283 0.9000 0.8929 0.8929 0.8646 0.8788 0.8717 0.9000],...
    [0.9000 0.8717 0.8788 0.8646 0.8929 0.8929 0.9000 0.9283],[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none','Tag','cam4');
H.cam(5) = patch([0.9000 0.8717 0.8788 0.8646 0.8929 0.8929 0.9000 0.9283],...
    [0.0717 0.1000 0.1071 0.1071 0.1354 0.1212 0.1283 0.1000],[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none','Tag','cam5');
H.cam(6) = patch([0.0717 0.1000 0.1071 0.1071 0.1354 0.1212 0.1283 0.1000],...
    [0.1000 0.1283 0.1212 0.1354 0.1071 0.1071 0.1000 0.0717],[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none','Tag','cam6');
H.cam(7) = patch([0.3200 0.2800 0.2800 0.2700 0.2700 0.2800 0.2800 0.3200],...
    [0.4800 0.4800 0.4900 0.4800 0.5200 0.5100 0.5200 0.5200],[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none','Tag','cam7');
H.cam(8) = patch([0.6800 0.7200 0.7200 0.7300 0.7300 0.7200 0.7200 0.6800],...
    [0.5200 0.5200 0.5100 0.5200 0.4800 0.4900 0.4800 0.4800],[1 1 1],...
    'Parent',gca,'CDataMapping','direct','AlphaDataMapping','none','Tag','cam8');

% Create area text
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.5 0.5 0],'String','A1','Tag','area1');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.5 0.8 0],'String','A2','Tag','area2');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.5 0.2 0],'String','A3','Tag','area3');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.2 0.5 0],'String','A4','Tag','area4');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.8 0.5 0],'String','A5','Tag','area5');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.2 0.8 0],'String','A6','Tag','area6');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.8 0.8 0],'String','A7','Tag','area7');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.8 0.2 0],'String','A8','Tag','area8');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.04,...
    'Position',[0.2 0.2 0],'String','A9','Tag','area9');

% Create label text
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.035,...
    'Position',[0.35 0.65 0],'String','C1','Tag','label1');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.035,...
    'Position',[0.65 0.35 0],'String','C2','Tag','label2');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.035,...
    'Position',[0.15 0.93 0],'String','C3','Tag','label3');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.035,...
    'Position',[0.85 0.93 0],'String','C4','Tag','label4');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.035,...
    'Position',[0.85 0.07 0],'String','C5','Tag','label5');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.035,...
    'Position',[0.15 0.07 0],'String','C6','Tag','label6');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.035,...
    'Position',[0.35 0.5 0],'String','C7','Tag','label7');
text('Parent',gca,'Interpreter','none','Units','normalized','LineStyle','none',...
    'HorizontalAlignment','center','FontUnits','normalized','FontSize',0.035,...
    'Position',[0.65 0.5 0],'String','C8','Tag','label8');

% Create historyBox
annotation(gcf,'textbox','Interpreter','none','FontUnits','normalized',...
    'FontSize',0.035,'FitHeightToText','on','BackgroundColor',[.75 .75 .75],...
    'LineStyle','none','Position',[0.55 0.93 0.4 0.035],'String','History:',...
    'FontWeight','bold','Tag','historyBoxLabel');
H.historybox = annotation(gcf,'textbox','Interpreter','none','FontUnits',...
    'normalized','FontSize',0.029,'FitHeightToText','off',...
    'BackgroundColor',[1 1 1],'Position',[0.55 0.506 0.4 0.404],'Tag','historyBox');

% Create poolBox
annotation(gcf,'textbox','Interpreter','none','FontUnits','normalized',...
    'FontSize',0.035,'FitHeightToText','on','BackgroundColor',[.75 .75 .75],...
    'LineStyle','none','Position',[0.55 0.473 0.4 0.035],'String','Pool:',...
    'FontWeight','bold','Tag','poolBoxLabel');
H.poolbox = annotation(gcf,'textbox','Interpreter','none','FontUnits',...
    'normalized','FontSize',0.029,'FitHeightToText','off',...
    'BackgroundColor',[1 1 1],'Position',[0.55 0.356 0.4 0.1],'Tag','poolBox');

% Create pool axes
% subplot(326);
axes('Parent',gcf,'ZTickLabel','','ZTick',zeros(1,0),...
    'YTickLabel',{'PAT','STR','TRK','OP'},'YTick',[1 2 3 4],...
    'XTickLabel',{'0','1','2','3','4','5','6','7','8','9','10'},...
    'XTick',[0 1 2 3 4 5 6 7 8 9 10],'XGrid','on','TickLength',[0.01 0.01],...
    'Position',[0.55 0.1 0.4 0.25],'FontUnits','normalized',...
    'FontSize',0.11,'Color',[0.75 0.75 0.75],'CameraUpVector',[0 1 0],...
    'CameraTarget',[5 2.5 0.5],'CameraPosition',[5 2.5 9.16],'ALim',[0 1]);
xlim([0 10]); ylim([0.5 4.5]); zlim([0 1]); box('on'); hold('all');

H.bar(1) = rectangle('Parent',gca,'Tag','barPAT','Position',[0 0.6 .05 0.8],...
    'EdgeColor',[0 0 0],'FaceColor',[0 .67 .67]);
H.bar(2) = rectangle('Parent',gca,'Tag','barSTR','Position',[0 1.6 .05 0.8],...
    'EdgeColor',[0 0 0],'FaceColor',[.67 .67 0]);
H.bar(3) = rectangle('Parent',gca,'Tag','barTRK','Position',[0 2.6 .05 0.8],...
    'EdgeColor',[0 0 0],'FaceColor',[.67 0 0]);
H.bar(4) = rectangle('Parent',gca,'Tag','barOP','Position',[0 3.6 .05 0.8],...
    'EdgeColor',[0 0 0],'FaceColor',[0 0 1]);

end