Commit 182cfd92e05e79980d635a00781310de72409e12
1 parent
2ec4f684
Introduce transforms which operate solely on metadata
Introduces MetadataTransform and UntrainableMetadataTransform, which provide a project(file,file) interface for defining operations that only affect metadata, and do not touch matrices. Modify a number of transforms to inherit from these interfaces instead of UntrainableTransform or UntrainableMetaTransform
Showing
4 changed files
with
69 additions
and
38 deletions
openbr/plugins/landmarks.cpp
| ... | ... | @@ -370,7 +370,7 @@ BR_REGISTER(Transform, ReadLandmarksTransform) |
| 370 | 370 | * \brief Name a point |
| 371 | 371 | * \author Scott Klum \cite sklum |
| 372 | 372 | */ |
| 373 | -class NamePointsTransform : public UntrainableMetaTransform | |
| 373 | +class NamePointsTransform : public UntrainableMetadataTransform | |
| 374 | 374 | { |
| 375 | 375 | Q_OBJECT |
| 376 | 376 | Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false) |
| ... | ... | @@ -378,16 +378,16 @@ class NamePointsTransform : public UntrainableMetaTransform |
| 378 | 378 | BR_PROPERTY(QList<int>, indices, QList<int>()) |
| 379 | 379 | BR_PROPERTY(QStringList, names, QStringList()) |
| 380 | 380 | |
| 381 | - void project(const Template &src, Template &dst) const | |
| 381 | + void project(const File &src, File &dst) const | |
| 382 | 382 | { |
| 383 | 383 | if (indices.size() != names.size()) qFatal("Point/name size mismatch"); |
| 384 | 384 | |
| 385 | 385 | dst = src; |
| 386 | 386 | |
| 387 | - QList<QPointF> points = src.file.points(); | |
| 387 | + QList<QPointF> points = src.points(); | |
| 388 | 388 | |
| 389 | 389 | for (int i=0; i<indices.size(); i++) { |
| 390 | - if (indices[i] < points.size()) dst.file.set(names[i], points[indices[i]]); | |
| 390 | + if (indices[i] < points.size()) dst.set(names[i], points[indices[i]]); | |
| 391 | 391 | else qFatal("Index out of range."); |
| 392 | 392 | } |
| 393 | 393 | } |
| ... | ... | @@ -400,18 +400,18 @@ BR_REGISTER(Transform, NamePointsTransform) |
| 400 | 400 | * \brief Remove a name from a point |
| 401 | 401 | * \author Scott Klum \cite sklum |
| 402 | 402 | */ |
| 403 | -class AnonymizePointsTransform : public UntrainableMetaTransform | |
| 403 | +class AnonymizePointsTransform : public UntrainableMetadataTransform | |
| 404 | 404 | { |
| 405 | 405 | Q_OBJECT |
| 406 | 406 | Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) |
| 407 | 407 | BR_PROPERTY(QStringList, names, QStringList()) |
| 408 | 408 | |
| 409 | - void project(const Template &src, Template &dst) const | |
| 409 | + void project(const File &src, File &dst) const | |
| 410 | 410 | { |
| 411 | 411 | dst = src; |
| 412 | 412 | |
| 413 | 413 | foreach (const QString &name, names) |
| 414 | - if (src.file.contains(name)) dst.file.appendPoint(src.file.get<QPointF>(name)); | |
| 414 | + if (src.contains(name)) dst.appendPoint(src.get<QPointF>(name)); | |
| 415 | 415 | } |
| 416 | 416 | }; |
| 417 | 417 | ... | ... |
openbr/plugins/misc.cpp
| ... | ... | @@ -239,7 +239,7 @@ BR_REGISTER(Transform, RemoveTransform) |
| 239 | 239 | * \brief Rename metadata key |
| 240 | 240 | * \author Josh Klontz \cite jklontz |
| 241 | 241 | */ |
| 242 | -class RenameTransform : public UntrainableMetaTransform | |
| 242 | +class RenameTransform : public UntrainableMetadataTransform | |
| 243 | 243 | { |
| 244 | 244 | Q_OBJECT |
| 245 | 245 | Q_PROPERTY(QString find READ get_find WRITE set_find RESET reset_find STORED false) |
| ... | ... | @@ -247,12 +247,12 @@ class RenameTransform : public UntrainableMetaTransform |
| 247 | 247 | BR_PROPERTY(QString, find, "") |
| 248 | 248 | BR_PROPERTY(QString, replace, "") |
| 249 | 249 | |
| 250 | - void project(const Template &src, Template &dst) const | |
| 250 | + void project(const File &src, File &dst) const | |
| 251 | 251 | { |
| 252 | 252 | dst = src; |
| 253 | - if (dst.file.localKeys().contains(find)) { | |
| 254 | - dst.file.set(replace, dst.file.value(find)); | |
| 255 | - dst.file.remove(find); | |
| 253 | + if (dst.localKeys().contains(find)) { | |
| 254 | + dst.set(replace, dst.value(find)); | |
| 255 | + dst.remove(find); | |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | }; |
| ... | ... | @@ -264,7 +264,7 @@ BR_REGISTER(Transform, RenameTransform) |
| 264 | 264 | * \brief Rename first found metadata key |
| 265 | 265 | * \author Josh Klontz \cite jklontz |
| 266 | 266 | */ |
| 267 | -class RenameFirstTransform : public UntrainableMetaTransform | |
| 267 | +class RenameFirstTransform : public UntrainableMetadataTransform | |
| 268 | 268 | { |
| 269 | 269 | Q_OBJECT |
| 270 | 270 | Q_PROPERTY(QStringList find READ get_find WRITE set_find RESET reset_find STORED false) |
| ... | ... | @@ -272,13 +272,13 @@ class RenameFirstTransform : public UntrainableMetaTransform |
| 272 | 272 | BR_PROPERTY(QStringList, find, QStringList()) |
| 273 | 273 | BR_PROPERTY(QString, replace, "") |
| 274 | 274 | |
| 275 | - void project(const Template &src, Template &dst) const | |
| 275 | + void project(const File &src, File &dst) const | |
| 276 | 276 | { |
| 277 | 277 | dst = src; |
| 278 | 278 | foreach (const QString &key, find) |
| 279 | - if (dst.file.localKeys().contains(key)) { | |
| 280 | - dst.file.set(replace, dst.file.value(key)); | |
| 281 | - dst.file.remove(key); | |
| 279 | + if (dst.localKeys().contains(key)) { | |
| 280 | + dst.set(replace, dst.value(key)); | |
| 281 | + dst.remove(key); | |
| 282 | 282 | break; |
| 283 | 283 | } |
| 284 | 284 | } |
| ... | ... | @@ -291,16 +291,16 @@ BR_REGISTER(Transform, RenameFirstTransform) |
| 291 | 291 | * \brief Change the br::Template::file extension |
| 292 | 292 | * \author Josh Klontz \cite jklontz |
| 293 | 293 | */ |
| 294 | -class AsTransform : public UntrainableMetaTransform | |
| 294 | +class AsTransform : public UntrainableMetadataTransform | |
| 295 | 295 | { |
| 296 | 296 | Q_OBJECT |
| 297 | 297 | Q_PROPERTY(QString extension READ get_extension WRITE set_extension RESET reset_extension STORED false) |
| 298 | 298 | BR_PROPERTY(QString, extension, "") |
| 299 | 299 | |
| 300 | - void project(const Template &src, Template &dst) const | |
| 300 | + void project(const File &src, File &dst) const | |
| 301 | 301 | { |
| 302 | 302 | dst = src; |
| 303 | - dst.file.name = dst.file.name.left(dst.file.name.lastIndexOf('.')+1) + extension; | |
| 303 | + dst.name = dst.name.left(dst.name.lastIndexOf('.')+1) + extension; | |
| 304 | 304 | } |
| 305 | 305 | }; |
| 306 | 306 | |
| ... | ... | @@ -311,7 +311,7 @@ BR_REGISTER(Transform, AsTransform) |
| 311 | 311 | * \brief Apply the input regular expression to the value of inputProperty, store the matched portion in outputProperty. |
| 312 | 312 | * \author Charles Otto \cite caotto |
| 313 | 313 | */ |
| 314 | -class RegexPropertyTransform : public UntrainableMetaTransform | |
| 314 | +class RegexPropertyTransform : public UntrainableMetadataTransform | |
| 315 | 315 | { |
| 316 | 316 | Q_OBJECT |
| 317 | 317 | Q_PROPERTY(QString regexp READ get_regexp WRITE set_regexp RESET reset_regexp STORED false) |
| ... | ... | @@ -321,14 +321,14 @@ class RegexPropertyTransform : public UntrainableMetaTransform |
| 321 | 321 | BR_PROPERTY(QString, inputProperty, "name") |
| 322 | 322 | BR_PROPERTY(QString, outputProperty, "Label") |
| 323 | 323 | |
| 324 | - void project(const Template &src, Template &dst) const | |
| 324 | + void project(const File &src, File &dst) const | |
| 325 | 325 | { |
| 326 | 326 | dst = src; |
| 327 | 327 | QRegularExpression re(regexp); |
| 328 | - QRegularExpressionMatch match = re.match(dst.file.get<QString>(inputProperty)); | |
| 328 | + QRegularExpressionMatch match = re.match(dst.get<QString>(inputProperty)); | |
| 329 | 329 | if (!match.hasMatch()) |
| 330 | - qFatal("Unable to match regular expression \"%s\" to base name \"%s\"!", qPrintable(regexp), qPrintable(dst.file.get<QString>(inputProperty))); | |
| 331 | - dst.file.set(outputProperty, match.captured(match.lastCapturedIndex())); | |
| 330 | + qFatal("Unable to match regular expression \"%s\" to base name \"%s\"!", qPrintable(regexp), qPrintable(dst.get<QString>(inputProperty))); | |
| 331 | + dst.set(outputProperty, match.captured(match.lastCapturedIndex())); | |
| 332 | 332 | } |
| 333 | 333 | }; |
| 334 | 334 | ... | ... |
openbr/plugins/openbr_internal.h
| ... | ... | @@ -314,6 +314,37 @@ struct WorkerProcess |
| 314 | 314 | void mainLoop(); |
| 315 | 315 | }; |
| 316 | 316 | |
| 317 | +/*! | |
| 318 | + * \brief A br::Transform that operates solely on metadata | |
| 319 | + */ | |
| 320 | +class MetadataTransform : public Transform | |
| 321 | +{ | |
| 322 | + Q_OBJECT | |
| 323 | +public: | |
| 324 | + | |
| 325 | + virtual void project(const File &src, File &dst) const = 0; | |
| 326 | + | |
| 327 | + void project(const Template & src, Template & dst) const | |
| 328 | + { | |
| 329 | + dst = src; | |
| 330 | + project(src.file, dst.file); | |
| 331 | + } | |
| 332 | + | |
| 333 | +protected: | |
| 334 | + MetadataTransform(bool trainable = true) : Transform(false,trainable) {} | |
| 335 | +}; | |
| 336 | + | |
| 337 | +/*! | |
| 338 | + * \brief A br::Transform that operates solely on metadata, and is untrainable | |
| 339 | + */ | |
| 340 | +class UntrainableMetadataTransform : public MetadataTransform | |
| 341 | +{ | |
| 342 | + Q_OBJECT | |
| 343 | + | |
| 344 | +protected: | |
| 345 | + UntrainableMetadataTransform() : MetadataTransform(false) {} | |
| 346 | +}; | |
| 347 | + | |
| 317 | 348 | } |
| 318 | 349 | |
| 319 | 350 | #endif // OPENBR_INTERNAL_H | ... | ... |
openbr/plugins/template.cpp
| ... | ... | @@ -9,17 +9,17 @@ namespace br |
| 9 | 9 | * \brief Retains only the values for the keys listed, to reduce template size |
| 10 | 10 | * \author Scott Klum \cite sklum |
| 11 | 11 | */ |
| 12 | -class KeepMetadataTransform : public UntrainableTransform | |
| 12 | +class KeepMetadataTransform : public UntrainableMetadataTransform | |
| 13 | 13 | { |
| 14 | 14 | Q_OBJECT |
| 15 | 15 | Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) |
| 16 | 16 | BR_PROPERTY(QStringList, keys, QStringList()) |
| 17 | 17 | |
| 18 | - void project(const Template &src, Template &dst) const | |
| 18 | + void project(const File &src, File &dst) const | |
| 19 | 19 | { |
| 20 | 20 | dst = src; |
| 21 | - foreach(const QString& localKey, dst.file.localKeys()) { | |
| 22 | - if (!keys.contains(localKey)) dst.file.remove(localKey); | |
| 21 | + foreach(const QString& localKey, dst.localKeys()) { | |
| 22 | + if (!keys.contains(localKey)) dst.remove(localKey); | |
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | }; |
| ... | ... | @@ -55,17 +55,17 @@ BR_REGISTER(Transform, RemoveTemplatesTransform) |
| 55 | 55 | * \brief Removes a metadata field from all templates |
| 56 | 56 | * \author Brendan Klare \cite bklare |
| 57 | 57 | */ |
| 58 | -class RemoveMetadataTransform : public UntrainableTransform | |
| 58 | +class RemoveMetadataTransform : public UntrainableMetadataTransform | |
| 59 | 59 | { |
| 60 | 60 | Q_OBJECT |
| 61 | 61 | Q_PROPERTY(QString attributeName READ get_attributeName WRITE set_attributeName RESET reset_attributeName STORED false) |
| 62 | 62 | BR_PROPERTY(QString, attributeName, "None") |
| 63 | 63 | |
| 64 | - void project(const Template &src, Template &dst) const | |
| 64 | + void project(const File &src, File &dst) const | |
| 65 | 65 | { |
| 66 | 66 | dst = src; |
| 67 | - if (dst.file.contains(attributeName)) | |
| 68 | - dst.file.remove(attributeName); | |
| 67 | + if (dst.contains(attributeName)) | |
| 68 | + dst.remove(attributeName); | |
| 69 | 69 | } |
| 70 | 70 | }; |
| 71 | 71 | BR_REGISTER(Transform, RemoveMetadataTransform) |
| ... | ... | @@ -75,19 +75,19 @@ BR_REGISTER(Transform, RemoveMetadataTransform) |
| 75 | 75 | * \brief Retains only landmarks/points at the provided indices |
| 76 | 76 | * \author Brendan Klare \cite bklare |
| 77 | 77 | */ |
| 78 | -class SelectPointsTransform : public UntrainableTransform | |
| 78 | +class SelectPointsTransform : public UntrainableMetadataTransform | |
| 79 | 79 | { |
| 80 | 80 | Q_OBJECT |
| 81 | 81 | Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false) |
| 82 | 82 | BR_PROPERTY(QList<int>, indices, QList<int>()) |
| 83 | 83 | |
| 84 | - void project(const Template &src, Template &dst) const | |
| 84 | + void project(const File &src, File &dst) const | |
| 85 | 85 | { |
| 86 | 86 | dst = src; |
| 87 | - QList<QPointF> origPoints = src.file.points(); | |
| 88 | - dst.file.clearPoints(); | |
| 87 | + QList<QPointF> origPoints = src.points(); | |
| 88 | + dst.clearPoints(); | |
| 89 | 89 | for (int i = 0; i < indices.size(); i++) |
| 90 | - dst.file.appendPoint(origPoints[indices[i]]); | |
| 90 | + dst.appendPoint(origPoints[indices[i]]); | |
| 91 | 91 | } |
| 92 | 92 | }; |
| 93 | 93 | ... | ... |