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")
65  << "\n";
66  std::cout << "kf_bounding_box_min: " << bbox.min.asString() << "\n";
67  std::cout << "kf_bounding_box_max: " << bbox.max.asString() << "\n";
68  std::cout << "kf_bounding_box_span: " << (bbox.max - bbox.min).asString()
69  << "\n";
70  std::cout << "timestamp_first_utc: "
71  << (timeMin ? mrpt::system::dateTimeToString(*timeMin) : "None")
72  << "\n";
73  std::cout << "timestamp_last_utc: "
74  << (timeMax ? mrpt::system::dateTimeToString(*timeMax) : "None")
75  << "\n";
76  std::cout << "timestamp_span: "
77  << ((timeMin && timeMax)
78  ? mrpt::system::formatTimeInterval(
79  mrpt::system::timeDifference(*timeMax, *timeMin))
80  : "None")
81  << "\n";
82  std::cout << "observations:\n";
83 
84  for (const auto& [label, type] : obsTypes)
85  {
86  std::cout << " - label: '" << label << "'\n";
87  std::cout << " class: '" << type << "'\n";
88  std::cout << " count: " << obsCount[label] << "\n";
89  }
90 
91  return 0;
92 }
93 
94 int printCommandsInfo(bool showErrorMsg)
95 {
96  if (showErrorMsg)
97  {
99  std::cerr << "Error: missing or unknown subcommand.\n";
101  }
102 
103  fprintf(
104  stderr,
105  R"XXX(Usage:
106 
107  sm-cli info <filename.simplemap> Loads and analyze the given map
108 
109 )XXX");
110 
111  return showErrorMsg ? 1 : 0;
112 }
cli
std::unique_ptr< cli_flags > cli
Definition: sm-cli-main.cpp:29
printCommandsInfo
static int printCommandsInfo(bool showErrorMsg)
Definition: sm-cli-info.cpp:94
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
sm-cli.h
commandInfo
int commandInfo()
Definition: sm-cli-info.cpp:19
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 2 2024 02:45:25