Commit c854997f59686c8ed1676060d71ecc5edb68f519

Authored by jklontz
2 parents 82113eb9 331bf830

Merge pull request #70 from biometrics/events

Something like this
openbr/openbr_plugin.cpp
@@ -1192,6 +1192,33 @@ void Transform::backProject(const TemplateList &dst, TemplateList &src) const @@ -1192,6 +1192,33 @@ void Transform::backProject(const TemplateList &dst, TemplateList &src) const
1192 futures.waitForFinished(); 1192 futures.waitForFinished();
1193 } 1193 }
1194 1194
  1195 +QList<Transform *> Transform::getChildren() const
  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 +
  1210 +TemplateEvent * Transform::getEvent(const QString & name)
  1211 +{
  1212 + foreach(Transform * child, getChildren())
  1213 + {
  1214 + TemplateEvent * probe = child->getEvent(name);
  1215 + if (probe)
  1216 + return probe;
  1217 + }
  1218 +
  1219 + return NULL;
  1220 +}
  1221 +
1195 /* Distance - public methods */ 1222 /* Distance - public methods */
1196 Distance *Distance::make(QString str, QObject *parent) 1223 Distance *Distance::make(QString str, QObject *parent)
1197 { 1224 {
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,17 @@ public: @@ -1144,6 +1159,17 @@ 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 + /*!
  1168 + * \brief Get a list of child transforms of this transform, child transforms are considered to be
  1169 + * any transforms stored as properties of this transform.
  1170 + */
  1171 + QList<Transform *> getChildren() const;
  1172 +
1147 protected: 1173 protected:
1148 Transform(bool independent = true, bool trainable = true); /*!< \brief Construct a transform. */ 1174 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. */ 1175 inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */
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"