ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
workspace.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include "mvs/consistency_graph.h"
11 #include "mvs/depth_map.h"
12 #include "mvs/model.h"
13 #include "mvs/normal_map.h"
14 #include "util/bitmap.h"
15 #include "util/cache.h"
16 #include "util/misc.h"
17 
18 namespace colmap {
19 namespace mvs {
20 
21 class Workspace {
22 public:
23  struct Options {
24  // The maximum cache size in gigabytes.
25  double cache_size = 32.0;
26 
27  // The number of threads to use when pre-loading workspace.
28  int num_threads = -1;
29 
30  // Maximum image size in either dimension.
31  int max_image_size = -1;
32 
33  // Whether to read image as RGB or gray scale.
34  bool image_as_rgb = true;
35 
36  // Location and type of workspace.
37  std::string workspace_path;
38  std::string workspace_format;
39  std::string input_type;
40  std::string stereo_folder = "stereo";
41  };
42 
43  Workspace(const Options& options);
44 
45  // Do nothing when we use a cache. Data is loaded as needed.
46  virtual void Load(const std::vector<std::string>& image_names);
47 
48  inline const Options& GetOptions() const { return options_; }
49 
50  inline const Model& GetModel() const { return model_; }
51 
52  virtual const Bitmap& GetBitmap(const int image_idx);
53  virtual const DepthMap& GetDepthMap(const int image_idx);
54  virtual const NormalMap& GetNormalMap(const int image_idx);
55 
56  // Get paths to bitmap, depth map, normal map and consistency graph.
57  std::string GetBitmapPath(const int image_idx) const;
58  std::string GetDepthMapPath(const int image_idx) const;
59  std::string GetNormalMapPath(const int image_idx) const;
60 
61  // Return whether bitmap, depth map, normal map, and consistency graph
62  // exist.
63  bool HasBitmap(const int image_idx) const;
64  bool HasDepthMap(const int image_idx) const;
65  bool HasNormalMap(const int image_idx) const;
66 
67 protected:
68  std::string GetFileName(const int image_idx) const;
69 
72 
73 private:
74  std::string depth_map_path_;
75  std::string normal_map_path_;
76  std::vector<std::unique_ptr<Bitmap>> bitmaps_;
77  std::vector<std::unique_ptr<DepthMap>> depth_maps_;
78  std::vector<std::unique_ptr<NormalMap>> normal_maps_;
79 };
80 
81 class CachedWorkspace : public Workspace {
82 public:
83  CachedWorkspace(const Options& options);
84 
85  void Load(const std::vector<std::string>& image_names) override {}
86 
87  inline void ClearCache() { cache_.Clear(); }
88 
89  const Bitmap& GetBitmap(const int image_idx) override;
90  const DepthMap& GetDepthMap(const int image_idx) override;
91  const NormalMap& GetNormalMap(const int image_idx) override;
92 
93 private:
94  class CachedImage {
95  public:
96  CachedImage() {}
97  CachedImage(CachedImage&& other);
98  CachedImage& operator=(CachedImage&& other);
99  inline size_t NumBytes() const { return num_bytes; }
100  size_t num_bytes = 0;
101  std::mutex mutex;
102  std::unique_ptr<Bitmap> bitmap;
103  std::unique_ptr<DepthMap> depth_map;
104  std::unique_ptr<NormalMap> normal_map;
105 
106  private:
107  NON_COPYABLE(CachedImage)
108  };
109 
110  MemoryConstrainedLRUCache<int, CachedImage> cache_;
111 };
112 
113 // Import a PMVS workspace into the COLMAP workspace format. Only images in the
114 // provided option file name will be imported and used for reconstruction.
115 void ImportPMVSWorkspace(const Workspace& workspace,
116  const std::string& option_name);
117 
118 } // namespace mvs
119 } // namespace colmap
const Bitmap & GetBitmap(const int image_idx) override
Definition: workspace.cc:178
const DepthMap & GetDepthMap(const int image_idx) override
Definition: workspace.cc:194
CachedWorkspace(const Options &options)
Definition: workspace.cc:173
void Load(const std::vector< std::string > &image_names) override
Definition: workspace.h:85
const NormalMap & GetNormalMap(const int image_idx) override
Definition: workspace.cc:210
std::string GetFileName(const int image_idx) const
Definition: workspace.cc:57
virtual const NormalMap & GetNormalMap(const int image_idx)
Definition: workspace.cc:127
const Options & GetOptions() const
Definition: workspace.h:48
virtual const DepthMap & GetDepthMap(const int image_idx)
Definition: workspace.cc:123
virtual void Load(const std::vector< std::string > &image_names)
Definition: workspace.cc:63
std::string GetDepthMapPath(const int image_idx) const
Definition: workspace.cc:135
bool HasBitmap(const int image_idx) const
Definition: workspace.cc:143
Workspace(const Options &options)
Definition: workspace.cc:41
bool HasNormalMap(const int image_idx) const
Definition: workspace.cc:151
const Model & GetModel() const
Definition: workspace.h:50
bool HasDepthMap(const int image_idx) const
Definition: workspace.cc:147
std::string GetBitmapPath(const int image_idx) const
Definition: workspace.cc:131
virtual const Bitmap & GetBitmap(const int image_idx)
Definition: workspace.cc:119
std::string GetNormalMapPath(const int image_idx) const
Definition: workspace.cc:139
void ImportPMVSWorkspace(const Workspace &workspace, const std::string &option_name)
Definition: workspace.cc:227
#define NON_COPYABLE(class_name)
Definition: types.h:30