diff --git a/openbr/plugins/landmarks.cpp b/openbr/plugins/landmarks.cpp index c3b924b..ff17d14 100644 --- a/openbr/plugins/landmarks.cpp +++ b/openbr/plugins/landmarks.cpp @@ -370,7 +370,7 @@ BR_REGISTER(Transform, ReadLandmarksTransform) * \brief Name a point * \author Scott Klum \cite sklum */ -class NamePointsTransform : public UntrainableMetaTransform +class NamePointsTransform : public UntrainableMetadataTransform { Q_OBJECT Q_PROPERTY(QList indices READ get_indices WRITE set_indices RESET reset_indices STORED false) @@ -378,16 +378,16 @@ class NamePointsTransform : public UntrainableMetaTransform BR_PROPERTY(QList, indices, QList()) BR_PROPERTY(QStringList, names, QStringList()) - void project(const Template &src, Template &dst) const + void project(const File &src, File &dst) const { if (indices.size() != names.size()) qFatal("Point/name size mismatch"); dst = src; - QList points = src.file.points(); + QList points = src.points(); for (int i=0; i(name)); + if (src.contains(name)) dst.appendPoint(src.get(name)); } }; diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index eee78ca..e46eda5 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -239,7 +239,7 @@ BR_REGISTER(Transform, RemoveTransform) * \brief Rename metadata key * \author Josh Klontz \cite jklontz */ -class RenameTransform : public UntrainableMetaTransform +class RenameTransform : public UntrainableMetadataTransform { Q_OBJECT Q_PROPERTY(QString find READ get_find WRITE set_find RESET reset_find STORED false) @@ -247,12 +247,12 @@ class RenameTransform : public UntrainableMetaTransform BR_PROPERTY(QString, find, "") BR_PROPERTY(QString, replace, "") - void project(const Template &src, Template &dst) const + void project(const File &src, File &dst) const { dst = src; - if (dst.file.localKeys().contains(find)) { - dst.file.set(replace, dst.file.value(find)); - dst.file.remove(find); + if (dst.localKeys().contains(find)) { + dst.set(replace, dst.value(find)); + dst.remove(find); } } }; @@ -264,7 +264,7 @@ BR_REGISTER(Transform, RenameTransform) * \brief Rename first found metadata key * \author Josh Klontz \cite jklontz */ -class RenameFirstTransform : public UntrainableMetaTransform +class RenameFirstTransform : public UntrainableMetadataTransform { Q_OBJECT Q_PROPERTY(QStringList find READ get_find WRITE set_find RESET reset_find STORED false) @@ -272,13 +272,13 @@ class RenameFirstTransform : public UntrainableMetaTransform BR_PROPERTY(QStringList, find, QStringList()) BR_PROPERTY(QString, replace, "") - void project(const Template &src, Template &dst) const + void project(const File &src, File &dst) const { dst = src; foreach (const QString &key, find) - if (dst.file.localKeys().contains(key)) { - dst.file.set(replace, dst.file.value(key)); - dst.file.remove(key); + if (dst.localKeys().contains(key)) { + dst.set(replace, dst.value(key)); + dst.remove(key); break; } } @@ -291,16 +291,16 @@ BR_REGISTER(Transform, RenameFirstTransform) * \brief Change the br::Template::file extension * \author Josh Klontz \cite jklontz */ -class AsTransform : public UntrainableMetaTransform +class AsTransform : public UntrainableMetadataTransform { Q_OBJECT Q_PROPERTY(QString extension READ get_extension WRITE set_extension RESET reset_extension STORED false) BR_PROPERTY(QString, extension, "") - void project(const Template &src, Template &dst) const + void project(const File &src, File &dst) const { dst = src; - dst.file.name = dst.file.name.left(dst.file.name.lastIndexOf('.')+1) + extension; + dst.name = dst.name.left(dst.name.lastIndexOf('.')+1) + extension; } }; @@ -311,7 +311,7 @@ BR_REGISTER(Transform, AsTransform) * \brief Apply the input regular expression to the value of inputProperty, store the matched portion in outputProperty. * \author Charles Otto \cite caotto */ -class RegexPropertyTransform : public UntrainableMetaTransform +class RegexPropertyTransform : public UntrainableMetadataTransform { Q_OBJECT Q_PROPERTY(QString regexp READ get_regexp WRITE set_regexp RESET reset_regexp STORED false) @@ -321,14 +321,14 @@ class RegexPropertyTransform : public UntrainableMetaTransform BR_PROPERTY(QString, inputProperty, "name") BR_PROPERTY(QString, outputProperty, "Label") - void project(const Template &src, Template &dst) const + void project(const File &src, File &dst) const { dst = src; QRegularExpression re(regexp); - QRegularExpressionMatch match = re.match(dst.file.get(inputProperty)); + QRegularExpressionMatch match = re.match(dst.get(inputProperty)); if (!match.hasMatch()) - qFatal("Unable to match regular expression \"%s\" to base name \"%s\"!", qPrintable(regexp), qPrintable(dst.file.get(inputProperty))); - dst.file.set(outputProperty, match.captured(match.lastCapturedIndex())); + qFatal("Unable to match regular expression \"%s\" to base name \"%s\"!", qPrintable(regexp), qPrintable(dst.get(inputProperty))); + dst.set(outputProperty, match.captured(match.lastCapturedIndex())); } }; diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index 98fab50..8124c5c 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -314,6 +314,37 @@ struct WorkerProcess void mainLoop(); }; +/*! + * \brief A br::Transform that operates solely on metadata + */ +class MetadataTransform : public Transform +{ + Q_OBJECT +public: + + virtual void project(const File &src, File &dst) const = 0; + + void project(const Template & src, Template & dst) const + { + dst = src; + project(src.file, dst.file); + } + +protected: + MetadataTransform(bool trainable = true) : Transform(false,trainable) {} +}; + +/*! + * \brief A br::Transform that operates solely on metadata, and is untrainable + */ +class UntrainableMetadataTransform : public MetadataTransform +{ + Q_OBJECT + +protected: + UntrainableMetadataTransform() : MetadataTransform(false) {} +}; + } #endif // OPENBR_INTERNAL_H diff --git a/openbr/plugins/template.cpp b/openbr/plugins/template.cpp index acfde7b..0b027fb 100644 --- a/openbr/plugins/template.cpp +++ b/openbr/plugins/template.cpp @@ -9,17 +9,17 @@ namespace br * \brief Retains only the values for the keys listed, to reduce template size * \author Scott Klum \cite sklum */ -class KeepMetadataTransform : public UntrainableTransform +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 project(const Template &src, Template &dst) const + void project(const File &src, File &dst) const { dst = src; - foreach(const QString& localKey, dst.file.localKeys()) { - if (!keys.contains(localKey)) dst.file.remove(localKey); + foreach(const QString& localKey, dst.localKeys()) { + if (!keys.contains(localKey)) dst.remove(localKey); } } }; @@ -55,17 +55,17 @@ BR_REGISTER(Transform, RemoveTemplatesTransform) * \brief Removes a metadata field from all templates * \author Brendan Klare \cite bklare */ -class RemoveMetadataTransform : public UntrainableTransform +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 project(const Template &src, Template &dst) const + void project(const File &src, File &dst) const { dst = src; - if (dst.file.contains(attributeName)) - dst.file.remove(attributeName); + if (dst.contains(attributeName)) + dst.remove(attributeName); } }; BR_REGISTER(Transform, RemoveMetadataTransform) @@ -75,19 +75,19 @@ BR_REGISTER(Transform, RemoveMetadataTransform) * \brief Retains only landmarks/points at the provided indices * \author Brendan Klare \cite bklare */ -class SelectPointsTransform : public UntrainableTransform +class SelectPointsTransform : public UntrainableMetadataTransform { Q_OBJECT Q_PROPERTY(QList indices READ get_indices WRITE set_indices RESET reset_indices STORED false) BR_PROPERTY(QList, indices, QList()) - void project(const Template &src, Template &dst) const + void project(const File &src, File &dst) const { dst = src; - QList origPoints = src.file.points(); - dst.file.clearPoints(); + QList origPoints = src.points(); + dst.clearPoints(); for (int i = 0; i < indices.size(); i++) - dst.file.appendPoint(origPoints[indices[i]]); + dst.appendPoint(origPoints[indices[i]]); } };