Commit c03f1c90a42d99a945d4313118a4d5ae50cddd8f

Authored by Charles Otto
1 parent 4c0fea7e

Preliminary support for accessing named events through a Transform method

openbr/openbr_plugin.h
@@ -1040,6 +1040,21 @@ private: @@ -1040,6 +1040,21 @@ private:
1040 * @{ 1040 * @{
1041 */ 1041 */
1042 1042
  1043 +class TemplateEvent : public QObject
  1044 +{
  1045 + Q_OBJECT
  1046 +
  1047 +public:
  1048 + void pulseSignal(const Template & output) const
  1049 + {
  1050 + emit theSignal(output);
  1051 + }
  1052 +
  1053 +signals:
  1054 + void theSignal(const Template & output) const;
  1055 +};
  1056 +
  1057 +
1043 /*! 1058 /*!
1044 * \brief Plugin base class for processing a template. 1059 * \brief Plugin base class for processing a template.
1045 * 1060 *
@@ -1144,6 +1159,15 @@ public: @@ -1144,6 +1159,15 @@ public:
1144 */ 1159 */
1145 virtual Transform * smartCopy() { return this;} 1160 virtual Transform * smartCopy() { return this;}
1146 1161
  1162 + /*!
  1163 + * \brief Recursively retrieve a named event, returns NULL if an event is not found.
  1164 + */
  1165 + virtual TemplateEvent * getEvent(const QString & name)
  1166 + {
  1167 + (void) name;
  1168 + return NULL;
  1169 + }
  1170 +
1147 protected: 1171 protected:
1148 Transform(bool independent = true, bool trainable = true); /*!< \brief Construct a transform. */ 1172 Transform(bool independent = true, bool trainable = true); /*!< \brief Construct a transform. */
1149 inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */ 1173 inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */
openbr/plugins/meta.cpp
@@ -615,6 +615,12 @@ public: @@ -615,6 +615,12 @@ 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 +
618 void train(const TemplateList &data) 624 void train(const TemplateList &data)
619 { 625 {
620 transform->train(data); 626 transform->train(data);
openbr/plugins/misc.cpp
@@ -562,6 +562,28 @@ class ExpandRectTransform : public UntrainableTransform @@ -562,6 +562,28 @@ class ExpandRectTransform : public UntrainableTransform
562 562
563 BR_REGISTER(Transform, ExpandRectTransform) 563 BR_REGISTER(Transform, ExpandRectTransform)
564 564
  565 +
  566 +class EventTransform : public UntrainableMetaTransform
  567 +{
  568 + Q_OBJECT
  569 + Q_PROPERTY(QString eventName READ get_eventName WRITE set_eventName RESET reset_eventName STORED false)
  570 + BR_PROPERTY(QString, eventName, "")
  571 +
  572 + TemplateEvent event;
  573 +
  574 + void project(const Template &src, Template &dst) const
  575 + {
  576 + dst = src;
  577 + event.pulseSignal(dst);
  578 + }
  579 +
  580 + TemplateEvent * getEvent(const QString & name)
  581 + {
  582 + return name == eventName ? &event : NULL;
  583 + }
  584 +};
  585 +BR_REGISTER(Transform, EventTransform)
  586 +
565 } 587 }
566 588
567 #include "misc.moc" 589 #include "misc.moc"
openbr/plugins/openbr_internal.h
@@ -234,6 +234,19 @@ public: @@ -234,6 +234,19 @@ 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 +
237 protected: 250 protected:
238 bool isTimeVarying; 251 bool isTimeVarying;
239 252