| 32 | namespace colmap { |
| 33 | |
| 34 | FeatureMatcherCache::FeatureMatcherCache( |
| 35 | const size_t cache_size, const std::shared_ptr<Database>& database) |
| 36 | : cache_size_(cache_size), |
| 37 | database_(THROW_CHECK_NOTNULL(database)), |
| 38 | descriptor_index_cache_(cache_size_, [this](const image_t image_id) { |
| 39 | auto descriptors = GetDescriptors(image_id); |
| 40 | auto index = FeatureDescriptorIndex::Create(); |
| 41 | index->Build(descriptors->ToFloat()); |
| 42 | return index; |
| 43 | }) { |
| 44 | keypoints_cache_ = |
| 45 | std::make_unique<ThreadSafeLRUCache<image_t, FeatureKeypoints>>( |
| 46 | cache_size_, [this](const image_t image_id) { |
| 47 | std::lock_guard<std::mutex> lock(database_mutex_); |
| 48 | return std::make_shared<FeatureKeypoints>( |
| 49 | database_->ReadKeypoints(image_id)); |
| 50 | }); |
| 51 | |
| 52 | descriptors_cache_ = |
| 53 | std::make_unique<ThreadSafeLRUCache<image_t, FeatureDescriptors>>( |
| 54 | cache_size_, [this](const image_t image_id) { |
| 55 | std::lock_guard<std::mutex> lock(database_mutex_); |
| 56 | return std::make_shared<FeatureDescriptors>( |
| 57 | database_->ReadDescriptors(image_id)); |
| 58 | }); |
| 59 | |
| 60 | keypoints_exists_cache_ = std::make_unique<ThreadSafeLRUCache<image_t, bool>>( |
| 61 | cache_size_, [this](const image_t image_id) { |
| 62 | std::lock_guard<std::mutex> lock(database_mutex_); |
| 63 | return std::make_shared<bool>(database_->ExistsKeypoints(image_id)); |
| 64 | }); |
| 65 | |
| 66 | descriptors_exists_cache_ = |
| 67 | std::make_unique<ThreadSafeLRUCache<image_t, bool>>( |
| 68 | cache_size_, [this](const image_t image_id) { |
| 69 | std::lock_guard<std::mutex> lock(database_mutex_); |
| 70 | return std::make_shared<bool>( |
| 71 | database_->ExistsDescriptors(image_id)); |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | void FeatureMatcherCache::AccessDatabase( |
| 76 | const std::function<void(Database& database)>& func) { |
nothing calls this directly
no test coverage detected