65 bitmaps_.resize(num_images);
66 depth_maps_.resize(num_images);
67 normal_maps_.resize(num_images);
69 auto LoadWorkspaceData = [&,
this](
const int image_idx) {
74 bitmaps_[image_idx].reset(
new Bitmap());
77 bitmaps_[image_idx]->Rescale((
int)
width, (int)
height);
81 depth_maps_[image_idx].reset(
new DepthMap());
88 normal_maps_[image_idx].reset(
new NormalMap());
100 std::cout <<
StringPrintf(
"Loading workspace data with %d threads...",
103 for (
size_t i = 0; i < image_names.size(); ++i) {
106 thread_pool.
AddTask(LoadWorkspaceData, image_idx);
110 "WARNING: Ignoring image %s, because input does not exist.",
111 image_names[i].c_str())
120 return *bitmaps_[image_idx];
124 return *depth_maps_[image_idx];
128 return *normal_maps_[image_idx];
155 CachedWorkspace::CachedImage::CachedImage(CachedImage&& other) {
156 num_bytes = other.num_bytes;
157 bitmap = std::move(other.bitmap);
158 depth_map = std::move(other.depth_map);
159 normal_map = std::move(other.normal_map);
162 CachedWorkspace::CachedImage& CachedWorkspace::CachedImage::operator=(
163 CachedImage&& other) {
164 if (
this != &other) {
165 num_bytes = other.num_bytes;
166 bitmap = std::move(other.bitmap);
167 depth_map = std::move(other.depth_map);
168 normal_map = std::move(other.normal_map);
175 cache_((size_t)(1024.0 * 1024.0 * 1024.0 * options.cache_size),
176 [](const int) {
return std::make_shared<CachedImage>(); }) {}
179 auto cached_image = cache_.
Get(image_idx);
180 std::lock_guard<std::mutex> lock(cached_image->mutex);
181 if (!cached_image->bitmap) {
182 cached_image->bitmap = std::make_unique<Bitmap>();
185 cached_image->bitmap->Rescale(
model_.
images.at(image_idx).GetWidth(),
188 cached_image->num_bytes += cached_image->bitmap->NumBytes();
191 return *cached_image->bitmap;
195 auto cached_image = cache_.
Get(image_idx);
196 std::lock_guard<std::mutex> lock(cached_image->mutex);
197 if (!cached_image->depth_map) {
198 cached_image->depth_map = std::make_unique<DepthMap>();
201 cached_image->depth_map->Downsize(
model_.
images.at(image_idx).GetWidth(),
204 cached_image->num_bytes += cached_image->depth_map->GetNumBytes();
207 return *cached_image->depth_map;
211 auto cached_image = cache_.
Get(image_idx);
212 std::lock_guard<std::mutex> lock(cached_image->mutex);
213 if (!cached_image->normal_map) {
214 cached_image->normal_map = std::make_unique<NormalMap>();
217 cached_image->normal_map->Downsize(
221 cached_image->num_bytes += cached_image->normal_map->GetNumBytes();
224 return *cached_image->normal_map;
228 const std::string& option_name) {
236 JoinPaths(workspace_path, stereo_folder,
"consistency_graphs"));
238 const auto option_lines =
240 for (
const auto& line : option_lines) {
246 int num_images = std::stoull(elems[1]);
248 std::vector<int> image_idxs;
249 if (num_images == -1) {
250 CHECK_EQ(elems.size(), 4);
251 const int range_lower = std::stoull(elems[2]);
252 const int range_upper = std::stoull(elems[3]);
253 CHECK_LT(range_lower, range_upper);
254 num_images = range_upper - range_lower;
255 image_idxs.resize(num_images);
256 std::iota(image_idxs.begin(), image_idxs.end(), range_lower);
258 CHECK_EQ(num_images + 2, elems.size());
259 image_idxs.reserve(num_images);
260 for (
size_t i = 2; i < elems.size(); ++i) {
261 const int image_idx = std::stoull(elems[i]);
262 image_idxs.push_back(image_idx);
266 std::vector<std::string> image_names;
267 image_names.reserve(num_images);
268 for (
const auto image_idx : image_idxs) {
269 const std::string image_name =
271 image_names.push_back(image_name);
274 const auto& overlapping_images =
277 const auto patch_match_path =
278 JoinPaths(workspace_path, stereo_folder,
"patch-match.cfg");
279 const auto fusion_path =
280 JoinPaths(workspace_path, stereo_folder,
"fusion.cfg");
281 std::ofstream patch_match_file(patch_match_path, std::ios::trunc);
282 std::ofstream fusion_file(fusion_path, std::ios::trunc);
283 CHECK(patch_match_file.is_open()) << patch_match_path;
284 CHECK(fusion_file.is_open()) << fusion_path;
285 for (
size_t i = 0; i < image_names.size(); ++i) {
286 const auto& ref_image_name = image_names[i];
287 patch_match_file << ref_image_name <<
std::endl;
288 if (overlapping_images.empty()) {
289 patch_match_file <<
"__auto__, 20" <<
std::endl;
291 for (
const int image_idx : overlapping_images[i]) {
297 fusion_file << ref_image_name <<
std::endl;
std::shared_ptr< core::Tensor > image
std::shared_ptr< value_t > Get(const key_t &key)
void UpdateNumBytes(const key_t &key)
auto AddTask(func_t &&f, args_t &&... args) -> std::future< typename std::result_of< func_t(args_t...)>::type >
void PrintMinutes() const
const Bitmap & GetBitmap(const int image_idx) override
const DepthMap & GetDepthMap(const int image_idx) override
CachedWorkspace(const Options &options)
const NormalMap & GetNormalMap(const int image_idx) override
std::string GetFileName(const int image_idx) const
virtual const NormalMap & GetNormalMap(const int image_idx)
const Options & GetOptions() const
virtual const DepthMap & GetDepthMap(const int image_idx)
virtual void Load(const std::vector< std::string > &image_names)
std::string GetDepthMapPath(const int image_idx) const
bool HasBitmap(const int image_idx) const
Workspace(const Options &options)
bool HasNormalMap(const int image_idx) const
const Model & GetModel() const
bool HasDepthMap(const int image_idx) const
std::string GetBitmapPath(const int image_idx) const
virtual const Bitmap & GetBitmap(const int image_idx)
std::string GetNormalMapPath(const int image_idx) const
QTextStream & endl(QTextStream &stream)
void ImportPMVSWorkspace(const Workspace &workspace, const std::string &option_name)
bool StringStartsWith(const std::string &str, const std::string &prefix)
void StringToLower(std::string *str)
std::vector< std::string > ReadTextFileLines(const std::string &path)
bool ExistsFile(const std::string &path)
void CreateDirIfNotExists(const std::string &path)
std::string JoinPaths(T const &... paths)
std::string EnsureTrailingSlash(const std::string &str)
std::vector< std::string > StringSplit(const std::string &str, const std::string &delim)
std::string StringPrintf(const char *format,...)
int GetEffectiveNumThreads(const int num_threads)
std::string GetImageName(const int image_idx) const
int GetImageIdx(const std::string &name) const
std::vector< Image > images
void Read(const std::string &path, const std::string &format)
const std::vector< std::vector< int > > & GetMaxOverlappingImagesFromPMVS() const
std::string workspace_format
std::string stereo_folder
std::string workspace_path