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