template.cpp
3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "openbr_internal.h"
#include <QRegularExpression>
namespace br
{
/*!
* \ingroup transforms
* \brief Retains only the values for the keys listed, to reduce template size
* \author Scott Klum \cite sklum
*/
class KeepMetadataTransform : public UntrainableMetadataTransform
{
Q_OBJECT
Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false)
BR_PROPERTY(QStringList, keys, QStringList())
void projectMetadata(const File &src, File &dst) const
{
dst = src;
foreach(const QString& localKey, dst.localKeys()) {
if (!keys.contains(localKey)) dst.remove(localKey);
}
}
};
BR_REGISTER(Transform, KeepMetadataTransform)
/*!
* \ingroup transforms
* \brief Remove templates with the specified file extension or metadata value.
* \author Josh Klontz \cite jklontz
*/
class RemoveTemplatesTransform : public UntrainableMetaTransform
{
Q_OBJECT
Q_PROPERTY(QString regexp READ get_regexp WRITE set_regexp RESET reset_regexp STORED false)
Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key STORED false)
BR_PROPERTY(QString, regexp, "")
BR_PROPERTY(QString, key, "")
void project(const Template &src, Template &dst) const
{
const QRegularExpression re(regexp);
const QRegularExpressionMatch match = re.match(key.isEmpty() ? src.file.suffix() : src.file.get<QString>(key));
if (match.hasMatch()) dst = Template();
else dst = src;
}
};
BR_REGISTER(Transform, RemoveTemplatesTransform)
/*!
* \ingroup transforms
* \brief Sets the metadata key/value pair.
* \author Josh Klontz \cite jklontz
*/
class SetMetadataTransform : public UntrainableMetadataTransform
{
Q_OBJECT
Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key STORED false)
Q_PROPERTY(QString value READ get_value WRITE set_value RESET reset_value STORED false)
BR_PROPERTY(QString, key, "")
BR_PROPERTY(QString, value, "")
void projectMetadata(const File &src, File &dst) const
{
dst = src;
dst.set(key, value);
}
};
BR_REGISTER(Transform, SetMetadataTransform)
/*!
* \ingroup transforms
* \brief Removes a metadata field from all templates
* \author Brendan Klare \cite bklare
*/
class RemoveMetadataTransform : public UntrainableMetadataTransform
{
Q_OBJECT
Q_PROPERTY(QString attributeName READ get_attributeName WRITE set_attributeName RESET reset_attributeName STORED false)
BR_PROPERTY(QString, attributeName, "None")
void projectMetadata(const File &src, File &dst) const
{
dst = src;
if (dst.contains(attributeName))
dst.remove(attributeName);
}
};
BR_REGISTER(Transform, RemoveMetadataTransform)
/*!
* \ingroup transforms
* \brief Retains only landmarks/points at the provided indices
* \author Brendan Klare \cite bklare
*/
class SelectPointsTransform : public UntrainableMetadataTransform
{
Q_OBJECT
Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false)
BR_PROPERTY(QList<int>, indices, QList<int>())
void projectMetadata(const File &src, File &dst) const
{
dst = src;
QList<QPointF> origPoints = src.points();
dst.clearPoints();
for (int i = 0; i < indices.size(); i++)
dst.appendPoint(origPoints[indices[i]]);
}
};
BR_REGISTER(Transform, SelectPointsTransform)
} // namespace br
#include "template.moc"