From 87e701e294e8785fbac86026fa26faa2982fe99c Mon Sep 17 00:00:00 2001 From: Charles Otto Date: Mon, 12 Aug 2013 14:14:50 -0400 Subject: [PATCH] Set up timeInvariantAlias in the TimeVaryingTransform constructor --- openbr/core/resource.h | 3 +++ openbr/plugins/frames.cpp | 5 ----- openbr/plugins/gui.cpp | 4 ---- openbr/plugins/openbr_internal.h | 30 +++++++++--------------------- openbr/plugins/stream.cpp | 5 ----- 5 files changed, 12 insertions(+), 35 deletions(-) diff --git a/openbr/core/resource.h b/openbr/core/resource.h index a620969..d418e78 100644 --- a/openbr/core/resource.h +++ b/openbr/core/resource.h @@ -40,6 +40,9 @@ class DefaultResourceMaker : public ResourceMaker T *make() const { return new T(); } }; +// Manage multiple copies of a limited resource in a thread-safe manner. +// TimeVaryingTransform makes a strong assumption that ResourceMaker::Make +// is only called in acquire, not in the constructor. template class Resource { diff --git a/openbr/plugins/frames.cpp b/openbr/plugins/frames.cpp index 586bcae..fb7f507 100644 --- a/openbr/plugins/frames.cpp +++ b/openbr/plugins/frames.cpp @@ -52,11 +52,6 @@ private: { (void) stream; } - - void init() - { - TimeVaryingTransform::init(); - } }; BR_REGISTER(Transform, AggregateFrames) diff --git a/openbr/plugins/gui.cpp b/openbr/plugins/gui.cpp index af2d9fe..93927b0 100644 --- a/openbr/plugins/gui.cpp +++ b/openbr/plugins/gui.cpp @@ -350,8 +350,6 @@ public: if (!Globals->useGui) return; - TimeVaryingTransform::init(); - if (displayBuffer) delete displayBuffer; displayBuffer = new QPixmap(); @@ -532,7 +530,6 @@ public: target_wait = 1000.0 / targetFPS; timer.start(); last_time = timer.elapsed(); - TimeVaryingTransform::init(); } protected: @@ -586,7 +583,6 @@ public: { initialized = false; framesSeen = 0; - TimeVaryingTransform::init(); } protected: diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index 5eeb31f..84ff5ee 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -110,12 +110,12 @@ public: virtual void project(const Template &src, Template &dst) const { - timeInvariantAlias->project(src,dst); + timeInvariantAlias.project(src,dst); } virtual void project(const TemplateList &src, TemplateList &dst) const { - timeInvariantAlias->project(src,dst); + timeInvariantAlias.project(src,dst); } // Get a compile failure if this isn't here to go along with the other @@ -144,21 +144,13 @@ public: return this->clone(); } - void init() - { - delete timeInvariantAlias; - timeInvariantAlias = new TimeInvariantWrapperTransform(this); - } - protected: - Transform * timeInvariantAlias; - TimeVaryingTransform(bool independent = true, bool trainable = true) : Transform(independent, trainable) + // Since copies aren't actually made until project is called, we can set up + // timeInvariantAlias in the constructor. + TimeInvariantWrapperTransform timeInvariantAlias; + TimeVaryingTransform(bool independent = true, bool trainable = true) : Transform(independent, trainable), timeInvariantAlias(this) { - timeInvariantAlias = NULL; - } - ~TimeVaryingTransform() - { - delete timeInvariantAlias; + // } }; @@ -177,7 +169,7 @@ public: virtual void project(const Template &src, Template &dst) const { if (timeVarying()) { - timeInvariantAlias->project(src,dst); + timeInvariantAlias.project(src,dst); return; } _project(src, dst); @@ -186,7 +178,7 @@ public: virtual void project(const TemplateList &src, TemplateList &dst) const { if (timeVarying()) { - timeInvariantAlias->project(src,dst); + timeInvariantAlias.project(src,dst); return; } _project(src, dst); @@ -203,10 +195,6 @@ public: isTimeVarying = isTimeVarying || transform->timeVarying(); trainable = trainable || transform->trainable; } - - // If we are time varying, set up timeInvariantAlias - if (this->timeVarying()) - TimeVaryingTransform::init(); } /*! diff --git a/openbr/plugins/stream.cpp b/openbr/plugins/stream.cpp index 898b089..15944be 100644 --- a/openbr/plugins/stream.cpp +++ b/openbr/plugins/stream.cpp @@ -1300,11 +1300,6 @@ public: if (!transform) return; - // Set up timeInvariantAlias - // this is only safe because copies are actually made in project - // calls, not during init. - TimeVaryingTransform::init(); - trainable = transform->trainable; basis.setParent(this->parent()); -- libgit2 0.21.4