summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/astra/AstraObjectFactory.h55
-rw-r--r--include/astra/Globals.h2
-rw-r--r--include/astra/PluginAlgorithm.h90
3 files changed, 134 insertions, 13 deletions
diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h
index 1ed4955..325989e 100644
--- a/include/astra/AstraObjectFactory.h
+++ b/include/astra/AstraObjectFactory.h
@@ -40,6 +40,10 @@ $Id$
#include "AlgorithmTypelist.h"
+#ifdef ASTRA_PYTHON
+#include "PluginAlgorithm.h"
+#endif
+
namespace astra {
@@ -59,20 +63,27 @@ public:
*/
~CAstraObjectFactory();
- /** Create, but don't initialize, a new projector object.
+ /** Create, but don't initialize, a new object.
*
- * @param _sType Type of the new projector.
- * @return Pointer to a new, unitialized projector.
+ * @param _sType Type of the new object.
+ * @return Pointer to a new, uninitialized object.
*/
T* create(std::string _sType);
- /** Create and initialize a new projector object.
+ /** Create and initialize a new object.
*
- * @param _cfg Configuration object to create and initialize a new projector.
+ * @param _cfg Configuration object to create and initialize a new object.
* @return Pointer to a new, initialized projector.
*/
T* create(const Config& _cfg);
+ /** Find a plugin.
+ *
+ * @param _sType Name of plugin to find.
+ * @return Pointer to a new, uninitialized object, or NULL if not found.
+ */
+ T* findPlugin(std::string _sType);
+
};
@@ -93,6 +104,15 @@ CAstraObjectFactory<T, TypeList>::~CAstraObjectFactory()
}
+
+//----------------------------------------------------------------------------------------
+// Hook for finding plugin in registered plugins.
+template <typename T, typename TypeList>
+T* CAstraObjectFactory<T, TypeList>::findPlugin(std::string _sType)
+{
+ return NULL;
+}
+
//----------------------------------------------------------------------------------------
// Create
template <typename T, typename TypeList>
@@ -101,6 +121,9 @@ T* CAstraObjectFactory<T, TypeList>::create(std::string _sType)
functor_find<T> finder = functor_find<T>();
finder.tofind = _sType;
CreateObject<TypeList>::find(finder);
+ if (finder.res == NULL) {
+ finder.res = findPlugin(_sType);
+ }
return finder.res;
}
@@ -109,14 +132,11 @@ T* CAstraObjectFactory<T, TypeList>::create(std::string _sType)
template <typename T, typename TypeList>
T* CAstraObjectFactory<T, TypeList>::create(const Config& _cfg)
{
- functor_find<T> finder = functor_find<T>();
- finder.tofind = _cfg.self.getAttribute("type");
- CreateObject<TypeList>::find(finder);
- if (finder.res == NULL) return NULL;
- if (finder.res->initialize(_cfg))
- return finder.res;
-
- delete finder.res;
+ T* object = create(_cfg.self.getAttribute("type"));
+ if (object == NULL) return NULL;
+ if (object->initialize(_cfg))
+ return object;
+ delete object;
return NULL;
}
//----------------------------------------------------------------------------------------
@@ -131,6 +151,15 @@ T* CAstraObjectFactory<T, TypeList>::create(const Config& _cfg)
*/
class _AstraExport CAlgorithmFactory : public CAstraObjectFactory<CAlgorithm, AlgorithmTypeList> {};
+#ifdef ASTRA_PYTHON
+template <>
+inline CAlgorithm* CAstraObjectFactory<CAlgorithm, AlgorithmTypeList>::findPlugin(std::string _sType)
+ {
+ CPluginAlgorithmFactory *fac = CPluginAlgorithmFactory::getSingletonPtr();
+ return fac->getPlugin(_sType);
+ }
+#endif
+
/**
* Class used to create 2D projectors from a string or a config object
*/
diff --git a/include/astra/Globals.h b/include/astra/Globals.h
index 4de07d1..f70c3a9 100644
--- a/include/astra/Globals.h
+++ b/include/astra/Globals.h
@@ -146,6 +146,8 @@ namespace astra {
const float32 PIdiv2 = PI / 2;
const float32 PIdiv4 = PI / 4;
const float32 eps = 1e-7f;
+
+ extern _AstraExport bool running_in_matlab;
}
//----------------------------------------------------------------------------------------
diff --git a/include/astra/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h
new file mode 100644
index 0000000..667e813
--- /dev/null
+++ b/include/astra/PluginAlgorithm.h
@@ -0,0 +1,90 @@
+/*
+-----------------------------------------------------------------------
+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$
+*/
+
+#ifndef _INC_ASTRA_PLUGINALGORITHM
+#define _INC_ASTRA_PLUGINALGORITHM
+
+#ifdef ASTRA_PYTHON
+
+#include "astra/Algorithm.h"
+#include "astra/Singleton.h"
+#include "astra/XMLDocument.h"
+#include "astra/XMLNode.h"
+
+// Slightly hackish forward declaration of PyObject
+struct _object;
+typedef _object PyObject;
+
+
+namespace astra {
+class _AstraExport CPluginAlgorithm : public CAlgorithm {
+
+public:
+
+ CPluginAlgorithm(PyObject* pyclass);
+ ~CPluginAlgorithm();
+
+ bool initialize(const Config& _cfg);
+ void run(int _iNrIterations);
+
+private:
+ PyObject * instance;
+
+};
+
+class _AstraExport CPluginAlgorithmFactory : public Singleton<CPluginAlgorithmFactory> {
+
+public:
+
+ CPluginAlgorithmFactory();
+ ~CPluginAlgorithmFactory();
+
+ CPluginAlgorithm * getPlugin(std::string name);
+
+ bool registerPlugin(std::string name, std::string className);
+ bool registerPlugin(std::string className);
+ bool registerPluginClass(std::string name, PyObject * className);
+ bool registerPluginClass(PyObject * className);
+
+ PyObject * getRegistered();
+ std::map<std::string, std::string> getRegisteredMap();
+
+ std::string getHelp(std::string name);
+
+private:
+ PyObject * pluginDict;
+ PyObject *inspect, *six;
+};
+
+PyObject* XMLNode2dict(XMLNode node);
+
+}
+
+#endif
+
+#endif