function [rec] = FDK_reconstruction(proj, filter, cutoff)
% funkce pro FDK rekonstrukci z projekčních dat
% proj .. projekční data
% filter .. filtr pro rekonstrukci
% cutoff.. cut-off frekvence
    addpath( genpath(recon.foldersearch(pwd, 'astra') ) ); % add astra 

    det_width = size(proj, 2);
    det_height = size(proj, 1);
    num_angles = size(proj, 3);
    angles = linspace(0, pi, num_angles);

    vol_geom = astra_create_vol_geom(det_width, det_width, det_height);
    % a few more inputs than in the 2D case, but the principle stays the same
    % for simulated data these numbers were optimal, for measured data the
    % distances are known
    source_origin = 10^7;
    origin_detector =10^7;
    proj_geom = astra_create_proj_geom('cone', 2.0, 2.0, det_width, det_height, angles,source_origin, origin_detector); % origin-detector distance);

    vol_id = astra_mex_data3d('create', '-vol', vol_geom);
    proj = perm_matlab_to_astra(proj);
    sino_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj);

    % konfigurace algoritmu
    cfg = astra_struct('FDK_CUDA');
    cfg.ProjectionDataId = sino_id;
    cfg.FilterType = filter;
    cfg.FilterD = cutoff;
    cfg.ReconstructionDataId = vol_id;
    algo_id = astra_mex_algorithm('create', cfg);
    astra_mex_algorithm('run', algo_id);
    rec = astra_mex_data3d('get', vol_id);


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
