1 #ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_POINT_CLOUD_H_ // NOLINT 2 #define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_POINT_CLOUD_H_ // NOLINT 3 4 #include <memory> 5 #include <string> 6 #include <unordered_map> 7 8 #include "dynamic_depth/element.h" 9 #include "xmpmeta/xml/deserializer.h" 10 #include "xmpmeta/xml/serializer.h" 11 12 // Implements the Point Cloud element from the Dynamic Depth specification, with 13 // serialization and deserialization. 14 namespace dynamic_depth { 15 16 class PointCloud : public Element { 17 public: 18 void GetNamespaces( 19 std::unordered_map<string, string>* ns_name_href_map) override; 20 21 bool Serialize( 22 ::dynamic_depth::xmpmeta::xml::Serializer* serializer) const override; 23 24 // Creates a Point Cloud from the given fields. Returns null if position is 25 // empty or points.size() is not divisible by 4. 26 // The first two arguments are required fields, the rest are optional. 27 // points is a list of (x, y, z, c) tuples, so it must have a size that is 28 // evenly divisible by 4. 29 // The first three values are the point's XYZ coordinates, and the fourth 30 // is the confidence value. More details are available in the specification. 31 static std::unique_ptr<PointCloud> FromData(const std::vector<float>& points, 32 bool metric); 33 34 // Returns the deserialized PointCloud; null if parsing fails. 35 // The returned pointer is owned by the caller. 36 static std::unique_ptr<PointCloud> FromDeserializer( 37 const ::dynamic_depth::xmpmeta::xml::Deserializer& parent_deserializer); 38 39 // Getters. 40 // Returns the number of (x, y, z, c) tuples, *not* the length of points_. 41 int GetPointCount() const; 42 const std::vector<float>& GetPoints() const; 43 bool GetMetric() const; 44 45 PointCloud(const PointCloud&) = delete; 46 void operator=(const PointCloud&) = delete; 47 48 private: 49 PointCloud(); 50 51 bool ParseFields( 52 const ::dynamic_depth::xmpmeta::xml::Deserializer& deserializer); 53 54 // Required fields. 55 std::vector<float> points_; 56 57 // Optional fields. 58 bool metric_; 59 }; 60 61 } // namespace dynamic_depth 62 63 #endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_POINT_CLOUD_H_ // NOLINT 64