CARLA
PointCloudIO.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/FileSystem.h"
10 
11 #include <fstream>
12 #include <iterator>
13 #include <iomanip>
14 
15 namespace carla {
16 namespace pointcloud {
17 
18  class PointCloudIO {
19 
20  public:
21  template <typename PointIt>
22  static void Dump(std::ostream &out, PointIt begin, PointIt end) {
23  WriteHeader(out, begin, end);
24  for (; begin != end; ++begin) {
25  begin->WriteDetection(out);
26  out << '\n';
27  }
28  }
29 
30  template <typename PointIt>
31  static std::string SaveToDisk(std::string path, PointIt begin, PointIt end) {
32  FileSystem::ValidateFilePath(path, ".ply");
33  std::ofstream out(path);
34  Dump(out, begin, end);
35  return path;
36  }
37 
38  private:
39  template <typename PointIt> static void WriteHeader(std::ostream &out, PointIt begin, PointIt end) {
40  DEBUG_ASSERT(std::distance(begin, end) >= 0);
41  out << "ply\n"
42  "format ascii 1.0\n"
43  "element vertex " << std::to_string(static_cast<size_t>(std::distance(begin, end))) << "\n";
44  begin->WritePlyHeaderInfo(out);
45  out << "\nend_header\n";
46  out << std::fixed << std::setprecision(4u);
47  }
48  };
49 
50 } // namespace pointcloud
51 } // namespace carla
static void WriteHeader(std::ostream &out, PointIt begin, PointIt end)
Definition: PointCloudIO.h:39
static void Dump(std::ostream &out, PointIt begin, PointIt end)
Definition: PointCloudIO.h:22
static void ValidateFilePath(std::string &filepath, const std::string &default_extension="")
Convenient function to validate a path before creating a file.
Definition: FileSystem.cpp:18
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
static std::string SaveToDisk(std::string path, PointIt begin, PointIt end)
Definition: PointCloudIO.h:31