load_xyz_file.cpp
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * A Modular Optimization framework for Localization and mApping (MOLA)
3  * Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
6 
14 #include <mp2p_icp/load_xyz_file.h>
15 #include <mrpt/io/CFileGZInputStream.h>
16 #include <mrpt/system/filesystem.h>
17 
18 #include <fstream>
19 
20 // Loads from XYZ file, possibly gz-compressed:
21 mrpt::maps::CSimplePointsMap::Ptr mp2p_icp::load_xyz_file(
22  const std::string& fil)
23 {
24  ASSERT_FILE_EXISTS_(fil);
25 
26  std::string fileToRead = fil;
27 
28  if (mrpt::system::extractFileExtension(fil) == "gz")
29  {
30  mrpt::io::CFileGZInputStream f(fil);
31  std::string buf;
32  while (!f.checkEOF())
33  {
34  const size_t N = 10000;
35  std::string tmp;
36  tmp.resize(N);
37  const auto n = f.Read(&tmp[0], N);
38  tmp.resize(n);
39  buf += tmp;
40  }
41 
42  const auto tmpFil = mrpt::system::getTempFileName();
43 
44  std::ofstream fo;
45  fo.open(tmpFil.c_str());
46  ASSERT_(fo.is_open());
47  fo << buf;
48 
49  fileToRead = tmpFil;
50  }
51 
52  auto m = mrpt::maps::CSimplePointsMap::Create();
53  m->load3D_from_text_file(fileToRead);
54  ASSERTMSG_(
55  m->size() > 1,
56  mrpt::format(
57  "Could not parse a valid point cloud from ASCII file '%s'",
58  fileToRead.c_str()));
59 
60  return m;
61 }
kitti-run-seq.f
string f
Definition: kitti-run-seq.py:12
testing::internal::string
::std::string string
Definition: gtest.h:1979
mp2p_icp::load_xyz_file
mrpt::maps::CSimplePointsMap::Ptr load_xyz_file(const std::string &fil)
Definition: load_xyz_file.cpp:21
load_xyz_file.h
Unit tests common utilities.


mp2p_icp
Author(s):
autogenerated on Thu Dec 26 2024 03:48:12