| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef SRC_DATAFILE_DATAFILE_HPP_ | ||
| 2 | #define SRC_DATAFILE_DATAFILE_HPP_ | ||
| 3 | |||
| 4 | #include <memory> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <string> | ||
| 7 | |||
| 8 | #include "common/spatial/attitude-utils.hpp" // Includes Vec3 and EulerAngles | ||
| 9 | #include "common/style.hpp" | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @file datafile.hpp | ||
| 13 | * @brief Declares data structures for serialized spatial data files, including headers, | ||
| 14 | * location records, and full data file representations. | ||
| 15 | * | ||
| 16 | * @note All decimal variables are written as type double regardless of underlying | ||
| 17 | * definition | ||
| 18 | */ | ||
| 19 | |||
| 20 | namespace found { | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @brief Represents the header of a data file used in the serialization process. | ||
| 24 | * | ||
| 25 | * Contains metadata such as a magic identifier, version, number of position records, | ||
| 26 | * and a CRC32 checksum for integrity verification. | ||
| 27 | */ | ||
| 28 | struct DataFileHeader { | ||
| 29 | /** | ||
| 30 | * @brief Magic identifier used to validate file type. | ||
| 31 | * | ||
| 32 | * The magic string "FOUN" is used to identify this file format during deserialization. | ||
| 33 | * This is similar to other file formats (e.g., PNG, PDF) that include a recognizable | ||
| 34 | * signature at the start of the file. If the magic value doesn't match, the file | ||
| 35 | * is considered invalid or corrupted. | ||
| 36 | */ | ||
| 37 | char magic[4] = {'F', 'O', 'U', 'N'}; | ||
| 38 | |||
| 39 | /** | ||
| 40 | * @brief Version of the file format. | ||
| 41 | * Default is 1. Used to support versioned deserialization in the future. | ||
| 42 | */ | ||
| 43 | uint32_t version = 1U; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * @brief Number of position entries (Vec3 elements) in the file. | ||
| 47 | */ | ||
| 48 | uint32_t num_positions; | ||
| 49 | |||
| 50 | /** | ||
| 51 | * @brief CRC32 checksum of the header (excluding this field) for validation. | ||
| 52 | */ | ||
| 53 | uint32_t crc; | ||
| 54 | }; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * @brief Represents a complete serialized data file. | ||
| 58 | * | ||
| 59 | * Contains the file header, relative orientation of the sensor, and a list of spatial position records. | ||
| 60 | */ | ||
| 61 | struct DataFile { | ||
| 62 | /** | ||
| 63 | * @brief Metadata header for the file (includes magic, version, and CRC). | ||
| 64 | */ | ||
| 65 | DataFileHeader header; | ||
| 66 | |||
| 67 | /** | ||
| 68 | * @brief Relative orientation (attitude) of the object as Euler angles. | ||
| 69 | * | ||
| 70 | * @note This is a backwards rotation, and is generated by reference and | ||
| 71 | * local backwards quaternions | ||
| 72 | * | ||
| 73 | * @note This must be multiplied by another backwards quaternion to get | ||
| 74 | * a meaningful orientation, the result of which is also a backwards quaternion | ||
| 75 | */ | ||
| 76 | Quaternion relative_attitude; | ||
| 77 | |||
| 78 | /** | ||
| 79 | * @brief Collection of location records in the file. | ||
| 80 | */ | ||
| 81 | std::unique_ptr<LocationRecord[]> positions; | ||
| 82 | |||
| 83 | /** | ||
| 84 | * The path of this DataFile. | ||
| 85 | * | ||
| 86 | * @note This is not a saved field | ||
| 87 | */ | ||
| 88 | std::string path; | ||
| 89 | |||
| 90 | /// Constructs this | ||
| 91 | 46 | DataFile() = default; | |
| 92 | |||
| 93 | /** | ||
| 94 | * Moves another DataFile | ||
| 95 | * | ||
| 96 | * @param other The file to copy | ||
| 97 | */ | ||
| 98 | 12 | DataFile(DataFile &&other) noexcept = default; | |
| 99 | |||
| 100 | /** | ||
| 101 | * Moves another DataFile | ||
| 102 | * | ||
| 103 | * @param other The file to copy | ||
| 104 | * | ||
| 105 | * @return The resulting data file (this) | ||
| 106 | */ | ||
| 107 | 13 | DataFile &operator=(DataFile &&other) = default; | |
| 108 | }; | ||
| 109 | |||
| 110 | } // namespace found | ||
| 111 | |||
| 112 | #endif // SRC_DATAFILE_DATAFILE_HPP_ | ||
| 113 |