From bcf2d579ea3e1c7ae9a4acb4fe9265443743751b Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Wed, 16 Jan 2013 15:15:38 -0500 Subject: [PATCH] Added filelist sorting by metadata key --- app/openbr-gui/initialize.cpp | 4 ++-- app/openbr-gui/initialize.h | 2 +- sdk/openbr_plugin.cpp | 34 ++++++++++++++++++++++++++++++++++ sdk/openbr_plugin.h | 4 +++- share/openbr/doc | 2 +- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app/openbr-gui/initialize.cpp b/app/openbr-gui/initialize.cpp index d906bd5..172017b 100644 --- a/app/openbr-gui/initialize.cpp +++ b/app/openbr-gui/initialize.cpp @@ -20,13 +20,13 @@ #include "initialize.h" -void br_initialize_gui() +void br_initialize_gui(const char *sdk_path) { Q_INIT_RESOURCE(icons); qRegisterMetaType("br::File"); qRegisterMetaType("br::FileList"); qRegisterMetaType("br::Template"); qRegisterMetaType("br::TemplateList"); - br_initialize_qt(); + br_initialize_qt(sdk_path); br_set_property("log", qPrintable(QString("%1/log.txt").arg(br_scratch_path()))); } diff --git a/app/openbr-gui/initialize.h b/app/openbr-gui/initialize.h index 4ea19bc..bd895ca 100644 --- a/app/openbr-gui/initialize.h +++ b/app/openbr-gui/initialize.h @@ -19,6 +19,6 @@ #include -BR_EXPORT_GUI void br_initialize_gui(); +BR_EXPORT_GUI void br_initialize_gui(const char *sdk_path = ""); #endif // __INITIALIZE_H diff --git a/sdk/openbr_plugin.cpp b/sdk/openbr_plugin.cpp index a2b6895..18b842d 100644 --- a/sdk/openbr_plugin.cpp +++ b/sdk/openbr_plugin.cpp @@ -26,6 +26,8 @@ #endif // BR_DISTRIBUTED #include +#include + #include "version.h" #include "core/bee.h" #include "core/common.h" @@ -357,6 +359,38 @@ QStringList FileList::names() const return names; } +typedef std::pair metadataPair; +bool comparator( const metadataPair &l, const metadataPair &r) +{ + return l.first < r.first; +} + +void FileList::sort(const QString& key) +{ + std::vector metadata; + + int i = 0; + + foreach (const File &file, *this) + { + metadataPair pair = std::make_pair(file.get(key).toString().toStdString().c_str(), i); + metadata.push_back(pair); + i++; + } + + std::sort(metadata.begin(), metadata.end(), comparator); + + for (int j = 0; j < metadata.size(); j++) + { + this->push_back(this->at(metadata[j].second)); + } + + iterator half = this->begin(); + half += metadata.size(); + + this->erase(this->begin(), half); +} + QList FileList::labels() const { QList labels; diff --git a/sdk/openbr_plugin.h b/sdk/openbr_plugin.h index cd4b27f..7298010 100644 --- a/sdk/openbr_plugin.h +++ b/sdk/openbr_plugin.h @@ -118,7 +118,7 @@ void reset_##NAME() { NAME = DEFAULT; } * --- | ---- | ----------- * path | QString | Resolve complete file paths from file names * enrollAll | bool | Enroll zero or more templates per file - * separator | QString | Sperate #name into multiple files + * separator | QString | Seperate #name into multiple files * Input_Index | int | Index of a template in a template list * Label | float | Classification/Regression class * Confidence | float | Classification/Regression quality @@ -135,6 +135,7 @@ void reset_##NAME() { NAME = DEFAULT; } * Yaw | float | Pose * Landmarks | QList | Landmark list * ROIs | QList | Region Of Interest (ROI) list + * Age | QString | Age used for demographic filtering * _* | * | Reserved for internal use */ struct BR_EXPORT File @@ -239,6 +240,7 @@ struct BR_EXPORT FileList : public QList QStringList flat() const; /*!< \brief Returns br::File::flat() for each file in the list. */ QStringList names() const; /*!< \brief Returns #br::File::name for each file in the list. */ + void sort(const QString& key); /*!< \brief Sort the list based on metadata. */ QList labels() const; /*!< \brief Returns br::File::label() for each file in the list. */ int failures() const; /*!< \brief Returns the number of files with br::File::failed(). */ }; diff --git a/share/openbr/doc b/share/openbr/doc index 504960d..1031e9e 160000 --- a/share/openbr/doc +++ b/share/openbr/doc @@ -1 +1 @@ -Subproject commit 504960df12db25e09c39ab098fb8614c1db51617 +Subproject commit 1031e9e416427f5dd8e9f4e7ff4dd74632626c22 -- libgit2 0.21.4