Commit 153fd33cba2201e7bba8a8c94d51d4705fcc8060
Merge pull request #383 from biometrics/filterMetadata
Filter metadata
Showing
1 changed file
with
81 additions
and
0 deletions
openbr/plugins/metadata/filtermetadata.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | + * Copyright 2015 Rank One Computing Corporation * | |
| 3 | + * * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * | |
| 5 | + * you may not use this file except in compliance with the License. * | |
| 6 | + * You may obtain a copy of the License at * | |
| 7 | + * * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * | |
| 9 | + * * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software * | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | |
| 13 | + * See the License for the specific language governing permissions and * | |
| 14 | + * limitations under the License. * | |
| 15 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 16 | + | |
| 17 | +#include <openbr/plugins/openbr_internal.h> | |
| 18 | + | |
| 19 | +namespace br | |
| 20 | +{ | |
| 21 | + | |
| 22 | +/*! | |
| 23 | + * \ingroup transforms | |
| 24 | + * \brief Filters templates such that the only remaining template wills have metadata values witihin the | |
| 25 | + * the specified ranges. | |
| 26 | + * \br_property QString key1,key2 The meta-data key(s) to filter on | |
| 27 | + * \br_property float value1,value2 The values to compare the values of key1 and key2 entires against | |
| 28 | + * \br_property QString compareType1 The comparison operation to perform. "le" -> val(key1) <= value1, "lt" -> val(key1) < value1, | |
| 29 | + * "ge" -> val(key1) >= value1, "gt" -> val(key1) > value1. | |
| 30 | + * \author Brendan Klare \cite bklare | |
| 31 | + */ | |
| 32 | +class FilterMetadataTransform : public UntrainableMetaTransform | |
| 33 | +{ | |
| 34 | + Q_OBJECT | |
| 35 | + Q_PROPERTY(QString key1 READ get_key1 WRITE set_key1 RESET reset_key1 STORED false) | |
| 36 | + Q_PROPERTY(QString compareType1 READ get_compareType1 WRITE set_compareType1 RESET reset_compareType1 STORED false) | |
| 37 | + Q_PROPERTY(float value1 READ get_value1 WRITE set_value1 RESET reset_value1 STORED false) | |
| 38 | + BR_PROPERTY(QString, key1, "") | |
| 39 | + BR_PROPERTY(QString, compareType1, "") | |
| 40 | + BR_PROPERTY(float, value1, 0) | |
| 41 | + | |
| 42 | + bool getCompare(float val1, float val2, QString compareType) const | |
| 43 | + { | |
| 44 | + bool pass = false; | |
| 45 | + if (compareType == "gt") | |
| 46 | + pass = val1 > val2; | |
| 47 | + else if (compareType == "ge") | |
| 48 | + pass = val1 >= val2; | |
| 49 | + else if (compareType == "lt") | |
| 50 | + pass = val1 < val2; | |
| 51 | + else if (compareType == "le") | |
| 52 | + pass = val1 <= val2; | |
| 53 | + else | |
| 54 | + qDebug() << "Unknown compare type: " << compareType; | |
| 55 | + return pass; | |
| 56 | + } | |
| 57 | + | |
| 58 | + void project(const Template &, Template &) const | |
| 59 | + { | |
| 60 | + qFatal("Filter can't do anything here"); | |
| 61 | + } | |
| 62 | + | |
| 63 | + void project(const TemplateList &src, TemplateList &dst) const | |
| 64 | + { | |
| 65 | + foreach (const Template &srcTemp, src) | |
| 66 | + { | |
| 67 | + if (!srcTemp.file.contains(key1)) | |
| 68 | + continue; | |
| 69 | + | |
| 70 | + if (getCompare(srcTemp.file.get<float>(key1), value1, compareType1)) | |
| 71 | + dst.append(srcTemp); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | +}; | |
| 76 | + | |
| 77 | +BR_REGISTER(Transform, FilterMetadataTransform) | |
| 78 | + | |
| 79 | +} // namespace br | |
| 80 | + | |
| 81 | +#include "metadata/filtermetadata.moc" | ... | ... |