diff options
author | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2016-01-21 14:30:32 +0100 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2016-01-21 14:30:47 +0100 |
commit | 96fa285132bf88462c33c5b24cc1b241fb3d4d73 (patch) | |
tree | 931f234c2e1c4f59fdf7a2bec3065f85c1e165fd /matlab | |
parent | 7f11ed333cdc93e9e93d4677f857d97ffbbfec87 (diff) | |
download | astra-96fa285132bf88462c33c5b24cc1b241fb3d4d73.tar.gz astra-96fa285132bf88462c33c5b24cc1b241fb3d4d73.tar.bz2 astra-96fa285132bf88462c33c5b24cc1b241fb3d4d73.tar.xz astra-96fa285132bf88462c33c5b24cc1b241fb3d4d73.zip |
Initialize Python plugins when available in Matlab
Diffstat (limited to 'matlab')
-rw-r--r-- | matlab/mex/astra_mex_plugin_c.cpp | 25 | ||||
-rw-r--r-- | matlab/mex/mexInitFunctions.cpp | 8 |
2 files changed, 32 insertions, 1 deletions
diff --git a/matlab/mex/astra_mex_plugin_c.cpp b/matlab/mex/astra_mex_plugin_c.cpp index 627e34a..9bd4446 100644 --- a/matlab/mex/astra_mex_plugin_c.cpp +++ b/matlab/mex/astra_mex_plugin_c.cpp @@ -37,11 +37,32 @@ $Id$ #include "astra/PluginAlgorithm.h" +#include <Python.h> + using namespace std; using namespace astra; //----------------------------------------------------------------------------------------- +/** astra_mex_plugin('init'); + * + * Initialize plugin support by initializing python and importing astra + */ +void astra_mex_plugin_init() +{ + if(!Py_IsInitialized()){ + Py_Initialize(); + PyEval_InitThreads(); + } + + // Importing astra may be overkill, since we only need to initialize + // PythonPluginAlgorithmFactory from astra.plugin_c. + PyObject *mod = PyImport_ImportModule("astra"); + Py_DECREF(mod); +} + + +//----------------------------------------------------------------------------------------- /** astra_mex_plugin('get_registered'); * * Print registered plugins. @@ -128,7 +149,9 @@ void mexFunction(int nlhs, mxArray* plhs[], initASTRAMex(); // SWITCH (MODE) - if (sMode == std::string("get_registered")) { + if (sMode == "init") { + astra_mex_plugin_init(); + } else if (sMode == std::string("get_registered")) { astra_mex_plugin_get_registered(nlhs, plhs, nrhs, prhs); }else if (sMode == std::string("get_help")) { astra_mex_plugin_get_help(nlhs, plhs, nrhs, prhs); diff --git a/matlab/mex/mexInitFunctions.cpp b/matlab/mex/mexInitFunctions.cpp index bd3df2c..7245af2 100644 --- a/matlab/mex/mexInitFunctions.cpp +++ b/matlab/mex/mexInitFunctions.cpp @@ -23,5 +23,13 @@ void initASTRAMex(){ if(!astra::CLogger::setCallbackScreen(&logCallBack)){ mexErrMsgTxt("Error initializing mex functions."); } + mexIsInitialized=true; + + + // If we have support for plugins, initialize them. + // (NB: Call this after setting mexIsInitialized, to avoid recursively + // calling initASTRAMex) + mexEvalString("if exist('astra_mex_plugin_c') == 3; astra_mex_plugin_c('init'); end"); + } |