summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/astra/algorithm.py11
-rw-r--r--python/astra/algorithm_c.pyx17
-rw-r--r--python/astra/src/PythonPluginAlgorithm.cpp8
-rw-r--r--python/astra/src/PythonPluginAlgorithm.h3
-rw-r--r--python/builder.py2
5 files changed, 40 insertions, 1 deletions
diff --git a/python/astra/algorithm.py b/python/astra/algorithm.py
index 33cca85..8862af3 100644
--- a/python/astra/algorithm.py
+++ b/python/astra/algorithm.py
@@ -66,6 +66,17 @@ def delete(ids):
"""
return a.delete(ids)
+def get_plugin_object(i):
+ """Return the Python object instance of a plugin algorithm.
+
+ :param i: ID of object corresponding to a plugin algorithm.
+ :type i: :class:`int`
+ :returns: The Python object instance of the plugin algorithm.
+
+ """
+ return a.get_plugin_object(i)
+
+
def clear():
"""Clear all matrix objects."""
return a.clear()
diff --git a/python/astra/algorithm_c.pyx b/python/astra/algorithm_c.pyx
index a190ee1..50f6052 100644
--- a/python/astra/algorithm_c.pyx
+++ b/python/astra/algorithm_c.pyx
@@ -47,6 +47,13 @@ cdef extern from *:
CReconstructionAlgorithm2D * dynamic_cast_recAlg2D "dynamic_cast<astra::CReconstructionAlgorithm2D*>" (CAlgorithm * )
CReconstructionAlgorithm3D * dynamic_cast_recAlg3D "dynamic_cast<astra::CReconstructionAlgorithm3D*>" (CAlgorithm * )
+cdef extern from "src/PythonPluginAlgorithm.h" namespace "astra":
+ cdef cppclass CPluginAlgorithm:
+ object getInstance()
+
+cdef extern from *:
+ CPluginAlgorithm * dynamic_cast_PluginAlg "dynamic_cast<astra::CPluginAlgorithm*>" (CAlgorithm * )
+
def create(config):
cdef Config * cfg = utils.dictToConfig(six.b('Algorithm'), config)
@@ -104,6 +111,16 @@ def delete(ids):
manAlg.remove(ids)
+def get_plugin_object(algorithm_id):
+ cdef CAlgorithm *alg
+ cdef CPluginAlgorithm *pluginAlg
+ alg = getAlg(algorithm_id)
+ pluginAlg = dynamic_cast_PluginAlg(alg)
+ if not pluginAlg:
+ raise Exception("Not a plugin algorithm")
+ return pluginAlg.getInstance()
+
+
def clear():
manAlg.clear()
diff --git a/python/astra/src/PythonPluginAlgorithm.cpp b/python/astra/src/PythonPluginAlgorithm.cpp
index d461f06..3c892ff 100644
--- a/python/astra/src/PythonPluginAlgorithm.cpp
+++ b/python/astra/src/PythonPluginAlgorithm.cpp
@@ -124,6 +124,14 @@ void CPluginAlgorithm::run(int _iNrIterations){
PyGILState_Release(state);
}
+PyObject *CPluginAlgorithm::getInstance() const {
+ if (instance)
+ Py_INCREF(instance);
+ return instance;
+}
+
+
+
CPythonPluginAlgorithmFactory::CPythonPluginAlgorithmFactory(){
if(!Py_IsInitialized()){
Py_Initialize();
diff --git a/python/astra/src/PythonPluginAlgorithm.h b/python/astra/src/PythonPluginAlgorithm.h
index 947e30d..b7072d6 100644
--- a/python/astra/src/PythonPluginAlgorithm.h
+++ b/python/astra/src/PythonPluginAlgorithm.h
@@ -49,6 +49,9 @@ public:
bool initialize(const Config& _cfg);
void run(int _iNrIterations);
+ // Return instance (including INCREF)
+ PyObject *getInstance() const;
+
private:
PyObject * instance;
diff --git a/python/builder.py b/python/builder.py
index dd99633..b373366 100644
--- a/python/builder.py
+++ b/python/builder.py
@@ -66,7 +66,7 @@ ext_modules = cythonize(os.path.join(self_path, 'astra', '*.pyx'),
cmdclass = {'build_ext': build_ext}
for m in ext_modules:
- if m.name == 'astra.plugin_c':
+ if m.name in ('astra.plugin_c', 'astra.algorithm_c'):
m.sources.append(os.path.join(self_path, 'astra', 'src',
'PythonPluginAlgorithm.cpp'))