summaryrefslogtreecommitdiff
path: root/includes/dynamic_depth/plane.h
blob: bec22890d7d33991766e24309e1ea54f7b10fe6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_PLANE_H_  // NOLINT
#define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_PLANE_H_  // NOLINT

#include <memory>
#include <string>
#include <unordered_map>

#include "dynamic_depth/element.h"
#include "dynamic_depth/pose.h"
#include "xmpmeta/xml/deserializer.h"
#include "xmpmeta/xml/serializer.h"

namespace photos_editing_formats {
namespace dynamic_depth {

// A Plane element for a Dynamic Depth device.
// Only horizontal planes are currently supported.
class Plane : public Element {
 public:
  // Appends child elements' namespaces' and their respective hrefs to the
  // given collection, and any parent nodes' names to prefix_names.
  // Key: Name of the namespace.
  // Value: Full namespace URL.
  // Example: ("Plane", "http://ns.google.com/photos/dd/1.0/plane/")
  void GetNamespaces(
      std::unordered_map<string, string>* ns_name_href_map) override;

  // Serializes this object.
  bool Serialize(xml::Serializer* serializer) const override;

  // Returns the deserialized Plane; null if parsing fails.
  static std::unique_ptr<Plane> FromDeserializer(
      const xml::Deserializer& parent_deserializer);

  // Creates a Plane from the given fields.
  // The Pose must be present.
  // boundary contains the bounding vertices: [x0, z0, x1, z1, ..., xn, zn].
  // extent_x is the length of the plane on the X axis.
  // extent_z is the length of the plane on the Z axis.
  static std::unique_ptr<Plane> FromData(std::unique_ptr<Pose> pose,
                                         const std::vector<float>& boundary,
                                         const double extent_x,
                                         const double extent_z);

  // Getters.
  const Pose* GetPose() const;

  // Returns the plane's bounding vertices on the XZ plane.
  const std::vector<float>& GetBoundary() const;

  // Returns the number of vertices in the boundary polygon.
  int GetBoundaryVertexCount() const;

  // Returns the plane's length along the X axis.
  const double GetExtentX() const;

  // Returns the plane's length along the Z axis.
  const double GetExtentZ() const;

  // Disallow copying.
  Plane(const Plane&) = delete;
  void operator=(const Plane&) = delete;

 private:
  Plane();

  // Extracts plane fields.
  bool ParsePlaneFields(const xml::Deserializer& deserializer);

  // The pose of the center of this plane.
  std::unique_ptr<Pose> pose_;

  // Contains the plane's bounding vertices: [x0, z0, x1, z1, ..., xn, zn].
  // Optional field, set to an empty vector if not present.
  std::vector<float> boundary_;

  // Required field if "Boundary" is present. Optional otherwise and
  // expected to be zero; set to 0 if not present.
  int boundary_vertex_count_;

  // The length of the plane on the X axis. A value of -1 represents infinity.
  // Optional field, set to -1 (infinity) if not present.
  double extent_x_;

  // The length of the plane on the Z axis. A value of -1 represents infinity.
  // Optional field, set to -1 (infinity) if not present.
  double extent_z_;
};

}  // namespace dynamic_depth
}  // namespace photos_editing_formats

#endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_PLANE_H_  // NOLINT