function h = plotPerson(axisHandler,person,connections,tags,colors)

% axes(axisHandler);
% if ~isempty(h)
%     delete(h)
% end
% keyboard
%Get all objects with tag person and delete them
h = findobj(axisHandler,'Tag','person'); % try to find the old point
if ~isempty(h)
    delete(h);
end

h = [];

%Create two lists of point to plot, the renamed and the original, plot
%in different colors

% keyboard

%If the tag name starts with a capital L it belongs to the orignal
%labeling
original_mask = strncmp(tags,'t.L',3);

original_points = person(:,original_mask);
original_tags = tags(original_mask);

renamed_mask = ~original_mask;

rename_points = person(:,renamed_mask);
renamed_tags = tags(renamed_mask);

% keyboard

left_mask = strncmp(tags,'t.l',3);

left_points = person(:,left_mask);

right_mask = strncmp(tags,'t.r',3);

right_points = person(:,right_mask);

all_other_mask = renamed_mask & ~left_mask & ~right_mask;
all_other_points = person(:,all_other_mask);


h(end+1) = plot3(axisHandler,original_points(1,:),original_points(2,:),original_points(3,:));
set(h(end),'color',colors(3,:),'marker','o','linestyle','none','markersize',10);
set(h(end),'MarkerFaceColor',colors(4,:))

% h(end+1) = plot3(rename_points(1,:),rename_points(2,:),rename_points(3,:));
% set(h(end),'color',colors(1,:),'marker','o','linestyle','none','markersize',10);
% set(h(end),'MarkerFaceColor',colors(2,:))

left_color = [255, 216, 0]/255;
right_color = [17, 140, 78]/255;
all_other_color = [255, 144, 9]/255;

h(end+1) = plot3(axisHandler,left_points(1,:),left_points(2,:),left_points(3,:));
set(h(end),'color',left_color,'marker','o','linestyle','none','markersize',10);
set(h(end),'MarkerFaceColor',left_color)

h(end+1) = plot3(axisHandler,right_points(1,:),right_points(2,:),right_points(3,:));
set(h(end),'color',right_color,'marker','o','linestyle','none','markersize',10);
set(h(end),'MarkerFaceColor',right_color)

h(end+1) = plot3(axisHandler,all_other_points(1,:),all_other_points(2,:),all_other_points(3,:));
set(h(end),'color',all_other_color,'marker','o','linestyle','none','markersize',10);
set(h(end),'MarkerFaceColor',all_other_color)

displacement = [0.02 0.02 0.02];

% keyboard

small_tags = cellfun(@(s)(s(3:end)), original_tags, 'UniformOutput', false);
displaced_points = original_points + repmat(displacement',1,size(original_points,2));
ht = text(displaced_points(1,:),displaced_points(2,:),displaced_points(3,:),small_tags,'Parent', axisHandler);
set(ht,'color',colors(6,:))
% set(ht,'fontsize',18)
h = [h ht'];

small_tags = cellfun(@(s)(s(3:end)), renamed_tags, 'UniformOutput', false);
displaced_points = rename_points + repmat(displacement',1,size(rename_points,2));
ht=text(displaced_points(1,:),displaced_points(2,:),displaced_points(3,:),small_tags,'Parent', axisHandler);
set(ht,'color',colors(6,:))
% set(ht,'fontsize',18)
h = [h ht'];

for i=1:length(tags)
    tag = char(tags{i});
    eval(sprintf('%s = [person(1,strcmp(''%s'',tags)) person(2,strcmp(''%s'',tags)) person(3,strcmp(''%s'',tags))]'';',tag,tag,tag,tag));
end

% keyboard

for i=1:size(connections,1)
    tag_1 = connections{i,1};
    tag_1 = tag_1(3:end);
    
    tag_2 = connections{i,2};
    tag_2 = tag_2(3:end);
    
    if isfield(t,tag_1) && isfield(t,tag_2)
        eval(sprintf('h(end+1) = plot3(axisHandler,[%s(1) %s(1)],[%s(2) %s(2)],[%s(3) %s(3)]);',connections{i,1},connections{i,2},connections{i,1},connections{i,2},connections{i,1},connections{i,2}))
        set(h(end),'LineWidth',1.5,'color',colors(5,:));
    end
end
    
set(h,'Tag','person')

% else
    
%     set(h(f), 'XData',person(1,:), 'YData',person(2,:), 'ZData',person(3,:));
%     f=f+1;
%     
%     for i=1:length(tags)
%         set(h(f), 'Position',[person(1,i)+0.010 person(2,i)+0.010 person(3,i)+0.010]);      
%         f=f+1;
%     end
%     
%     for i=1:length(tags)
%         eval(sprintf('%s = [person(1,strcmp(''%s'',tags)) person(2,strcmp(''%s'',tags)) person(3,strcmp(''%s'',tags))]'';',char(tags{i}),char(tags{i}),char(tags{i}),char(tags{i})));
%     end
%     
%     
%     for i=1:size(connections,1)
%         if exist(connections{i,1},'var') && exist(connections{i,2},'var')
%             eval(sprintf('set(h(%d),''XData'',[%s(1) %s(1)],''YData'',[%s(2) %s(2)],''ZData'',[%s(3) %s(3)]);',f,connections{i,1},connections{i,2},connections{i,1},connections{i,2},connections{i,1},connections{i,2}))
%             f=f+1;
%     %         eval(sprintf('set(h(),[%s(1) %s(1)],[%s(2) %s(2)],[%s(3) %s(3)]);',connections{i,1},connections{i,2},connections{i,1},connections{i,2},connections{i,1},connections{i,2}))
%         end
%     end
%     
% end
