From cce8c565f2f56c575870ef922b6d28b5f99ca8c8 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 16 Oct 2017 23:15:46 +0200 Subject: Fix outdated function call in matlab DART algorithm. (Thanks @NathanaelSix) --- matlab/algorithms/DART/StatisticsDefault.m | 2 +- matlab/algorithms/DART/tools/DARToptimizerBoneStudy.m | 2 +- matlab/algorithms/DART/tools/ProjDiffOptimFunc.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'matlab') diff --git a/matlab/algorithms/DART/StatisticsDefault.m b/matlab/algorithms/DART/StatisticsDefault.m index 02e877b..84275d9 100644 --- a/matlab/algorithms/DART/StatisticsDefault.m +++ b/matlab/algorithms/DART/StatisticsDefault.m @@ -42,7 +42,7 @@ classdef StatisticsDefault < matlab.mixin.Copyable % projection difference if strcmp(this.proj_diff, 'yes') - new_sino = DART.tomography.createForwardProjection(DART, DART.S); + new_sino = DART.tomography.project(DART.S); stats.proj_diff = sum((new_sino(:) - DART.base.sinogram(:)) .^2 ) ./ (sum(DART.base.sinogram(:)) ); stats.proj_diff_hist(DART.iterationcount) = stats.proj_diff; end diff --git a/matlab/algorithms/DART/tools/DARToptimizerBoneStudy.m b/matlab/algorithms/DART/tools/DARToptimizerBoneStudy.m index c641f87..f488cd6 100644 --- a/matlab/algorithms/DART/tools/DARToptimizerBoneStudy.m +++ b/matlab/algorithms/DART/tools/DARToptimizerBoneStudy.m @@ -97,7 +97,7 @@ function rmse = optim_func(values, D_base, params, Optim) % compute rmse ROI = load('roi.mat'); [rmse, f_250, f_100, w_250, w_125] = compute_rmse(D.S, ROI); - %projection = D.tomography.createForwardProjection(D, D.S); + %projection = D.tomography.project(D.S); %proj_diff = sum((projection(:) - D.base.sinogram(:)).^2); % save diff --git a/matlab/algorithms/DART/tools/ProjDiffOptimFunc.m b/matlab/algorithms/DART/tools/ProjDiffOptimFunc.m index 72b328f..64d71fd 100644 --- a/matlab/algorithms/DART/tools/ProjDiffOptimFunc.m +++ b/matlab/algorithms/DART/tools/ProjDiffOptimFunc.m @@ -19,7 +19,7 @@ classdef ProjDiffOptimFunc < handle methods (Access=public) function proj_diff = calculate(~, D, ~) - projection = D.tomography.createForwardProjection(D, D.S); + projection = D.tomography.project(D.S); proj_diff = sum((projection(:) - D.base.sinogram(:)).^2); end -- cgit v1.2.3 From b3a80d71aa9a80223729b8cb47a55297f985faaf Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 17 Oct 2017 10:41:55 +0200 Subject: Improve matlab create_vol_geom --- matlab/tools/astra_create_vol_geom.m | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'matlab') diff --git a/matlab/tools/astra_create_vol_geom.m b/matlab/tools/astra_create_vol_geom.m index bf24609..24fa957 100644 --- a/matlab/tools/astra_create_vol_geom.m +++ b/matlab/tools/astra_create_vol_geom.m @@ -38,21 +38,12 @@ if numel(varargin) == 1 && numel(varargin{1}) == 1 vol_geom = struct(); vol_geom.GridRowCount = varargin{1}(1); vol_geom.GridColCount = varargin{1}(1); - vol_geom.option.WindowMinX = -varargin{1}(1) / 2; - vol_geom.option.WindowMaxX = varargin{1}(1) / 2; - vol_geom.option.WindowMinY = -varargin{1}(1) / 2; - vol_geom.option.WindowMaxY = varargin{1}(1) / 2; - % astra_create_vol_geom([row_count col_count]) elseif numel(varargin) == 1 && numel(varargin{1}) == 2 vol_geom = struct(); vol_geom.GridRowCount = varargin{1}(1); vol_geom.GridColCount = varargin{1}(2); - vol_geom.option.WindowMinX = -varargin{1}(2) / 2; - vol_geom.option.WindowMaxX = varargin{1}(2) / 2; - vol_geom.option.WindowMinY = -varargin{1}(1) / 2; - vol_geom.option.WindowMaxY = varargin{1}(1) / 2; % astra_create_vol_geom([row_count col_count slice_count]) elseif numel(varargin) == 1 && numel(varargin{1}) == 3 @@ -60,22 +51,12 @@ elseif numel(varargin) == 1 && numel(varargin{1}) == 3 vol_geom.GridRowCount = varargin{1}(1); vol_geom.GridColCount = varargin{1}(2); vol_geom.GridSliceCount = varargin{1}(3); - vol_geom.option.WindowMinX = -varargin{1}(2) / 2; - vol_geom.option.WindowMaxX = varargin{1}(2) / 2; - vol_geom.option.WindowMinY = -varargin{1}(1) / 2; - vol_geom.option.WindowMaxY = varargin{1}(1) / 2; - vol_geom.option.WindowMinZ = -varargin{1}(3) / 2; - vol_geom.option.WindowMaxZ = varargin{1}(3) / 2; % astra_create_vol_geom(row_count, col_count) elseif numel(varargin) == 2 vol_geom = struct(); vol_geom.GridRowCount = varargin{1}; vol_geom.GridColCount = varargin{2}; - vol_geom.option.WindowMinX = -varargin{2} / 2; - vol_geom.option.WindowMaxX = varargin{2} / 2; - vol_geom.option.WindowMinY = -varargin{1} / 2; - vol_geom.option.WindowMaxY = varargin{1} / 2; % astra_create_vol_geom(row_count, col_count, min_x, max_x, min_y, max_y) elseif numel(varargin) == 6 @@ -108,3 +89,15 @@ elseif numel(varargin) == 9 vol_geom.option.WindowMaxZ = varargin{9}; end + +% set the window options, if not set already. +if ~isfield(vol_geom, 'option') || ~isfield(vol_geom.option, 'WindowMinX') + vol_geom.option.WindowMinX = -vol_geom.GridColCount / 2; + vol_geom.option.WindowMaxX = vol_geom.GridColCount / 2; + vol_geom.option.WindowMinY = -vol_geom.GridRowCount / 2; + vol_geom.option.WindowMaxY = vol_geom.GridRowCount / 2; + if isfield(vol_geom, 'GridSliceCount') + vol_geom.option.WindowMinZ = -vol_geom.GridSliceCount / 2; + vol_geom.option.WindowMaxZ = vol_geom.GridSliceCount / 2; + end +end -- cgit v1.2.3 From 207e8f099f8004de82ee02fff235e85638ca2223 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 17 Oct 2017 17:39:11 +0200 Subject: Add astra_get_gpu_info utility function --- matlab/mex/astra_mex_c.cpp | 19 +++++++++++++++++++ matlab/tools/astra_get_gpu_info.m | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 matlab/tools/astra_get_gpu_info.m (limited to 'matlab') diff --git a/matlab/mex/astra_mex_c.cpp b/matlab/mex/astra_mex_c.cpp index d9ff8f3..c16059f 100644 --- a/matlab/mex/astra_mex_c.cpp +++ b/matlab/mex/astra_mex_c.cpp @@ -39,6 +39,7 @@ along with the ASTRA Toolbox. If not, see . #ifdef ASTRA_CUDA #include "../cuda/2d/darthelper.h" +#include "../cuda/2d/util.h" #include "astra/CompositeGeometryManager.h" #endif @@ -131,6 +132,22 @@ void astra_mex_set_gpu_index(int nlhs, mxArray* plhs[], int nrhs, const mxArray* #endif } +/** get_gpu_info = astra_mex('get_gpu_info'); + * + * Get GPU info + */ +void astra_mex_get_gpu_info(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ +#ifdef ASTRA_CUDA + int device = -1; + if (nrhs >= 2 && mxIsDouble(prhs[1]) && mxGetN(prhs[1]) * mxGetM(prhs[1]) == 1 ) { + device = (int)mxGetScalar(prhs[1]); + } + mexPrintf("%s\n", astraCUDA::getCudaDeviceString(device).c_str()); +#endif +} + + //----------------------------------------------------------------------------------------- /** version_number = astra_mex('version'); * @@ -222,6 +239,8 @@ void mexFunction(int nlhs, mxArray* plhs[], astra_mex_credits(nlhs, plhs, nrhs, prhs); } else if (sMode == std::string("set_gpu_index")) { astra_mex_set_gpu_index(nlhs, plhs, nrhs, prhs); + } else if (sMode == std::string("get_gpu_info")) { + astra_mex_get_gpu_info(nlhs, plhs, nrhs, prhs); } else if (sMode == std::string("info")) { astra_mex_info(nlhs, plhs, nrhs, prhs); } else if (sMode == std::string("delete")) { diff --git a/matlab/tools/astra_get_gpu_info.m b/matlab/tools/astra_get_gpu_info.m new file mode 100644 index 0000000..c220371 --- /dev/null +++ b/matlab/tools/astra_get_gpu_info.m @@ -0,0 +1,20 @@ +function astra_set_gpu_index(index) + +%-------------------------------------------------------------------------- +% Set the index of the GPU to use +%-------------------------------------------------------------------------- +%-------------------------------------------------------------------------- +% This file is part of the ASTRA Toolbox +% +% Copyright: 2010-2016, iMinds-Vision Lab, University of Antwerp +% 2014-2016, CWI, Amsterdam +% License: Open Source under GPLv3 +% Contact: astra@uantwerpen.be +% Website: http://www.astra-toolbox.com/ +%-------------------------------------------------------------------------- + +if nargin < 1 + astra_mex('get_gpu_info'); +else + astra_mex('get_gpu_info', index); +end -- cgit v1.2.3 From 84e163009c10f6ac5631cf5f29a4923852542eaf Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 17 Oct 2017 22:29:52 +0200 Subject: Add basic post-install matlab tests --- matlab/tools/astra_test_CUDA.m | 59 ++++++++++++++++++++++++++++++++++++++++ matlab/tools/astra_test_noCUDA.m | 32 ++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 matlab/tools/astra_test_CUDA.m create mode 100644 matlab/tools/astra_test_noCUDA.m (limited to 'matlab') diff --git a/matlab/tools/astra_test_CUDA.m b/matlab/tools/astra_test_CUDA.m new file mode 100644 index 0000000..4171f20 --- /dev/null +++ b/matlab/tools/astra_test_CUDA.m @@ -0,0 +1,59 @@ +%-------------------------------------------------------------------------- +% Clears and frees memory of all objects (data, projectors, algorithms) +% currently in the astra-library. +%-------------------------------------------------------------------------- +%-------------------------------------------------------------------------- +% This file is part of the ASTRA Toolbox +% +% Copyright: 2010-2017, iMinds-Vision Lab, University of Antwerp +% 2014-2017, CWI, Amsterdam +% License: Open Source under GPLv3 +% Contact: astra@uantwerpen.be +% Website: http://www.astra-toolbox.com/ +%-------------------------------------------------------------------------- + +%% +fprintf('Getting GPU info...') +astra_get_gpu_info() + +%% +astra_test_noCUDA() + +%% +fprintf('Testing basic CUDA 2D functionality...') + +vg = astra_create_vol_geom(2, 32); +pg = astra_create_proj_geom('parallel', 1, 32, [0]); +proj_id = astra_create_projector('cuda', pg, vg); + +vol = rand(2, 32); +[sino_id, sino] = astra_create_sino(vol, proj_id); +astra_mex_data2d('delete', sino_id); +astra_mex_projector('delete', proj_id); + +err = max(abs(sino - sum(vol))); + +if err < 1e-6 + disp('Ok') +else + disp('Error') +end + +%% +fprintf('Testing basic CUDA 3D functionality...') + +vg = astra_create_vol_geom(2, 32, 32); +pg = astra_create_proj_geom('parallel3d', 1, 1, 32, 32, [0]); + +vol = rand(32, 2, 32); +[sino_id, sino] = astra_create_sino3d_cuda(vol, pg, vg); +astra_mex_data3d('delete', sino_id); + +err = max(max(abs(sino - sum(vol,2)))); + +if err < 1e-6 + disp('Ok') +else + disp('Error') +end + diff --git a/matlab/tools/astra_test_noCUDA.m b/matlab/tools/astra_test_noCUDA.m new file mode 100644 index 0000000..6437661 --- /dev/null +++ b/matlab/tools/astra_test_noCUDA.m @@ -0,0 +1,32 @@ +%-------------------------------------------------------------------------- +% Clears and frees memory of all objects (data, projectors, algorithms) +% currently in the astra-library. +%-------------------------------------------------------------------------- +%-------------------------------------------------------------------------- +% This file is part of the ASTRA Toolbox +% +% Copyright: 2010-2017, iMinds-Vision Lab, University of Antwerp +% 2014-2017, CWI, Amsterdam +% License: Open Source under GPLv3 +% Contact: astra@uantwerpen.be +% Website: http://www.astra-toolbox.com/ +%-------------------------------------------------------------------------- + +fprintf('Testing basic CPU 2D functionality...') + +vg = astra_create_vol_geom(2, 32); +pg = astra_create_proj_geom('parallel', 1, 32, [0]); +proj_id = astra_create_projector('line', pg, vg); + +vol = rand(2, 32); +[sino_id, sino] = astra_create_sino(vol, proj_id); +astra_mex_data2d('delete', sino_id); +astra_mex_projector('delete', proj_id); + +err = max(abs(sino - sum(vol))); + +if err < 1e-6 + disp('Ok') +else + disp('Error') +end -- cgit v1.2.3 From 454bb20b5d7eb36f1efbf6659652ace26cc229e0 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 6 Nov 2017 14:53:53 +0100 Subject: Fix matlab interface build --- matlab/mex/astra_mex_c.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'matlab') diff --git a/matlab/mex/astra_mex_c.cpp b/matlab/mex/astra_mex_c.cpp index c16059f..017946a 100644 --- a/matlab/mex/astra_mex_c.cpp +++ b/matlab/mex/astra_mex_c.cpp @@ -38,7 +38,7 @@ along with the ASTRA Toolbox. If not, see . #include "astra/AstraObjectManager.h" #ifdef ASTRA_CUDA -#include "../cuda/2d/darthelper.h" +#include "../cuda/2d/astra.h" #include "../cuda/2d/util.h" #include "astra/CompositeGeometryManager.h" #endif -- cgit v1.2.3