| 60 | } |
| 61 | |
| 62 | void Workspace::Load(const std::vector<std::string>& image_names) { |
| 63 | const size_t num_images = model_.images.size(); |
| 64 | bitmaps_.resize(num_images); |
| 65 | depth_maps_.resize(num_images); |
| 66 | normal_maps_.resize(num_images); |
| 67 | |
| 68 | auto LoadWorkspaceData = [&, this](const int image_idx) { |
| 69 | const size_t width = model_.images.at(image_idx).GetWidth(); |
| 70 | const size_t height = model_.images.at(image_idx).GetHeight(); |
| 71 | |
| 72 | // Read and rescale bitmap |
| 73 | auto bitmap = std::make_unique<Bitmap>(); |
| 74 | bitmap->Read(GetBitmapPath(image_idx), options_.image_as_rgb); |
| 75 | if (bitmap->Width() != static_cast<int>(width) || |
| 76 | bitmap->Height() != static_cast<int>(height)) { |
| 77 | bitmap->Rescale(static_cast<int>(width), static_cast<int>(height)); |
| 78 | } |
| 79 | bitmaps_[image_idx] = std::move(bitmap); |
| 80 | |
| 81 | // Read and rescale depth map |
| 82 | auto depth_map = std::make_unique<DepthMap>(); |
| 83 | depth_map->Read(GetDepthMapPath(image_idx)); |
| 84 | if (depth_map->GetWidth() != width || depth_map->GetHeight() != height) { |
| 85 | depth_map->Downsize(width, height); |
| 86 | } |
| 87 | depth_maps_[image_idx] = std::move(depth_map); |
| 88 | |
| 89 | // Read and rescale normal map |
| 90 | auto normal_map = std::make_unique<NormalMap>(); |
| 91 | normal_map->Read(GetNormalMapPath(image_idx)); |
| 92 | if (normal_map->GetWidth() != width || normal_map->GetHeight() != height) { |
| 93 | normal_map->Downsize(width, height); |
| 94 | } |
| 95 | normal_maps_[image_idx] = std::move(normal_map); |
| 96 | }; |
| 97 | |
| 98 | const int num_threads = GetEffectiveNumThreads(options_.num_threads); |
| 99 | ThreadPool thread_pool(num_threads); |
| 100 | Timer timer; |
| 101 | timer.Start(); |
| 102 | |
| 103 | LOG(INFO) << StringPrintf("Loading workspace data with %d threads...", |
| 104 | num_threads); |
| 105 | for (size_t i = 0; i < image_names.size(); ++i) { |
| 106 | const int image_idx = model_.GetImageIdx(image_names[i]); |
| 107 | if (HasBitmap(image_idx) && HasDepthMap(image_idx)) { |
| 108 | thread_pool.AddTask(LoadWorkspaceData, image_idx); |
| 109 | } else { |
| 110 | LOG(WARNING) << StringPrintf( |
| 111 | "Ignoring image %s, because input does not exist.", |
| 112 | image_names[i].c_str()); |
| 113 | } |
| 114 | } |
| 115 | thread_pool.Wait(); |
| 116 | timer.PrintMinutes(); |
| 117 | } |
| 118 | |
| 119 | const Bitmap& Workspace::GetBitmap(const int image_idx) { |