• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_POSE_H_  // NOLINT
2 #define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_POSE_H_  // NOLINT
3 
4 #include <memory>
5 #include <string>
6 #include <unordered_map>
7 #include <vector>
8 
9 #include "dynamic_depth/element.h"
10 #include "xmpmeta/xml/deserializer.h"
11 #include "xmpmeta/xml/serializer.h"
12 
13 namespace dynamic_depth {
14 
15 /**
16  * Implements the Pose element in the Dynamic Depth specification, with
17  * serialization and deserialization.
18  * See xdm.org.
19  */
20 class Pose : public Element {
21  public:
22   // Appends child elements' namespaces' and their respective hrefs to the
23   // given collection, and any parent nodes' names to prefix_names.
24   // Key: Name of the namespace.
25   // Value: Full namespace URL.
26   // Example: ("Pose", "http://ns.google.com/photos/dd/1.0/pose/")
27   void GetNamespaces(
28       std::unordered_map<string, string>* ns_name_href_map) override;
29 
30   // Serializes this object. Returns true on success.
31   bool Serialize(
32       ::dynamic_depth::xmpmeta::xml::Serializer* serializer) const override;
33 
34   // Creates a Pose from the given data.
35   // The order of values in position is x, y, z.
36   // The order of values in orientation is the quaternion x, y, z, w fields.
37   // This is assusmed to be un-normalized.
38   // Position coordinates are relative to Camera 0, and must be 0 for Camera 0.
39   // Position and orientation are in raw coordinates, and will be stored as
40   // normalied values.
41   // At least one valid position or orientation must be provided. These
42   // arguments will be ignored if the vector is of the wrong size.
43   static std::unique_ptr<Pose> FromData(const std::vector<float>& position,
44                                         const std::vector<float>& orientation,
45                                         const int64 timestamp = -1);
46 
47   // Returns the deserialized XdmAudio; null if parsing fails.
48   // The returned pointer is owned by the caller.
49   static std::unique_ptr<Pose> FromDeserializer(
50       const ::dynamic_depth::xmpmeta::xml::Deserializer& parent_deserializer,
51       const char* parent_namespace);
52 
53   // Returns true if the device's position is provided.
54   bool HasPosition() const;
55 
56   // Returns true if the device's orientation is provided.
57   bool HasOrientation() const;
58 
59   // Returns the device's position fields, or an empty vector if they are
60   // not present.
61   const std::vector<float>& GetPosition() const;
62 
63   // Returns the device's orientation fields, or an empty vector if they are
64   // not present.
65   const std::vector<float>& GetOrientation() const;
66 
67   // Timestamp.
68   int64 GetTimestamp() const;
69 
70   // Disallow copying.
71   Pose(const Pose&) = delete;
72   void operator=(const Pose&) = delete;
73 
74  private:
75   Pose();
76 
77   // Extracts camera pose fields.
78   bool ParsePoseFields(
79       const ::dynamic_depth::xmpmeta::xml::Deserializer& deserializer);
80 
81   // Position variables, in meters relative to camera 0.
82   // If providing position data, all three fields must be set.
83   // Stored in normalized form.
84   // TODO(miraleung): Cleanup: consider std::optional for this and orientation_.
85   std::vector<float> position_;
86 
87   // Orientation variables.
88   // If providing orientation data, all four fields must be set.
89   // Stored in normalized form.
90   std::vector<float> orientation_;
91 
92   // Timestamp is Epoch time in milliseconds.
93   int64 timestamp_;
94 };
95 
96 }  // namespace dynamic_depth
97 
98 #endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_POSE_H_  // NOLINT
99