sm-cli-info.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/math/TBoundingBox.h>
13 #include <mrpt/system/filesystem.h>
14 
15 #include "sm-cli.h"
16 
17 static int printCommandsInfo(bool showErrorMsg);
18 
20 {
21  const auto& lstCmds = cli->argCmd.getValue();
22  if (cli->argHelp.isSet()) return printCommandsInfo(false);
23  if (lstCmds.size() != 2) return printCommandsInfo(true);
24 
25  // Take second unlabeled argument:
26  const std::string file = lstCmds.at(1);
27 
28  const mrpt::maps::CSimpleMap sm = read_input_sm_from_cli(file);
29 
30  // estimate path bounding box:
31  auto bbox = mrpt::math::TBoundingBox::PlusMinusInfinity();
32  bool hasTwist = false;
33  std::optional<mrpt::Clock::time_point> timeMin, timeMax;
34 
35  std::map<std::string, std::string> obsTypes;
36  std::map<std::string, size_t> obsCount;
37 
38  for (const auto& [pose, sf, twist] : sm)
39  {
40  if (twist.has_value()) hasTwist = true;
41 
42  const auto p = pose->getMeanVal().asTPose();
43  bbox.updateWithPoint(p.translation());
44 
45  if (!sf) continue;
46 
47  for (const auto& o : *sf)
48  {
49  ASSERT_(o);
50  auto t = o->getTimeStamp();
51  if (!timeMin || t < *timeMin) timeMin = t;
52  if (!timeMax || t > *timeMax) timeMax = t;
53 
54  obsTypes[o->sensorLabel] = o->GetRuntimeClass()->className;
55  obsCount[o->sensorLabel]++;
56  }
57  }
58 
59  const auto sizeBytes = mrpt::system::getFileSize(file);
60 
61  std::cout << "\n";
62  std::cout << "size_bytes: " << sizeBytes << "\n";
63  std::cout << "keyframe_count: " << sm.size() << "\n";
64  std::cout << "has_twist: " << (hasTwist ? "true" : "false") << "\n";
65  std::cout << "kf_bounding_box_min: " << bbox.min.asString() << "\n";
66  std::cout << "kf_bounding_box_max: " << bbox.max.asString() << "\n";
67  std::cout << "kf_bounding_box_span: " << (bbox.max - bbox.min).asString() << "\n";
68  std::cout << "timestamp_first_utc: "
69  << (timeMin ? mrpt::system::dateTimeToString(*timeMin) : "None") << "\n";
70  std::cout << "timestamp_last_utc: "
71  << (timeMax ? mrpt::system::dateTimeToString(*timeMax) : "None") << "\n";
72  std::cout << "timestamp_span: "
73  << ((timeMin && timeMax) ? mrpt::system::formatTimeInterval(
74  mrpt::system::timeDifference(*timeMax, *timeMin))
75  : "None")
76  << "\n";
77  std::cout << "observations:\n";
78 
79  for (const auto& [label, type] : obsTypes)
80  {
81  std::cout << " - label: '" << label << "'\n";
82  std::cout << " class: '" << type << "'\n";
83  std::cout << " count: " << obsCount[label] << "\n";
84  }
85 
86  return 0;
87 }
88 
89 int printCommandsInfo(bool showErrorMsg)
90 {
91  if (showErrorMsg)
92  {
94  std::cerr << "Error: missing or unknown subcommand.\n";
96  }
97 
98  fprintf(
99  stderr,
100  R"XXX(Usage:
101 
102  sm-cli info <filename.simplemap> Loads and analyze the given map
103 
104 )XXX");
105 
106  return showErrorMsg ? 1 : 0;
107 }
cli
std::unique_ptr< cli_flags > cli
Definition: sm-cli-main.cpp:29
printCommandsInfo
static int printCommandsInfo(bool showErrorMsg)
Definition: sm-cli-info.cpp:89
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
sm-cli.h
commandInfo
int commandInfo()
Definition: sm-cli-info.cpp:19
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