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(const std::string& fil)
22 {
23  ASSERT_FILE_EXISTS_(fil);
24 
25  std::string fileToRead = fil;
26 
27  if (mrpt::system::extractFileExtension(fil) == "gz")
28  {
29  mrpt::io::CFileGZInputStream f(fil);
30  std::string buf;
31  while (!f.checkEOF())
32  {
33  const size_t N = 10000;
34  std::string tmp;
35  tmp.resize(N);
36  const auto n = f.Read(&tmp[0], N);
37  tmp.resize(n);
38  buf += tmp;
39  }
40 
41  const auto tmpFil = mrpt::system::getTempFileName();
42 
43  std::ofstream fo;
44  fo.open(tmpFil.c_str());
45  ASSERT_(fo.is_open());
46  fo << buf;
47 
48  fileToRead = tmpFil;
49  }
50 
51  auto m = mrpt::maps::CSimplePointsMap::Create();
52  m->load3D_from_text_file(fileToRead);
53  ASSERTMSG_(
54  m->size() > 1,
55  mrpt::format(
56  "Could not parse a valid point cloud from ASCII file '%s'", fileToRead.c_str()));
57 
58  return m;
59 }
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 Mon May 26 2025 02:45:49