| 124 | } |
| 125 | |
| 126 | void Serializer::serializeVioOutput(spectacularAI::VioOutputPtr vioOutput) { |
| 127 | const spectacularAI::Camera &camera = *vioOutput->getCameraPose(0).camera; |
| 128 | const Matrix4d &cameraToWorld = vioOutput->getCameraPose(0).getCameraToWorldMatrix(); |
| 129 | |
| 130 | // Only properties used in current visualization are serialized, i.e. add more stuff if needed. |
| 131 | nlohmann::json json; |
| 132 | json["cameraPoses"] = { |
| 133 | { |
| 134 | {"camera", serializeCamera(camera)}, |
| 135 | {"cameraToWorld", cameraToWorld} |
| 136 | } |
| 137 | }; |
| 138 | json["trackingStatus"] = static_cast<int32_t>(vioOutput->status); |
| 139 | |
| 140 | std::string jsonStr = json.dump(); |
| 141 | uint32_t jsonLength = jsonStr.length(); |
| 142 | |
| 143 | MessageHeader header = { |
| 144 | .magicBytes = MAGIC_BYTES, |
| 145 | .messageId = messageIdCounter, |
| 146 | .jsonSize = jsonLength, |
| 147 | .binarySize = 0 |
| 148 | }; |
| 149 | |
| 150 | std::lock_guard<std::mutex> lock(outputMutex); |
| 151 | outputStream.write(reinterpret_cast<char*>(&header), sizeof(MessageHeader)); |
| 152 | outputStream.write(jsonStr.c_str(), jsonStr.size()); |
| 153 | outputStream.flush(); |
| 154 | messageIdCounter++; |
| 155 | } |
| 156 | |
| 157 | void Serializer::serializeMappingOutput(spectacularAI::mapping::MapperOutputPtr mapperOutput) { |
| 158 | std::map<std::string, nlohmann::json> jsonKeyFrames; |
no test coverage detected