function [xm, ym, zm] = plotsegRAY(data, AxesAFS, pv, lcs)
    
if data.afs.SegStruc(pv-1,1) == 2
    if data.afs.seg{pv-1}.isplane
        axes(AxesAFS);
        fill3(data.afs.seg{pv-1}.plane(:,1), data.afs.seg{pv-1}.plane(:,2), data.afs.seg{pv-1}.plane(:,3), lcs(data.afs.seg{pv-1}.col,:), 'facealpha',.15);
        hold(AxesAFS, 'on');
    end
elseif data.afs.SegStruc(pv-1,1) == 3
    pts = data.afs.lines{data.afs.SegStruc(pv-1,2)}.pts;
    plot3(pts(:,1), pts(:,2), pts(:,3), 'color', lcs(data.afs.seg{pv-1}.col,:), 'Linewidth',3);
    hold(AxesAFS, 'on');
end

for j=1:length(data.afs.seg{pv-1}.line)
    if data.afs.seg{pv-1}.col <= size(lcs,1)
        plot3(AxesAFS, data.afs.pts(data.afs.seg{pv-1}.line{j}.lin,1), data.afs.pts(data.afs.seg{pv-1}.line{j}.lin,2), data.afs.pts(data.afs.seg{pv-1}.line{j}.lin,3), 'color', lcs(data.afs.seg{pv-1}.col,:));
    else
        plot3(AxesAFS, data.afs.pts(data.afs.seg{pv-1}.line{j}.lin,1), data.afs.pts(data.afs.seg{pv-1}.line{j}.lin,2), data.afs.pts(data.afs.seg{pv-1}.line{j}.lin,3), 'k');
    end
    hold(AxesAFS, 'on');
end
axis(AxesAFS, 'tight');

xm = get(AxesAFS, 'XLim');
ym = get(AxesAFS, 'YLim');
zm = get(AxesAFS, 'ZLim');

if xm(1) < 0 xm(1) = xm(1)*1.05; else xm(1) = xm(1)*0.95;end;
if xm(2) > 0 xm(2) = xm(2)*1.05; else xm(2) = xm(2)*0.95;end;

if ym(1) < 0 ym(1) = ym(1)*1.05; else ym(1) = ym(1)*0.95;end;
if ym(2) > 0 ym(2) = ym(2)*1.05; else ym(2) = ym(2)*0.95;end;

if zm(1) < 0 zm(1) = zm(1)*1.05; else zm(1) = zm(1)*0.95;end;
if zm(2) > 0 zm(2) = zm(2)*1.05; else zm(2) = zm(2)*0.95;end;

xlabel(AxesAFS, '\alpha')
ylabel(AxesAFS, '\beta')
zlabel(AxesAFS, '\gamma')

for i=1:4
    if (data.InitT(i,2) > xm(1)) && (data.InitT(i,2) < xm(2)) && (data.InitT(i,3) > ym(1)) && (data.InitT(i,3) < ym(2)) && (data.InitT(i,4) > zm(1)) && (data.InitT(i,4) < zm(2))
        plot3(AxesAFS, data.InitT(i,2), data.InitT(i,3), data.InitT(i,4), '*', 'color', lcs(i,:), 'Markersize', 10, 'Linewidth', 2);
    end
end

if data.plotIP
    axes(AxesAFS);
    trisurf(data.INNPOL.surf,data.INNPOL.t(:,1),data.INNPOL.t(:,2),data.INNPOL.t(:,3), 'Facecolor','r');
end
if data.plotFP
    axes(AxesAFS);
    trisurf(data.FIRPOL.surf,data.FIRPOL.t(:,1),data.FIRPOL.t(:,2),data.FIRPOL.t(:,3), 'Facecolor','k', 'Facealpha', 0.1);
end
hold(AxesAFS, 'off');

set(AxesAFS, 'XLim', xm, 'YLim', ym, 'ZLim', zm);