function UR_show_airways3D(airways,path,up)
% UR_show_airways_3D - 3D visualization of airway corridors
% On input:
%     airways (airways data structure): describes airways
%     path (nx1 vector): corridor sequence
%     up (Boolean): if 1 then plot in 3D, else in plane
% On output:
%     N/A (displays plot of airways)
% Call:
%     UR_show_airways3D(aw,[],1);
% Author:
%     T. Henderson
%     UU
%     Summer 2019
%

UPPER_ZONE = 1;
LOWER_ZONE = 2;
ENTER_ZONE = 3;
EXIT_ZONE = 4;
CIRCLE_ZONE = 5;
LAUNCH_ZONE = 6;
LAND_ZONE = 7;
Z_UPPER = 501; % 534
Z_LOWER = 499; % 467
Z_CIRCLE = 500;

vertexes = airways.vertexes;
corridors = airways.corridors;

clf
hold on
num_corridors = length(corridors(:,1));
for c = 1:num_corridors
    switch corridors(c,7)
        case UPPER_ZONE
            plot3([corridors(c,1),corridors(c,4)],...
                [corridors(c,2),corridors(c,5)],...
                [corridors(c,3),corridors(c,6)],'k');
        case LOWER_ZONE
            plot3([corridors(c,1),corridors(c,4)],...
                [corridors(c,2),corridors(c,5)],...
                [corridors(c,3),corridors(c,6)],'m');
        case ENTER_ZONE
            plot3([corridors(c,1),corridors(c,4)],...
                [corridors(c,2),corridors(c,5)],...
                [corridors(c,3),corridors(c,6)],'g');
        case EXIT_ZONE
            plot3([corridors(c,1),corridors(c,4)],...
                [corridors(c,2),corridors(c,5)],...
                [corridors(c,3),corridors(c,6)],'g');
        case CIRCLE_ZONE
            plot3([corridors(c,1),corridors(c,4)],...
                [corridors(c,2),corridors(c,5)],...
                [corridors(c,3),corridors(c,6)],'b');
        case LAUNCH_ZONE
            plot3([corridors(c,1),corridors(c,4)],...
                [corridors(c,2),corridors(c,5)],...
                [corridors(c,3),corridors(c,6)],'y');
        case LAND_ZONE
            plot3([corridors(c,1),corridors(c,4)],...
                [corridors(c,2),corridors(c,5)],...
                [corridors(c,3),corridors(c,6)],'c');
    end
end

num_vertexes = length(vertexes(:,1));
for v = 1:num_vertexes
    s = num2str(v);
    if find(v==airways.launch_vertexes)
        s = [s,'u'];
    end
    if find(v==airways.land_vertexes)
        s = [s,'d'];
    end
    text(vertexes(v,1),vertexes(v,2),vertexes(v,3),s);
end

if ~isempty(path)
    cv = airways.cor_vertexes;
    ce = airways.cor_edges;
    len_path = length(path);
    for e = 1:len_path-1
        index1 = path(e);
        index2 = path(e+1);
        pt1 = cv(index1,:);
        pt2 = cv(index2,:);
        if up==1
            plot3([pt1(1),pt2(1)],[pt1(2),pt2(2)],[Z_UPPER,Z_UPPER],'r');
        else
            plot3([pt1(1),pt2(1)],[pt1(2),pt2(2)],[pt1(3),pt2(3)],'r');
        end
    end
end
