diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index 759b360..29f0836 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,15 @@ 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) + { + (void) name; + return NULL; + } + 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/meta.cpp b/openbr/plugins/meta.cpp index f00676c..749b4d9 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -615,6 +615,12 @@ public: return output; } + virtual TemplateEvent * getEvent(const QString & name) + { + return transform->getEvent(name); + } + + void train(const TemplateList &data) { transform->train(data); 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" diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index fb7a1b5..7376990 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -234,6 +234,19 @@ public: return output; } + virtual TemplateEvent * getEvent(const QString & name) + { + foreach(Transform* t, transforms ) + { + TemplateEvent * probe = t->getEvent(name); + if (probe) + return probe; + } + + return NULL; + } + + protected: bool isTimeVarying;