diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index 4144beb..4f9aa3b 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -33,7 +33,8 @@ struct AlgorithmCore }; QSharedPointer transform; - QSharedPointer simplifiedTransform; + Transform *simplifiedTransform; + QSharedPointer deleteSimplifiedTransform; QSharedPointer comparison; QSharedPointer distance; QSharedPointer progressCounter; @@ -83,8 +84,10 @@ struct AlgorithmCore } qDebug("Training Time: %s", qPrintable(QtUtils::toTime(Globals->startTime.elapsed()/1000.0f))); - bool junk; - simplifiedTransform = QSharedPointer(transform->simplify(junk)); + bool newTForm = false; + simplifiedTransform = transform->simplify(newTForm); + if (newTForm) + deleteSimplifiedTransform.reset(simplifiedTransform); } void store(const QString &model) const @@ -170,7 +173,7 @@ struct AlgorithmCore Gallery *temp = Gallery::make(input); qint64 total = temp->totalSize(); - Transform *enroll = simplifiedTransform.data(); + Transform *enroll = simplifiedTransform; if (multiProcess) enroll = wrapTransform(enroll, "ProcessWrapper"); @@ -450,7 +453,7 @@ struct AlgorithmCore // if we have to enroll the row gallery, add that transform to the list if (needEnrollRows) - enrollCompare.prepend(simplifiedTransform.data()); + enrollCompare.prepend(simplifiedTransform); Transform *compareRegionBase = pipeTransforms(enrollCompare); // If in multi-process mode, wrap the enroll+compare structure in a ProcessWrapper. @@ -528,10 +531,12 @@ private: void init(const QString &description) { - bool junk; + bool newTForm = false; if (loadOrExpand(description)) { - simplifiedTransform = QSharedPointer(transform->simplify(junk)); + simplifiedTransform = transform->simplify(newTForm); + if (newTForm) + deleteSimplifiedTransform.reset(simplifiedTransform); return; } @@ -539,7 +544,9 @@ private: File parsed("."+description); if (loadOrExpand(parsed.suffix())) { applyAdditionalProperties(parsed, transform.data()); - simplifiedTransform = QSharedPointer(transform->simplify(junk)); + simplifiedTransform = transform->simplify(newTForm); + if (newTForm) + deleteSimplifiedTransform.reset(simplifiedTransform); return; } @@ -551,7 +558,9 @@ private: //! [Creating the template generation and comparison methods] transform = QSharedPointer(Transform::make(words[0], NULL)); - simplifiedTransform = QSharedPointer(transform->simplify(junk)); + simplifiedTransform = transform->simplify(newTForm); + if (newTForm) + deleteSimplifiedTransform.reset(simplifiedTransform); if (words.size() > 1) { if (!compareTransform) { diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index b0ee2f3..d4b2535 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -585,25 +585,45 @@ QStringList Object::parameters() const return parameters; } -QStringList Object::prunedArguments(bool expanded) +QStringList Object::prunedArguments(bool expanded) const { QStringList arguments; - + QString className = this->metaObject()->className(); + QScopedPointer shellObject; + + if (className.startsWith("br::")) + className = className.mid(4); + if (!className.startsWith(".")) + className = "." + className; + + if (className.endsWith("Distance")) { + className.chop(QString("Distance").size()); + shellObject.reset(Factory::make(className)); + } + else if (className.endsWith("Transform")) { + className.chop(QString("Transform").size()); + shellObject.reset(Factory::make(className)); + } + else if (className.endsWith("Format")) { + className.chop(QString("Format").size()); + shellObject.reset(Factory::make(className)); + } + else if (className.endsWith("Initializer")) { + className.chop(QString("Initializer").size()); + shellObject.reset(Factory::make(className)); + } + else if (className.endsWith("Output")) { + className.chop(QString("Output").size()); + shellObject.reset(Factory::make(className)); + } + for (int i=firstAvailablePropertyIdx; ipropertyCount(); i++) { const char *name = metaObject()->property(i).name(); - QVariant oldVal = property(name); - QVariant defaultVal = oldVal; - - if (metaObject()->property(i).isResettable()) { - metaObject()->property(i).reset(this); - defaultVal = property(name); - } + QVariant defaultVal = shellObject->property(name); - if (defaultVal != oldVal) { - metaObject()->property(i).write(this, oldVal); + if (defaultVal != property(name)) arguments.append(name + QString("=") + argument(i, expanded)); - } } return arguments; @@ -647,7 +667,7 @@ QString Object::argument(int index, bool expanded) const return variant.toString(); } -QString Object::description(bool expanded) +QString Object::description(bool expanded) const { (void) expanded; QString argumentString = prunedArguments(expanded).join(","); @@ -1311,8 +1331,7 @@ Transform *Transform::make(QString str, QObject *parent) Transform *Transform::clone() const { - Transform *temp = (Transform *) this; - Transform *clone = Factory::make("."+temp->description(false)); + Transform *clone = Factory::make("."+description(false)); return clone; } diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index fe35c79..fd17f87 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -601,9 +601,9 @@ public: } QStringList parameters() const; /*!< \brief A string describing the parameters the object takes. */ - 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. */ + 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. */ QString argument(int index, bool expanded) const; /*!< \brief A string value for the argument at the specified index. */ - virtual QString description(bool expanded = false); /*!< \brief Returns a string description of the object. */ + virtual QString description(bool expanded = false) const; /*!< \brief Returns a string description of the object. */ void setProperty(const QString &name, QVariant value); /*!< \brief Overload of QObject::setProperty to handle OpenBR data types. */ 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. */ diff --git a/openbr/plugins/independent.cpp b/openbr/plugins/independent.cpp index c4fb3b9..e071bc6 100644 --- a/openbr/plugins/independent.cpp +++ b/openbr/plugins/independent.cpp @@ -132,7 +132,7 @@ class IndependentTransform : public MetaTransform QList transforms; - QString description(bool expanded) + QString description(bool expanded) const { return transform->description(expanded); } diff --git a/openbr/plugins/meta.cpp b/openbr/plugins/meta.cpp index 82b4076..1d1300a 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -482,9 +482,9 @@ BR_REGISTER(Transform, CacheTransform) class LoadStoreTransform : public MetaTransform { Q_OBJECT - Q_PROPERTY(QString description2 READ get_description2 WRITE set_description2 RESET reset_description2 STORED false) + Q_PROPERTY(QString transformString READ get_transformString WRITE set_transformString RESET reset_transformString STORED false) Q_PROPERTY(QString fileName READ get_fileName WRITE set_fileName RESET reset_fileName STORED false) - BR_PROPERTY(QString, description2, "Identity") + BR_PROPERTY(QString, transformString, "Identity") BR_PROPERTY(QString, fileName, QString()) public: @@ -493,10 +493,12 @@ public: LoadStoreTransform() : transform(NULL) {} - QString description(bool expanded = false) + QString description(bool expanded = false) const { - if (expanded) - return transform->description(expanded); + if (expanded) { + QString res = transform->description(expanded); + return res; + } return br::Object::description(expanded); } @@ -517,10 +519,10 @@ private: void init() { if (transform != NULL) return; - if (fileName.isEmpty()) baseName = QRegExp("^[a-zA-Z0-9]+$").exactMatch(description2) ? description2 : QtUtils::shortTextHash(description2); + if (fileName.isEmpty()) baseName = QRegExp("^[a-zA-Z0-9]+$").exactMatch(transformString) ? transformString : QtUtils::shortTextHash(transformString); else baseName = fileName; if (!tryLoad()) - transform = make(description2); + transform = make(transformString); else trainable = false; } @@ -586,8 +588,8 @@ private: QByteArray data; QtUtils::readFile(file, data, true); QDataStream stream(&data, QFile::ReadOnly); - stream >> description2; - transform = Transform::make(description2); + stream >> transformString; + transform = Transform::make(transformString); transform->load(stream); return true; } diff --git a/share/openbr/models b/share/openbr/models index 3b22c62..79938fe 160000 --- a/share/openbr/models +++ b/share/openbr/models @@ -1 +1 @@ -Subproject commit 3b22c625a176c3834a0a04216977e9da02ee0d7f +Subproject commit 79938fe401faafead086b4711dd0b8f898a7a21e