// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma // de Barcelona (UAB). // // This work is licensed under the terms of the MIT license. // For a copy, see . #pragma once #include "carla/FileSystem.h" #include #include #include namespace carla { namespace pointcloud { class PointCloudIO { public: template static void Dump(std::ostream &out, PointIt begin, PointIt end) { WriteHeader(out, begin, end); for (; begin != end; ++begin) { begin->WriteDetection(out); out << '\n'; } } template static std::string SaveToDisk(std::string path, PointIt begin, PointIt end) { FileSystem::ValidateFilePath(path, ".ply"); std::ofstream out(path); Dump(out, begin, end); return path; } private: template static void WriteHeader(std::ostream &out, PointIt begin, PointIt end) { DEBUG_ASSERT(std::distance(begin, end) >= 0); out << "ply\n" "format ascii 1.0\n" "element vertex " << std::to_string(static_cast(std::distance(begin, end))) << "\n"; begin->WritePlyHeaderInfo(out); out << "\nend_header\n"; out << std::fixed << std::setprecision(4u); } }; } // namespace pointcloud } // namespace carla