Commit cc6651c380df092ca486ce31e535fc225f48694f
1 parent
b85fa624
Rename LoadStore's algorithm decription property, restore const to description
Also, more careful memory management of the simplified transform in AlgorithmCore
Showing
6 changed files
with
67 additions
and
37 deletions
openbr/core/core.cpp
| @@ -33,7 +33,8 @@ struct AlgorithmCore | @@ -33,7 +33,8 @@ struct AlgorithmCore | ||
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| 35 | QSharedPointer<Transform> transform; | 35 | QSharedPointer<Transform> transform; |
| 36 | - QSharedPointer<Transform> simplifiedTransform; | 36 | + Transform *simplifiedTransform; |
| 37 | + QSharedPointer<Transform> deleteSimplifiedTransform; | ||
| 37 | QSharedPointer<Transform> comparison; | 38 | QSharedPointer<Transform> comparison; |
| 38 | QSharedPointer<Distance> distance; | 39 | QSharedPointer<Distance> distance; |
| 39 | QSharedPointer<Transform> progressCounter; | 40 | QSharedPointer<Transform> progressCounter; |
| @@ -83,8 +84,10 @@ struct AlgorithmCore | @@ -83,8 +84,10 @@ struct AlgorithmCore | ||
| 83 | } | 84 | } |
| 84 | 85 | ||
| 85 | qDebug("Training Time: %s", qPrintable(QtUtils::toTime(Globals->startTime.elapsed()/1000.0f))); | 86 | qDebug("Training Time: %s", qPrintable(QtUtils::toTime(Globals->startTime.elapsed()/1000.0f))); |
| 86 | - bool junk; | ||
| 87 | - simplifiedTransform = QSharedPointer<Transform>(transform->simplify(junk)); | 87 | + bool newTForm = false; |
| 88 | + simplifiedTransform = transform->simplify(newTForm); | ||
| 89 | + if (newTForm) | ||
| 90 | + deleteSimplifiedTransform.reset(simplifiedTransform); | ||
| 88 | } | 91 | } |
| 89 | 92 | ||
| 90 | void store(const QString &model) const | 93 | void store(const QString &model) const |
| @@ -170,7 +173,7 @@ struct AlgorithmCore | @@ -170,7 +173,7 @@ struct AlgorithmCore | ||
| 170 | Gallery *temp = Gallery::make(input); | 173 | Gallery *temp = Gallery::make(input); |
| 171 | qint64 total = temp->totalSize(); | 174 | qint64 total = temp->totalSize(); |
| 172 | 175 | ||
| 173 | - Transform *enroll = simplifiedTransform.data(); | 176 | + Transform *enroll = simplifiedTransform; |
| 174 | 177 | ||
| 175 | if (multiProcess) | 178 | if (multiProcess) |
| 176 | enroll = wrapTransform(enroll, "ProcessWrapper"); | 179 | enroll = wrapTransform(enroll, "ProcessWrapper"); |
| @@ -450,7 +453,7 @@ struct AlgorithmCore | @@ -450,7 +453,7 @@ struct AlgorithmCore | ||
| 450 | 453 | ||
| 451 | // if we have to enroll the row gallery, add that transform to the list | 454 | // if we have to enroll the row gallery, add that transform to the list |
| 452 | if (needEnrollRows) | 455 | if (needEnrollRows) |
| 453 | - enrollCompare.prepend(simplifiedTransform.data()); | 456 | + enrollCompare.prepend(simplifiedTransform); |
| 454 | 457 | ||
| 455 | Transform *compareRegionBase = pipeTransforms(enrollCompare); | 458 | Transform *compareRegionBase = pipeTransforms(enrollCompare); |
| 456 | // If in multi-process mode, wrap the enroll+compare structure in a ProcessWrapper. | 459 | // If in multi-process mode, wrap the enroll+compare structure in a ProcessWrapper. |
| @@ -528,10 +531,12 @@ private: | @@ -528,10 +531,12 @@ private: | ||
| 528 | 531 | ||
| 529 | void init(const QString &description) | 532 | void init(const QString &description) |
| 530 | { | 533 | { |
| 531 | - bool junk; | 534 | + bool newTForm = false; |
| 532 | 535 | ||
| 533 | if (loadOrExpand(description)) { | 536 | if (loadOrExpand(description)) { |
| 534 | - simplifiedTransform = QSharedPointer<Transform>(transform->simplify(junk)); | 537 | + simplifiedTransform = transform->simplify(newTForm); |
| 538 | + if (newTForm) | ||
| 539 | + deleteSimplifiedTransform.reset(simplifiedTransform); | ||
| 535 | return; | 540 | return; |
| 536 | } | 541 | } |
| 537 | 542 | ||
| @@ -539,7 +544,9 @@ private: | @@ -539,7 +544,9 @@ private: | ||
| 539 | File parsed("."+description); | 544 | File parsed("."+description); |
| 540 | if (loadOrExpand(parsed.suffix())) { | 545 | if (loadOrExpand(parsed.suffix())) { |
| 541 | applyAdditionalProperties(parsed, transform.data()); | 546 | applyAdditionalProperties(parsed, transform.data()); |
| 542 | - simplifiedTransform = QSharedPointer<Transform>(transform->simplify(junk)); | 547 | + simplifiedTransform = transform->simplify(newTForm); |
| 548 | + if (newTForm) | ||
| 549 | + deleteSimplifiedTransform.reset(simplifiedTransform); | ||
| 543 | return; | 550 | return; |
| 544 | } | 551 | } |
| 545 | 552 | ||
| @@ -551,7 +558,9 @@ private: | @@ -551,7 +558,9 @@ private: | ||
| 551 | 558 | ||
| 552 | //! [Creating the template generation and comparison methods] | 559 | //! [Creating the template generation and comparison methods] |
| 553 | transform = QSharedPointer<Transform>(Transform::make(words[0], NULL)); | 560 | transform = QSharedPointer<Transform>(Transform::make(words[0], NULL)); |
| 554 | - simplifiedTransform = QSharedPointer<Transform>(transform->simplify(junk)); | 561 | + simplifiedTransform = transform->simplify(newTForm); |
| 562 | + if (newTForm) | ||
| 563 | + deleteSimplifiedTransform.reset(simplifiedTransform); | ||
| 555 | 564 | ||
| 556 | if (words.size() > 1) { | 565 | if (words.size() > 1) { |
| 557 | if (!compareTransform) { | 566 | if (!compareTransform) { |
openbr/openbr_plugin.cpp
| @@ -585,25 +585,45 @@ QStringList Object::parameters() const | @@ -585,25 +585,45 @@ QStringList Object::parameters() const | ||
| 585 | return parameters; | 585 | return parameters; |
| 586 | } | 586 | } |
| 587 | 587 | ||
| 588 | -QStringList Object::prunedArguments(bool expanded) | 588 | +QStringList Object::prunedArguments(bool expanded) const |
| 589 | { | 589 | { |
| 590 | QStringList arguments; | 590 | QStringList arguments; |
| 591 | - | 591 | + QString className = this->metaObject()->className(); |
| 592 | + QScopedPointer<Object> shellObject; | ||
| 593 | + | ||
| 594 | + if (className.startsWith("br::")) | ||
| 595 | + className = className.mid(4); | ||
| 596 | + if (!className.startsWith(".")) | ||
| 597 | + className = "." + className; | ||
| 598 | + | ||
| 599 | + if (className.endsWith("Distance")) { | ||
| 600 | + className.chop(QString("Distance").size()); | ||
| 601 | + shellObject.reset(Factory<Distance>::make(className)); | ||
| 602 | + } | ||
| 603 | + else if (className.endsWith("Transform")) { | ||
| 604 | + className.chop(QString("Transform").size()); | ||
| 605 | + shellObject.reset(Factory<Transform>::make(className)); | ||
| 606 | + } | ||
| 607 | + else if (className.endsWith("Format")) { | ||
| 608 | + className.chop(QString("Format").size()); | ||
| 609 | + shellObject.reset(Factory<Format>::make(className)); | ||
| 610 | + } | ||
| 611 | + else if (className.endsWith("Initializer")) { | ||
| 612 | + className.chop(QString("Initializer").size()); | ||
| 613 | + shellObject.reset(Factory<Initializer>::make(className)); | ||
| 614 | + } | ||
| 615 | + else if (className.endsWith("Output")) { | ||
| 616 | + className.chop(QString("Output").size()); | ||
| 617 | + shellObject.reset(Factory<Output>::make(className)); | ||
| 618 | + } | ||
| 619 | + | ||
| 592 | for (int i=firstAvailablePropertyIdx; i<metaObject()->propertyCount(); i++) { | 620 | for (int i=firstAvailablePropertyIdx; i<metaObject()->propertyCount(); i++) { |
| 593 | const char *name = metaObject()->property(i).name(); | 621 | const char *name = metaObject()->property(i).name(); |
| 594 | 622 | ||
| 595 | - QVariant oldVal = property(name); | ||
| 596 | - QVariant defaultVal = oldVal; | ||
| 597 | - | ||
| 598 | - if (metaObject()->property(i).isResettable()) { | ||
| 599 | - metaObject()->property(i).reset(this); | ||
| 600 | - defaultVal = property(name); | ||
| 601 | - } | 623 | + QVariant defaultVal = shellObject->property(name); |
| 602 | 624 | ||
| 603 | - if (defaultVal != oldVal) { | ||
| 604 | - metaObject()->property(i).write(this, oldVal); | 625 | + if (defaultVal != property(name)) |
| 605 | arguments.append(name + QString("=") + argument(i, expanded)); | 626 | arguments.append(name + QString("=") + argument(i, expanded)); |
| 606 | - } | ||
| 607 | } | 627 | } |
| 608 | 628 | ||
| 609 | return arguments; | 629 | return arguments; |
| @@ -647,7 +667,7 @@ QString Object::argument(int index, bool expanded) const | @@ -647,7 +667,7 @@ QString Object::argument(int index, bool expanded) const | ||
| 647 | return variant.toString(); | 667 | return variant.toString(); |
| 648 | } | 668 | } |
| 649 | 669 | ||
| 650 | -QString Object::description(bool expanded) | 670 | +QString Object::description(bool expanded) const |
| 651 | { | 671 | { |
| 652 | (void) expanded; | 672 | (void) expanded; |
| 653 | QString argumentString = prunedArguments(expanded).join(","); | 673 | QString argumentString = prunedArguments(expanded).join(","); |
| @@ -1311,8 +1331,7 @@ Transform *Transform::make(QString str, QObject *parent) | @@ -1311,8 +1331,7 @@ Transform *Transform::make(QString str, QObject *parent) | ||
| 1311 | 1331 | ||
| 1312 | Transform *Transform::clone() const | 1332 | Transform *Transform::clone() const |
| 1313 | { | 1333 | { |
| 1314 | - Transform *temp = (Transform *) this; | ||
| 1315 | - Transform *clone = Factory<Transform>::make("."+temp->description(false)); | 1334 | + Transform *clone = Factory<Transform>::make("."+description(false)); |
| 1316 | return clone; | 1335 | return clone; |
| 1317 | } | 1336 | } |
| 1318 | 1337 |
openbr/openbr_plugin.h
| @@ -601,9 +601,9 @@ public: | @@ -601,9 +601,9 @@ public: | ||
| 601 | } | 601 | } |
| 602 | 602 | ||
| 603 | QStringList parameters() const; /*!< \brief A string describing the parameters the object takes. */ | 603 | QStringList parameters() const; /*!< \brief A string describing the parameters the object takes. */ |
| 604 | - QStringList prunedArguments(bool expanded = false); /*!< \brief A string describing the values the object has, default valued parameters will not be listed. If expanded is true, all abbreviations and model file names should be replaced with a description of the object generated from those names. */ | 604 | + QStringList prunedArguments(bool expanded = false) const; /*!< \brief A string describing the values the object has, default valued parameters will not be listed. If expanded is true, all abbreviations and model file names should be replaced with a description of the object generated from those names. */ |
| 605 | QString argument(int index, bool expanded) const; /*!< \brief A string value for the argument at the specified index. */ | 605 | QString argument(int index, bool expanded) const; /*!< \brief A string value for the argument at the specified index. */ |
| 606 | - virtual QString description(bool expanded = false); /*!< \brief Returns a string description of the object. */ | 606 | + virtual QString description(bool expanded = false) const; /*!< \brief Returns a string description of the object. */ |
| 607 | 607 | ||
| 608 | void setProperty(const QString &name, QVariant value); /*!< \brief Overload of QObject::setProperty to handle OpenBR data types. */ | 608 | void setProperty(const QString &name, QVariant value); /*!< \brief Overload of QObject::setProperty to handle OpenBR data types. */ |
| 609 | virtual bool setPropertyRecursive(const QString &name, QVariant value); /*!< \brief Recursive version of setProperty, try to set the property on this object, or its children, returns true if successful. */ | 609 | virtual bool setPropertyRecursive(const QString &name, QVariant value); /*!< \brief Recursive version of setProperty, try to set the property on this object, or its children, returns true if successful. */ |
openbr/plugins/independent.cpp
| @@ -132,7 +132,7 @@ class IndependentTransform : public MetaTransform | @@ -132,7 +132,7 @@ class IndependentTransform : public MetaTransform | ||
| 132 | 132 | ||
| 133 | QList<Transform*> transforms; | 133 | QList<Transform*> transforms; |
| 134 | 134 | ||
| 135 | - QString description(bool expanded) | 135 | + QString description(bool expanded) const |
| 136 | { | 136 | { |
| 137 | return transform->description(expanded); | 137 | return transform->description(expanded); |
| 138 | } | 138 | } |
openbr/plugins/meta.cpp
| @@ -482,9 +482,9 @@ BR_REGISTER(Transform, CacheTransform) | @@ -482,9 +482,9 @@ BR_REGISTER(Transform, CacheTransform) | ||
| 482 | class LoadStoreTransform : public MetaTransform | 482 | class LoadStoreTransform : public MetaTransform |
| 483 | { | 483 | { |
| 484 | Q_OBJECT | 484 | Q_OBJECT |
| 485 | - Q_PROPERTY(QString description2 READ get_description2 WRITE set_description2 RESET reset_description2 STORED false) | 485 | + Q_PROPERTY(QString transformString READ get_transformString WRITE set_transformString RESET reset_transformString STORED false) |
| 486 | Q_PROPERTY(QString fileName READ get_fileName WRITE set_fileName RESET reset_fileName STORED false) | 486 | Q_PROPERTY(QString fileName READ get_fileName WRITE set_fileName RESET reset_fileName STORED false) |
| 487 | - BR_PROPERTY(QString, description2, "Identity") | 487 | + BR_PROPERTY(QString, transformString, "Identity") |
| 488 | BR_PROPERTY(QString, fileName, QString()) | 488 | BR_PROPERTY(QString, fileName, QString()) |
| 489 | 489 | ||
| 490 | public: | 490 | public: |
| @@ -493,10 +493,12 @@ public: | @@ -493,10 +493,12 @@ public: | ||
| 493 | 493 | ||
| 494 | LoadStoreTransform() : transform(NULL) {} | 494 | LoadStoreTransform() : transform(NULL) {} |
| 495 | 495 | ||
| 496 | - QString description(bool expanded = false) | 496 | + QString description(bool expanded = false) const |
| 497 | { | 497 | { |
| 498 | - if (expanded) | ||
| 499 | - return transform->description(expanded); | 498 | + if (expanded) { |
| 499 | + QString res = transform->description(expanded); | ||
| 500 | + return res; | ||
| 501 | + } | ||
| 500 | return br::Object::description(expanded); | 502 | return br::Object::description(expanded); |
| 501 | } | 503 | } |
| 502 | 504 | ||
| @@ -517,10 +519,10 @@ private: | @@ -517,10 +519,10 @@ private: | ||
| 517 | void init() | 519 | void init() |
| 518 | { | 520 | { |
| 519 | if (transform != NULL) return; | 521 | if (transform != NULL) return; |
| 520 | - if (fileName.isEmpty()) baseName = QRegExp("^[a-zA-Z0-9]+$").exactMatch(description2) ? description2 : QtUtils::shortTextHash(description2); | 522 | + if (fileName.isEmpty()) baseName = QRegExp("^[a-zA-Z0-9]+$").exactMatch(transformString) ? transformString : QtUtils::shortTextHash(transformString); |
| 521 | else baseName = fileName; | 523 | else baseName = fileName; |
| 522 | if (!tryLoad()) | 524 | if (!tryLoad()) |
| 523 | - transform = make(description2); | 525 | + transform = make(transformString); |
| 524 | else | 526 | else |
| 525 | trainable = false; | 527 | trainable = false; |
| 526 | } | 528 | } |
| @@ -586,8 +588,8 @@ private: | @@ -586,8 +588,8 @@ private: | ||
| 586 | QByteArray data; | 588 | QByteArray data; |
| 587 | QtUtils::readFile(file, data, true); | 589 | QtUtils::readFile(file, data, true); |
| 588 | QDataStream stream(&data, QFile::ReadOnly); | 590 | QDataStream stream(&data, QFile::ReadOnly); |
| 589 | - stream >> description2; | ||
| 590 | - transform = Transform::make(description2); | 591 | + stream >> transformString; |
| 592 | + transform = Transform::make(transformString); | ||
| 591 | transform->load(stream); | 593 | transform->load(stream); |
| 592 | return true; | 594 | return true; |
| 593 | } | 595 | } |