diff options
-rw-r--r-- | astra_vc14.vcxproj | 2 | ||||
-rw-r--r-- | astra_vc14.vcxproj.filters | 6 | ||||
-rw-r--r-- | build/linux/Makefile.in | 1 | ||||
-rw-r--r-- | build/msvc/gen.py | 2 | ||||
-rw-r--r-- | include/astra/Features.h | 52 | ||||
-rw-r--r-- | matlab/mex/astra_mex_algorithm_c.cpp | 2 | ||||
-rw-r--r-- | matlab/mex/astra_mex_c.cpp | 38 | ||||
-rw-r--r-- | matlab/mex/astra_mex_data3d_c.cpp | 2 | ||||
-rw-r--r-- | matlab/mex/astra_mex_direct_c.cpp | 2 | ||||
-rw-r--r-- | matlab/mex/mexDataManagerHelpFunctions.cpp | 2 | ||||
-rw-r--r-- | matlab/mex/mexHelpFunctions.h | 6 | ||||
-rw-r--r-- | python/astra/__init__.py | 2 | ||||
-rw-r--r-- | python/astra/astra.py | 14 | ||||
-rw-r--r-- | python/astra/astra_c.pyx | 8 | ||||
-rw-r--r-- | src/Features.cpp | 41 |
15 files changed, 167 insertions, 13 deletions
diff --git a/astra_vc14.vcxproj b/astra_vc14.vcxproj index 6c19c41..d281179 100644 --- a/astra_vc14.vcxproj +++ b/astra_vc14.vcxproj @@ -508,6 +508,7 @@ <ClCompile Include="src\FanFlatBeamStripKernelProjector2D.cpp" /> <ClCompile Include="src\FanFlatProjectionGeometry2D.cpp" /> <ClCompile Include="src\FanFlatVecProjectionGeometry2D.cpp" /> + <ClCompile Include="src\Features.cpp" /> <ClCompile Include="src\FilteredBackProjectionAlgorithm.cpp" /> <ClCompile Include="src\Filters.cpp" /> <ClCompile Include="src\Float32Data.cpp" /> @@ -596,6 +597,7 @@ <ClInclude Include="include\astra\FanFlatBeamStripKernelProjector2D.h" /> <ClInclude Include="include\astra\FanFlatProjectionGeometry2D.h" /> <ClInclude Include="include\astra\FanFlatVecProjectionGeometry2D.h" /> + <ClInclude Include="include\astra\Features.h" /> <ClInclude Include="include\astra\FilteredBackProjectionAlgorithm.h" /> <ClInclude Include="include\astra\Filters.h" /> <ClInclude Include="include\astra\Float32Data.h" /> diff --git a/astra_vc14.vcxproj.filters b/astra_vc14.vcxproj.filters index 226068e..cb3622d 100644 --- a/astra_vc14.vcxproj.filters +++ b/astra_vc14.vcxproj.filters @@ -168,6 +168,9 @@ <ClCompile Include="src\Config.cpp"> <Filter>Global & Other\source</Filter> </ClCompile> + <ClCompile Include="src\Features.cpp"> + <Filter>Global & Other\source</Filter> + </ClCompile> <ClCompile Include="src\Filters.cpp"> <Filter>Global & Other\source</Filter> </ClCompile> @@ -437,6 +440,9 @@ <ClInclude Include="include\astra\Config.h"> <Filter>Global & Other\headers</Filter> </ClInclude> + <ClInclude Include="include\astra\Features.h"> + <Filter>Global & Other\headers</Filter> + </ClInclude> <ClInclude Include="include\astra\Filters.h"> <Filter>Global & Other\headers</Filter> </ClInclude> diff --git a/build/linux/Makefile.in b/build/linux/Makefile.in index 2ec3851..f4c5c20 100644 --- a/build/linux/Makefile.in +++ b/build/linux/Makefile.in @@ -141,6 +141,7 @@ BASE_OBJECTS=\ src/FanFlatBeamStripKernelProjector2D.lo \ src/FanFlatProjectionGeometry2D.lo \ src/FanFlatVecProjectionGeometry2D.lo \ + src/Features.lo \ src/FilteredBackProjectionAlgorithm.lo \ src/Filters.lo \ src/Float32Data2D.lo \ diff --git a/build/msvc/gen.py b/build/msvc/gen.py index a42d8e5..42d0e0e 100644 --- a/build/msvc/gen.py +++ b/build/msvc/gen.py @@ -214,6 +214,7 @@ P_astra["filters"]["Global & Other\\source"] = [ "src\\AstraObjectManager.cpp", "src\\CompositeGeometryManager.cpp", "src\\Config.cpp", +"src\\Features.cpp", "src\\Filters.cpp", "src\\Fourier.cpp", "src\\Globals.cpp", @@ -354,6 +355,7 @@ P_astra["filters"]["Global & Other\\headers"] = [ "include\\astra\\clog.h", "include\\astra\\CompositeGeometryManager.h", "include\\astra\\Config.h", +"include\\astra\\Features.h", "include\\astra\\Filters.h", "include\\astra\\Fourier.h", "include\\astra\\Globals.h", diff --git a/include/astra/Features.h b/include/astra/Features.h new file mode 100644 index 0000000..d88ae71 --- /dev/null +++ b/include/astra/Features.h @@ -0,0 +1,52 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +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 <http://www.gnu.org/licenses/>. + +----------------------------------------------------------------------- +*/ + +#ifndef _INC_ASTRA_FEATURES +#define _INC_ASTRA_FEATURES + +#include "astra/Globals.h" + +namespace astra { +_AstraExport bool hasFeature(const std::string &feature); +} + +/* + +FEATURES: + +cuda: is cuda support compiled in? + NB: To check if there is also actually a usable GPU, use cudaAvailable() + +mex_link: is there support for the matlab command astra_mex_data3d('link')? + +For future backward-incompatible changes, extra features will be added here + + +*/ + + +#endif diff --git a/matlab/mex/astra_mex_algorithm_c.cpp b/matlab/mex/astra_mex_algorithm_c.cpp index 80c0424..7804eeb 100644 --- a/matlab/mex/astra_mex_algorithm_c.cpp +++ b/matlab/mex/astra_mex_algorithm_c.cpp @@ -34,8 +34,6 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. #include "mexInitFunctions.h" #include "astra/Globals.h" -#define USE_MATLAB_UNDOCUMENTED - #ifdef USE_MATLAB_UNDOCUMENTED extern "C" { bool utIsInterruptPending(); } diff --git a/matlab/mex/astra_mex_c.cpp b/matlab/mex/astra_mex_c.cpp index f494ce6..43c438e 100644 --- a/matlab/mex/astra_mex_c.cpp +++ b/matlab/mex/astra_mex_c.cpp @@ -35,6 +35,7 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. #include "mexInitFunctions.h" #include "astra/Globals.h" +#include "astra/Features.h" #include "astra/AstraObjectManager.h" #ifdef ASTRA_CUDA @@ -132,6 +133,7 @@ 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 @@ -149,6 +151,38 @@ void astra_mex_get_gpu_info(int nlhs, mxArray* plhs[], int nrhs, const mxArray* //----------------------------------------------------------------------------------------- +/** has_feature = astra_mex('has_feature'); + * + * Check a feature flag. See include/astra/Features.h. + */ +void astra_mex_has_feature(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +{ + if (2 > nrhs) { + mexErrMsgTxt("Usage: astra_mex('has_feature', feature);\n"); + return; + } + + string sMode = mexToString(prhs[0]); + bool ret = false; + + // NB: When adding features here, also document them centrally in + // include/astra/Features.h + if (sMode == "mex_link") { +#ifdef USE_MATLAB_UNDOCUMENTED + ret = true; +#else + ret = false; +#endif + } else { + ret = astra::hasFeature(sMode); + } + + plhs[0] = mxCreateDoubleScalar(ret ? 1 : 0); +} + + + +//----------------------------------------------------------------------------------------- /** version_number = astra_mex('version'); * * Fetch the version number of the toolbox. @@ -208,7 +242,7 @@ void astra_mex_delete(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[] static void printHelp() { mexPrintf("Please specify a mode of operation.\n"); - mexPrintf(" Valid modes: version, use_cuda, credits, set_gpu_index, info, delete\n"); + mexPrintf(" Valid modes: version, use_cuda, credits, set_gpu_index, has_feature, info, delete\n"); } //----------------------------------------------------------------------------------------- @@ -241,6 +275,8 @@ void mexFunction(int nlhs, mxArray* plhs[], 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("has_feature")) { + astra_mex_has_feature(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/mex/astra_mex_data3d_c.cpp b/matlab/mex/astra_mex_data3d_c.cpp index 5504955..4642693 100644 --- a/matlab/mex/astra_mex_data3d_c.cpp +++ b/matlab/mex/astra_mex_data3d_c.cpp @@ -55,8 +55,6 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. using namespace std; using namespace astra; -#define USE_MATLAB_UNDOCUMENTED - //----------------------------------------------------------------------------------------- /** * id = astra_mex_io_data('create', datatype, geometry, data); diff --git a/matlab/mex/astra_mex_direct_c.cpp b/matlab/mex/astra_mex_direct_c.cpp index 1a129f4..0090d13 100644 --- a/matlab/mex/astra_mex_direct_c.cpp +++ b/matlab/mex/astra_mex_direct_c.cpp @@ -54,8 +54,6 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. using namespace std; using namespace astra; -#define USE_MATLAB_UNDOCUMENTED - class CFloat32CustomMemory_simple : public astra::CFloat32CustomMemory { public: diff --git a/matlab/mex/mexDataManagerHelpFunctions.cpp b/matlab/mex/mexDataManagerHelpFunctions.cpp index a71928b..dc225ac 100644 --- a/matlab/mex/mexDataManagerHelpFunctions.cpp +++ b/matlab/mex/mexDataManagerHelpFunctions.cpp @@ -36,8 +36,6 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. #include "astra/Float32VolumeData3DMemory.h" #include "astra/Float32ProjectionData3DMemory.h" -#define USE_MATLAB_UNDOCUMENTED - #ifdef USE_MATLAB_UNDOCUMENTED extern "C" { mxArray *mxCreateSharedDataCopy(const mxArray *pr); diff --git a/matlab/mex/mexHelpFunctions.h b/matlab/mex/mexHelpFunctions.h index bf22929..56994dc 100644 --- a/matlab/mex/mexHelpFunctions.h +++ b/matlab/mex/mexHelpFunctions.h @@ -28,6 +28,10 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. #ifndef _INC_ASTRA_MEX_HELPFUNCTIONS #define _INC_ASTRA_MEX_HELPFUNCTIONS + +#define USE_MATLAB_UNDOCUMENTED + + #include <string> #include <list> #include <iostream> @@ -66,6 +70,4 @@ mxArray* XMLNodeToStruct(astra::XMLNode xml); mxArray* stringToMxArray(std::string input); mxArray* buildStruct(std::map<std::string, mxArray*> mInput); - - #endif diff --git a/python/astra/__init__.py b/python/astra/__init__.py index 1a7f444..ae35316 100644 --- a/python/astra/__init__.py +++ b/python/astra/__init__.py @@ -27,7 +27,7 @@ from . import matlab as m from .creators import astra_dict,create_vol_geom, create_proj_geom, create_backprojection, create_sino, create_reconstruction, create_projector,create_sino3d_gpu, create_backprojection3d_gpu from .functions import data_op, add_noise_to_sino, clear, move_vol_geom, geom_size, geom_2vec, geom_postalignment from .extrautils import clipCircle -from .astra import set_gpu_index, get_gpu_info, use_cuda +from .astra import set_gpu_index, get_gpu_info, use_cuda, has_feature from . import data2d from . import astra from . import data3d diff --git a/python/astra/astra.py b/python/astra/astra.py index ef46db1..e74d29a 100644 --- a/python/astra/astra.py +++ b/python/astra/astra.py @@ -54,6 +54,20 @@ def get_gpu_info(idx=-1): """ return a.get_gpu_info(idx) +def has_feature(feature): + """Check a feature flag. + + These are used to check if certain functionality has been + enabled at compile time, if new functionality is present, or if + a backward-incompatible change is present. + + See include/astra/Features.h for a list. + + :param feature: The name of the feature + :type feature: :class:`str` + :returns: :class:`bool` -- The presence of the feature + """ + return a.has_feature(feature) def delete(ids): """Delete an astra object. diff --git a/python/astra/astra_c.pyx b/python/astra/astra_c.pyx index 65dbf28..69909b5 100644 --- a/python/astra/astra_c.pyx +++ b/python/astra/astra_c.pyx @@ -28,7 +28,7 @@ include "config.pxi" import six -from .utils import wrap_from_bytes +from .utils import wrap_from_bytes, wrap_to_bytes from libcpp.string cimport string from libcpp.vector cimport vector @@ -40,6 +40,9 @@ cdef extern from "astra/Globals.h" namespace "astra": bool cudaEnabled() bool cudaAvailable() +cdef extern from "astra/Features.h" namespace "astra": + bool hasFeature(string) + IF HAVE_CUDA==True: cdef extern from "astra/cuda/2d/astra.h" namespace "astraCUDA": bool setGPUIndex(int) @@ -120,3 +123,6 @@ def info(ids): if ptr: s = ptr.getType() + six.b("\t") + ptr.getInfo(i) six.print_(wrap_from_bytes(s)) + +def has_feature(feature): + return hasFeature(wrap_to_bytes(feature)) diff --git a/src/Features.cpp b/src/Features.cpp new file mode 100644 index 0000000..9114131 --- /dev/null +++ b/src/Features.cpp @@ -0,0 +1,41 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +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 <http://www.gnu.org/licenses/>. + +----------------------------------------------------------------------- +*/ + +#include "astra/Features.h" +#include "astra/Globals.h" + +namespace astra { + +_AstraExport bool hasFeature(const std::string &flag) { + if (flag == "cuda") { + return cudaEnabled(); + } + + return false; +} + +} |