| 76 | } |
| 77 | |
| 78 | void serializePointCloud(const std::string &filename, std::shared_ptr<spectacularAI::mapping::PointCloud> pointCloud) { |
| 79 | std::ofstream outputStream(filename.c_str(), std::ios::out | std::ios::binary | std::ios::trunc); |
| 80 | if (!outputStream.is_open()) { |
| 81 | throw std::runtime_error("Failed to create temporary file <" + filename + "> for pointcloud serialization."); |
| 82 | } |
| 83 | |
| 84 | std::size_t points = pointCloud->size(); |
| 85 | if (points > 0) { |
| 86 | outputStream.write( |
| 87 | reinterpret_cast<const char*>(pointCloud->getPositionData()), |
| 88 | sizeof(spectacularAI::Vector3f) * points); |
| 89 | |
| 90 | if (pointCloud->hasNormals()) { |
| 91 | outputStream.write( |
| 92 | reinterpret_cast<const char*>(pointCloud->getNormalData()), |
| 93 | sizeof(spectacularAI::Vector3f) * points); |
| 94 | } |
| 95 | |
| 96 | if (pointCloud->hasColors()) { |
| 97 | outputStream.write( |
| 98 | reinterpret_cast<const char*>(pointCloud->getRGB24Data()), |
| 99 | sizeof(std::uint8_t) * 3 * points); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | outputStream.close(); |
| 104 | } |
| 105 | |
| 106 | } // anonymous namespace |
| 107 |
no test coverage detected