Commit 87e701e294e8785fbac86026fa26faa2982fe99c

Authored by Charles Otto
1 parent 8f957ce1

Set up timeInvariantAlias in the TimeVaryingTransform constructor

Since copies are only actually made in calls to distribute, we don't need to be
initialized to set up the TimeInvariantWrapperTransform, and can do it in the
constructor. This means subclasses don't need to explicitly call
TimeVaryingTransform::init, although it depends quite strongly on Resource
having a particular behavior.
openbr/core/resource.h
... ... @@ -40,6 +40,9 @@ class DefaultResourceMaker : public ResourceMaker<T>
40 40 T *make() const { return new T(); }
41 41 };
42 42  
  43 +// Manage multiple copies of a limited resource in a thread-safe manner.
  44 +// TimeVaryingTransform makes a strong assumption that ResourceMaker::Make
  45 +// is only called in acquire, not in the constructor.
43 46 template <typename T>
44 47 class Resource
45 48 {
... ...
openbr/plugins/frames.cpp
... ... @@ -52,11 +52,6 @@ private:
52 52 {
53 53 (void) stream;
54 54 }
55   -
56   - void init()
57   - {
58   - TimeVaryingTransform::init();
59   - }
60 55 };
61 56  
62 57 BR_REGISTER(Transform, AggregateFrames)
... ...
openbr/plugins/gui.cpp
... ... @@ -350,8 +350,6 @@ public:
350 350 if (!Globals->useGui)
351 351 return;
352 352  
353   - TimeVaryingTransform::init();
354   -
355 353 if (displayBuffer)
356 354 delete displayBuffer;
357 355 displayBuffer = new QPixmap();
... ... @@ -532,7 +530,6 @@ public:
532 530 target_wait = 1000.0 / targetFPS;
533 531 timer.start();
534 532 last_time = timer.elapsed();
535   - TimeVaryingTransform::init();
536 533 }
537 534  
538 535 protected:
... ... @@ -586,7 +583,6 @@ public:
586 583 {
587 584 initialized = false;
588 585 framesSeen = 0;
589   - TimeVaryingTransform::init();
590 586 }
591 587  
592 588 protected:
... ...
openbr/plugins/openbr_internal.h
... ... @@ -110,12 +110,12 @@ public:
110 110  
111 111 virtual void project(const Template &src, Template &dst) const
112 112 {
113   - timeInvariantAlias->project(src,dst);
  113 + timeInvariantAlias.project(src,dst);
114 114 }
115 115  
116 116 virtual void project(const TemplateList &src, TemplateList &dst) const
117 117 {
118   - timeInvariantAlias->project(src,dst);
  118 + timeInvariantAlias.project(src,dst);
119 119 }
120 120  
121 121 // Get a compile failure if this isn't here to go along with the other
... ... @@ -144,21 +144,13 @@ public:
144 144 return this->clone();
145 145 }
146 146  
147   - void init()
148   - {
149   - delete timeInvariantAlias;
150   - timeInvariantAlias = new TimeInvariantWrapperTransform(this);
151   - }
152   -
153 147 protected:
154   - Transform * timeInvariantAlias;
155   - TimeVaryingTransform(bool independent = true, bool trainable = true) : Transform(independent, trainable)
  148 + // Since copies aren't actually made until project is called, we can set up
  149 + // timeInvariantAlias in the constructor.
  150 + TimeInvariantWrapperTransform timeInvariantAlias;
  151 + TimeVaryingTransform(bool independent = true, bool trainable = true) : Transform(independent, trainable), timeInvariantAlias(this)
156 152 {
157   - timeInvariantAlias = NULL;
158   - }
159   - ~TimeVaryingTransform()
160   - {
161   - delete timeInvariantAlias;
  153 + //
162 154 }
163 155 };
164 156  
... ... @@ -177,7 +169,7 @@ public:
177 169 virtual void project(const Template &src, Template &dst) const
178 170 {
179 171 if (timeVarying()) {
180   - timeInvariantAlias->project(src,dst);
  172 + timeInvariantAlias.project(src,dst);
181 173 return;
182 174 }
183 175 _project(src, dst);
... ... @@ -186,7 +178,7 @@ public:
186 178 virtual void project(const TemplateList &src, TemplateList &dst) const
187 179 {
188 180 if (timeVarying()) {
189   - timeInvariantAlias->project(src,dst);
  181 + timeInvariantAlias.project(src,dst);
190 182 return;
191 183 }
192 184 _project(src, dst);
... ... @@ -203,10 +195,6 @@ public:
203 195 isTimeVarying = isTimeVarying || transform->timeVarying();
204 196 trainable = trainable || transform->trainable;
205 197 }
206   -
207   - // If we are time varying, set up timeInvariantAlias
208   - if (this->timeVarying())
209   - TimeVaryingTransform::init();
210 198 }
211 199  
212 200 /*!
... ...
openbr/plugins/stream.cpp
... ... @@ -1300,11 +1300,6 @@ public:
1300 1300 if (!transform)
1301 1301 return;
1302 1302  
1303   - // Set up timeInvariantAlias
1304   - // this is only safe because copies are actually made in project
1305   - // calls, not during init.
1306   - TimeVaryingTransform::init();
1307   -
1308 1303 trainable = transform->trainable;
1309 1304  
1310 1305 basis.setParent(this->parent());
... ...