• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_EARTH_POSE_H_  // NOLINT
2 #define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_EARTH_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 // Implements the EarthPose element in the Dynamic Depth specification, with
16 // serialization and deserialization.
17 class EarthPose : 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: ("EarthPose", "http://ns.google.com/photos/dd/1.0/earthpose/")
24   void GetNamespaces(
25       std::unordered_map<string, string>* ns_name_href_map) override;
26 
27   // Serializes this object. Returns true on success.
28   bool Serialize(
29       ::dynamic_depth::xmpmeta::xml::Serializer* serializer) const override;
30 
31   // Creates a EarthPose from the given data.
32   // The order of values in position is latitude, longitude, altitude..
33   // The order of values in orientation is the quaternion x, y, z, w fields.
34   // rotation angle in quaternion format.
35   // Position and orientation are in raw coordinates, and will be stored as
36   // normalied values. Please refer to the Dynamic Depth specification for the
37   // Realm coordinate system.
38   // At least one valid position or orientation must be provided. These
39   // arguments will be ignored if the vector is of the wrong size.
40   static std::unique_ptr<EarthPose> FromData(
41       const std::vector<double>& position,
42       const std::vector<float>& orientation, const int64 timestamp = -1);
43 
44   // Returns the deserialized XdmAudio; null if parsing fails.
45   // The returned pointer is owned by the caller.
46   static std::unique_ptr<EarthPose> FromDeserializer(
47       const ::dynamic_depth::xmpmeta::xml::Deserializer& parent_deserializer);
48 
49   // Returns true if the device's position is provided.
50   bool HasPosition() const;
51 
52   // Returns true if the device's orientation is provided.
53   bool HasOrientation() const;
54 
55   // Returns the device's position fields, or an empty vector if they are
56   // not present.
57   const std::vector<double>& GetPosition() const;
58 
59   // Returns the device's orientation fields, or an empty vector if they are
60   // not present.
61   const std::vector<float>& GetOrientation() const;
62 
63   // Timestamp.
64   int64 GetTimestamp() const;
65 
66   // Disallow copying.
67   EarthPose(const EarthPose&) = delete;
68   void operator=(const EarthPose&) = delete;
69 
70  private:
71   EarthPose();
72 
73   // Extracts device pose fields.
74   bool ParseEarthPoseFields(
75       const ::dynamic_depth::xmpmeta::xml::Deserializer& deserializer);
76 
77   // Position variables, in meters relative to camera 0.
78   // If providing position data, all three fields must be set.
79   // Stored in normalized form.
80   // TODO(miraleung): Cleanup: consider std::optional for this and orientation_.
81   std::vector<double> position_;
82 
83   // Orientation variables.
84   // If providing orientation data, all four fields must be set.
85   // Stored in normalized form.
86   std::vector<float> orientation_;
87 
88   // Timestamp is Epoch time in milliseconds.
89   int64 timestamp_;
90 };
91 
92 }  // namespace dynamic_depth
93 
94 #endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_EARTH_POSE_H_  // NOLINT
95