Commit 8f693acfabc33c369e600f2dee199c8549e42440
1 parent
a9423b01
remove tail
Showing
1 changed file
with
0 additions
and
115 deletions
openbr/plugins/output/tail.cpp deleted
| 1 | -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | - * Copyright 2012 The MITRE 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 | -#include <openbr/plugins/openbr_internal.h> | |
| 17 | - | |
| 18 | -#include <openbr/core/qtutils.h> | |
| 19 | - | |
| 20 | -namespace br | |
| 21 | -{ | |
| 22 | - | |
| 23 | -/*! | |
| 24 | - * \ingroup outputs | |
| 25 | - * \brief The highest scoring matches. | |
| 26 | - * \author Josh Klontz \cite jklontz | |
| 27 | - */ | |
| 28 | -class tailOutput : public Output | |
| 29 | -{ | |
| 30 | - Q_OBJECT | |
| 31 | - | |
| 32 | - struct Comparison | |
| 33 | - { | |
| 34 | - br::File query, target; | |
| 35 | - float value; | |
| 36 | - | |
| 37 | - Comparison(const br::File &_query, const br::File &_target, float _value) | |
| 38 | - : query(_query), target(_target), value(_value) {} | |
| 39 | - | |
| 40 | - QString toString(bool args) const | |
| 41 | - { | |
| 42 | - return QString::number(value) + "," + (args ? target.flat() : (QString)target) + "," + (args ? query.flat() : (QString)query); | |
| 43 | - } | |
| 44 | - | |
| 45 | - bool operator<(const Comparison &other) const | |
| 46 | - { | |
| 47 | - return value < other.value; | |
| 48 | - } | |
| 49 | - }; | |
| 50 | - | |
| 51 | - float threshold; | |
| 52 | - int atLeast, atMost; | |
| 53 | - bool args; | |
| 54 | - float lastValue; | |
| 55 | - QList<Comparison> comparisons; | |
| 56 | - QMutex comparisonsLock; | |
| 57 | - | |
| 58 | - ~tailOutput() | |
| 59 | - { | |
| 60 | - if (file.isNull() || comparisons.isEmpty()) return; | |
| 61 | - QStringList lines; lines.reserve(comparisons.size()+1); | |
| 62 | - lines.append("Value,Target,Query"); | |
| 63 | - foreach (const Comparison &duplicate, comparisons) | |
| 64 | - lines.append(duplicate.toString(args)); | |
| 65 | - QtUtils::writeFile(file, lines); | |
| 66 | - } | |
| 67 | - | |
| 68 | - void initialize(const FileList &targetFiles, const FileList &queryFiles) | |
| 69 | - { | |
| 70 | - Output::initialize(targetFiles, queryFiles); | |
| 71 | - threshold = file.get<float>("threshold", -std::numeric_limits<float>::max()); | |
| 72 | - atLeast = file.get<int>("atLeast", 1); | |
| 73 | - atMost = file.get<int>("atMost", std::numeric_limits<int>::max()); | |
| 74 | - args = file.get<bool>("args", false); | |
| 75 | - lastValue = -std::numeric_limits<float>::max(); | |
| 76 | - } | |
| 77 | - | |
| 78 | - void set(float value, int i, int j) | |
| 79 | - { | |
| 80 | - // Return early for self similar matrices | |
| 81 | - if (selfSimilar && (i <= j)) return; | |
| 82 | - | |
| 83 | - // Consider only values passing the criteria | |
| 84 | - if ((value < threshold) && (value <= lastValue) && (comparisons.size() >= atLeast)) | |
| 85 | - return; | |
| 86 | - | |
| 87 | - comparisonsLock.lock(); | |
| 88 | - if (comparisons.isEmpty() || (value < comparisons.last().value)) { | |
| 89 | - // Special cases | |
| 90 | - comparisons.append(Comparison(queryFiles[i], targetFiles[j], value)); | |
| 91 | - } else { | |
| 92 | - // General case | |
| 93 | - for (int k=0; k<comparisons.size(); k++) { | |
| 94 | - if (comparisons[k].value <= value) { | |
| 95 | - comparisons.insert(k, Comparison(queryFiles[i], targetFiles[j], value)); | |
| 96 | - break; | |
| 97 | - } | |
| 98 | - } | |
| 99 | - } | |
| 100 | - | |
| 101 | - while (comparisons.size() > atMost) | |
| 102 | - comparisons.removeLast(); | |
| 103 | - while ((comparisons.size() > atLeast) && (comparisons.last().value < threshold)) | |
| 104 | - comparisons.removeLast(); | |
| 105 | - | |
| 106 | - lastValue = comparisons.last().value; | |
| 107 | - comparisonsLock.unlock(); | |
| 108 | - } | |
| 109 | -}; | |
| 110 | - | |
| 111 | -BR_REGISTER(Output, tailOutput) | |
| 112 | - | |
| 113 | -} // namespace br | |
| 114 | - | |
| 115 | -#include "output/tail.moc" |