Commit 05f05e11e7c8c536a101f029b49917c01907ec36

Authored by Josh Klontz
1 parent 6ddb9821

implemented check of demographic filters prior to matching templates

sdk/openbr_plugin.cpp
... ... @@ -1238,6 +1238,22 @@ void Distance::compare(const TemplateList &target, const TemplateList &query, Ou
1238 1238 if (Globals->parallelism) Globals->trackFutures(futures);
1239 1239 }
1240 1240  
  1241 +float Distance::compare(const Template &target, const Template &query) const
  1242 +{
  1243 + if (!Globals->demographicFilters.isEmpty()) {
  1244 + // The if statement is a faster check then iterating over an empty list of filters
  1245 + foreach (const QString &filter, Globals->demographicFilters) {
  1246 + const QString targetMetadata = target.file.getString(filter, "");
  1247 + const QString queryMetadata = query.file.getString(filter, "");
  1248 + if (targetMetadata.isEmpty() || queryMetadata.isEmpty()) continue;
  1249 + if (targetMetadata != queryMetadata) return -std::numeric_limits<float>::max();
  1250 + }
  1251 + }
  1252 +
  1253 + return a * (_compare(target, query) - b);
  1254 +}
  1255 +
  1256 +/* Distance - private methods */
1241 1257 void Distance::compareBlock(const TemplateList &target, const TemplateList &query, Output *output, int targetOffset, int queryOffset) const
1242 1258 {
1243 1259 for (int i=0; i<query.size(); i++)
... ...
sdk/openbr_plugin.h
... ... @@ -1040,7 +1040,7 @@ public:
1040 1040 static QSharedPointer<Distance> fromAlgorithm(const QString &algorithm); /*!< \brief Retrieve an algorithm's distance. */
1041 1041 virtual void train(const TemplateList &src); /*!< \brief Train the distance. */
1042 1042 virtual void compare(const TemplateList &target, const TemplateList &query, Output *output) const; /*!< \brief Compare two template lists. */
1043   - inline float compare(const Template &target, const Template &query) const { return a * (_compare(target, query) - b); } /*!< \brief Compute the normalized distance between two templates. */
  1043 + float compare(const Template &target, const Template &query) const; /*!< \brief Compute the normalized distance between two templates. */
1044 1044  
1045 1045 private:
1046 1046 virtual void compareBlock(const TemplateList &target, const TemplateList &query, Output *output, int targetOffset, int queryOffset) const;
... ...