Commit 5c6a8fabec1f0da4326a41508aa6c358f29c383d
1 parent
cc6651c3
Various issues
Refactor handling of simplified pointer in AlgorithmCore Remove parameter from serialize, it's literally impossible for it to do anything useful Remove spaces after * and & (saving valuable bytes of source code).
Showing
8 changed files
with
41 additions
and
36 deletions
openbr/core/core.cpp
| @@ -23,6 +23,11 @@ | @@ -23,6 +23,11 @@ | ||
| 23 | 23 | ||
| 24 | namespace br { | 24 | namespace br { |
| 25 | 25 | ||
| 26 | +void noDelete(Transform *target) | ||
| 27 | +{ | ||
| 28 | + (void) target; | ||
| 29 | +} | ||
| 30 | + | ||
| 26 | struct AlgorithmCore | 31 | struct AlgorithmCore |
| 27 | { | 32 | { |
| 28 | enum CompareMode | 33 | enum CompareMode |
| @@ -33,8 +38,7 @@ struct AlgorithmCore | @@ -33,8 +38,7 @@ struct AlgorithmCore | ||
| 33 | }; | 38 | }; |
| 34 | 39 | ||
| 35 | QSharedPointer<Transform> transform; | 40 | QSharedPointer<Transform> transform; |
| 36 | - Transform *simplifiedTransform; | ||
| 37 | - QSharedPointer<Transform> deleteSimplifiedTransform; | 41 | + QSharedPointer<Transform> simplifiedTransform; |
| 38 | QSharedPointer<Transform> comparison; | 42 | QSharedPointer<Transform> comparison; |
| 39 | QSharedPointer<Distance> distance; | 43 | QSharedPointer<Distance> distance; |
| 40 | QSharedPointer<Transform> progressCounter; | 44 | QSharedPointer<Transform> progressCounter; |
| @@ -84,10 +88,18 @@ struct AlgorithmCore | @@ -84,10 +88,18 @@ struct AlgorithmCore | ||
| 84 | } | 88 | } |
| 85 | 89 | ||
| 86 | qDebug("Training Time: %s", qPrintable(QtUtils::toTime(Globals->startTime.elapsed()/1000.0f))); | 90 | qDebug("Training Time: %s", qPrintable(QtUtils::toTime(Globals->startTime.elapsed()/1000.0f))); |
| 91 | + | ||
| 92 | + simplifyTransform(); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + void simplifyTransform() | ||
| 96 | + { | ||
| 87 | bool newTForm = false; | 97 | bool newTForm = false; |
| 88 | - simplifiedTransform = transform->simplify(newTForm); | 98 | + Transform *temp = transform->simplify(newTForm); |
| 89 | if (newTForm) | 99 | if (newTForm) |
| 90 | - deleteSimplifiedTransform.reset(simplifiedTransform); | 100 | + simplifiedTransform = QSharedPointer<Transform>(temp); |
| 101 | + else | ||
| 102 | + simplifiedTransform = QSharedPointer<Transform>(temp, noDelete); | ||
| 91 | } | 103 | } |
| 92 | 104 | ||
| 93 | void store(const QString &model) const | 105 | void store(const QString &model) const |
| @@ -97,7 +109,7 @@ struct AlgorithmCore | @@ -97,7 +109,7 @@ struct AlgorithmCore | ||
| 97 | QDataStream out(&data, QFile::WriteOnly); | 109 | QDataStream out(&data, QFile::WriteOnly); |
| 98 | 110 | ||
| 99 | // Serialize algorithm to stream | 111 | // Serialize algorithm to stream |
| 100 | - transform->serialize(out, false); | 112 | + transform->serialize(out); |
| 101 | 113 | ||
| 102 | qint32 mode = None; | 114 | qint32 mode = None; |
| 103 | if (!distance.isNull()) | 115 | if (!distance.isNull()) |
| @@ -108,10 +120,10 @@ struct AlgorithmCore | @@ -108,10 +120,10 @@ struct AlgorithmCore | ||
| 108 | out << mode; | 120 | out << mode; |
| 109 | 121 | ||
| 110 | if (mode == DistanceCompare) | 122 | if (mode == DistanceCompare) |
| 111 | - distance->serialize(out, false); | 123 | + distance->serialize(out); |
| 112 | 124 | ||
| 113 | if (mode == TransformCompare) | 125 | if (mode == TransformCompare) |
| 114 | - comparison->serialize(out, false); | 126 | + comparison->serialize(out); |
| 115 | 127 | ||
| 116 | // Compress and save to file | 128 | // Compress and save to file |
| 117 | QtUtils::writeFile(model, data, -1); | 129 | QtUtils::writeFile(model, data, -1); |
| @@ -173,7 +185,7 @@ struct AlgorithmCore | @@ -173,7 +185,7 @@ struct AlgorithmCore | ||
| 173 | Gallery *temp = Gallery::make(input); | 185 | Gallery *temp = Gallery::make(input); |
| 174 | qint64 total = temp->totalSize(); | 186 | qint64 total = temp->totalSize(); |
| 175 | 187 | ||
| 176 | - Transform *enroll = simplifiedTransform; | 188 | + Transform *enroll = simplifiedTransform.data(); |
| 177 | 189 | ||
| 178 | if (multiProcess) | 190 | if (multiProcess) |
| 179 | enroll = wrapTransform(enroll, "ProcessWrapper"); | 191 | enroll = wrapTransform(enroll, "ProcessWrapper"); |
| @@ -453,7 +465,7 @@ struct AlgorithmCore | @@ -453,7 +465,7 @@ struct AlgorithmCore | ||
| 453 | 465 | ||
| 454 | // if we have to enroll the row gallery, add that transform to the list | 466 | // if we have to enroll the row gallery, add that transform to the list |
| 455 | if (needEnrollRows) | 467 | if (needEnrollRows) |
| 456 | - enrollCompare.prepend(simplifiedTransform); | 468 | + enrollCompare.prepend(simplifiedTransform.data()); |
| 457 | 469 | ||
| 458 | Transform *compareRegionBase = pipeTransforms(enrollCompare); | 470 | Transform *compareRegionBase = pipeTransforms(enrollCompare); |
| 459 | // If in multi-process mode, wrap the enroll+compare structure in a ProcessWrapper. | 471 | // If in multi-process mode, wrap the enroll+compare structure in a ProcessWrapper. |
| @@ -534,9 +546,7 @@ private: | @@ -534,9 +546,7 @@ private: | ||
| 534 | bool newTForm = false; | 546 | bool newTForm = false; |
| 535 | 547 | ||
| 536 | if (loadOrExpand(description)) { | 548 | if (loadOrExpand(description)) { |
| 537 | - simplifiedTransform = transform->simplify(newTForm); | ||
| 538 | - if (newTForm) | ||
| 539 | - deleteSimplifiedTransform.reset(simplifiedTransform); | 549 | + simplifyTransform(); |
| 540 | return; | 550 | return; |
| 541 | } | 551 | } |
| 542 | 552 | ||
| @@ -544,9 +554,7 @@ private: | @@ -544,9 +554,7 @@ private: | ||
| 544 | File parsed("."+description); | 554 | File parsed("."+description); |
| 545 | if (loadOrExpand(parsed.suffix())) { | 555 | if (loadOrExpand(parsed.suffix())) { |
| 546 | applyAdditionalProperties(parsed, transform.data()); | 556 | applyAdditionalProperties(parsed, transform.data()); |
| 547 | - simplifiedTransform = transform->simplify(newTForm); | ||
| 548 | - if (newTForm) | ||
| 549 | - deleteSimplifiedTransform.reset(simplifiedTransform); | 557 | + simplifyTransform(); |
| 550 | return; | 558 | return; |
| 551 | } | 559 | } |
| 552 | 560 | ||
| @@ -558,9 +566,7 @@ private: | @@ -558,9 +566,7 @@ private: | ||
| 558 | 566 | ||
| 559 | //! [Creating the template generation and comparison methods] | 567 | //! [Creating the template generation and comparison methods] |
| 560 | transform = QSharedPointer<Transform>(Transform::make(words[0], NULL)); | 568 | transform = QSharedPointer<Transform>(Transform::make(words[0], NULL)); |
| 561 | - simplifiedTransform = transform->simplify(newTForm); | ||
| 562 | - if (newTForm) | ||
| 563 | - deleteSimplifiedTransform.reset(simplifiedTransform); | 569 | + simplifyTransform(); |
| 564 | 570 | ||
| 565 | if (words.size() > 1) { | 571 | if (words.size() > 1) { |
| 566 | if (!compareTransform) { | 572 | if (!compareTransform) { |
openbr/openbr_plugin.cpp
| @@ -669,7 +669,6 @@ QString Object::argument(int index, bool expanded) const | @@ -669,7 +669,6 @@ QString Object::argument(int index, bool expanded) const | ||
| 669 | 669 | ||
| 670 | QString Object::description(bool expanded) const | 670 | QString Object::description(bool expanded) const |
| 671 | { | 671 | { |
| 672 | - (void) expanded; | ||
| 673 | QString argumentString = prunedArguments(expanded).join(","); | 672 | QString argumentString = prunedArguments(expanded).join(","); |
| 674 | if (argumentString.endsWith(",")) | 673 | if (argumentString.endsWith(",")) |
| 675 | argumentString.chop(1); | 674 | argumentString.chop(1); |
openbr/openbr_plugin.h
| @@ -594,9 +594,9 @@ public: | @@ -594,9 +594,9 @@ public: | ||
| 594 | virtual void load(QDataStream &stream); /*!< \brief Deserialize the object. Default implementation calls init() after deserialization. */ | 594 | virtual void load(QDataStream &stream); /*!< \brief Deserialize the object. Default implementation calls init() after deserialization. */ |
| 595 | 595 | ||
| 596 | /*!< \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*/ | 596 | /*!< \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*/ |
| 597 | - virtual void serialize(QDataStream &stream, bool force) | 597 | + virtual void serialize(QDataStream &stream) const |
| 598 | { | 598 | { |
| 599 | - stream << description(force); | 599 | + stream << description(); |
| 600 | store(stream); | 600 | store(stream); |
| 601 | } | 601 | } |
| 602 | 602 |
openbr/plugins/eigen3.cpp
| @@ -634,7 +634,7 @@ class SparseLDATransform : public Transform | @@ -634,7 +634,7 @@ class SparseLDATransform : public Transform | ||
| 634 | void store(QDataStream &stream) const | 634 | void store(QDataStream &stream) const |
| 635 | { | 635 | { |
| 636 | stream << pcaKeep; | 636 | stream << pcaKeep; |
| 637 | - ldaSparse.store(stream); | 637 | + stream << ldaSparse; |
| 638 | stream << dimsOut; | 638 | stream << dimsOut; |
| 639 | stream << selections; | 639 | stream << selections; |
| 640 | } | 640 | } |
openbr/plugins/independent.cpp
| @@ -96,7 +96,7 @@ class DownsampleTrainingTransform : public Transform | @@ -96,7 +96,7 @@ class DownsampleTrainingTransform : public Transform | ||
| 96 | 96 | ||
| 97 | Transform *simplify(bool &newTForm) | 97 | Transform *simplify(bool &newTForm) |
| 98 | { | 98 | { |
| 99 | - Transform * res = transform->simplify(newTForm); | 99 | + Transform *res = transform->simplify(newTForm); |
| 100 | return res; | 100 | return res; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| @@ -151,11 +151,11 @@ class IndependentTransform : public MetaTransform | @@ -151,11 +151,11 @@ class IndependentTransform : public MetaTransform | ||
| 151 | return true; | 151 | return true; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | - Transform * simplify(bool & newTransform) | 154 | + Transform *simplify(bool &newTransform) |
| 155 | { | 155 | { |
| 156 | newTransform = false; | 156 | newTransform = false; |
| 157 | bool newChild = false; | 157 | bool newChild = false; |
| 158 | - Transform * temp = transform->simplify(newChild); | 158 | + Transform *temp = transform->simplify(newChild); |
| 159 | if (temp == transform) { | 159 | if (temp == transform) { |
| 160 | return this; | 160 | return this; |
| 161 | } | 161 | } |
| @@ -163,14 +163,14 @@ class IndependentTransform : public MetaTransform | @@ -163,14 +163,14 @@ class IndependentTransform : public MetaTransform | ||
| 163 | indep->transform = temp; | 163 | indep->transform = temp; |
| 164 | 164 | ||
| 165 | bool subInd = false; | 165 | bool subInd = false; |
| 166 | - IndependentTransform * test = dynamic_cast<IndependentTransform *> (temp); | 166 | + IndependentTransform *test = dynamic_cast<IndependentTransform *> (temp); |
| 167 | if (test) { | 167 | if (test) { |
| 168 | // child was independent? this changes things... | 168 | // child was independent? this changes things... |
| 169 | subInd = true; | 169 | subInd = true; |
| 170 | indep->transform = test->transform; | 170 | indep->transform = test->transform; |
| 171 | for (int i=0; i < transforms.size(); i++) { | 171 | for (int i=0; i < transforms.size(); i++) { |
| 172 | bool newThing = false; | 172 | bool newThing = false; |
| 173 | - IndependentTransform * probe = dynamic_cast<IndependentTransform *> (transforms[i]->simplify(newThing)); | 173 | + IndependentTransform *probe = dynamic_cast<IndependentTransform *> (transforms[i]->simplify(newThing)); |
| 174 | indep->transforms.append(probe->transform); | 174 | indep->transforms.append(probe->transform); |
| 175 | if (newThing) | 175 | if (newThing) |
| 176 | probe->setParent(indep); | 176 | probe->setParent(indep); |
openbr/plugins/meta.cpp
| @@ -502,9 +502,9 @@ public: | @@ -502,9 +502,9 @@ public: | ||
| 502 | return br::Object::description(expanded); | 502 | return br::Object::description(expanded); |
| 503 | } | 503 | } |
| 504 | 504 | ||
| 505 | - Transform * simplify(bool & newTForm) | 505 | + Transform *simplify(bool &newTForm) |
| 506 | { | 506 | { |
| 507 | - Transform * res = transform->simplify(newTForm); | 507 | + Transform *res = transform->simplify(newTForm); |
| 508 | return res; | 508 | return res; |
| 509 | } | 509 | } |
| 510 | 510 |
openbr/plugins/openbr_internal.h
| @@ -201,11 +201,11 @@ public: | @@ -201,11 +201,11 @@ public: | ||
| 201 | this->trainable = transform->trainable; | 201 | this->trainable = transform->trainable; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | - virtual Transform * simplify(bool & newTransform) | 204 | + virtual Transform *simplify(bool &newTransform) |
| 205 | { | 205 | { |
| 206 | newTransform = false; | 206 | newTransform = false; |
| 207 | bool newChild = false; | 207 | bool newChild = false; |
| 208 | - Transform * temp = transform->simplify(newTransform); | 208 | + Transform *temp = transform->simplify(newTransform); |
| 209 | if (temp == transform) | 209 | if (temp == transform) |
| 210 | return this; | 210 | return this; |
| 211 | 211 | ||
| @@ -213,7 +213,7 @@ public: | @@ -213,7 +213,7 @@ public: | ||
| 213 | return NULL; | 213 | return NULL; |
| 214 | 214 | ||
| 215 | // else make a copy to point at the new transform | 215 | // else make a copy to point at the new transform |
| 216 | - Transform * child = transform; | 216 | + Transform *child = transform; |
| 217 | transform = NULL; | 217 | transform = NULL; |
| 218 | WrapperTransform *output = dynamic_cast<WrapperTransform *>(Transform::make(description(), NULL)); | 218 | WrapperTransform *output = dynamic_cast<WrapperTransform *>(Transform::make(description(), NULL)); |
| 219 | transform = child; | 219 | transform = child; |
| @@ -247,7 +247,7 @@ public: | @@ -247,7 +247,7 @@ public: | ||
| 247 | return this; | 247 | return this; |
| 248 | } | 248 | } |
| 249 | newTransform = true; | 249 | newTransform = true; |
| 250 | - Transform * temp = transform; | 250 | + Transform *temp = transform; |
| 251 | transform = NULL; | 251 | transform = NULL; |
| 252 | WrapperTransform *output = dynamic_cast<WrapperTransform *>(Transform::make(description(), NULL)); | 252 | WrapperTransform *output = dynamic_cast<WrapperTransform *>(Transform::make(description(), NULL)); |
| 253 | transform = temp; | 253 | transform = temp; |
| @@ -347,7 +347,7 @@ public: | @@ -347,7 +347,7 @@ public: | ||
| 347 | return output; | 347 | return output; |
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | - virtual Transform * simplify(bool & newTransform) | 350 | + virtual Transform *simplify(bool &newTransform) |
| 351 | { | 351 | { |
| 352 | newTransform = false; | 352 | newTransform = false; |
| 353 | QList<Transform *> newTransforms; | 353 | QList<Transform *> newTransforms; |
| @@ -357,7 +357,7 @@ public: | @@ -357,7 +357,7 @@ public: | ||
| 357 | for (int i=0; i < transforms.size();i++) | 357 | for (int i=0; i < transforms.size();i++) |
| 358 | { | 358 | { |
| 359 | bool newChild = false; | 359 | bool newChild = false; |
| 360 | - Transform * temp = transforms[i]->simplify(newChild); | 360 | + Transform *temp = transforms[i]->simplify(newChild); |
| 361 | if (temp == NULL) { | 361 | if (temp == NULL) { |
| 362 | anyNew = true; | 362 | anyNew = true; |
| 363 | continue; | 363 | continue; |
openbr/plugins/process.cpp
| @@ -555,7 +555,7 @@ class ProcessWrapperTransform : public WrapperTransform | @@ -555,7 +555,7 @@ class ProcessWrapperTransform : public WrapperTransform | ||
| 555 | serialized.clear(); | 555 | serialized.clear(); |
| 556 | if (transform) { | 556 | if (transform) { |
| 557 | QDataStream out(&serialized, QFile::WriteOnly); | 557 | QDataStream out(&serialized, QFile::WriteOnly); |
| 558 | - transform->serialize(out, true); | 558 | + transform->serialize(out); |
| 559 | } | 559 | } |
| 560 | } | 560 | } |
| 561 | 561 |