ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
option_manager.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 <boost/program_options.hpp>
11 #include <memory>
12 
13 #include "util/logging.h"
14 
15 namespace colmap {
16 
17 struct ImageReaderOptions;
18 struct SiftExtractionOptions;
19 struct SiftMatchingOptions;
20 struct ExhaustiveMatchingOptions;
21 struct SequentialMatchingOptions;
22 struct VocabTreeMatchingOptions;
23 struct SpatialMatchingOptions;
24 struct TransitiveMatchingOptions;
25 struct ImagePairsMatchingOptions;
26 struct BundleAdjustmentOptions;
28 struct TexturingOptions;
29 struct RenderOptions;
30 
31 namespace mvs {
32 struct PatchMatchOptions;
33 struct StereoFusionOptions;
34 struct PoissonMeshingOptions;
35 struct DelaunayMeshingOptions;
36 } // namespace mvs
37 
39 public:
40  OptionManager(bool add_project_options = true);
41 
42  // Create "optimal" set of options for different reconstruction scenarios.
43  // Note that the existing options are modified, so if your parameters are
44  // already low quality, they will be further modified.
46  void ModifyForVideoData();
47  void ModifyForInternetData();
48 
49  // Create "optimal" set of options for different quality settings.
50  // Note that the existing options are modified, so if your parameters are
51  // already low quality, they will be further degraded.
52  void ModifyForLowQuality();
54  void ModifyForHighQuality();
56 
57  void AddAllOptions();
58  void AddLogOptions();
59  void AddRandomOptions();
60  void AddDatabaseOptions();
61  void AddImageOptions();
62  void AddExtractionOptions();
63  void AddMatchingOptions();
71  void AddMapperOptions();
76  void AddTexturingOptions();
77  void AddRenderOptions();
78 
79  template <typename T>
80  void AddRequiredOption(const std::string& name,
81  T* option,
82  const std::string& help_text = "");
83  template <typename T>
84  void AddDefaultOption(const std::string& name,
85  T* option,
86  const std::string& help_text = "");
87 
88  void Reset();
89  void ResetOptions(const bool reset_paths);
90 
91  bool Check();
92 
93  void Parse(const int argc, char** argv);
94  bool Read(const std::string& path);
95  bool ReRead(const std::string& path);
96  void Write(const std::string& path) const;
97 
98  std::shared_ptr<std::string> project_path;
99  std::shared_ptr<std::string> database_path;
100  std::shared_ptr<std::string> image_path;
101 
102  std::shared_ptr<ImageReaderOptions> image_reader;
103  std::shared_ptr<SiftExtractionOptions> sift_extraction;
104 
105  std::shared_ptr<SiftMatchingOptions> sift_matching;
106  std::shared_ptr<ExhaustiveMatchingOptions> exhaustive_matching;
107  std::shared_ptr<SequentialMatchingOptions> sequential_matching;
108  std::shared_ptr<VocabTreeMatchingOptions> vocab_tree_matching;
109  std::shared_ptr<SpatialMatchingOptions> spatial_matching;
110  std::shared_ptr<TransitiveMatchingOptions> transitive_matching;
111  std::shared_ptr<ImagePairsMatchingOptions> image_pairs_matching;
112 
113  std::shared_ptr<BundleAdjustmentOptions> bundle_adjustment;
114  std::shared_ptr<IncrementalMapperOptions> mapper;
115 
116  std::shared_ptr<mvs::PatchMatchOptions> patch_match_stereo;
117  std::shared_ptr<mvs::StereoFusionOptions> stereo_fusion;
118  std::shared_ptr<mvs::PoissonMeshingOptions> poisson_meshing;
119  std::shared_ptr<mvs::DelaunayMeshingOptions> delaunay_meshing;
120  std::shared_ptr<TexturingOptions> texturing;
121 
122  std::shared_ptr<RenderOptions> render;
123 
124 private:
125  template <typename T>
126  void AddAndRegisterRequiredOption(const std::string& name,
127  T* option,
128  const std::string& help_text = "");
129  template <typename T>
130  void AddAndRegisterDefaultOption(const std::string& name,
131  T* option,
132  const std::string& help_text = "");
133 
134  template <typename T>
135  void RegisterOption(const std::string& name, const T* option);
136 
137  std::shared_ptr<boost::program_options::options_description> desc_;
138 
139  std::vector<std::pair<std::string, const bool*>> options_bool_;
140  std::vector<std::pair<std::string, const int*>> options_int_;
141  std::vector<std::pair<std::string, const double*>> options_double_;
142  std::vector<std::pair<std::string, const std::string*>> options_string_;
143 
144  bool added_log_options_;
145  bool added_random_options_;
146  bool added_database_options_;
147  bool added_image_options_;
148  bool added_extraction_options_;
149  bool added_match_options_;
150  bool added_exhaustive_match_options_;
151  bool added_sequential_match_options_;
152  bool added_vocab_tree_match_options_;
153  bool added_spatial_match_options_;
154  bool added_transitive_match_options_;
155  bool added_image_pairs_match_options_;
156  bool added_ba_options_;
157  bool added_mapper_options_;
158  bool added_patch_match_stereo_options_;
159  bool added_stereo_fusion_options_;
160  bool added_poisson_meshing_options_;
161  bool added_delaunay_meshing_options_;
162  bool added_texturing_options_;
163  bool added_render_options_;
164 };
165 
167 // Implementation
169 
170 template <typename T>
171 void OptionManager::AddRequiredOption(const std::string& name,
172  T* option,
173  const std::string& help_text) {
174  desc_->add_options()(name.c_str(),
175  boost::program_options::value<T>(option)->required(),
176  help_text.c_str());
177 }
178 
179 template <typename T>
180 void OptionManager::AddDefaultOption(const std::string& name,
181  T* option,
182  const std::string& help_text) {
183  desc_->add_options()(
184  name.c_str(),
185  boost::program_options::value<T>(option)->default_value(*option),
186  help_text.c_str());
187 }
188 
189 template <typename T>
190 void OptionManager::AddAndRegisterRequiredOption(const std::string& name,
191  T* option,
192  const std::string& help_text) {
193  desc_->add_options()(name.c_str(),
194  boost::program_options::value<T>(option)->required(),
195  help_text.c_str());
196  RegisterOption(name, option);
197 }
198 
199 template <typename T>
200 void OptionManager::AddAndRegisterDefaultOption(const std::string& name,
201  T* option,
202  const std::string& help_text) {
203  desc_->add_options()(
204  name.c_str(),
205  boost::program_options::value<T>(option)->default_value(*option),
206  help_text.c_str());
207  RegisterOption(name, option);
208 }
209 
210 template <typename T>
211 void OptionManager::RegisterOption(const std::string& name, const T* option) {
212  if (std::is_same<T, bool>::value) {
213  options_bool_.emplace_back(name, reinterpret_cast<const bool*>(option));
214  } else if (std::is_same<T, int>::value) {
215  options_int_.emplace_back(name, reinterpret_cast<const int*>(option));
216  } else if (std::is_same<T, double>::value) {
217  options_double_.emplace_back(name,
218  reinterpret_cast<const double*>(option));
219  } else if (std::is_same<T, std::string>::value) {
220  options_string_.emplace_back(
221  name, reinterpret_cast<const std::string*>(option));
222  } else {
223  LOG(FATAL) << "Unsupported option type";
224  }
225 }
226 
227 } // namespace colmap
std::string name
std::shared_ptr< SequentialMatchingOptions > sequential_matching
std::shared_ptr< TransitiveMatchingOptions > transitive_matching
void AddRequiredOption(const std::string &name, T *option, const std::string &help_text="")
OptionManager(bool add_project_options=true)
std::shared_ptr< mvs::PoissonMeshingOptions > poisson_meshing
std::shared_ptr< mvs::DelaunayMeshingOptions > delaunay_meshing
std::shared_ptr< TexturingOptions > texturing
bool Read(const std::string &path)
bool ReRead(const std::string &path)
std::shared_ptr< mvs::PatchMatchOptions > patch_match_stereo
std::shared_ptr< RenderOptions > render
void AddDefaultOption(const std::string &name, T *option, const std::string &help_text="")
std::shared_ptr< std::string > database_path
std::shared_ptr< mvs::StereoFusionOptions > stereo_fusion
std::shared_ptr< SiftMatchingOptions > sift_matching
std::shared_ptr< BundleAdjustmentOptions > bundle_adjustment
std::shared_ptr< IncrementalMapperOptions > mapper
void ResetOptions(const bool reset_paths)
std::shared_ptr< std::string > project_path
void Write(const std::string &path) const
std::shared_ptr< SiftExtractionOptions > sift_extraction
std::shared_ptr< ImageReaderOptions > image_reader
std::shared_ptr< VocabTreeMatchingOptions > vocab_tree_matching
void Parse(const int argc, char **argv)
std::shared_ptr< ExhaustiveMatchingOptions > exhaustive_matching
std::shared_ptr< SpatialMatchingOptions > spatial_matching
std::shared_ptr< ImagePairsMatchingOptions > image_pairs_matching
std::shared_ptr< std::string > image_path
static const std::string path
Definition: PointCloud.cpp:59
colmap::IncrementalMapperOptions IncrementalMapperOptions
colmap::RenderOptions RenderOptions