ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
option_utils.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 <iostream>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include "base/image_reader.h"
17 #include "feature/extraction.h"
18 #include "feature/matching.h"
19 #include "feature/sift.h"
20 #include "mvs/fusion.h"
21 #include "mvs/meshing.h"
22 #include "mvs/patch_match.h"
24 
25 namespace cloudViewer {
26 
28 public:
29  OptionsParser();
31 
32  void reset();
33 
34  inline bool parseOptions() {
35  return parseOptions(this->argc_, this->argv_);
36  }
37  bool parseOptions(int& argc, char**& argv);
38 
39  inline int getArgc() const { return this->argc_; }
40  inline char** getArgv() { return this->argv_; }
41 
42  template <typename T>
43  void registerOption(const std::string& name, const T* option) {
44  if (std::is_same<T, bool>::value) {
45  options_bool_.emplace_back(name,
46  reinterpret_cast<const bool*>(option));
47  } else if (std::is_same<T, int>::value) {
48  options_int_.emplace_back(name,
49  reinterpret_cast<const int*>(option));
50  } else if (std::is_same<T, double>::value) {
51  options_double_.emplace_back(
52  name, reinterpret_cast<const double*>(option));
53  } else if (std::is_same<T, std::string>::value) {
54  if (!reinterpret_cast<const std::string*>(option)->empty()) {
55  options_string_.emplace_back(
56  name, reinterpret_cast<const std::string*>(option));
57  }
58  } else {
59  std::cerr << "Unsupported option type" << std::endl;
60  }
61  }
62 
63  // colmap
65  const colmap::ImageReaderOptions& image_reader_options,
66  const colmap::SiftExtractionOptions& sift_extraction_options);
67 
68  void addMatchingOptions(
69  const colmap::SiftMatchingOptions& sift_matching_options);
70 
72  const colmap::SiftMatchingOptions& sift_matching_options,
74  exhaustive_matching_options);
75 
77  const colmap::SiftMatchingOptions& sift_matching_options,
79  sequential_matching_options);
80 
82  const colmap::SiftMatchingOptions& sift_matching_options,
83  const colmap::SpatialMatchingOptions& spatial_matching_options);
84 
86  const colmap::SiftMatchingOptions& sift_matching_options,
88  transitive_matching_options);
89 
91  const colmap::SiftMatchingOptions& sift_matching_options,
93  vocab_tree_matching_options);
94 
96  const colmap::SiftMatchingOptions& sift_matching_options,
98  image_pairs_matching_options);
99 
100  void addMapperOptions(
101  const colmap::IncrementalMapperOptions& incremental_mapper_options);
102 
104  const colmap::BundleAdjustmentOptions& bundle_adjustment_options);
105 
106  // colmap::mvs
108  const colmap::mvs::PatchMatchOptions& patch_match_options);
110  const colmap::mvs::StereoFusionOptions& stereo_fusion_options);
112  const colmap::mvs::PoissonMeshingOptions& poisson_meshing_options);
114  delaunay_meshing_options);
115 
116 public:
117  static void ReleaseOptions(int argc, char** argv) {
118  if (argv) {
119  for (int i = 0; i < argc; ++i) {
120  if (argv[i]) {
121  delete[] argv[i];
122  }
123  }
124  argv = nullptr;
125  }
126  }
127 
128  static void SetValue(const std::string& value, int argc_, char** argv_) {
129  argv_[argc_] = new char[value.size() + 1];
130  std::copy(value.begin(), value.end(), argv_[argc_]);
131  argv_[argc_][value.size()] = '\0'; // don't forget the terminating 0
132  }
133 
134 private:
135  inline void releaseOptions() {
136  if (this->argc_ > 0 && this->argv_) {
137  ReleaseOptions(this->argc_, this->argv_);
138  }
139  this->argc_ = 0;
140  }
141 
142  inline unsigned long getParametersCount() {
143  return static_cast<unsigned long>(
144  options_int_.size() + options_bool_.size() +
145  options_double_.size() + options_string_.size());
146  }
147 
148 private:
149  int argc_;
150  char** argv_;
151  std::vector<std::pair<std::string, const bool*>> options_bool_;
152  std::vector<std::pair<std::string, const int*>> options_int_;
153  std::vector<std::pair<std::string, const double*>> options_double_;
154  std::vector<std::pair<std::string, const std::string*>> options_string_;
155 };
156 
157 } // namespace cloudViewer
std::string name
bool copy
Definition: VtkUtils.cpp:74
void addDelaunayMeshingOptions(const colmap::mvs::DelaunayMeshingOptions &delaunay_meshing_options)
static void ReleaseOptions(int argc, char **argv)
Definition: option_utils.h:117
void addBundleAdjustmentOptions(const colmap::BundleAdjustmentOptions &bundle_adjustment_options)
void addExtractionOptions(const colmap::ImageReaderOptions &image_reader_options, const colmap::SiftExtractionOptions &sift_extraction_options)
void addStereoFusionOptions(const colmap::mvs::StereoFusionOptions &stereo_fusion_options)
void addSequentialMatchingOptions(const colmap::SiftMatchingOptions &sift_matching_options, const colmap::SequentialMatchingOptions &sequential_matching_options)
void addMapperOptions(const colmap::IncrementalMapperOptions &incremental_mapper_options)
void addImagePairsMatchingOptions(const colmap::SiftMatchingOptions &sift_matching_options, const colmap::ImagePairsMatchingOptions &image_pairs_matching_options)
void addExhaustiveMatchingOptions(const colmap::SiftMatchingOptions &sift_matching_options, const colmap::ExhaustiveMatchingOptions &exhaustive_matching_options)
void addPoissonMeshingOptions(const colmap::mvs::PoissonMeshingOptions &poisson_meshing_options)
void registerOption(const std::string &name, const T *option)
Definition: option_utils.h:43
void addVocabTreeMatchingOptions(const colmap::SiftMatchingOptions &sift_matching_options, const colmap::VocabTreeMatchingOptions &vocab_tree_matching_options)
void addSpatialMatchingOptions(const colmap::SiftMatchingOptions &sift_matching_options, const colmap::SpatialMatchingOptions &spatial_matching_options)
void addTransitiveMatchingOptions(const colmap::SiftMatchingOptions &sift_matching_options, const colmap::TransitiveMatchingOptions &transitive_matching_options)
static void SetValue(const std::string &value, int argc_, char **argv_)
Definition: option_utils.h:128
void addMatchingOptions(const colmap::SiftMatchingOptions &sift_matching_options)
void addPatchMatchStereoOptions(const colmap::mvs::PatchMatchOptions &patch_match_options)
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
Generic file read and write utility for python interface.