Commit 8a0b57f43612ffdb805d283a52d6ce5e0e7da7e6
1 parent
ab563f10
Refactor conditionals in AlgorithmCore::init
This saves upwards of 3 lines of code!
Showing
3 changed files
with
24 additions
and
28 deletions
openbr/core/core.cpp
| @@ -522,41 +522,37 @@ struct AlgorithmCore | @@ -522,41 +522,37 @@ struct AlgorithmCore | ||
| 522 | private: | 522 | private: |
| 523 | QString name; | 523 | QString name; |
| 524 | 524 | ||
| 525 | - QString getFileName(const QString &description) const | ||
| 526 | - { | ||
| 527 | - const QString file = Globals->sdkPath + "/share/openbr/models/algorithms/" + description; | ||
| 528 | - QFileInfo qFile(file); | ||
| 529 | - return qFile.exists() && !qFile.isDir() ? file : QString(); | ||
| 530 | - } | ||
| 531 | - | ||
| 532 | - void init(const QString &description) | 525 | + // Check if description is either an abbreviation or a model file, if so load it |
| 526 | + bool loadOrExpand(const QString & description) | ||
| 533 | { | 527 | { |
| 534 | // Check if a trained binary already exists for this algorithm | 528 | // Check if a trained binary already exists for this algorithm |
| 535 | - const QString file = getFileName(description); | ||
| 536 | - if (!file.isEmpty()) return init(file); | 529 | + QString file = Globals->sdkPath + "/share/openbr/models/algorithms/" + description; |
| 530 | + QFileInfo eFile(file); | ||
| 531 | + file = eFile.exists() && !eFile.isDir() ? file : description; | ||
| 537 | 532 | ||
| 538 | - QFileInfo dFile(description); | ||
| 539 | - if (dFile.exists()) { | 533 | + QFileInfo dFile(file); |
| 534 | + if (dFile.exists() && !dFile.isDir()) { | ||
| 540 | qDebug("Loading %s", qPrintable(dFile.fileName())); | 535 | qDebug("Loading %s", qPrintable(dFile.fileName())); |
| 541 | - load(description); | ||
| 542 | - return; | 536 | + load(file); |
| 537 | + return true; | ||
| 543 | } | 538 | } |
| 544 | 539 | ||
| 545 | - File parsed("."+description); | ||
| 546 | - const QString parsedFname = getFileName(parsed.suffix()); | ||
| 547 | - QFileInfo pFile(parsedFname); | ||
| 548 | - if (pFile.exists()) { | ||
| 549 | - load(parsedFname); | ||
| 550 | - applyAdditionalProperties(parsed, transform.data()); | ||
| 551 | - return; | 540 | + // Expand abbreviated algorithms to their full strings |
| 541 | + if (Globals->abbreviations.contains(description)) { | ||
| 542 | + init(Globals->abbreviations[description]); | ||
| 543 | + return true; | ||
| 552 | } | 544 | } |
| 545 | + return false; | ||
| 546 | + } | ||
| 553 | 547 | ||
| 554 | - // Expand abbreviated algorithms to their full strings | ||
| 555 | - if (Globals->abbreviations.contains(description)) | ||
| 556 | - return init(Globals->abbreviations[description]); | 548 | + void init(const QString &description) |
| 549 | + { | ||
| 550 | + if (loadOrExpand(description)) | ||
| 551 | + return; | ||
| 557 | 552 | ||
| 558 | - if (Globals->abbreviations.contains(parsed.suffix())) { | ||
| 559 | - init(Globals->abbreviations[parsed.suffix()]); | 553 | + // check if the description is an abbreviation or model file with additional arguments supplied |
| 554 | + File parsed("."+description); | ||
| 555 | + if (loadOrExpand(parsed.suffix())) { | ||
| 560 | applyAdditionalProperties(parsed, transform.data()); | 556 | applyAdditionalProperties(parsed, transform.data()); |
| 561 | return; | 557 | return; |
| 562 | } | 558 | } |
openbr/openbr_plugin.cpp
| @@ -1443,7 +1443,7 @@ void Distance::compareBlock(const TemplateList &target, const TemplateList &quer | @@ -1443,7 +1443,7 @@ void Distance::compareBlock(const TemplateList &target, const TemplateList &quer | ||
| 1443 | else output->setRelative(compare(target[j], query[i]), i+queryOffset, j+targetOffset); | 1443 | else output->setRelative(compare(target[j], query[i]), i+queryOffset, j+targetOffset); |
| 1444 | } | 1444 | } |
| 1445 | 1445 | ||
| 1446 | -void br::applyAdditionalProperties(File & temp, Transform * target) | 1446 | +void br::applyAdditionalProperties(const File &temp, Transform *target) |
| 1447 | { | 1447 | { |
| 1448 | QVariantMap meta = temp.localMetadata(); | 1448 | QVariantMap meta = temp.localMetadata(); |
| 1449 | for (QVariantMap::iterator i = meta.begin(); i != meta.end(); ++i) { | 1449 | for (QVariantMap::iterator i = meta.begin(); i != meta.end(); ++i) { |
openbr/plugins/openbr_internal.h