Commit 656823d52267ec9c0425ee01ab09b455ca67c39b
1 parent
4962807c
removed cache transform
Showing
1 changed file
with
0 additions
and
95 deletions
openbr/plugins/core/cache.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 | - | |
| 17 | -#include <openbr/plugins/openbr_internal.h> | |
| 18 | - | |
| 19 | -namespace br | |
| 20 | -{ | |
| 21 | - | |
| 22 | -/*! | |
| 23 | - * \ingroup transforms | |
| 24 | - * \brief Caches Transform::project() results. | |
| 25 | - * \author Josh Klontz \cite jklontz | |
| 26 | - */ | |
| 27 | -class CacheTransform : public MetaTransform | |
| 28 | -{ | |
| 29 | - Q_OBJECT | |
| 30 | - Q_PROPERTY(br::Transform* transform READ get_transform WRITE set_transform RESET reset_transform) | |
| 31 | - BR_PROPERTY(br::Transform*, transform, NULL) | |
| 32 | - | |
| 33 | - static QHash<QString, Template> cache; | |
| 34 | - static QMutex cacheLock; | |
| 35 | - | |
| 36 | -public: | |
| 37 | - ~CacheTransform() | |
| 38 | - { | |
| 39 | - if (cache.isEmpty()) return; | |
| 40 | - | |
| 41 | - // Write to cache | |
| 42 | - QFile file("Cache"); | |
| 43 | - if (!file.open(QFile::WriteOnly)) | |
| 44 | - qFatal("Unable to open %s for writing.", qPrintable(file.fileName())); | |
| 45 | - QDataStream stream(&file); | |
| 46 | - stream << cache; | |
| 47 | - file.close(); | |
| 48 | - } | |
| 49 | - | |
| 50 | -private: | |
| 51 | - void init() | |
| 52 | - { | |
| 53 | - if (!transform) return; | |
| 54 | - | |
| 55 | - trainable = transform->trainable; | |
| 56 | - if (!cache.isEmpty()) return; | |
| 57 | - | |
| 58 | - // Read from cache | |
| 59 | - QFile file("Cache"); | |
| 60 | - if (file.exists()) { | |
| 61 | - if (!file.open(QFile::ReadOnly)) | |
| 62 | - qFatal("Unable to open %s for reading.", qPrintable(file.fileName())); | |
| 63 | - QDataStream stream(&file); | |
| 64 | - stream >> cache; | |
| 65 | - file.close(); | |
| 66 | - } | |
| 67 | - } | |
| 68 | - | |
| 69 | - void train(const QList<TemplateList> &data) | |
| 70 | - { | |
| 71 | - transform->train(data); | |
| 72 | - } | |
| 73 | - | |
| 74 | - void project(const Template &src, Template &dst) const | |
| 75 | - { | |
| 76 | - const QString &file = src.file; | |
| 77 | - if (cache.contains(file)) { | |
| 78 | - dst = cache[file]; | |
| 79 | - } else { | |
| 80 | - transform->project(src, dst); | |
| 81 | - cacheLock.lock(); | |
| 82 | - cache[file] = dst; | |
| 83 | - cacheLock.unlock(); | |
| 84 | - } | |
| 85 | - } | |
| 86 | -}; | |
| 87 | - | |
| 88 | -QHash<QString, Template> CacheTransform::cache; | |
| 89 | -QMutex CacheTransform::cacheLock; | |
| 90 | - | |
| 91 | -BR_REGISTER(Transform, CacheTransform) | |
| 92 | - | |
| 93 | -} // namespace br | |
| 94 | - | |
| 95 | -#include "core/cache.moc" |