function [rec] = FBP_reconstruction(proj, filter, cutoff)
% funkce na rekonstrukci pomocí FBP
% proj.. pojekční data
% filter .. frekvenční filtr - RamLak, Hann, cosine, Hamming atd..
% cutoff .. cut-off frekvence pro tento filtr

    addpath( genpath(recon.foldersearch(pwd, 'astra') ) ); % add astra 

    det_width = size(proj, 2);
    det_height = size(proj, 1);
    num_angles = size(proj, 3);
    
    for i=1:det_height
        sinogram=transpose(squeeze(proj(i,:,:)));
        [a,b] = size(sinogram);
        vol_geom = astra_create_vol_geom(b,b);
        angles = linspace2(0,pi,num_angles);
        proj_geom = astra_create_proj_geom('parallel', 1.0, round(1*b), angles);
        %proj_geom = astra_geom_postalignment(proj_geom, [cor_shift, det_width/2]);
        proj_id = astra_create_projector('cuda', proj_geom, vol_geom);
        sinogram_id = astra_mex_data2d('create', '-sino', proj_geom, sinogram);
        rec_id = astra_mex_data2d('create','-vol',vol_geom);
        
        % nakofigurování algoritmu
        cfg = astra_struct('FBP_CUDA');
        cfg.FilterType = filter;
        cfg.FilterD = cutoff;
        cfg.ReconstructionDataId = rec_id;
        cfg.ProjectionDataId = sinogram_id;
        cfg.ProjectorId = proj_id;
        
        alg_id = astra_mex_algorithm('create', cfg);
        astra_mex_algorithm('run', alg_id);
        
        % Get the result
        rec(:,:,i) = astra_mex_data2d('get', rec_id);
        
        astra_mex_algorithm('delete', alg_id);
        astra_mex_data2d('delete', rec_id);
        astra_mex_data2d('delete', sinogram_id);

    end 

function astra_proj = perm_matlab_to_astra( matlab_proj)
            perm_vec = [2, 3, 1]; % vector for permuting data so that astra likes them
            % permutes data from my coord system to ASTRA's
            astra_proj = permute(matlab_proj, perm_vec);
            % so that projs are the way ASTRA likes it
end
end
