Commit da83e1c63b67e4a4af4cc346ce8c7ef29b5897f0
1 parent
2256f42b
Generalizing if a bit better
Showing
1 changed file
with
7 additions
and
7 deletions
openbr/plugins/imgproc/if.cpp
| @@ -22,12 +22,12 @@ class IfTransform : public MetaTransform | @@ -22,12 +22,12 @@ class IfTransform : public MetaTransform | ||
| 22 | BR_PROPERTY(QString, comparison, "e") | 22 | BR_PROPERTY(QString, comparison, "e") |
| 23 | BR_PROPERTY(bool, projectOnEmpty, false) | 23 | BR_PROPERTY(bool, projectOnEmpty, false) |
| 24 | 24 | ||
| 25 | - bool compare(const QString &metadata) const | 25 | + bool compare(const QVariant &metadata) const |
| 26 | { | 26 | { |
| 27 | bool result, ok1 = true, ok2 = true; | 27 | bool result, ok1 = true, ok2 = true; |
| 28 | 28 | ||
| 29 | - if (comparison == "empty") | ||
| 30 | - result = metadata.isEmpty(); | 29 | + if (comparison == "empty") |
| 30 | + result = metadata.isNull() || (metadata.canConvert<QString>() && metadata.toString().isEmpty()); | ||
| 31 | else if (comparison == "e") | 31 | else if (comparison == "e") |
| 32 | result = metadata == value; | 32 | result = metadata == value; |
| 33 | else if (comparison == "ne") | 33 | else if (comparison == "ne") |
| @@ -41,7 +41,7 @@ class IfTransform : public MetaTransform | @@ -41,7 +41,7 @@ class IfTransform : public MetaTransform | ||
| 41 | else if (comparison == "ge") | 41 | else if (comparison == "ge") |
| 42 | result = metadata.toFloat(&ok1) >= value.toFloat(&ok2); | 42 | result = metadata.toFloat(&ok1) >= value.toFloat(&ok2); |
| 43 | else if (comparison == "c") // contains | 43 | else if (comparison == "c") // contains |
| 44 | - result = metadata.contains(value); | 44 | + result = metadata.toString().contains(value); |
| 45 | else | 45 | else |
| 46 | qFatal("Unrecognized comparison string."); | 46 | qFatal("Unrecognized comparison string."); |
| 47 | 47 | ||
| @@ -57,14 +57,14 @@ public: | @@ -57,14 +57,14 @@ public: | ||
| 57 | if (transform->trainable) { | 57 | if (transform->trainable) { |
| 58 | TemplateList passed; | 58 | TemplateList passed; |
| 59 | for (int i=0; i<data.size(); i++) | 59 | for (int i=0; i<data.size(); i++) |
| 60 | - if ((data[i].file.contains(key) || projectOnEmpty) && compare(data[i].file.get<QString>(key, QString()))) | 60 | + if ((data[i].file.contains(key) || projectOnEmpty) && compare(data[i].file.value(key))) |
| 61 | passed.append(data[i]); | 61 | passed.append(data[i]); |
| 62 | transform->train(passed); | 62 | transform->train(passed); |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | void project(const Template &src, Template &dst) const { | 66 | void project(const Template &src, Template &dst) const { |
| 67 | - if ((src.file.contains(key) || projectOnEmpty) && compare(src.file.get<QString>(key, QString()))) | 67 | + if ((src.file.contains(key) || projectOnEmpty) && compare(src.file.value(key))) |
| 68 | transform->project(src, dst); | 68 | transform->project(src, dst); |
| 69 | else | 69 | else |
| 70 | dst = src; | 70 | dst = src; |
| @@ -73,7 +73,7 @@ public: | @@ -73,7 +73,7 @@ public: | ||
| 73 | void project(const TemplateList &src, TemplateList &dst) const { | 73 | void project(const TemplateList &src, TemplateList &dst) const { |
| 74 | TemplateList ifTrue, ifFalse; | 74 | TemplateList ifTrue, ifFalse; |
| 75 | foreach (const Template &t, src) { | 75 | foreach (const Template &t, src) { |
| 76 | - if ((t.file.contains(key) || projectOnEmpty) && compare(t.file.get<QString>(key, QString()))) | 76 | + if ((t.file.contains(key) || projectOnEmpty) && compare(t.file.value(key))) |
| 77 | ifTrue.append(t); | 77 | ifTrue.append(t); |
| 78 | else | 78 | else |
| 79 | ifFalse.append(t); | 79 | ifFalse.append(t); |