Read@CVL
BaseModule.h
Go to the documentation of this file.
1 /*******************************************************************************************************
2  ReadFramework is the basis for modules developed at CVL/TU Wien for the EU project READ.
3 
4  Copyright (C) 2016 Markus Diem <diem@caa.tuwien.ac.at>
5  Copyright (C) 2016 Stefan Fiel <fiel@caa.tuwien.ac.at>
6  Copyright (C) 2016 Florian Kleber <kleber@caa.tuwien.ac.at>
7 
8  This file is part of ReadFramework.
9 
10  ReadFramework is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  ReadFramework is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23  The READ project has received funding from the European Union’s Horizon 2020
24  research and innovation programme under grant agreement No 674943
25 
26  related links:
27  [1] http://www.caa.tuwien.ac.at/cvl/
28  [2] https://transkribus.eu/Transkribus/
29  [3] https://github.com/TUWien/
30  [4] http://nomacs.org
31  *******************************************************************************************************/
32 
33 #pragma once
34 
35 #pragma warning(push, 0) // no warnings from includes
36 #include <QObject>
37 #include <QSharedPointer>
38 #include <QDebug>
39 #pragma warning(pop)
40 
41 #include <opencv2/core.hpp>
42 
43 #pragma warning (disable: 4251) // inlined Qt functions in dll interface
44 
45 #ifndef DllCoreExport
46 #ifdef DLL_CORE_EXPORT
47 #define DllCoreExport Q_DECL_EXPORT
48 #else
49 #define DllCoreExport Q_DECL_IMPORT
50 #endif
51 #endif
52 
53 // Qt defines
54 class QSettings;
55 
56 namespace rdf {
57 
58 #define mDebug qDebug().noquote() << debugName()
59 #define mInfo qInfo().noquote() << debugName()
60 #define mWarning qWarning().noquote() << debugName()
61 #define mCritical qCritical().noquote() << debugName()
62 
64 
65 public:
66  ModuleConfig(const QString& moduleName = "Generic Module");
67 
68  friend DllCoreExport QDataStream& operator<<(QDataStream& s, const ModuleConfig& m);
69  friend DllCoreExport QDebug operator<< (QDebug d, const ModuleConfig &m);
70 
71  void loadSettings();
72  void loadSettings(QSettings& settings);
73  void saveSettings() const;
74  void saveSettings(QSettings& settings) const;
75  void saveDefaultSettings() const;
76  virtual void saveDefaultSettings(QSettings& settings) const;
77 
78  QString name() const;
79  virtual QString toString() const;
80 
81 protected:
82  virtual void load(const QSettings& settings);
83  virtual void save(QSettings& settings) const;
84 
85  QString mModuleName;
87  template <class num>
88  num checkParam(num param, num min, num max, const QString & name) const {
89 
90  if (param < min) {
91  qWarning().noquote() << name << "must be >" << min << "but it is: " << param;
92  return min;
93  }
94 
95  if (param > max) {
96  qWarning().noquote() << name << "must be <" << max << "but it is: " << param;
97  return max;
98  }
99 
100  return param;
101  }
102 
103 };
104 
105 class ScaleFactory;
106 
108 
109 public:
111  const QString& moduleName = "Generic Module",
112  const QSharedPointer<ScaleFactory>& sf = QSharedPointer<ScaleFactory>());
113 
114  void setScaleFactory(const QSharedPointer<ScaleFactory>& sf);
115  QSharedPointer<ScaleFactory> scaleFactory();
116 
117 protected:
118  QSharedPointer<ScaleFactory> mScaleFactory;
119 };
120 
121 
127 
128 public:
129 
134  Module();
135 
136  friend DllCoreExport QDataStream& operator<<(QDataStream& s, const Module& m);
137  friend DllCoreExport QDebug operator<< (QDebug d, const Module &m);
138 
139 
145  virtual bool isEmpty() const = 0;
146 
151  virtual QString name() const;
152 
157  virtual QString toString() const;
158 
163  virtual bool compute() = 0;
164 
165  virtual void setConfig(QSharedPointer<ModuleConfig> config);
166  QSharedPointer<ModuleConfig> config() const;
167 
168 protected:
169  QSharedPointer<ModuleConfig> mConfig;
171  virtual bool checkInput() const = 0;
172  QString debugName() const;
173 
174 };
175 
176 }
QSharedPointer< ScaleFactory > mScaleFactory
Definition: BaseModule.h:118
Definition: BaseModule.h:63
#define DllCoreExport
Definition: BaseModule.h:49
QDataStream & operator<<(QDataStream &s, const BaseElement &e)
Definition: BaseImageElement.cpp:81
num checkParam(num param, num min, num max, const QString &name) const
Definition: BaseModule.h:88
config
Definition: DependencyCollector.py:271
Definition: BaseModule.h:107
Definition: ScaleFactory.h:95
QSharedPointer< ModuleConfig > mConfig
Definition: BaseModule.h:169
DllCoreExport bool save(const QImage &img, const QString &savePath, int compression=-1)
Saves the specified QImage img.
Definition: Image.cpp:180
DllCoreExport QImage load(const QString &path, bool *ok=0)
Definition: Image.cpp:152
QString mModuleName
Definition: BaseModule.h:85
This is the base class for all modules. It provides all functions which are implemented by the module...
Definition: BaseModule.h:126
Definition: Algorithms.cpp:45