Commit d2a3197cb88a8d72165ce0c78c8b747ec04dab23

Authored by Charles Otto
1 parent d0aa1fd8

Some additional comments about train/project overloads

Showing 1 changed file with 27 additions and 6 deletions
openbr/openbr_plugin.h
@@ -1058,7 +1058,15 @@ public: @@ -1058,7 +1058,15 @@ public:
1058 static QSharedPointer<Transform> fromAlgorithm(const QString &algorithm); /*!< \brief Retrieve an algorithm's transform. */ 1058 static QSharedPointer<Transform> fromAlgorithm(const QString &algorithm); /*!< \brief Retrieve an algorithm's transform. */
1059 1059
1060 virtual Transform *clone() const; /*!< \brief Copy the transform. */ 1060 virtual Transform *clone() const; /*!< \brief Copy the transform. */
1061 - /*!< \brief Train the transform, separate list items represent the way calls to project would be broken up*/ 1061 +
  1062 + /*!< \brief Train the transform, separate list items represent the way calls to project would be broken up
  1063 + * Transforms that have to call train on another transform should implement train(QList), the strucutre of the
  1064 + * list should mirror the calls that would be made to project by the parent transform. For example, DistributeTemplates
  1065 + * would make a separate project call for each template it receives, and therefore sets the QList to contain single item
  1066 + * template lists before passing it on.
  1067 + * This version of train(QList) is appropriate for transforms that perform training on themselves, and don't call train
  1068 + * on other transforms. It combines everything in data into a single TemplateList, then calls train(TemplateList)
  1069 + */
1062 virtual void train(const QList<TemplateList> &data) 1070 virtual void train(const QList<TemplateList> &data)
1063 { 1071 {
1064 TemplateList combined; 1072 TemplateList combined;
@@ -1071,16 +1079,27 @@ public: @@ -1071,16 +1079,27 @@ public:
1071 // Terminal train, call with a complete training set when no further structure is needed 1079 // Terminal train, call with a complete training set when no further structure is needed
1072 virtual void train(const TemplateList &data) = 0; /*!< \brief Train the transform. */ 1080 virtual void train(const TemplateList &data) = 0; /*!< \brief Train the transform. */
1073 1081
1074 - virtual void project(const Template &src, Template &dst) const = 0; /*!< \brief Apply the transform. */  
1075 - virtual void project(const TemplateList &src, TemplateList &dst) const; /*!< \brief Apply the transform. */ 1082 + /*!< \brief Apply the transform to a single template. Typically used by independent transforms */
  1083 + virtual void project(const Template &src, Template &dst) const = 0;
  1084 + /*!< \brief Apply the transform, taking the full template list as input.
  1085 + * A TemplateList is what is typically passed from transform to transform. Transforms that just
  1086 + * need to operatoe on a single template at a time (and want to output exactly 1 template) can implement
  1087 + * project(template), but transforms that want to change the structure of the TemplateList (such as flatten), or
  1088 + * or output more or less than one template (e.g. detection methods) should implement project(TemplateList) directly
  1089 + */
  1090 + virtual void project(const TemplateList &src, TemplateList &dst) const;
1076 1091
1077 - /*!< \brief Apply the transform, may update the transform's internal state */ 1092 + /*!< \brief Apply the transform to a single template, may update the transform's internal state
  1093 + * By default, just call project, we can always call a const function from a non-const function.
  1094 + * If a transform implements projectUpdate, it should report true to timeVarying so that it can be
  1095 + * handled correctly by e.g. Stream.
  1096 + */
1078 virtual void projectUpdate(const Template &src, Template &dst) 1097 virtual void projectUpdate(const Template &src, Template &dst)
1079 { 1098 {
1080 project(src, dst); 1099 project(src, dst);
1081 } 1100 }
1082 1101
1083 - /*!< \brief Apply the transform, may update the transform's internal state */ 1102 + /*!< \brief Apply the transform, may update the transform's internal state. */
1084 virtual void projectUpdate(const TemplateList &src, TemplateList &dst) 1103 virtual void projectUpdate(const TemplateList &src, TemplateList &dst)
1085 { 1104 {
1086 project(src,dst); 1105 project(src,dst);
@@ -1142,7 +1161,9 @@ public: @@ -1142,7 +1161,9 @@ public:
1142 * \brief Perform the minimum amount of work necessary to make a 1161 * \brief Perform the minimum amount of work necessary to make a
1143 * transform that can be used safely from a different thread than this 1162 * transform that can be used safely from a different thread than this
1144 * transform. For transforms that aren't time-varying, nothing needs to be 1163 * transform. For transforms that aren't time-varying, nothing needs to be
1145 - * done, returning this is sufficient. 1164 + * done, returning this is sufficient. Time varying transforms should implement this method
  1165 + * and copy enough of their state that projectUpdate can safely be called on the original
  1166 + * instance, and the copy concurrently.
1146 */ 1167 */
1147 virtual Transform * smartCopy() { return this;} 1168 virtual Transform * smartCopy() { return this;}
1148 1169