ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
model.cpp
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 #include "exe/model.h"
9 
10 #include "pipelines/model.h"
11 #include "pipelines/option_utils.h"
12 
13 namespace cloudViewer {
14 
15 int AlignModel(const std::string& input_path,
16  const std::string& output_path,
17  const std::string& database_path /*= ""*/,
18  const std::string& ref_images_path /*= ""*/,
19  const std::string& transform_path /*= ""*/,
20  const std::string& alignment_type /*= "plane"*/,
21  double max_error /* = 0.0*/,
22  int min_common_images /*= 3*/,
23  bool robust_alignment /*= true*/,
24  bool estimate_scale /*= true*/) {
25  OptionsParser parser;
26  parser.registerOption("database_path", &database_path);
27  parser.registerOption("input_path", &input_path);
28  parser.registerOption("output_path", &output_path);
29  parser.registerOption("ref_images_path", &ref_images_path);
30  parser.registerOption("transform_path", &transform_path);
31  // supported {plane, ecef, enu, enu-unscaled, custom}
32  parser.registerOption("alignment_type", &alignment_type);
33  parser.registerOption("robust_alignment_max_error", &max_error);
34  parser.registerOption("min_common_images", &min_common_images);
35  parser.registerOption("robust_alignment", &robust_alignment);
36  parser.registerOption("estimate_scale", &estimate_scale);
37  if (!parser.parseOptions()) return EXIT_FAILURE;
38 
39  return colmap::RunModelAligner(parser.getArgc(), parser.getArgv());
40 }
41 
42 int AnalyzeModel(const std::string& input_path) {
43  OptionsParser parser;
44  parser.registerOption("path", &input_path); // equal to input_path
45  if (!parser.parseOptions()) return EXIT_FAILURE;
46 
47  return colmap::RunModelAnalyzer(parser.getArgc(), parser.getArgv());
48 }
49 
50 int CompareModel(const std::string& input_path1,
51  const std::string& input_path2,
52  const std::string& output_path /*= ""*/,
53  double min_inlier_observations /*= 0.3*/,
54  double max_reproj_error /*= 8.0*/) {
55  OptionsParser parser;
56  parser.registerOption("input_path1", &input_path1);
57  parser.registerOption("input_path2", &input_path2);
58  parser.registerOption("output_path", &output_path);
59  parser.registerOption("min_inlier_observations", &min_inlier_observations);
60  parser.registerOption("max_reproj_error", &max_reproj_error);
61  if (!parser.parseOptions()) return EXIT_FAILURE;
62 
63  return colmap::RunModelComparer(parser.getArgc(), parser.getArgv());
64 }
65 
66 int ConvertModel(const std::string& input_path,
67  const std::string& output_path,
68  const std::string& output_type,
69  bool skip_distortion /*= false*/) {
70  OptionsParser parser;
71  parser.registerOption("input_path", &input_path);
72  parser.registerOption("output_path", &output_path);
73  // supported type {BIN, TXT, NVM, Bundler, VRML, PLY, R3D, CAM}
74  parser.registerOption("output_type", &output_type);
75  parser.registerOption("skip_distortion", &skip_distortion);
76  if (!parser.parseOptions()) return EXIT_FAILURE;
77 
78  return colmap::RunModelConverter(parser.getArgc(), parser.getArgv());
79 }
80 
81 int CropModel(const std::string& input_path,
82  const std::string& output_path,
83  const std::string& boundary,
84  const std::string& gps_transform_path /* = ""*/) {
85  OptionsParser parser;
86  parser.registerOption("input_path", &input_path);
87  parser.registerOption("output_path", &output_path);
88  parser.registerOption("boundary", &boundary);
89  parser.registerOption("gps_transform_path", &gps_transform_path);
90  if (!parser.parseOptions()) return EXIT_FAILURE;
91 
92  return colmap::RunModelCropper(parser.getArgc(), parser.getArgv());
93 }
94 
95 int MergeModel(const std::string& input_path1,
96  const std::string& input_path2,
97  const std::string& output_path,
98  double max_reproj_error /* = 64.0*/) {
99  OptionsParser parser;
100  parser.registerOption("input_path1", &input_path1);
101  parser.registerOption("input_path2", &input_path2);
102  parser.registerOption("output_path", &output_path);
103  parser.registerOption("max_reproj_error", &max_reproj_error);
104  if (!parser.parseOptions()) return EXIT_FAILURE;
105 
106  return colmap::RunModelMerger(parser.getArgc(), parser.getArgv());
107 }
108 
109 int AlignModelOrientation(const std::string& image_path,
110  const std::string& input_path,
111  const std::string& output_path,
112  std::string method /*= "MANHATTAN-WORLD"*/,
113  int max_image_size /*= 1024*/) {
114  OptionsParser parser;
115  parser.registerOption("image_path", &image_path);
116  parser.registerOption("input_path", &input_path);
117  parser.registerOption("output_path", &output_path);
118  // supported {MANHATTAN-WORLD, IMAGE-ORIENTATION}
119  parser.registerOption("method", &method);
120  parser.registerOption("max_image_size", &max_image_size);
121  if (!parser.parseOptions()) return EXIT_FAILURE;
122 
124  parser.getArgv());
125 }
126 
127 int SplitModel(const std::string& input_path,
128  const std::string& output_path,
129  const std::string& split_type,
130  const std::string& split_params,
131  const std::string& gps_transform_path /*= ""*/,
132  std::size_t min_reg_images /*= 10*/,
133  std::size_t min_num_points /*= 100*/,
134  double overlap_ratio /*= 0.0*/,
135  double min_area_ratio /*= 0.0*/,
136  int num_threads /*= -1*/) {
137  OptionsParser parser;
138  parser.registerOption("input_path", &input_path);
139  parser.registerOption("output_path", &output_path);
140  // supported {tiles, extent, parts}
141  parser.registerOption("split_type", &split_type);
142  parser.registerOption("split_params", &split_params);
143  parser.registerOption("gps_transform_path", &gps_transform_path);
144  parser.registerOption("min_reg_images", &min_reg_images);
145  parser.registerOption("min_num_points", &min_num_points);
146  parser.registerOption("overlap_ratio", &overlap_ratio);
147  parser.registerOption("min_area_ratio", &min_area_ratio);
148  parser.registerOption("num_threads", &num_threads);
149  if (!parser.parseOptions()) return EXIT_FAILURE;
150 
151  return colmap::RunModelSplitter(parser.getArgc(), parser.getArgv());
152 }
153 
154 int TransformModel(const std::string& input_path,
155  const std::string& output_path,
156  const std::string& transform_path,
157  bool is_inverse /*= false*/) {
158  OptionsParser parser;
159  parser.registerOption("input_path", &input_path);
160  parser.registerOption("output_path", &output_path);
161  parser.registerOption("transform_path", &transform_path);
162  parser.registerOption("is_inverse", &is_inverse);
163 
164  if (!parser.parseOptions()) return EXIT_FAILURE;
165 
166  return colmap::RunModelTransformer(parser.getArgc(), parser.getArgv());
167 }
168 
169 } // namespace cloudViewer
void registerOption(const std::string &name, const T *option)
Definition: option_utils.h:43
Generic file read and write utility for python interface.
int TransformModel(const std::string &input_path, const std::string &output_path, const std::string &transform_path, bool is_inverse)
Definition: model.cpp:154
int AnalyzeModel(const std::string &input_path)
Definition: model.cpp:42
int AlignModelOrientation(const std::string &image_path, const std::string &input_path, const std::string &output_path, std::string method, int max_image_size)
Definition: model.cpp:109
int MergeModel(const std::string &input_path1, const std::string &input_path2, const std::string &output_path, double max_reproj_error)
Definition: model.cpp:95
int CropModel(const std::string &input_path, const std::string &output_path, const std::string &boundary, const std::string &gps_transform_path)
Definition: model.cpp:81
int AlignModel(const std::string &input_path, const std::string &output_path, const std::string &database_path, const std::string &ref_images_path, const std::string &transform_path, const std::string &alignment_type, double max_error, int min_common_images, bool robust_alignment, bool estimate_scale)
Definition: model.cpp:15
int SplitModel(const std::string &input_path, const std::string &output_path, const std::string &split_type, const std::string &split_params, const std::string &gps_transform_path, std::size_t min_reg_images, std::size_t min_num_points, double overlap_ratio, double min_area_ratio, int num_threads)
Definition: model.cpp:127
int CompareModel(const std::string &input_path1, const std::string &input_path2, const std::string &output_path, double min_inlier_observations, double max_reproj_error)
Definition: model.cpp:50
int ConvertModel(const std::string &input_path, const std::string &output_path, const std::string &output_type, bool skip_distortion)
Definition: model.cpp:66
int RunModelAligner(int argc, char **argv)
Definition: model.cc:196
int RunModelOrientationAligner(int argc, char **argv)
Definition: model.cc:628
int RunModelConverter(int argc, char **argv)
Definition: model.cc:463
int RunModelComparer(int argc, char **argv)
Definition: model.cc:367
int RunModelCropper(int argc, char **argv)
Definition: model.cc:509
int RunModelMerger(int argc, char **argv)
Definition: model.cc:582
int RunModelSplitter(int argc, char **argv)
Definition: model.cc:694
int RunModelAnalyzer(int argc, char **argv)
Definition: model.cc:332
int RunModelTransformer(int argc, char **argv)
Definition: model.cc:879