sm-cli-export-kfs.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 #include <mrpt/poses/CPose3DInterpolator.h>
13 
14 #include <fstream>
15 
16 #include "sm-cli.h"
17 
18 static int printCommandsExportKF(bool showErrorMsg);
19 
21 {
22  const auto& lstCmds = cli->argCmd.getValue();
23  if (cli->argHelp.isSet()) return printCommandsExportKF(false);
24  if (lstCmds.size() != 2 || !cli->arg_output.isSet()) return printCommandsExportKF(true);
25 
26  // Take second unlabeled argument:
27  const std::string file = lstCmds.at(1);
28 
29  const mrpt::maps::CSimpleMap sm = read_input_sm_from_cli(file);
30 
31  const auto outFil = cli->arg_output.getValue();
32  const auto outTwistFil = cli->arg_output_twist.getValue();
33 
34  std::optional<std::ofstream> outTwist;
35  if (!outTwistFil.empty())
36  {
37  outTwist.emplace(outTwistFil, std::ofstream::out);
38  }
39 
40  mrpt::poses::CPose3DInterpolator kfs;
41 
42  size_t kfsWithoutTimestamp = 0;
43 
44  for (const auto& [kf, sf, twist] : sm)
45  {
46  const auto pose = kf->getMeanVal();
47  std::optional<mrpt::Clock::time_point> tim;
48 
49  ASSERT_(sf);
50  for (const auto& obs : *sf)
51  {
52  if (!obs) continue;
53  auto t = obs->getTimeStamp();
54  if (t == mrpt::system::InvalidTimeStamp()) continue;
55  tim = t;
56  break;
57  }
58  if (!tim)
59  {
60  ++kfsWithoutTimestamp;
61  continue;
62  }
63 
64  kfs.insert(*tim, pose);
65 
66  if (outTwist && twist)
67  {
68  const auto& tw = *twist;
69  *outTwist << mrpt::format(
70  "%.06f %f %f %f %f %f %f\n", //
71  mrpt::Clock::toDouble(*tim), // time
72  tw.vx, tw.vy, tw.vz, // linear vel
73  tw.wx, tw.wy, tw.wz // angular vel
74  );
75  }
76  }
77 
78  if (kfsWithoutTimestamp)
79  {
80  std::cerr << "Warning: " << kfsWithoutTimestamp
81  << " keyframes cannot be exported since they lack "
82  "observations with timestamp."
83  << std::endl;
84  }
85 
86  std::cout << "Saving " << kfs.size() << " keyframe poses to: '" << outFil << "'" << std::endl;
87 
88  kfs.saveToTextFile_TUM(outFil);
89 
90  return 0;
91 }
92 
93 int printCommandsExportKF(bool showErrorMsg)
94 {
95  if (showErrorMsg)
96  {
98  std::cerr << "Error: missing or unknown subcommand.\n";
100  }
101 
102  fprintf(
103  stderr,
104  R"XXX(Usage:
105 
106  sm-cli export-keyframes <filename> --output <OUTPUT.tum> [--output-twist <TWIST.txt>]
107 
108 )XXX");
109 
110  return showErrorMsg ? 1 : 0;
111 }
cli
std::unique_ptr< cli_flags > cli
Definition: sm-cli-main.cpp:29
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:113
kitti-batch-convert.out
string out
Definition: kitti-batch-convert.py:7
sm-cli.h
printCommandsExportKF
static int printCommandsExportKF(bool showErrorMsg)
Definition: sm-cli-export-kfs.cpp:93
commandExportKF
int commandExportKF()
Definition: sm-cli-export-kfs.cpp:20
setConsoleNormalColor
void setConsoleNormalColor()
Definition: sm-cli-main.cpp:48
setConsoleErrorColor
void setConsoleErrorColor()
Definition: sm-cli-main.cpp:43
t
geometry_msgs::TransformStamped t


mp2p_icp
Author(s):
autogenerated on Mon May 26 2025 02:45:50