diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index 4f9aa3b..42660f4 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -23,6 +23,11 @@ namespace br { +void noDelete(Transform *target) +{ + (void) target; +} + struct AlgorithmCore { enum CompareMode @@ -33,8 +38,7 @@ struct AlgorithmCore }; QSharedPointer transform; - Transform *simplifiedTransform; - QSharedPointer deleteSimplifiedTransform; + QSharedPointer simplifiedTransform; QSharedPointer comparison; QSharedPointer distance; QSharedPointer progressCounter; @@ -84,10 +88,18 @@ struct AlgorithmCore } qDebug("Training Time: %s", qPrintable(QtUtils::toTime(Globals->startTime.elapsed()/1000.0f))); + + simplifyTransform(); + } + + void simplifyTransform() + { bool newTForm = false; - simplifiedTransform = transform->simplify(newTForm); + Transform *temp = transform->simplify(newTForm); if (newTForm) - deleteSimplifiedTransform.reset(simplifiedTransform); + simplifiedTransform = QSharedPointer(temp); + else + simplifiedTransform = QSharedPointer(temp, noDelete); } void store(const QString &model) const @@ -97,7 +109,7 @@ struct AlgorithmCore QDataStream out(&data, QFile::WriteOnly); // Serialize algorithm to stream - transform->serialize(out, false); + transform->serialize(out); qint32 mode = None; if (!distance.isNull()) @@ -108,10 +120,10 @@ struct AlgorithmCore out << mode; if (mode == DistanceCompare) - distance->serialize(out, false); + distance->serialize(out); if (mode == TransformCompare) - comparison->serialize(out, false); + comparison->serialize(out); // Compress and save to file QtUtils::writeFile(model, data, -1); @@ -173,7 +185,7 @@ struct AlgorithmCore Gallery *temp = Gallery::make(input); qint64 total = temp->totalSize(); - Transform *enroll = simplifiedTransform; + Transform *enroll = simplifiedTransform.data(); if (multiProcess) enroll = wrapTransform(enroll, "ProcessWrapper"); @@ -453,7 +465,7 @@ struct AlgorithmCore // if we have to enroll the row gallery, add that transform to the list if (needEnrollRows) - enrollCompare.prepend(simplifiedTransform); + enrollCompare.prepend(simplifiedTransform.data()); Transform *compareRegionBase = pipeTransforms(enrollCompare); // If in multi-process mode, wrap the enroll+compare structure in a ProcessWrapper. @@ -534,9 +546,7 @@ private: bool newTForm = false; if (loadOrExpand(description)) { - simplifiedTransform = transform->simplify(newTForm); - if (newTForm) - deleteSimplifiedTransform.reset(simplifiedTransform); + simplifyTransform(); return; } @@ -544,9 +554,7 @@ private: File parsed("."+description); if (loadOrExpand(parsed.suffix())) { applyAdditionalProperties(parsed, transform.data()); - simplifiedTransform = transform->simplify(newTForm); - if (newTForm) - deleteSimplifiedTransform.reset(simplifiedTransform); + simplifyTransform(); return; } @@ -558,9 +566,7 @@ private: //! [Creating the template generation and comparison methods] transform = QSharedPointer(Transform::make(words[0], NULL)); - simplifiedTransform = transform->simplify(newTForm); - if (newTForm) - deleteSimplifiedTransform.reset(simplifiedTransform); + simplifyTransform(); if (words.size() > 1) { if (!compareTransform) { diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index d4b2535..f456f52 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -669,7 +669,6 @@ QString Object::argument(int index, bool expanded) const QString Object::description(bool expanded) const { - (void) expanded; QString argumentString = prunedArguments(expanded).join(","); if (argumentString.endsWith(",")) argumentString.chop(1); diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index fd17f87..a329910 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -594,9 +594,9 @@ public: virtual void load(QDataStream &stream); /*!< \brief Deserialize the object. Default implementation calls init() after deserialization. */ /*!< \brief Serialize an object created via the plugin system, including the string used to build the base object, allowing re-creation of the object without knowledge of its base string*/ - virtual void serialize(QDataStream &stream, bool force) + virtual void serialize(QDataStream &stream) const { - stream << description(force); + stream << description(); store(stream); } diff --git a/openbr/plugins/eigen3.cpp b/openbr/plugins/eigen3.cpp index c546a48..45fd671 100644 --- a/openbr/plugins/eigen3.cpp +++ b/openbr/plugins/eigen3.cpp @@ -634,7 +634,7 @@ class SparseLDATransform : public Transform void store(QDataStream &stream) const { stream << pcaKeep; - ldaSparse.store(stream); + stream << ldaSparse; stream << dimsOut; stream << selections; } diff --git a/openbr/plugins/independent.cpp b/openbr/plugins/independent.cpp index e071bc6..be61582 100644 --- a/openbr/plugins/independent.cpp +++ b/openbr/plugins/independent.cpp @@ -96,7 +96,7 @@ class DownsampleTrainingTransform : public Transform Transform *simplify(bool &newTForm) { - Transform * res = transform->simplify(newTForm); + Transform *res = transform->simplify(newTForm); return res; } @@ -151,11 +151,11 @@ class IndependentTransform : public MetaTransform return true; } - Transform * simplify(bool & newTransform) + Transform *simplify(bool &newTransform) { newTransform = false; bool newChild = false; - Transform * temp = transform->simplify(newChild); + Transform *temp = transform->simplify(newChild); if (temp == transform) { return this; } @@ -163,14 +163,14 @@ class IndependentTransform : public MetaTransform indep->transform = temp; bool subInd = false; - IndependentTransform * test = dynamic_cast (temp); + IndependentTransform *test = dynamic_cast (temp); if (test) { // child was independent? this changes things... subInd = true; indep->transform = test->transform; for (int i=0; i < transforms.size(); i++) { bool newThing = false; - IndependentTransform * probe = dynamic_cast (transforms[i]->simplify(newThing)); + IndependentTransform *probe = dynamic_cast (transforms[i]->simplify(newThing)); indep->transforms.append(probe->transform); if (newThing) probe->setParent(indep); diff --git a/openbr/plugins/meta.cpp b/openbr/plugins/meta.cpp index 1d1300a..c3777e3 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -502,9 +502,9 @@ public: return br::Object::description(expanded); } - Transform * simplify(bool & newTForm) + Transform *simplify(bool &newTForm) { - Transform * res = transform->simplify(newTForm); + Transform *res = transform->simplify(newTForm); return res; } diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index 8ef6060..91ad9cb 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -201,11 +201,11 @@ public: this->trainable = transform->trainable; } - virtual Transform * simplify(bool & newTransform) + virtual Transform *simplify(bool &newTransform) { newTransform = false; bool newChild = false; - Transform * temp = transform->simplify(newTransform); + Transform *temp = transform->simplify(newTransform); if (temp == transform) return this; @@ -213,7 +213,7 @@ public: return NULL; // else make a copy to point at the new transform - Transform * child = transform; + Transform *child = transform; transform = NULL; WrapperTransform *output = dynamic_cast(Transform::make(description(), NULL)); transform = child; @@ -247,7 +247,7 @@ public: return this; } newTransform = true; - Transform * temp = transform; + Transform *temp = transform; transform = NULL; WrapperTransform *output = dynamic_cast(Transform::make(description(), NULL)); transform = temp; @@ -347,7 +347,7 @@ public: return output; } - virtual Transform * simplify(bool & newTransform) + virtual Transform *simplify(bool &newTransform) { newTransform = false; QList newTransforms; @@ -357,7 +357,7 @@ public: for (int i=0; i < transforms.size();i++) { bool newChild = false; - Transform * temp = transforms[i]->simplify(newChild); + Transform *temp = transforms[i]->simplify(newChild); if (temp == NULL) { anyNew = true; continue; diff --git a/openbr/plugins/process.cpp b/openbr/plugins/process.cpp index 1646a96..4169c05 100644 --- a/openbr/plugins/process.cpp +++ b/openbr/plugins/process.cpp @@ -555,7 +555,7 @@ class ProcessWrapperTransform : public WrapperTransform serialized.clear(); if (transform) { QDataStream out(&serialized, QFile::WriteOnly); - transform->serialize(out, true); + transform->serialize(out); } }