• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_PLANE_H_  // NOLINT
2 #define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_PLANE_H_  // NOLINT
3 
4 #include <memory>
5 #include <string>
6 #include <unordered_map>
7 
8 #include "dynamic_depth/element.h"
9 #include "dynamic_depth/pose.h"
10 #include "xmpmeta/xml/deserializer.h"
11 #include "xmpmeta/xml/serializer.h"
12 
13 namespace dynamic_depth {
14 
15 // A Plane element for a Dynamic Depth device.
16 // Only horizontal planes are currently supported.
17 class Plane : public Element {
18  public:
19   // Appends child elements' namespaces' and their respective hrefs to the
20   // given collection, and any parent nodes' names to prefix_names.
21   // Key: Name of the namespace.
22   // Value: Full namespace URL.
23   // Example: ("Plane", "http://ns.google.com/photos/dd/1.0/plane/")
24   void GetNamespaces(
25       std::unordered_map<string, string>* ns_name_href_map) override;
26 
27   // Serializes this object.
28   bool Serialize(
29       ::dynamic_depth::xmpmeta::xml::Serializer* serializer) const override;
30 
31   // Returns the deserialized Plane; null if parsing fails.
32   static std::unique_ptr<Plane> FromDeserializer(
33       const ::dynamic_depth::xmpmeta::xml::Deserializer& parent_deserializer);
34 
35   // Creates a Plane from the given fields.
36   // The Pose must be present.
37   // boundary contains the bounding vertices: [x0, z0, x1, z1, ..., xn, zn].
38   // extent_x is the length of the plane on the X axis.
39   // extent_z is the length of the plane on the Z axis.
40   static std::unique_ptr<Plane> FromData(std::unique_ptr<Pose> pose,
41                                          const std::vector<float>& boundary,
42                                          const double extent_x,
43                                          const double extent_z);
44 
45   // Getters.
46   const Pose* GetPose() const;
47 
48   // Returns the plane's bounding vertices on the XZ plane.
49   const std::vector<float>& GetBoundary() const;
50 
51   // Returns the number of vertices in the boundary polygon.
52   int GetBoundaryVertexCount() const;
53 
54   // Returns the plane's length along the X axis.
55   const double GetExtentX() const;
56 
57   // Returns the plane's length along the Z axis.
58   const double GetExtentZ() const;
59 
60   // Disallow copying.
61   Plane(const Plane&) = delete;
62   void operator=(const Plane&) = delete;
63 
64  private:
65   Plane();
66 
67   // Extracts plane fields.
68   bool ParsePlaneFields(
69       const ::dynamic_depth::xmpmeta::xml::Deserializer& deserializer);
70 
71   // The pose of the center of this plane.
72   std::unique_ptr<Pose> pose_;
73 
74   // Contains the plane's bounding vertices: [x0, z0, x1, z1, ..., xn, zn].
75   // Optional field, set to an empty vector if not present.
76   std::vector<float> boundary_;
77 
78   // Required field if "Boundary" is present. Optional otherwise and
79   // expected to be zero; set to 0 if not present.
80   int boundary_vertex_count_;
81 
82   // The length of the plane on the X axis. A value of -1 represents infinity.
83   // Optional field, set to -1 (infinity) if not present.
84   double extent_x_;
85 
86   // The length of the plane on the Z axis. A value of -1 represents infinity.
87   // Optional field, set to -1 (infinity) if not present.
88   double extent_z_;
89 };
90 
91 }  // namespace dynamic_depth
92 
93 #endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_PLANE_H_  // NOLINT
94