diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 82e5e15..e157eaf 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -1192,6 +1192,33 @@ void Transform::backProject(const TemplateList &dst, TemplateList &src) const futures.waitForFinished(); } +QList Transform::getChildren() const +{ + QList output; + for (int i=0; i < metaObject()->propertyCount(); i++) { + const char * prop_name = metaObject()->property(i).name(); + const QVariant & variant = this->property(prop_name); + + if (variant.canConvert()) + output.append(variant.value()); + if (variant.canConvert >()) + output.append(variant.value >()); + } + return output; +} + +TemplateEvent * Transform::getEvent(const QString & name) +{ + foreach(Transform * child, getChildren()) + { + TemplateEvent * probe = child->getEvent(name); + if (probe) + return probe; + } + + return NULL; +} + /* Distance - public methods */ Distance *Distance::make(QString str, QObject *parent) { diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index 759b360..0ecf867 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -1040,6 +1040,21 @@ private: * @{ */ +class TemplateEvent : public QObject +{ + Q_OBJECT + +public: + void pulseSignal(const Template & output) const + { + emit theSignal(output); + } + +signals: + void theSignal(const Template & output) const; +}; + + /*! * \brief Plugin base class for processing a template. * @@ -1144,6 +1159,17 @@ public: */ virtual Transform * smartCopy() { return this;} + /*! + * \brief Recursively retrieve a named event, returns NULL if an event is not found. + */ + virtual TemplateEvent * getEvent(const QString & name); + + /*! + * \brief Get a list of child transforms of this transform, child transforms are considered to be + * any transforms stored as properties of this transform. + */ + QList getChildren() const; + protected: Transform(bool independent = true, bool trainable = true); /*!< \brief Construct a transform. */ inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */ diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index 4ae217a..f0b1fbb 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -562,6 +562,28 @@ class ExpandRectTransform : public UntrainableTransform BR_REGISTER(Transform, ExpandRectTransform) + +class EventTransform : public UntrainableMetaTransform +{ + Q_OBJECT + Q_PROPERTY(QString eventName READ get_eventName WRITE set_eventName RESET reset_eventName STORED false) + BR_PROPERTY(QString, eventName, "") + + TemplateEvent event; + + void project(const Template &src, Template &dst) const + { + dst = src; + event.pulseSignal(dst); + } + + TemplateEvent * getEvent(const QString & name) + { + return name == eventName ? &event : NULL; + } +}; +BR_REGISTER(Transform, EventTransform) + } #include "misc.moc"