itom
Loading...
Searching...
No Matches
pythonAlgorithms.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#pragma once
24
25/* includes */
26#ifndef Q_MOC_RUN
27 //see numpy help ::array api :: Miscellaneous :: Importing the api (this line must before include global.h)
28 #define PY_ARRAY_UNIQUE_SYMBOL itom_ARRAY_API
29 #define NO_IMPORT_ARRAY
30
31 #include "python/pythonWrapper.h"
32#endif
33
34#include "common/addInInterface.h"
35
36#include <qstring.h>
37
38namespace ito
39{
40
42{
43
44public:
45 static PyMethodDef PythonMethodItomAlgorithms[];
46 static PyModuleDef PythonModuleItomAlgorithms;
47
48 static void AddAlgorithmFunctions(PyObject* mod);
49
51 static PyObject* PyGenericAlgorithm(const QString &algorithmName, PyObject *self, PyObject *args, PyObject *kwds);
52
53 static PyObject* PyGenericAlgorithm2(const AddInAlgo::FilterDef *filterDef, PyObject *self, PyObject *args, PyObject *kwds);
54
55private:
56
58 /*
59 For each algorithm, a PyAlgorithm object is created (in AddAlgorithmFunctions)
60 and added as member to the itom.algorithms module. The PyAlgorithm class has
61 the __call__ method implemented, that calls the real algorithm.
62
63 Then, it is equal to call
64
65 itom.filter("lowPassFilter", arg1, arg2, ...)
66
67 or
68
69 itom.algorithms.lowPassFilter(arg1, arg2, ...)
70
71 However, the latter provides auto completion and calltips.
72 */
73 typedef struct
74 {
75 PyObject_HEAD
76 const ito::AddInAlgo::FilterDef *filterDef;
77 }
79
80 #define PyAlgorithm_Check(op) PyObject_TypeCheck(op, &ito::PythonAlgorithms::PyAlgorithmType)
81
82 //-------------------------------------------------------------------------------------------------
83 // constructor, destructor, alloc, dellaoc
84 //-------------------------------------------------------------------------------------------------
85 static void PyAlgorithm_dealloc(PyAlgorithm *self);
86 static PyObject* PyAlgorithm_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
87 static int PyAlgorithm_init(PyAlgorithm *self, PyObject *args, PyObject *kwds);
88 static PyObject* PyAlgorithm_call(PyAlgorithm *self, PyObject *args, PyObject *kwds);
89 static PyObject* PyAlgorithm_repr(PyAlgorithm *self);
90
91 // creates a new PyAlgorithm object.
92 static PyObject* createPyAlgorithm(const ito::AddInAlgo::FilterDef *filterDef);
93
94 //-------------------------------------------------------------------------------------------------
95 // type structures
96 //-------------------------------------------------------------------------------------------------
97 static PyTypeObject PyAlgorithmType;
98 static PyModuleDef PyAlgorithmModule;
99};
100
101} //end namespace ito
container for publishing filters provided by any plugin
Definition addInInterface.h:974
Definition pythonAlgorithms.h:42
static void AddAlgorithmFunctions(PyObject *mod)
calls an algorithm with a given name and the required args and kwds.
Definition pythonAlgorithms.cpp:38
Definition apiFunctionsGraph.cpp:40
PyAlgorithm is a thin wrapper class for calling any itom algorithm, defined in an algo plugin.
Definition pythonAlgorithms.h:74