From 8f37932efdbf7585c85ba1e7653e7080e17d7714 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 23 Jul 2015 11:39:28 +0200 Subject: Reduce code duplication --- include/astra/AstraObjectFactory.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index 1ed4955..efe997d 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -109,14 +109,11 @@ T* CAstraObjectFactory::create(std::string _sType) template T* CAstraObjectFactory::create(const Config& _cfg) { - functor_find finder = functor_find(); - finder.tofind = _cfg.self.getAttribute("type"); - CreateObject::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; } //---------------------------------------------------------------------------------------- -- cgit v1.2.3 From 2f800d5c1a305a23906783ecaa075e3d5274ef26 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 23 Jul 2015 11:49:39 +0200 Subject: Fix comments --- include/astra/AstraObjectFactory.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index efe997d..c935a7c 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -59,16 +59,16 @@ 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); -- cgit v1.2.3 From 9e077994b382b2df63e4b79dd2afebc50366d419 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 23 Jul 2015 11:43:47 +0200 Subject: Add hooks for plugin support to AstraObjectFactory To use these hooks, add a specialization of findPlugin for the desired type of object (e.g., Algorithms). --- include/astra/AstraObjectFactory.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include') diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index c935a7c..356acf9 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -73,6 +73,13 @@ public: */ 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 +100,15 @@ CAstraObjectFactory::~CAstraObjectFactory() } + +//---------------------------------------------------------------------------------------- +// Hook for finding plugin in registered plugins. +template +T* CAstraObjectFactory::findPlugin(std::string _sType) +{ + return NULL; +} + //---------------------------------------------------------------------------------------- // Create template @@ -101,6 +117,9 @@ T* CAstraObjectFactory::create(std::string _sType) functor_find finder = functor_find(); finder.tofind = _sType; CreateObject::find(finder); + if (finder.res == NULL) { + finder.res = findPlugin(_sType); + } return finder.res; } -- cgit v1.2.3 From 18b6d25f7e4f0943b3592f3bb4f6ca5ed9c285d3 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 19 Jun 2015 22:28:06 +0200 Subject: Add support for Python algorithm plugins --- include/astra/AstraObjectFactory.h | 13 ++++++ include/astra/PluginAlgorithm.h | 85 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 include/astra/PluginAlgorithm.h (limited to 'include') diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index 356acf9..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 { @@ -147,6 +151,15 @@ T* CAstraObjectFactory::create(const Config& _cfg) */ class _AstraExport CAlgorithmFactory : public CAstraObjectFactory {}; +#ifdef ASTRA_PYTHON +template <> +inline CAlgorithm* CAstraObjectFactory::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/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h new file mode 100644 index 0000000..7d6c64a --- /dev/null +++ b/include/astra/PluginAlgorithm.h @@ -0,0 +1,85 @@ +/* +----------------------------------------------------------------------- +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 . + +----------------------------------------------------------------------- +$Id$ +*/ + +#ifndef _INC_ASTRA_PLUGINALGORITHM +#define _INC_ASTRA_PLUGINALGORITHM + +#ifdef ASTRA_PYTHON + +#include +#include "bytesobject.h" +#include "astra/Algorithm.h" +#include "astra/Singleton.h" +#include "astra/XMLDocument.h" +#include "astra/XMLNode.h" + +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 { + +public: + + CPluginAlgorithmFactory(); + ~CPluginAlgorithmFactory(); + + CPluginAlgorithm * getPlugin(std::string name); + + bool registerPlugin(std::string name, std::string className); + bool registerPluginClass(std::string name, PyObject * className); + + PyObject * getRegistered(); + + std::string getHelp(std::string name); + +private: + PyObject * pluginDict; + PyObject *ospath, *inspect, *six, *astra; + std::vector getPluginPathList(); +}; + +PyObject* XMLNode2dict(XMLNode node); + +} + +#endif + +#endif \ No newline at end of file -- cgit v1.2.3 From 2f871bc7068d6c87a7d950ae044ba66b0b8dcd3f Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 17 Jul 2015 12:05:46 +0200 Subject: Remove config text file loading for plugins --- include/astra/PluginAlgorithm.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/astra/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h index 7d6c64a..a82c579 100644 --- a/include/astra/PluginAlgorithm.h +++ b/include/astra/PluginAlgorithm.h @@ -72,8 +72,7 @@ public: private: PyObject * pluginDict; - PyObject *ospath, *inspect, *six, *astra; - std::vector getPluginPathList(); + PyObject *inspect, *six; }; PyObject* XMLNode2dict(XMLNode node); -- cgit v1.2.3 From 3d136b7c819b0b142ad056bf01c8c1191eea9ba0 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 17 Jul 2015 16:22:05 +0200 Subject: Fix numpy lapack loading when running in Matlab --- include/astra/Globals.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/astra/Globals.h b/include/astra/Globals.h index 4de07d1..dc2d7e6 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 bool running_in_matlab; } //---------------------------------------------------------------------------------------- -- cgit v1.2.3 From d91b51f6d58003de84a9d6dd8189fceba0e81a5a Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Mon, 20 Jul 2015 14:07:21 +0200 Subject: Allow registering plugins without explicit name, and fix exception handling when running in Matlab --- include/astra/PluginAlgorithm.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/astra/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h index a82c579..b56228e 100644 --- a/include/astra/PluginAlgorithm.h +++ b/include/astra/PluginAlgorithm.h @@ -64,9 +64,12 @@ public: 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 getRegisteredMap(); std::string getHelp(std::string name); -- cgit v1.2.3 From 07c31b932078544205d61551edd4a66f69be30ae Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 2 Dec 2015 11:25:59 +0100 Subject: Avoid unnecessary include in header --- include/astra/PluginAlgorithm.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/astra/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h index b56228e..667e813 100644 --- a/include/astra/PluginAlgorithm.h +++ b/include/astra/PluginAlgorithm.h @@ -31,13 +31,16 @@ $Id$ #ifdef ASTRA_PYTHON -#include -#include "bytesobject.h" #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 { @@ -84,4 +87,4 @@ PyObject* XMLNode2dict(XMLNode node); #endif -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From 5df8492fcca44965f87884509668c1b75509e584 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 2 Dec 2015 14:56:42 +0100 Subject: Fix Windows build --- include/astra/Globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/astra/Globals.h b/include/astra/Globals.h index dc2d7e6..f70c3a9 100644 --- a/include/astra/Globals.h +++ b/include/astra/Globals.h @@ -147,7 +147,7 @@ namespace astra { const float32 PIdiv4 = PI / 4; const float32 eps = 1e-7f; - extern bool running_in_matlab; + extern _AstraExport bool running_in_matlab; } //---------------------------------------------------------------------------------------- -- cgit v1.2.3