From 353d2496ceb630e2f574474c80ce75de7ba85ac7 Mon Sep 17 00:00:00 2001 From: Charles Otto Date: Sun, 24 Nov 2013 19:35:46 -0800 Subject: [PATCH] Rework smartCopy --- openbr/openbr_plugin.h | 4 +++- openbr/plugins/meta.cpp | 13 ++++++++++--- openbr/plugins/openbr_internal.h | 15 ++++++++++----- openbr/plugins/stream.cpp | 8 ++------ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index 60a13e6..609610b 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -1209,7 +1209,9 @@ public: * and copy enough of their state that projectUpdate can safely be called on the original * instance, and the copy concurrently. */ - virtual Transform * smartCopy() { return this;} + virtual Transform * smartCopy(bool & newTransform) { newTransform=false; return this;} + + virtual Transform * smartCopy() {bool junk; return smartCopy(junk);} /*! * \brief Recursively retrieve a named event, returns NULL if an event is not found. diff --git a/openbr/plugins/meta.cpp b/openbr/plugins/meta.cpp index 19aa56b..c713c98 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -614,13 +614,20 @@ class DistributeTemplateTransform : public MetaTransform public: - Transform * smartCopy() + Transform * smartCopy(bool & newTransform) { - if (!transform->timeVarying()) + if (!transform->timeVarying()) { + newTransform = false; return this; + } + newTransform = true; DistributeTemplateTransform * output = new DistributeTemplateTransform; - output->transform = transform->smartCopy(); + bool newChild = false; + output->transform = transform->smartCopy(newChild); + if (newChild) + output->transform->setParent(output); + return output; } diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index b56daad..2680873 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -139,8 +139,9 @@ public: *\brief For transforms that don't do any training, this default implementation * which creates a new copy of the Transform from its description string is sufficient. */ - virtual Transform * smartCopy() + virtual Transform * smartCopy(bool & newTransform) { + newTransform = true; return this->clone(); } @@ -250,10 +251,13 @@ public: * it creates a new copy of its own class, and gives that copy the child transforms * returned by calling smartCopy on this transforms children */ - Transform * smartCopy() + Transform * smartCopy(bool & newTransform) { - if (!timeVarying()) + if (!timeVarying()) { + newTransform = false; return this; + } + newTransform = true; QString name = metaObject()->className(); name.replace("Transform",""); @@ -266,8 +270,9 @@ public: foreach(Transform* t, transforms ) { - Transform * maybe_copy = t->smartCopy(); - if (maybe_copy->parent() == NULL) + bool newItem = false; + Transform * maybe_copy = t->smartCopy(newItem); + if (newItem) maybe_copy->setParent(output); output->transforms.append(maybe_copy); } diff --git a/openbr/plugins/stream.cpp b/openbr/plugins/stream.cpp index 56f8b55..43673d1 100644 --- a/openbr/plugins/stream.cpp +++ b/openbr/plugins/stream.cpp @@ -1092,10 +1092,6 @@ public: // dst is set to all output received by the final stage, along // with anything output via the calls to finalize. - //dst = collectionStage->getOutput(); - - // dst is set to all output received by the final stage, along - // with anything output via the calls to finalize. foreach(const TemplateList & list, collector->sets) { dst.append(list); } @@ -1378,10 +1374,10 @@ public: basis.init(); } - Transform * smartCopy() + Transform * smartCopy(bool & newTransform) { // We just want the DirectStream to begin with, so just return a copy of that. - DirectStreamTransform * res = (DirectStreamTransform *) basis.smartCopy(); + DirectStreamTransform * res = (DirectStreamTransform *) basis.smartCopy(newTransform); res->activeFrames = this->activeFrames; return res; } -- libgit2 0.21.4