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


mp2p_icp
Author(s):
autogenerated on Wed Oct 23 2024 02:45:41