PointCloudCrafter
Loading...
Searching...
No Matches
cli_config.hpp
1/*
2 * Copyright 2024 Markus Pielmeier, Florian Sauerbeck,
3 * Dominik Kulmer, Maximilian Leitenstern
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <string>
21#include <utility>
22#include <vector>
23
24#include "cli/CLI11.hpp"
25#include "formats.hpp"
26
27namespace config
28{
33{
34 std::string transform_file{};
35 std::vector<double> cropbox{};
36 double cropsphere{0.0};
37 double cropcylinder{0.0};
38 std::vector<double> voxelfilter{};
39 std::pair<double, int> outlier_radius_filter{};
40 std::pair<double, int> outlier_stat_filter{};
41 int64_t max_frames{-1};
42 int64_t skip_frames{0};
43 int64_t stride_frames{1};
44 std::string out_dir{};
45 bool timestamps{false};
46 bool sequential_names{false};
47 bool inverse_crop{false};
48 double split_grid_size{0.0};
49 bool load_pcd{true};
50 bool load_ply{false};
51 bool load_txt{false};
52 bool load_kitti{false};
53 bool load_nuscenes{false};
54 bool load_obj{false};
55 bool save_pcd{false};
56 bool save_ply{false};
57 bool save_txt{false};
58 bool save_kitti{false};
59 bool save_nuscenes{false};
60
65 pointcloudcrafter::tools::formats::FileFormat get_load_format() const
66 {
67 if (load_ply) return pointcloudcrafter::tools::formats::FileFormat::PLY;
68 if (load_txt) return pointcloudcrafter::tools::formats::FileFormat::TXT;
69 if (load_kitti) return pointcloudcrafter::tools::formats::FileFormat::KITTI;
70 if (load_nuscenes) return pointcloudcrafter::tools::formats::FileFormat::NUSCENES;
71 if (load_obj) return pointcloudcrafter::tools::formats::FileFormat::OBJ;
72 return pointcloudcrafter::tools::formats::FileFormat::PCD;
73 }
74
79 pointcloudcrafter::tools::formats::FileFormat get_save_format() const
80 {
81 if (save_pcd) return pointcloudcrafter::tools::formats::FileFormat::PCD;
82 if (save_ply) return pointcloudcrafter::tools::formats::FileFormat::PLY;
83 if (save_txt) return pointcloudcrafter::tools::formats::FileFormat::TXT;
84 if (save_kitti) return pointcloudcrafter::tools::formats::FileFormat::KITTI;
85 if (save_nuscenes) return pointcloudcrafter::tools::formats::FileFormat::NUSCENES;
86 return get_load_format();
87 }
88
94 {
95 // Output
96 app->add_flag("--timestamps", timestamps, "Save point cloud timestamps to a text file")
97 ->group("Output");
98
99 app->add_flag("--sequential-name", sequential_names, "Use sequential file names")
100 ->group("Output");
101
102 // Frame selection
103 app->add_option("-m,--max-frames", max_frames, "Maximum number of frames (-1 = unlimited)")
104 ->group("General");
105
106 app->add_option("-j,--skip-frames", skip_frames, "Number of frames to skip at the beginning")
107 ->group("General");
108
109 app->add_option("-s,--stride-frames", stride_frames, "Write every Nth frame")
110 ->group("General");
111
112 // File format
113 app->add_flag("--save-pcd", save_pcd, "Save PCD files (default)")
114 ->group("File Format");
115 app->add_flag("--save-ply", save_ply, "Save PLY files")
116 ->group("File Format");
117 app->add_flag("--save-txt", save_txt, "Save TXT ASCII files")
118 ->group("File Format");
119 app->add_flag("--save-kitti", save_kitti, "Save KITTI binary files")
120 ->group("File Format");
121 app->add_flag("--save-nuscenes", save_nuscenes, "Save nuScenes binary files")
122 ->group("File Format");
123
124 // Transforms
125 app->add_option(
126 "--split", split_grid_size,
127 "Split point cloud into grid cells of given size")
128 ->type_name("FLOAT")
129 ->group("Transforms");
130
131 app->add_option(
132 "--tf, --transform-file", transform_file,
133 "TXT file with transform ([frame_id] r1 r2 r3 x r4 r5 r6 y r7 r8 r9 z)")
134 ->group("Transforms");
135
136 // Filtering
137 app->add_option("--cb, --crop-box", cropbox, "Crop box [xmin ymin zmin xmax ymax zmax]")
138 ->expected(6)
139 ->type_name("FLOAT FLOAT FLOAT FLOAT FLOAT FLOAT")
140 ->group("Filtering");
141
142 app->add_option("--cs, --crop-sphere", cropsphere, "Crop to sphere with given radius")
143 ->type_name("FLOAT")
144 ->group("Filtering");
145
146 app->add_option("--cc, --crop-cylinder", cropcylinder, "Crop to cylinder with given radius")
147 ->type_name("FLOAT")
148 ->group("Filtering");
149
150 app->add_flag("--inverse-crop", inverse_crop, "Inverse crop filters")
151 ->group("Filtering");
152
153 app->add_option("--vf, --voxel-filter", voxelfilter, "Voxel size [x y z]")
154 ->expected(3)
155 ->type_name("FLOAT FLOAT FLOAT")
156 ->group("Filtering");
157
158 app->add_option(
159 "--orf, --outlier-radius-filter", outlier_radius_filter,
160 "Radius outlier removal [radius min_neighbors]")
161 ->expected(1)
162 ->type_name("FLOAT INT")
163 ->group("Filtering");
164
165 app->add_option(
166 "--osf, --outlier-stat-filter", outlier_stat_filter,
167 "Statistical outlier removal [threshold mean_k]")
168 ->expected(1)
169 ->type_name("FLOAT INT")
170 ->group("Filtering");
171 }
172};
173
178{
179 std::string input_path{};
180 std::vector<double> translation{};
181 std::vector<double> rotation{};
182 bool degree{false};
183 bool merge_clouds{false};
184
190 {
191 app->add_option("input-path", input_path, "Path to point cloud file or directory")
192 ->required()
193 ->group("Required");
194
195 app->add_option("out-dir", out_dir, "Output directory for point cloud file(s)")
196 ->required()
197 ->group("Required");
198
199 app->add_flag("--load-pcd", load_pcd, "Load PCD files (default)")
200 ->group("File Format");
201 app->add_flag("--load-ply", load_ply, "Load PLY files")
202 ->group("File Format");
203 app->add_flag("--load-txt", load_txt, "Load TXT ASCII files")
204 ->group("File Format");
205 app->add_flag("--load-kitti", load_kitti, "Load KITTI binary files")
206 ->group("File Format");
207 app->add_flag("--load-nuscenes", load_nuscenes, "Load nuScenes binary files")
208 ->group("File Format");
209 app->add_flag("--load-obj", load_obj, "Load OBJ files")
210 ->group("File Format");
211
212 app->add_option("-t,--translation", translation, "Translation [x y z]")
213 ->expected(3)
214 ->type_name("FLOAT FLOAT FLOAT")
215 ->group("Transforms");
216
217 app->add_option("-r,--rotation", rotation, "Rotation [roll pitch yaw]")
218 ->expected(3)
219 ->type_name("FLOAT FLOAT FLOAT")
220 ->group("Transforms");
221
222 app->add_flag("--deg", degree, "Rotation in degrees instead of radians")
223 ->group("Transforms");
224
225 app->add_flag("--merge-clouds", merge_clouds, "Merge all point clouds into a single file")
226 ->group("Transforms");
227
229 }
230};
231
236{
237 std::string bag_path{};
238 std::vector<std::string> topics{};
239 std::string target_frame{};
240 std::string urdf_file{};
241
247 {
248 app->add_option("bag-path", bag_path, "Path to ROS 2 bag")
249 ->required()
250 ->group("Required");
251
252 app->add_option("out-dir", out_dir, "Output directory for point cloud file(s)")
253 ->required()
254 ->group("Required");
255
256 app->add_option("topic-names", topics, "PointCloud2 topic names")
257 ->required()
258 ->group("Required");
259
260 app->add_option("-t,--target-frame", target_frame, "Target TF frame for all point clouds")
261 ->group("Transforms");
262
263 app->add_option(
264 "--urdf, --urdf-file", urdf_file,
265 "URDF file providing additional static TF transforms")
266 ->group("Transforms");
267
269 }
270};
271
272} // namespace config
Creates a command line program, with very few defaults.
Definition CLI11.hpp:5883
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition CLI11.hpp:6415
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
Definition CLI11.hpp:7372
CRTP * group(const std::string &name)
Changes the group membership.
Definition CLI11.hpp:4449
CRTP * required(bool value=true)
Set the option as required.
Definition CLI11.hpp:4458
Option * expected(int value)
Set the number of expected arguments.
Definition CLI11.hpp:5207
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition CLI11.hpp:5111
FileConfig input configuration.
Definition cli_config.hpp:178
void add_cli_options(CLI::App *app)
Add FileConfig CLI options to the given app.
Definition cli_config.hpp:189
Common modifier configuration.
Definition cli_config.hpp:33
void add_modifier_options(CLI::App *app)
Add common modifier CLI options to the given app.
Definition cli_config.hpp:93
pointcloudcrafter::tools::formats::FileFormat get_save_format() const
Get the save format based on flags.
Definition cli_config.hpp:79
pointcloudcrafter::tools::formats::FileFormat get_load_format() const
Get the load format based on flags.
Definition cli_config.hpp:65
Rosbag input configuration.
Definition cli_config.hpp:236
void add_cli_options(CLI::App *app)
Add Rosbag CLI options to the given app.
Definition cli_config.hpp:246