From ba3629c6c1bc1d03ccdc6ef2aeae6872ea59559f Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Sat, 20 Jun 2015 00:33:23 +0200 Subject: Fix matlab compilation without CUDA --- matlab/mex/astra_mex_c.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'matlab') diff --git a/matlab/mex/astra_mex_c.cpp b/matlab/mex/astra_mex_c.cpp index 4a331f5..a9b9654 100644 --- a/matlab/mex/astra_mex_c.cpp +++ b/matlab/mex/astra_mex_c.cpp @@ -36,9 +36,9 @@ $Id$ #include "mexInitFunctions.h" #include "astra/Globals.h" - +#ifdef ASTRA_CUDA #include "../cuda/2d/darthelper.h" - +#endif using namespace std; using namespace astra; -- cgit v1.2.3 From f6b6a2f84806a89fe6bacc583e13cb14629fb5dc Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Sat, 20 Jun 2015 00:35:16 +0200 Subject: Actually use the rec_type argument in astra_create_reconstruction_cuda --- matlab/tools/astra_create_reconstruction_cuda.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'matlab') diff --git a/matlab/tools/astra_create_reconstruction_cuda.m b/matlab/tools/astra_create_reconstruction_cuda.m index 7d9e1dd..7d0421c 100644 --- a/matlab/tools/astra_create_reconstruction_cuda.m +++ b/matlab/tools/astra_create_reconstruction_cuda.m @@ -45,7 +45,7 @@ if strcmp(rec_type,'') end % configure -cfg = astra_struct('SIRT_CUDA'); +cfg = astra_struct(rec_type); cfg.ProjectionGeometry = proj_geom; cfg.ReconstructionGeometry = vol_geom; cfg.ProjectionDataId = sinogram_id; -- cgit v1.2.3 From 63d78fbaafa7d247347f9052db86f575d89260b7 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Wed, 24 Jun 2015 20:28:46 +0200 Subject: Fix config to struct/dict translation for array options --- matlab/mex/mexHelpFunctions.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'matlab') diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp index 87a9672..58e84d2 100644 --- a/matlab/mex/mexHelpFunctions.cpp +++ b/matlab/mex/mexHelpFunctions.cpp @@ -336,7 +336,11 @@ mxArray* XMLNodeToStruct(astra::XMLNode node) // option if (subnode.getName() == "Option") { - mOptions[subnode.getAttribute("key")] = stringToMxArray(subnode.getAttribute("value")); + if(subnode.hasAttribute("value")){ + mOptions[subnode.getAttribute("key")] = stringToMxArray(subnode.getAttribute("value")); + }else{ + mOptions[subnode.getAttribute("key")] = stringToMxArray(subnode.getContent()); + } } // regular content -- cgit v1.2.3 From 9e3472ea9041b8755050427d8bdb8a4701019c55 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Thu, 25 Jun 2015 21:52:07 +0200 Subject: Fix memory leak in configuration code --- matlab/mex/astra_mex_projector3d_c.cpp | 8 ++++++-- matlab/mex/astra_mex_projector_c.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'matlab') diff --git a/matlab/mex/astra_mex_projector3d_c.cpp b/matlab/mex/astra_mex_projector3d_c.cpp index c3b547f..e25802c 100644 --- a/matlab/mex/astra_mex_projector3d_c.cpp +++ b/matlab/mex/astra_mex_projector3d_c.cpp @@ -137,7 +137,9 @@ void astra_mex_projector3d_get_projection_geometry(int nlhs, mxArray* plhs[], in // step3: get projection_geometry and turn it into a MATLAB struct if (1 <= nlhs) { - plhs[0] = configToStruct(pProjector->getProjectionGeometry()->getConfiguration()); + Config *cfg = pProjector->getProjectionGeometry()->getConfiguration(); + plhs[0] = configToStruct(cfg); + delete cfg; } } @@ -163,7 +165,9 @@ void astra_mex_projector3d_get_volume_geometry(int nlhs, mxArray* plhs[], int nr // step3: get projection_geometry and turn it into a MATLAB struct if (1 <= nlhs) { - plhs[0] = configToStruct(pProjector->getVolumeGeometry()->getConfiguration()); + Config *cfg = pProjector->getVolumeGeometry()->getConfiguration(); + plhs[0] = configToStruct(cfg); + delete cfg; } } diff --git a/matlab/mex/astra_mex_projector_c.cpp b/matlab/mex/astra_mex_projector_c.cpp index 204ba8e..bf701af 100644 --- a/matlab/mex/astra_mex_projector_c.cpp +++ b/matlab/mex/astra_mex_projector_c.cpp @@ -160,7 +160,9 @@ void astra_mex_projector_projection_geometry(int nlhs, mxArray* plhs[], int nrhs // step3: get projection_geometry and turn it into a MATLAB struct if (1 <= nlhs) { - plhs[0] = configToStruct(pProjector->getProjectionGeometry()->getConfiguration()); + Config *cfg = pProjector->getProjectionGeometry()->getConfiguration(); + plhs[0] = configToStruct(cfg); + delete cfg; } } @@ -189,8 +191,9 @@ void astra_mex_projector_volume_geometry(int nlhs, mxArray* plhs[], int nrhs, co // step3: get projection_geometry and turn it into a MATLAB struct if (1 <= nlhs) { - plhs[0] = configToStruct(pProjector->getVolumeGeometry()->getConfiguration()); - + Config *cfg = pProjector->getVolumeGeometry()->getConfiguration(); + plhs[0] = configToStruct(cfg); + delete cfg; } } -- cgit v1.2.3 From 4d39c35d6c9124c26de64c9d227a25f612903a2a Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 17 Jul 2015 13:44:59 +0200 Subject: Fix formatting when passing strings to log from high-level code --- matlab/mex/astra_mex_log_c.cpp | 8 ++++---- matlab/mex/mexInitFunctions.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'matlab') diff --git a/matlab/mex/astra_mex_log_c.cpp b/matlab/mex/astra_mex_log_c.cpp index ea4621e..905612c 100644 --- a/matlab/mex/astra_mex_log_c.cpp +++ b/matlab/mex/astra_mex_log_c.cpp @@ -55,7 +55,7 @@ void astra_mex_log_debug(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prh string filename = mexToString(prhs[1]); int linenumber = (int)mxGetScalar(prhs[2]); string message = mexToString(prhs[3]); - astra::CLogger::debug(filename.c_str(),linenumber,message.c_str()); + astra::CLogger::debug(filename.c_str(),linenumber,"%s",message.c_str()); } //----------------------------------------------------------------------------------------- @@ -75,7 +75,7 @@ void astra_mex_log_info(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs string filename = mexToString(prhs[1]); int linenumber = (int)mxGetScalar(prhs[2]); string message = mexToString(prhs[3]); - astra::CLogger::info(filename.c_str(),linenumber,message.c_str()); + astra::CLogger::info(filename.c_str(),linenumber,"%s",message.c_str()); } //----------------------------------------------------------------------------------------- @@ -95,7 +95,7 @@ void astra_mex_log_warn(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs string filename = mexToString(prhs[1]); int linenumber = (int)mxGetScalar(prhs[2]); string message = mexToString(prhs[3]); - astra::CLogger::warn(filename.c_str(),linenumber,message.c_str()); + astra::CLogger::warn(filename.c_str(),linenumber,"%s",message.c_str()); } //----------------------------------------------------------------------------------------- @@ -115,7 +115,7 @@ void astra_mex_log_error(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prh string filename = mexToString(prhs[1]); int linenumber = (int)mxGetScalar(prhs[2]); string message = mexToString(prhs[3]); - astra::CLogger::error(filename.c_str(),linenumber,message.c_str()); + astra::CLogger::error(filename.c_str(),linenumber,"%s",message.c_str()); } //----------------------------------------------------------------------------------------- diff --git a/matlab/mex/mexInitFunctions.cpp b/matlab/mex/mexInitFunctions.cpp index d8a50d7..89a31a1 100644 --- a/matlab/mex/mexInitFunctions.cpp +++ b/matlab/mex/mexInitFunctions.cpp @@ -8,7 +8,7 @@ bool mexIsInitialized=false; * */ void logCallBack(const char *msg, size_t len){ - mexPrintf(msg); + mexPrintf("%s",msg); } /** -- cgit v1.2.3 From 026aa46c5db24ddd687cec0fa6e056a2ee3790c5 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 12 Aug 2015 15:45:12 +0200 Subject: Fix algorithm object leak in astra_create_fbp_reconstruction.m --- matlab/tools/astra_create_fbp_reconstruction.m | 1 + 1 file changed, 1 insertion(+) (limited to 'matlab') diff --git a/matlab/tools/astra_create_fbp_reconstruction.m b/matlab/tools/astra_create_fbp_reconstruction.m index 5540f27..a2561b7 100644 --- a/matlab/tools/astra_create_fbp_reconstruction.m +++ b/matlab/tools/astra_create_fbp_reconstruction.m @@ -19,6 +19,7 @@ cfg.ProjectorId = proj_id; cfg.Options.GPUindex = 0; alg_id = astra_mex_algorithm('create', cfg); astra_mex_algorithm('run', alg_id); +astra_mex_algorithm('delete', alg_id); if numel(sinogram) ~= 1 astra_mex_data2d('delete', sinogram_id); -- cgit v1.2.3 From 9cfe943682bd6e02d5fb8493cb9c4c98623cb441 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 4 Sep 2015 14:16:41 +0200 Subject: Fix algorithm leak in opTomo --- matlab/tools/opTomo.m | 2 ++ 1 file changed, 2 insertions(+) (limited to 'matlab') diff --git a/matlab/tools/opTomo.m b/matlab/tools/opTomo.m index 14128d2..71dfb1e 100644 --- a/matlab/tools/opTomo.m +++ b/matlab/tools/opTomo.m @@ -248,6 +248,7 @@ classdef opTomo < opSpot % cleanup astra_mex_data3d('delete', vol_id); astra_mex_data3d('delete', sino_id); + astra_mex_algorithm('delete', alg_id); else % X is passed as a vector, reshape it into projection data x = reshape(x, op.proj_size); @@ -272,6 +273,7 @@ classdef opTomo < opSpot % cleanup astra_mex_data3d('delete', vol_id); astra_mex_data3d('delete', sino_id); + astra_mex_algorithm('delete', alg_id); end end % opTomo_intrnl3D -- cgit v1.2.3 From 11717f66b49fbe41faf923f267c6893ce9af46ad Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 17 Sep 2015 16:54:37 +0200 Subject: Use mxLogical instead of bool. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should improve compatibility with Octave according to Christian Häggström. --- matlab/mex/astra_mex_data2d_c.cpp | 4 ++-- matlab/mex/astra_mex_matrix_c.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'matlab') diff --git a/matlab/mex/astra_mex_data2d_c.cpp b/matlab/mex/astra_mex_data2d_c.cpp index 909d229..935e476 100644 --- a/matlab/mex/astra_mex_data2d_c.cpp +++ b/matlab/mex/astra_mex_data2d_c.cpp @@ -222,7 +222,7 @@ void astra_mex_data2d_create(int& nlhs, mxArray* plhs[], int& nrhs, const mxArra // logical data if (mxIsLogical(prhs[3])) { - bool* pbMatlabData = mxGetLogicals(prhs[3]); + mxLogical* pbMatlabData = mxGetLogicals(prhs[3]); int i = 0; int col, row; for (col = 0; col < dims[1]; ++col) { @@ -322,7 +322,7 @@ void astra_mex_data2d_store(int nlhs, mxArray* plhs[], int nrhs, const mxArray* // logical data if (mxIsLogical(prhs[2])) { - bool* pbMatlabData = mxGetLogicals(prhs[2]); + mxLogical* pbMatlabData = mxGetLogicals(prhs[2]); int i = 0; int col, row; for (col = 0; col < dims[1]; ++col) { diff --git a/matlab/mex/astra_mex_matrix_c.cpp b/matlab/mex/astra_mex_matrix_c.cpp index aa31383..e07ddb6 100644 --- a/matlab/mex/astra_mex_matrix_c.cpp +++ b/matlab/mex/astra_mex_matrix_c.cpp @@ -112,7 +112,7 @@ static bool matlab_to_astra(const mxArray* _rhs, CSparseMatrix* _pMatrix) mwIndex *colStarts = mxGetJc(_rhs); mwIndex *rowIndices = mxGetIr(_rhs); double *floatValues = 0; - bool *boolValues = 0; + mxLogical *boolValues = 0; bool bLogical = mxIsLogical(_rhs); if (bLogical) boolValues = mxGetLogicals(_rhs); -- cgit v1.2.3 From 1cc67c1e4d9b6b24c096f52d6f086a3f224ece8a Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 7 Oct 2015 17:29:20 +0200 Subject: Add astra_mex_direct('FP3D'/'BP3D', ...) --- matlab/mex/astra_mex_direct_c.cpp | 332 ++++++++++++++++++++++++++++++++++++++ matlab/tools/astra_mex_direct.m | 24 +++ 2 files changed, 356 insertions(+) create mode 100755 matlab/mex/astra_mex_direct_c.cpp create mode 100644 matlab/tools/astra_mex_direct.m (limited to 'matlab') diff --git a/matlab/mex/astra_mex_direct_c.cpp b/matlab/mex/astra_mex_direct_c.cpp new file mode 100755 index 0000000..94eb1cd --- /dev/null +++ b/matlab/mex/astra_mex_direct_c.cpp @@ -0,0 +1,332 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp + 2014-2015, CWI, Amsterdam + +Contact: astra@uantwerpen.be +Website: http://sf.net/projects/astra-toolbox + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +$Id$ +*/ + +/** \file astra_mex_direct_c.cpp + * + * \brief Utility functions for low-overhead FP and BP calls. + */ +#include +#include "mexHelpFunctions.h" +#include "mexCopyDataHelpFunctions.h" +#include "mexDataManagerHelpFunctions.h" + +#include + +#include "astra/Globals.h" + +#include "astra/AstraObjectManager.h" + +#include "astra/Float32ProjectionData2D.h" +#include "astra/Float32VolumeData2D.h" +#include "astra/CudaProjector3D.h" +#include "astra/Projector3D.h" +#include "astra/Float32ProjectionData3DMemory.h" +#include "astra/Float32VolumeData3DMemory.h" + +#include "astra/CudaForwardProjectionAlgorithm3D.h" + +#include "astra/CudaBackProjectionAlgorithm3D.h" + +using namespace std; +using namespace astra; + +#define USE_MATLAB_UNDOCUMENTED + + +class CFloat32CustomMemory_simple : public astra::CFloat32CustomMemory { +public: + CFloat32CustomMemory_simple(float *ptr) { m_fPtr = ptr; } + ~CFloat32CustomMemory_simple() { } +}; + +#ifdef ASTRA_CUDA + +//----------------------------------------------------------------------------------------- +/** + * projection = astra_mex_direct_c('FP3D', projector_id, volume); + * Both 'projection' and 'volume' are Matlab arrays. + */ +void astra_mex_direct_fp3d(int& nlhs, mxArray* plhs[], int& nrhs, const mxArray* prhs[]) +{ + // TODO: Add an optional way of specifying extra options + + if (nrhs < 3) { + mexErrMsgTxt("Not enough arguments. Syntax: astra_mex_direct_c('FP3D', projector_id, data)"); + return; + } + + int iPid = (int)(mxGetScalar(prhs[1])); + astra::CProjector3D* pProjector; + pProjector = astra::CProjector3DManager::getSingleton().get(iPid); + if (!pProjector) { + mexErrMsgTxt("Projector not found."); + return; + } + if (!pProjector->isInitialized()) { + mexErrMsgTxt("Projector not initialized."); + return; + } + bool isCuda = false; + if (dynamic_cast(pProjector)) + isCuda = true; + if (!isCuda) { + mexErrMsgTxt("Only CUDA projectors are currently supported."); + return; + } + + astra::CVolumeGeometry3D* pVolGeom = pProjector->getVolumeGeometry(); + astra::CProjectionGeometry3D* pProjGeom = pProjector->getProjectionGeometry(); + + const mxArray* const data = prhs[2]; + if (!checkDataType(data)) { + mexErrMsgTxt("Data must be single or double."); + return; + } + + if (!checkDataSize(data, pVolGeom)) { + mexErrMsgTxt("The dimensions of the data do not match those specified in the geometry."); + return; + } + + + // Allocate input data + astra::CFloat32VolumeData3DMemory* pInput; + if (mxIsSingle(data)) { + astra::CFloat32CustomMemory* m = new CFloat32CustomMemory_simple((float *)mxGetData(data)); + pInput = new astra::CFloat32VolumeData3DMemory(pVolGeom, m); + } else { + pInput = new astra::CFloat32VolumeData3DMemory(pVolGeom); + copyMexToCFloat32Array(data, pInput->getData(), pInput->getSize()); + } + + + // Allocate output data + // If the input is single, we also allocate single output. + // Otherwise, double. + astra::CFloat32ProjectionData3DMemory* pOutput; + mxArray *pOutputMx; + if (mxIsSingle(data)) { + mwSize dims[3]; + dims[0] = pProjGeom->getDetectorColCount(); + dims[1] = pProjGeom->getProjectionCount(); + dims[2] = pProjGeom->getDetectorRowCount(); + pOutputMx = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL); + + astra::CFloat32CustomMemory* m = new CFloat32CustomMemory_simple((float *)mxGetData(pOutputMx)); + pOutput = new astra::CFloat32ProjectionData3DMemory(pProjGeom, m); + } else { + pOutput = new astra::CFloat32ProjectionData3DMemory(pProjGeom); + } + + // Perform FP + + astra::CCudaForwardProjectionAlgorithm3D* pAlg; + pAlg = new astra::CCudaForwardProjectionAlgorithm3D(); + pAlg->initialize(pProjector, pOutput, pInput); + + if (!pAlg->isInitialized()) { + mexErrMsgTxt("Error initializing algorithm."); + // TODO: Delete pOutputMx? + delete pAlg; + delete pInput; + delete pOutput; + return; + } + + pAlg->run(); + + delete pAlg; + + + if (mxIsSingle(data)) { + + } else { + pOutputMx = createEquivMexArray(pOutput); + copyCFloat32ArrayToMex(pOutput->getData(), pOutputMx); + } + plhs[0] = pOutputMx; + + delete pOutput; + delete pInput; +} +//----------------------------------------------------------------------------------------- +/** + * projection = astra_mex_direct_c('BP3D', projector_id, volume); + * Both 'projection' and 'volume' are Matlab arrays. + */ +void astra_mex_direct_bp3d(int& nlhs, mxArray* plhs[], int& nrhs, const mxArray* prhs[]) +{ + // TODO: Add an optional way of specifying extra options + + if (nrhs < 3) { + mexErrMsgTxt("Not enough arguments. Syntax: astra_mex_direct_c('BP3D', projector_id, data)"); + return; + } + + int iPid = (int)(mxGetScalar(prhs[1])); + astra::CProjector3D* pProjector; + pProjector = astra::CProjector3DManager::getSingleton().get(iPid); + if (!pProjector) { + mexErrMsgTxt("Projector not found."); + return; + } + if (!pProjector->isInitialized()) { + mexErrMsgTxt("Projector not initialized."); + return; + } + bool isCuda = false; + if (dynamic_cast(pProjector)) + isCuda = true; + if (!isCuda) { + mexErrMsgTxt("Only CUDA projectors are currently supported."); + return; + } + + astra::CVolumeGeometry3D* pVolGeom = pProjector->getVolumeGeometry(); + astra::CProjectionGeometry3D* pProjGeom = pProjector->getProjectionGeometry(); + + const mxArray* const data = prhs[2]; + if (!checkDataType(data)) { + mexErrMsgTxt("Data must be single or double."); + return; + } + + if (!checkDataSize(data, pProjGeom)) { + mexErrMsgTxt("The dimensions of the data do not match those specified in the geometry."); + return; + } + + + // Allocate input data + astra::CFloat32ProjectionData3DMemory* pInput; + if (mxIsSingle(data)) { + astra::CFloat32CustomMemory* m = new CFloat32CustomMemory_simple((float *)mxGetData(data)); + pInput = new astra::CFloat32ProjectionData3DMemory(pProjGeom, m); + } else { + pInput = new astra::CFloat32ProjectionData3DMemory(pProjGeom); + copyMexToCFloat32Array(data, pInput->getData(), pInput->getSize()); + } + + + // Allocate output data + // If the input is single, we also allocate single output. + // Otherwise, double. + astra::CFloat32VolumeData3DMemory* pOutput; + mxArray *pOutputMx; + if (mxIsSingle(data)) { + mwSize dims[3]; + dims[0] = pVolGeom->getGridColCount(); + dims[1] = pVolGeom->getGridRowCount(); + dims[2] = pVolGeom->getGridSliceCount(); + pOutputMx = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL); + + astra::CFloat32CustomMemory* m = new CFloat32CustomMemory_simple((float *)mxGetData(pOutputMx)); + pOutput = new astra::CFloat32VolumeData3DMemory(pVolGeom, m); + } else { + pOutput = new astra::CFloat32VolumeData3DMemory(pVolGeom); + } + + // Perform BP + + astra::CCudaBackProjectionAlgorithm3D* pAlg; + pAlg = new astra::CCudaBackProjectionAlgorithm3D(); + pAlg->initialize(pProjector, pInput, pOutput); + + if (!pAlg->isInitialized()) { + mexErrMsgTxt("Error initializing algorithm."); + // TODO: Delete pOutputMx? + delete pAlg; + delete pInput; + delete pOutput; + return; + } + + pAlg->run(); + + delete pAlg; + + + if (mxIsSingle(data)) { + + } else { + pOutputMx = createEquivMexArray(pOutput); + copyCFloat32ArrayToMex(pOutput->getData(), pOutputMx); + } + plhs[0] = pOutputMx; + + delete pOutput; + delete pInput; +} + +#endif + +//----------------------------------------------------------------------------------------- + +static void printHelp() +{ + mexPrintf("Please specify a mode of operation.\n"); + mexPrintf("Valid modes: FP3D, BP3D\n"); +} + + +//----------------------------------------------------------------------------------------- +/** + * ... = astra_mex_direct_c(mode,...); + */ +void mexFunction(int nlhs, mxArray* plhs[], + int nrhs, const mxArray* prhs[]) +{ + + // INPUT: Mode + string sMode; + if (1 <= nrhs) { + sMode = mexToString(prhs[0]); + } else { + printHelp(); + return; + } + +#ifndef ASTRA_CUDA + mexErrMsgTxt("Only CUDA projectors are currently supported."); + return; +#else + + // 3D data + if (sMode == "FP3D") { + astra_mex_direct_fp3d(nlhs, plhs, nrhs, prhs); + } else if (sMode == "BP3D") { + astra_mex_direct_bp3d(nlhs, plhs, nrhs, prhs); + } else { + printHelp(); + } +#endif + + return; +} + + diff --git a/matlab/tools/astra_mex_direct.m b/matlab/tools/astra_mex_direct.m new file mode 100644 index 0000000..58c4fd2 --- /dev/null +++ b/matlab/tools/astra_mex_direct.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_direct(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% astra_mex_data3d. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the ASTRA Toolbox +% +% Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp +% 2014-2015, CWI, Amsterdam +% License: Open Source under GPLv3 +% Contact: astra@uantwerpen.be +% Website: http://sf.net/projects/astra-toolbox +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_direct_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_direct_c(varargin{:}); +end -- cgit v1.2.3 From 793afbc3fa1cca64292716869e503cb66942606d Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 7 Oct 2015 17:29:40 +0200 Subject: Build astra_mex_direct in MSVC --- matlab/mex/astra_mex_direct_vc09.vcproj | 612 +++++++++++++++++++++++++++++++ matlab/mex/astra_mex_direct_vc11.vcxproj | 306 ++++++++++++++++ 2 files changed, 918 insertions(+) create mode 100644 matlab/mex/astra_mex_direct_vc09.vcproj create mode 100644 matlab/mex/astra_mex_direct_vc11.vcxproj (limited to 'matlab') diff --git a/matlab/mex/astra_mex_direct_vc09.vcproj b/matlab/mex/astra_mex_direct_vc09.vcproj new file mode 100644 index 0000000..04b49ac --- /dev/null +++ b/matlab/mex/astra_mex_direct_vc09.vcproj @@ -0,0 +1,612 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/matlab/mex/astra_mex_direct_vc11.vcxproj b/matlab/mex/astra_mex_direct_vc11.vcxproj new file mode 100644 index 0000000..15c3c06 --- /dev/null +++ b/matlab/mex/astra_mex_direct_vc11.vcxproj @@ -0,0 +1,306 @@ + + + + + Debug_CUDA + Win32 + + + Debug_CUDA + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release_CUDA + Win32 + + + Release_CUDA + x64 + + + Release + Win32 + + + Release + x64 + + + + astra_mex_direct + {0F68F4E2-BE1B-4A9A-B101-AECF4C069CC7} + astraMatlab + + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + DynamicLibrary + v110 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>11.0.60610.1 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw32 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw64 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw32 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw64 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw32 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw64 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw32 + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(OutDir)obj\$(ProjectName)\ + $(ProjectName)_c + .mexw64 + + + + MultiThreadedDebugDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + StreamingSIMDExtensions2 + Disabled + ASTRA_CUDA;__SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw32 + AstraCuda32D.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\win32\;..\..\bin\win32\Debug_CUDA;$(MATLAB_ROOT)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDebugDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + Disabled + ASTRA_CUDA;__SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw64 + AstraCuda64D.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\x64\;..\..\bin\x64\Debug_CUDA;$(MATLAB_ROOT)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDebugDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + StreamingSIMDExtensions2 + Disabled + __SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw32 + Astra32D.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\win32\;..\..\bin\win32\Debug;$(MATLAB_ROOT)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDebugDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + Disabled + __SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw64 + Astra64D.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\x64\;..\..\bin\x64\Debug;$(MATLAB_ROOT)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + StreamingSIMDExtensions2 + MaxSpeed + ASTRA_CUDA;__SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw32 + AstraCuda32.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\win32\;..\..\bin\win32\Release_CUDA;$(MATLAB_ROOT)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + MaxSpeed + ASTRA_CUDA;__SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw64 + AstraCuda64.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\x64\;..\..\bin\x64\Release_CUDA;$(MATLAB_ROOT)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + StreamingSIMDExtensions2 + MaxSpeed + __SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw32 + Astra32.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\win32\;..\..\bin\win32\Release;$(MATLAB_ROOT)\extern\lib\win32\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + MultiThreadedDLL + $(MATLAB_ROOT)\extern\include\;$(CUDA_PATH)\include;..\..\lib\include;..\..\include;%(AdditionalIncludeDirectories) + true + MaxSpeed + __SSE2__;%(PreprocessorDefinitions) + true + + + $(OutDir)$(ProjectName)_c.mexw64 + Astra64.lib;libmex.lib;libmx.lib;libut.lib;%(AdditionalDependencies) + ..\..\lib\x64\;..\..\bin\x64\Release;$(MATLAB_ROOT)\extern\lib\win64\microsoft;%(AdditionalLibraryDirectories) + mex.def + true + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 0ebd8dfe60cc0d1f05d65d3840278defce0da091 Mon Sep 17 00:00:00 2001 From: Nicola Vigano Date: Wed, 7 Oct 2015 17:25:06 +0200 Subject: Add options passing to projectors from matlab Signed-off-by: Nicola Vigano --- matlab/tools/astra_create_projector.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'matlab') diff --git a/matlab/tools/astra_create_projector.m b/matlab/tools/astra_create_projector.m index da9c083..9bbef9e 100644 --- a/matlab/tools/astra_create_projector.m +++ b/matlab/tools/astra_create_projector.m @@ -1,7 +1,7 @@ -function proj_id = astra_create_projector(type, proj_geom, vol_geom) +function proj_id = astra_create_projector(type, proj_geom, vol_geom, options) %-------------------------------------------------------------------------- -% proj_id = astra_create_projector(type, proj_geom, vol_geom) +% proj_id = astra_create_projector(type, proj_geom, vol_geom, options) % % Create a new projector object based on projection and volume geometry. % Used when the default values of each projector are sufficient. @@ -9,6 +9,7 @@ function proj_id = astra_create_projector(type, proj_geom, vol_geom) % type: type of the projector. 'blob', 'line', 'linear' 'strip', ... See API for more information. % proj_geom: MATLAB struct containing the projection geometry. % vol_geom: MATLAB struct containing the volume geometry. +% options: Optional MATLAB struct containing projector options (like: 'GPUindex', 'DetectorSuperSampling', and 'VoxelSuperSampling') % proj_id: identifier of the projector as it is now stored in the astra-library. %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- @@ -38,6 +39,10 @@ if strcmp(type,'blob') cfg_proj.Kernel.KernelValues = blob_values; end +if exist('options', 'var') + cfg_proj.options = options; +end + if strcmp(type,'linear3d') || strcmp(type,'linearcone') || strcmp(type,'cuda3d') proj_id = astra_mex_projector3d('create', cfg_proj); else -- cgit v1.2.3 From 37dd051faf2a8085c1abb5623eb5e79363471642 Mon Sep 17 00:00:00 2001 From: Nicola Vigano Date: Thu, 2 Apr 2015 17:07:25 +0200 Subject: astra_mex_direct: Don't initialize newly allocated mxArray This avoids letting matlab initialize the memory we will overwrite shortly after. --- matlab/mex/astra_mex_direct_c.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'matlab') diff --git a/matlab/mex/astra_mex_direct_c.cpp b/matlab/mex/astra_mex_direct_c.cpp index 94eb1cd..38b3f59 100755 --- a/matlab/mex/astra_mex_direct_c.cpp +++ b/matlab/mex/astra_mex_direct_c.cpp @@ -135,7 +135,15 @@ void astra_mex_direct_fp3d(int& nlhs, mxArray* plhs[], int& nrhs, const mxArray* dims[0] = pProjGeom->getDetectorColCount(); dims[1] = pProjGeom->getProjectionCount(); dims[2] = pProjGeom->getDetectorRowCount(); - pOutputMx = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL); + + // Allocate uninitialized mxArray of size dims. + // (It will be zeroed by CudaForwardProjectionAlgorithm3D) + const mwSize zero_dims[2] = {0, 0}; + pOutputMx = mxCreateNumericArray(2, zero_dims, mxSINGLE_CLASS, mxREAL); + mxSetDimensions(pOutputMx, dims, 3); + const mwSize num_elems = mxGetNumberOfElements(pOutputMx); + const mwSize elem_size = mxGetElementSize(pOutputMx); + mxSetData(pOutputMx, mxMalloc(elem_size * num_elems)); astra::CFloat32CustomMemory* m = new CFloat32CustomMemory_simple((float *)mxGetData(pOutputMx)); pOutput = new astra::CFloat32ProjectionData3DMemory(pProjGeom, m); @@ -243,7 +251,15 @@ void astra_mex_direct_bp3d(int& nlhs, mxArray* plhs[], int& nrhs, const mxArray* dims[0] = pVolGeom->getGridColCount(); dims[1] = pVolGeom->getGridRowCount(); dims[2] = pVolGeom->getGridSliceCount(); - pOutputMx = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL); + + // Allocate uninitialized mxArray of size dims. + // (It will be zeroed by CudaBackProjectionAlgorithm3D) + const mwSize zero_dims[2] = {0, 0}; + pOutputMx = mxCreateNumericArray(2, zero_dims, mxSINGLE_CLASS, mxREAL); + mxSetDimensions(pOutputMx, dims, 3); + const mwSize num_elems = mxGetNumberOfElements(pOutputMx); + const mwSize elem_size = mxGetElementSize(pOutputMx); + mxSetData(pOutputMx, mxMalloc(elem_size * num_elems)); astra::CFloat32CustomMemory* m = new CFloat32CustomMemory_simple((float *)mxGetData(pOutputMx)); pOutput = new astra::CFloat32VolumeData3DMemory(pVolGeom, m); -- cgit v1.2.3