function [Sol,tim] = transformRAY(data,bndpts,nx,pv,Footnote,type)
tim = cputime;

Sol.T = [];
Sol.A = [];

if data.afs.SegStruc(pv,1) == 1
    nb = floor(100/bndpts*2);
    
    OUT = data.afs.seg{pv}.OUT;
    INN = data.afs.seg{pv}.INN;
    
    if size(OUT, 1) == 0
        return
    end
    
    [mi,id(1)] = max(OUT(:,1));
    [mi,id(2)] = min(OUT(:,1));
    [mi,id(3)] = max(OUT(:,2));
    [mi,id(4)] = min(OUT(:,2));
    [mi,id(5)] = max(OUT(:,3));
    [mi,id(6)] = min(OUT(:,3));
    
    for i=1:nb:size(OUT,1)
        id(end+1) = i;
    end
    
    id = unique(id);
    T = OUT(id,:);
    
    ID = id;
    
    id= [];
    [mi,id(1)] = max(INN(:,1));
    [mi,id(2)] = min(INN(:,1));
    [mi,id(3)] = max(INN(:,2));
    [mi,id(4)] = min(INN(:,2));
    [mi,id(5)] = max(INN(:,3));
    [mi,id(6)] = min(INN(:,3));
    for i=1:nb:size(INN,1)-floor(nb/2)
        id(end+1) = i+floor(nb/2);
    end
    
    id = unique(id);
    T = [T; INN(id,:)];
    
    ID = unique([ID, id]);
    
    for i=ID
        al = linspace(0,1,nx+2);
        for j=2:nx+1
            T = [T; al(j)*OUT(i,:)+(1-al(j))*INN(i,:)];
        end
    end
    
    if type == 1
        set(Footnote,'String',['Feasible spectra computed for ',num2str(size(T,1)),' out of ',num2str(size(OUT,1)),' rays of this segment.']);
    end
    
    Sol.T = T;
    Sol.A = [ones(size(T,1),1) T]*data.V';
    
    tim = cputime-tim;
    
elseif data.afs.SegStruc(pv,1) == 2
    
    nb = floor(100/bndpts*2);
    
    T = data.afs.seg{data.afs.SegStruc(pv,2)}.plane;
    T = [T; data.afs.seg{pv}.OUT(1:nb:end,:)];
    
    if type == 1
        set(Footnote,'String',['Feasible spectra computed for ',num2str(size(T,1)),' rays of this segment as well as for the boundary of the plane segmnet are plotted.']);
    end
    
    Sol.T = T;
    Sol.A = [ones(size(T,1),1) T]*data.V';
    
    tim = cputime-tim;
    
elseif data.afs.SegStruc(pv,1) == 3
    pts = data.afs.lines{data.afs.SegStruc(pv,2)}.pts(1:2,:);
    T = pts;
    
    al = linspace(0,1,nx+2);
    for j=2:nx+1
        T = [T; al(j)*pts(1,:)+(1-al(j))*pts(2,:)];
    end
    
    if type == 1
        set(Footnote,'String',['A number of ',num2str(size(T,1)),' feasible spectra are computed.']);
    end
    
    Sol.T = T;
    Sol.A = [ones(size(T,1),1) T]*data.V';
    
    tim = cputime-tim;
    
elseif data.afs.SegStruc(pv,1) == 4
    T = data.afs.seg{data.afs.SegStruc(pv,2)}.pts(1,:);
    
    if type == 1
        set(Footnote,'String',['A number of ',num2str(size(T,1)),' feasible spectra are computed.']);
    end
    
    Sol.T = T;
    Sol.A = [ones(size(T,1),1) T]*data.V';
    
    tim = cputime-tim;
    
end
