summaryrefslogtreecommitdiffstats
path: root/matlab/mex
diff options
context:
space:
mode:
authorDaniel M. Pelt <D.M.Pelt@cwi.nl>2015-06-19 22:28:06 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2015-07-23 11:57:15 +0200
commit18b6d25f7e4f0943b3592f3bb4f6ca5ed9c285d3 (patch)
tree8919012d1c610eaf6b2e8c157082a85fb71137a4 /matlab/mex
parent9e077994b382b2df63e4b79dd2afebc50366d419 (diff)
downloadastra-18b6d25f7e4f0943b3592f3bb4f6ca5ed9c285d3.tar.gz
astra-18b6d25f7e4f0943b3592f3bb4f6ca5ed9c285d3.tar.bz2
astra-18b6d25f7e4f0943b3592f3bb4f6ca5ed9c285d3.tar.xz
astra-18b6d25f7e4f0943b3592f3bb4f6ca5ed9c285d3.zip
Add support for Python algorithm plugins
Diffstat (limited to 'matlab/mex')
-rw-r--r--matlab/mex/astra_mex_plugin_c.cpp139
1 files changed, 139 insertions, 0 deletions
diff --git a/matlab/mex/astra_mex_plugin_c.cpp b/matlab/mex/astra_mex_plugin_c.cpp
new file mode 100644
index 0000000..2d9b9a0
--- /dev/null
+++ b/matlab/mex/astra_mex_plugin_c.cpp
@@ -0,0 +1,139 @@
+/*
+-----------------------------------------------------------------------
+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 <http://www.gnu.org/licenses/>.
+
+-----------------------------------------------------------------------
+$Id$
+*/
+
+/** \file astra_mex_plugin_c.cpp
+ *
+ * \brief Manages Python plugins.
+ */
+
+#include <mex.h>
+#include "mexHelpFunctions.h"
+#include "mexInitFunctions.h"
+
+#include "astra/PluginAlgorithm.h"
+
+#include "Python.h"
+#include "bytesobject.h"
+
+using namespace std;
+using namespace astra;
+
+
+//-----------------------------------------------------------------------------------------
+/** astra_mex_plugin('get_registered');
+ *
+ * Print registered plugins.
+ */
+void astra_mex_plugin_get_registered(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
+{
+ astra::CPluginAlgorithmFactory *fact = astra::CPluginAlgorithmFactory::getSingletonPtr();
+ PyObject *dict = fact->getRegistered();
+ PyObject *key, *value;
+ Py_ssize_t pos = 0;
+ while (PyDict_Next(dict, &pos, &key, &value)) {
+ mexPrintf("%s: %s\n",PyBytes_AsString(key),PyBytes_AsString(value));
+ }
+ Py_DECREF(dict);
+}
+
+//-----------------------------------------------------------------------------------------
+/** astra_mex_plugin('register', name, class_name);
+ *
+ * Register plugin.
+ */
+void astra_mex_plugin_register(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
+{
+ if (3 <= nrhs) {
+ string name = mexToString(prhs[1]);
+ string class_name = mexToString(prhs[2]);
+ astra::CPluginAlgorithmFactory *fact = astra::CPluginAlgorithmFactory::getSingletonPtr();
+ fact->registerPlugin(name, class_name);
+ }else{
+ mexPrintf("astra_mex_plugin('register', name, class_name);\n");
+ }
+}
+
+//-----------------------------------------------------------------------------------------
+/** astra_mex_plugin('get_help', name);
+ *
+ * Get help about plugin.
+ */
+void astra_mex_plugin_get_help(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
+{
+ if (2 <= nrhs) {
+ string name = mexToString(prhs[1]);
+ astra::CPluginAlgorithmFactory *fact = astra::CPluginAlgorithmFactory::getSingletonPtr();
+ mexPrintf((fact->getHelp(name)+"\n").c_str());
+ }else{
+ mexPrintf("astra_mex_plugin('get_help', name);\n");
+ }
+}
+
+
+//-----------------------------------------------------------------------------------------
+
+static void printHelp()
+{
+ mexPrintf("Please specify a mode of operation.\n");
+ mexPrintf(" Valid modes: register, get_registered, get_help\n");
+}
+
+//-----------------------------------------------------------------------------------------
+/**
+ * ... = astra_mex(type,...);
+ */
+void mexFunction(int nlhs, mxArray* plhs[],
+ int nrhs, const mxArray* prhs[])
+{
+
+ // INPUT0: Mode
+ string sMode = "";
+ if (1 <= nrhs) {
+ sMode = mexToString(prhs[0]);
+ } else {
+ printHelp();
+ return;
+ }
+
+ initASTRAMex();
+
+ // SWITCH (MODE)
+ 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);
+ }else if (sMode == std::string("register")) {
+ astra_mex_plugin_register(nlhs, plhs, nrhs, prhs);
+ } else {
+ printHelp();
+ }
+
+ return;
+}
+
+