sm-cli-trim.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2023 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mrpt/core/exceptions.h>
11 #include <mrpt/maps/CSimpleMap.h>
12 
13 #include "sm-cli.h"
14 
15 static int printCommandsTrim(bool showErrorMsg);
16 
18 {
19  const auto& lstCmds = cli->argCmd.getValue();
20  if (cli->argHelp.isSet()) return printCommandsTrim(false);
21  if (lstCmds.size() != 2 || !cli->arg_min_corner.isSet() ||
22  !cli->arg_max_corner.isSet() || !cli->arg_output.isSet())
23  return printCommandsTrim(true);
24 
25  // Take second unlabeled argument:
26  const std::string file = lstCmds.at(1);
27 
28  const auto cornerMin =
29  mrpt::math::TPoint3D::FromString(cli->arg_min_corner.getValue());
30  const auto cornerMax =
31  mrpt::math::TPoint3D::FromString(cli->arg_max_corner.getValue());
32 
33  const auto bbox = mrpt::math::TBoundingBox(cornerMin, cornerMax);
34 
35  const mrpt::maps::CSimpleMap sm = read_input_sm_from_cli(file);
36 
37  mrpt::maps::CSimpleMap outSM;
38 
39  for (const auto& [posePDF, sf, twist] : sm)
40  {
41  ASSERT_(posePDF);
42  const auto p = posePDF->getMeanVal();
43 
44  if (!bbox.containsPoint(p.translation())) continue;
45 
46  outSM.insert(posePDF, sf, twist);
47  }
48 
49  const auto outFil = cli->arg_output.getValue();
50 
51  std::cout << "Writing trimmed simplemap with " << outSM.size()
52  << " keyframes to '" << outFil << "'" << std::endl;
53 
54  outSM.saveToFile(outFil);
55 
56  return 0;
57 }
58 
59 int printCommandsTrim(bool showErrorMsg)
60 {
61  if (showErrorMsg)
62  {
64  std::cerr << "Error: missing or unknown subcommand.\n";
66  }
67 
68  fprintf(
69  stderr,
70  R"XXX(Usage:
71 
72  sm-cli trim <filename> --min-corner "[xmin ymin zmin]" --max-corner "[xmax ymax zmax]" --output <OUTPUT.simplemap>
73 
74 )XXX");
75 
76  return showErrorMsg ? 1 : 0;
77 }
cli
std::unique_ptr< cli_flags > cli
Definition: sm-cli-main.cpp:29
printCommandsTrim
static int printCommandsTrim(bool showErrorMsg)
Definition: sm-cli-trim.cpp:59
testing::internal::string
::std::string string
Definition: gtest.h:1979
read_input_sm_from_cli
mrpt::maps::CSimpleMap read_input_sm_from_cli(const std::string &inFile)
Definition: sm-cli-main.cpp:119
commandTrim
int commandTrim()
Definition: sm-cli-trim.cpp:17
sm-cli.h
setConsoleNormalColor
void setConsoleNormalColor()
Definition: sm-cli-main.cpp:49
setConsoleErrorColor
void setConsoleErrorColor()
Definition: sm-cli-main.cpp:43


mp2p_icp
Author(s):
autogenerated on Wed Oct 2 2024 02:45:25