Commit 298a68aaab66a84ca2f6ef906606df3d87c59a19

Authored by Charles Otto
1 parent 17a93ada

Traverse the transform tree using properties

Look for properties with type Transform * or QList<Transform *> and for
getEvent, follow the tree using those, rather than having separate methods for
different transforms with children.
openbr/openbr_plugin.cpp
@@ -1192,6 +1192,21 @@ void Transform::backProject(const TemplateList &amp;dst, TemplateList &amp;src) const @@ -1192,6 +1192,21 @@ void Transform::backProject(const TemplateList &amp;dst, TemplateList &amp;src) const
1192 futures.waitForFinished(); 1192 futures.waitForFinished();
1193 } 1193 }
1194 1194
  1195 +QList<Transform *> Transform::getChildren()
  1196 +{
  1197 + QList<Transform *> output;
  1198 + for (int i=0; i < metaObject()->propertyCount(); i++) {
  1199 + const char * prop_name = metaObject()->property(i).name();
  1200 + const QVariant & variant = this->property(prop_name);
  1201 +
  1202 + if (variant.canConvert<Transform *>())
  1203 + output.append(variant.value<Transform *>());
  1204 + if (variant.canConvert<QList<Transform *> >())
  1205 + output.append(variant.value<QList<Transform *> >());
  1206 + }
  1207 + return output;
  1208 +}
  1209 +
1195 /* Distance - public methods */ 1210 /* Distance - public methods */
1196 Distance *Distance::make(QString str, QObject *parent) 1211 Distance *Distance::make(QString str, QObject *parent)
1197 { 1212 {
openbr/openbr_plugin.h
@@ -1164,11 +1164,19 @@ public: @@ -1164,11 +1164,19 @@ public:
1164 */ 1164 */
1165 virtual TemplateEvent * getEvent(const QString & name) 1165 virtual TemplateEvent * getEvent(const QString & name)
1166 { 1166 {
1167 - (void) name; 1167 + foreach(Transform * child, getChildren())
  1168 + {
  1169 + TemplateEvent * probe = child->getEvent(name);
  1170 + if (probe)
  1171 + return probe;
  1172 + }
  1173 +
1168 return NULL; 1174 return NULL;
1169 } 1175 }
1170 1176
1171 protected: 1177 protected:
  1178 + QList<Transform *> getChildren();
  1179 +
1172 Transform(bool independent = true, bool trainable = true); /*!< \brief Construct a transform. */ 1180 Transform(bool independent = true, bool trainable = true); /*!< \brief Construct a transform. */
1173 inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */ 1181 inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */
1174 }; 1182 };
openbr/plugins/meta.cpp
@@ -615,12 +615,6 @@ public: @@ -615,12 +615,6 @@ public:
615 return output; 615 return output;
616 } 616 }
617 617
618 - virtual TemplateEvent * getEvent(const QString & name)  
619 - {  
620 - return transform->getEvent(name);  
621 - }  
622 -  
623 -  
624 void train(const TemplateList &data) 618 void train(const TemplateList &data)
625 { 619 {
626 transform->train(data); 620 transform->train(data);
openbr/plugins/openbr_internal.h
@@ -234,19 +234,6 @@ public: @@ -234,19 +234,6 @@ public:
234 return output; 234 return output;
235 } 235 }
236 236
237 - virtual TemplateEvent * getEvent(const QString & name)  
238 - {  
239 - foreach(Transform* t, transforms )  
240 - {  
241 - TemplateEvent * probe = t->getEvent(name);  
242 - if (probe)  
243 - return probe;  
244 - }  
245 -  
246 - return NULL;  
247 - }  
248 -  
249 -  
250 protected: 237 protected:
251 bool isTimeVarying; 238 bool isTimeVarying;
252 239