Go to the documentation of this file.
15 #include <mrpt/3rdparty/tclap/CmdLine.h>
16 #include <mrpt/maps/CPointsMapXYZI.h>
17 #include <mrpt/maps/CPointsMapXYZIRT.h>
18 #include <mrpt/maps/CSimplePointsMap.h>
19 #include <mrpt/math/CMatrixDynamic.h>
20 #include <mrpt/obs/CObservationPointCloud.h>
21 #include <mrpt/system/filesystem.h>
24 static TCLAP::CmdLine
cmd(
"txt2mm");
26 static TCLAP::ValueArg<std::string>
argInput(
28 "Path to input TXT or CSV file. One point per row. Columns separated by "
29 "spaces or commas. See docs for supported formats.",
30 true,
"input.txt",
"input.txt",
cmd);
32 static TCLAP::ValueArg<std::string>
argOutput(
33 "o",
"output",
"Output file to write to.",
true,
"out.mm",
"out.mm",
cmd);
35 static TCLAP::ValueArg<std::string>
argFormat(
37 "Point cloud format. Mandatory flag.\n"
38 "Options: (xyz|xyzi|xyzirt)",
39 true,
"xyz",
"(xyz|xyzi|xyzirt)",
cmd);
41 static TCLAP::ValueArg<std::string>
argLayer(
42 "l",
"layer",
"Target layer name (Default: \"raw\").",
false,
"raw",
"raw",
47 "Column index for the X coordinate in the input data (Default: 0).",
false,
48 0,
"column index",
cmd);
52 "Column index for the Intensity channel in the input data (Default: 3).",
53 false, 3,
"column index",
cmd);
57 "Column index for the Ring channel in the input data (Default: 4).",
false,
58 4,
"column index",
cmd);
62 "Column index for the Timestamp channel in the input data (Default: 5).",
63 false, 5,
"column index",
cmd);
65 static TCLAP::ValueArg<uint64_t>
argID(
66 "",
"id",
"Metric map numeric ID (Default: none).",
false, 0,
"[ID]",
cmd);
68 static TCLAP::ValueArg<std::string>
argLabel(
69 "",
"label",
"Metric map label string (Default: none).",
false,
"label",
72 int main(
int argc,
char** argv)
77 if (!
cmd.parse(argc, argv))
return 1;
80 ASSERT_FILE_EXISTS_(
f);
82 std::cout <<
"Reading data from '" <<
f <<
"'..." << std::endl;
84 mrpt::math::CMatrixFloat data;
85 data.loadFromTextFile(
f);
87 const size_t nRows = data.size().at(0), nCols = data.size().at(1);
89 std::cout <<
"Done: " << nRows <<
" rows, " << nCols <<
" columns."
92 mrpt::maps::CPointsMap::Ptr pc;
102 ASSERT_GE_(nCols, 3U);
103 pc = mrpt::maps::CSimplePointsMap::Create();
106 std::cout <<
"Warning: Only the first 3 columns from the file "
107 "will be used for the output format 'xyz'"
110 for (
size_t i = 0; i < nRows; i++)
112 data(i, idxX + 0), data(i, idxX + 1), data(i, idxX + 2));
114 else if (format ==
"xyzi")
116 ASSERT_GE_(nCols, 4U);
117 auto pts = mrpt::maps::CPointsMapXYZI::Create();
120 std::cout <<
"Warning: Only the first 4 columns from the file "
121 "will be used for the output format 'xyzi'"
124 for (
size_t i = 0; i < nRows; i++)
126 pts->insertPointFast(
127 data(i, idxX + 0), data(i, idxX + 1), data(i, idxX + 2));
128 pts->insertPointField_Intensity(data(i, idxI));
133 else if (format ==
"xyzirt")
135 ASSERT_GE_(nCols, 6U);
136 auto pts = mrpt::maps::CPointsMapXYZI::Create();
139 std::cout <<
"Warning: Only the first 6 columns from the file "
140 "will be used for the output format 'xyzirt'"
143 for (
size_t i = 0; i < nRows; i++)
145 pts->insertPointFast(
146 data(i, idxX + 0), data(i, idxX + 1), data(i, idxX + 2));
147 pts->insertPointField_Intensity(data(i, idxI));
148 pts->insertPointField_Ring(data(i, idxR));
149 pts->insertPointField_Timestamp(data(i, idxT));
157 "Invalid --format set to '%s'. Valid values: (xyz|xyzi|xyzirt)",
163 mm.
layers[
"raw"] = std::move(pc);
169 std::cout <<
"Saving map to: " <<
argOutput.getValue() << std::endl;
173 "Error writing to target file '%s'",
176 catch (
const std::exception& e)
178 std::cerr << mrpt::exception_to_str(e);
static TCLAP::ValueArg< int > argIndexI("", "column-i", "Column index for the Intensity channel in the input data (Default: 3).", false, 3, "column index", cmd)
static TCLAP::ValueArg< std::string > argFormat("f", "format", "Point cloud format. Mandatory flag.\n" "Options: (xyz|xyzi|xyzirt)", true, "xyz", "(xyz|xyzi|xyzirt)", cmd)
static TCLAP::ValueArg< int > argIndexXYZ("", "column-x", "Column index for the X coordinate in the input data (Default: 0).", false, 0, "column index", cmd)
static TCLAP::ValueArg< uint64_t > argID("", "id", "Metric map numeric ID (Default: none).", false, 0, "[ID]", cmd)
static TCLAP::ValueArg< int > argIndexT("", "column-t", "Column index for the Timestamp channel in the input data (Default: 5).", false, 5, "column index", cmd)
static TCLAP::ValueArg< std::string > argInput("i", "input", "Path to input TXT or CSV file. One point per row. Columns separated by " "spaces or commas. See docs for supported formats.", true, "input.txt", "input.txt", cmd)
bool save_to_file(const std::string &fileName) const
static TCLAP::CmdLine cmd("txt2mm")
std::optional< std::string > label
static TCLAP::ValueArg< int > argIndexR("", "column-r", "Column index for the Ring channel in the input data (Default: 4).", false, 4, "column index", cmd)
int main(int argc, char **argv)
virtual std::string contents_summary() const
static TCLAP::ValueArg< std::string > argLabel("", "label", "Metric map label string (Default: none).", false, "label", "[label]", cmd)
static TCLAP::ValueArg< std::string > argLayer("l", "layer", "Target layer name (Default: \"raw\").", false, "raw", "raw", cmd)
static TCLAP::ValueArg< std::string > argOutput("o", "output", "Output file to write to.", true, "out.mm", "out.mm", cmd)
Generic representation of pointcloud(s) and/or extracted features.
Generic container of pointcloud(s), extracted features and other maps.
std::optional< uint64_t > id
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
mp2p_icp
Author(s):
autogenerated on Wed Oct 23 2024 02:45:40