From 05f05e11e7c8c536a101f029b49917c01907ec36 Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Sun, 13 Jan 2013 12:00:16 -0500 Subject: [PATCH] implemented check of demographic filters prior to matching templates --- sdk/openbr_plugin.cpp | 16 ++++++++++++++++ sdk/openbr_plugin.h | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sdk/openbr_plugin.cpp b/sdk/openbr_plugin.cpp index 8c42988..20685c3 100644 --- a/sdk/openbr_plugin.cpp +++ b/sdk/openbr_plugin.cpp @@ -1238,6 +1238,22 @@ void Distance::compare(const TemplateList &target, const TemplateList &query, Ou if (Globals->parallelism) Globals->trackFutures(futures); } +float Distance::compare(const Template &target, const Template &query) const +{ + if (!Globals->demographicFilters.isEmpty()) { + // The if statement is a faster check then iterating over an empty list of filters + foreach (const QString &filter, Globals->demographicFilters) { + const QString targetMetadata = target.file.getString(filter, ""); + const QString queryMetadata = query.file.getString(filter, ""); + if (targetMetadata.isEmpty() || queryMetadata.isEmpty()) continue; + if (targetMetadata != queryMetadata) return -std::numeric_limits::max(); + } + } + + return a * (_compare(target, query) - b); +} + +/* Distance - private methods */ void Distance::compareBlock(const TemplateList &target, const TemplateList &query, Output *output, int targetOffset, int queryOffset) const { for (int i=0; i fromAlgorithm(const QString &algorithm); /*!< \brief Retrieve an algorithm's distance. */ virtual void train(const TemplateList &src); /*!< \brief Train the distance. */ virtual void compare(const TemplateList &target, const TemplateList &query, Output *output) const; /*!< \brief Compare two template lists. */ - inline float compare(const Template &target, const Template &query) const { return a * (_compare(target, query) - b); } /*!< \brief Compute the normalized distance between two templates. */ + float compare(const Template &target, const Template &query) const; /*!< \brief Compute the normalized distance between two templates. */ private: virtual void compareBlock(const TemplateList &target, const TemplateList &query, Output *output, int targetOffset, int queryOffset) const; -- libgit2 0.21.4