Read@CVL
ElementsHelper.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 #include "Elements.h"
36 
37 #pragma warning(push, 0) // no warnings from includes
38 #include <QColor>
39 #include <QPen>
40 #pragma warning(pop)
41 
42 #pragma warning(disable: 4251) // dll interface warning
43 
44 #ifndef DllCoreExport
45 #ifdef DLL_CORE_EXPORT
46 #define DllCoreExport Q_DECL_EXPORT
47 #else
48 #define DllCoreExport Q_DECL_IMPORT
49 #endif
50 #endif
51 
52 // Qt defines
53 class QSettings;
54 
55 namespace rdf {
56 
57 // read defines
58 
60 
61 public:
63 
64  Region::Type type() const;
65 
66  void setDraw(bool draw);
67  bool draw() const;
68 
69  void setDrawPoly(bool draw);
70  bool drawPoly() const;
71 
72  void setDrawBaseline(bool draw);
73  bool drawBaseline() const;
74 
75  void setDrawBaselineLimits(bool draw);
76  bool drawBaselineLimits() const;
77 
78  void setDrawText(bool draw);
79  bool drawText() const;
80 
81  void setPen(const QPen& pen);
82  QPen pen() const;
83 
84  void setBrush(const QColor& col);
85  QColor brush() const;
86 
87  void load(QSettings& settings);
88  void save(QSettings& settings) const;
89 
90 protected:
91 
93  QPen mPen;
94  QColor mBrush;
95 
96  bool mDraw = true;
97  bool mDrawPoly = true;
98  bool mDrawBaseline = false;
99  bool mDrawBaselineLimits = true;
100  bool mDrawText = true;
101 
102  void assignDefaultColor(const Region::Type& type);
103 };
104 
106 
107 public:
108  static RegionXmlHelper& instance();
109 
110  enum XmlTags {
118 
132 
133  tag_end
134  };
135 
136  QString tag(const XmlTags& tagId) const;
137 
138 private:
139  RegionXmlHelper();
141 
142  QStringList createTags() const;
143  QStringList mTags;
144 };
145 
147 
148 public:
149  static RegionManager& instance();
150 
151  Region::Type type(const QString& typeName) const;
152  QString typeName(const Region::Type& type) const;
153  QStringList typeNames() const;
154  bool isValidTypeName(const QString& typeName) const;
155 
156  QSharedPointer<Region> createRegion(
157  const Region::Type& type) const;
158  QSharedPointer<RegionTypeConfig> getConfig(
159  const QSharedPointer<Region>& r,
160  const QVector<QSharedPointer<RegionTypeConfig> >& config = QVector<QSharedPointer<RegionTypeConfig> >()) const;
161 
162  void drawRegion(
163  QPainter& p,
164  QSharedPointer<rdf::Region> region,
165  const QVector<QSharedPointer<RegionTypeConfig> >& config = QVector<QSharedPointer<RegionTypeConfig> >(),
166  bool recursive = true,
167  bool activeSelection = false) const;
168 
169  QVector<QSharedPointer<rdf::Region> > regionsAt(
170  QSharedPointer<rdf::Region> root,
171  const QPoint& p,
172  const QVector<QSharedPointer<RegionTypeConfig> >& config = QVector<QSharedPointer<RegionTypeConfig> >()) const;
173 
174  QVector<QSharedPointer<RegionTypeConfig> > regionTypeConfig() const;
175 
176  void selectRegions(
177  const QVector<QSharedPointer<Region>>& selRegions,
178  QSharedPointer<Region> rootRegion = QSharedPointer<Region>()) const;
179 
180  template <typename T>
181  static QVector<QSharedPointer<T> > filter(
182  QSharedPointer<rdf::Region> root,
183  const Region::Type& type,
184  bool removeChildren = true) {
185 
186  QVector<QSharedPointer<Region> > regions = Region::allRegions(root.data());
187  QVector<QSharedPointer<T> > filteredRegions;
188 
189  for (auto r : regions) {
190 
191  if (r->type() == type) {
192 
193  // remove all children
194  if (removeChildren)
195  r->removeAllChildren();
196 
197  filteredRegions << r.dynamicCast<T>();
198  }
199  }
200 
201  return filteredRegions;
202  }
203 
204 private:
205  RegionManager();
207 
208  QStringList createTypeNames() const;
209  QVector<QSharedPointer<RegionTypeConfig> > createConfig() const;
210 
211  QStringList mTypeNames;
212  QVector<QSharedPointer<RegionTypeConfig> > mTypeConfig;
213 };
214 
215 
216 }
static QVector< QSharedPointer< Region > > allRegions(const Region *root)
Definition: Elements.cpp:336
Definition: ElementsHelper.h:124
#define DllCoreExport
Definition: BaseImageElement.h:43
Type
Definition: Elements.h:68
XmlTags
Definition: ElementsHelper.h:110
Definition: ElementsHelper.h:105
Definition: ElementsHelper.h:123
Definition: ElementsHelper.h:130
Definition: ElementsHelper.h:131
Definition: ElementsHelper.h:146
Definition: ElementsHelper.h:111
QPen mPen
Definition: ElementsHelper.h:93
Definition: ElementsHelper.h:129
Definition: ElementsHelper.h:115
Definition: ElementsHelper.h:122
Definition: ElementsHelper.h:119
Definition: ElementsHelper.h:112
Definition: ElementsHelper.h:116
Definition: ElementsHelper.h:128
config
Definition: DependencyCollector.py:271
QColor mBrush
Definition: ElementsHelper.h:94
Definition: ElementsHelper.h:125
Definition: ElementsHelper.h:121
DllCoreExport bool save(const QImage &img, const QString &savePath, int compression=-1)
Saves the specified QImage img.
Definition: Image.cpp:180
Definition: ElementsHelper.h:127
Definition: Elements.h:69
DllCoreExport QImage load(const QString &path, bool *ok=0)
Definition: Image.cpp:152
Definition: ElementsHelper.h:114
Definition: ElementsHelper.h:113
Definition: ElementsHelper.h:117
Definition: ElementsHelper.h:59
Definition: Algorithms.cpp:45
static QVector< QSharedPointer< T > > filter(QSharedPointer< rdf::Region > root, const Region::Type &type, bool removeChildren=true)
Definition: ElementsHelper.h:181
Definition: ElementsHelper.h:120
Definition: ElementsHelper.h:126