Ocean
AKPlaneTracker6DOF.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_DEVICES_ARKIT_AK_PLANE_TRACKER_6_DOF_H
9 #define META_OCEAN_DEVICES_ARKIT_AK_PLANE_TRACKER_6_DOF_H
10 
13 
16 
17 namespace Ocean
18 {
19 
20 namespace Devices
21 {
22 
23 namespace ARKit
24 {
25 
26 /**
27  * This class implements a 6DOF plane tracker based on ARKit.
28  * @ingroup devicesarkit
29  */
30 class OCEAN_DEVICES_ARKIT_EXPORT AKPlaneTracker6DOF :
31  virtual public AKDevice,
32  virtual public SceneTracker6DOF,
33  virtual public VisualTracker
34 {
35  friend class AKFactory;
36 
37  protected:
38 
39  /**
40  * Definition of an unordered map mapping anchor identifier strings to unique ids.
41  */
42  typedef std::unordered_map<std::string, Index32> IdentifierMap;
43 
44  public:
45 
46  /**
47  * Starts the device.
48  * @see Device::start().
49  */
50  bool start() override;
51 
52  /**
53  * Pauses the device.
54  * @see Device::pause().
55  */
56  bool pause() override;
57 
58  /**
59  * Stops the device.
60  * @see Device::stop().
61  */
62  bool stop() override;
63 
64  /**
65  * Sets the multi-view visual input of this tracker.
66  * @see VisualTracker::setInput().
67  */
68  void setInput(Media::FrameMediumRefs&& frameMediums) override;
69 
70  /**
71  * Returns whether a specific object is currently actively tracked by this tracker.
72  * @see Tracker::isObjectTracked().
73  */
74  bool isObjectTracked(const ObjectId& objectId) const override;
75 
76  /**
77  * Event function for a new 6DOF pose.
78  * @param world_T_camera The transformation between camera and world, invalid if unknown/lost
79  * @param timestamp The timestamp of the new transformation
80  * @param arFrame The current ARFRame object containing additional data for the sample, must be valid
81  */
82  API_AVAILABLE(ios(11.3))
83  void onNewSample(const HomogenousMatrix4& world_T_camera, const Timestamp& timestamp, ARFrame* arFrame);
84 
85  /**
86  * Event function for a new 6DOF pose.
87  * @param world_T_camera The transformation between camera and world, invalid if unknown/lost
88  * @param sceneElement The scene element which is part of the sample, nullptr if no scene element is known
89  * @param timestamp The timestamp of the new transformation
90  * @param metadata The metadata of the sample
91  */
92  void onNewSample(const HomogenousMatrix4& world_T_camera, SharedSceneElement&& sceneElement, const Timestamp& timestamp, Metadata&& metadata);
93 
94  /**
95  * Returns the name of this tracker.
96  * @return The trackers's name
97  */
98  static inline std::string deviceNameAKPlaneTracker6DOF();
99 
100  /**
101  * Returns the device type of this tracker.
102  * @return The tracker's device type
103  */
104  static inline DeviceType deviceTypeAKPlaneTracker6DOF();
105 
106  protected:
107 
108  /**
109  * Creates a new 6DOF plane tracker.
110  */
111  explicit AKPlaneTracker6DOF();
112 
113  /**
114  * Destructs this 6DOF tracker.
115  */
116  ~AKPlaneTracker6DOF() override;
117 
118  protected:
119 
120  /// The unique id for the world object.
121  ObjectId worldObjectId_ = invalidObjectId();
122 
123  /// True, if the tracker has been started.
124  bool isStarted_ = false;
125 
126  /// True, if the world object is currently tracked.
127  bool worldIsTracked_ = false;
128 
129  /// The map mapping unique plane identifier strings to plane ids.
130  IdentifierMap identifierMap_;
131 
132  /// The counter for unique plane ids.
133  unsigned int planeIdCounter_ = 0u;
134 };
135 
136 inline std::string AKPlaneTracker6DOF::deviceNameAKPlaneTracker6DOF()
137 {
138  return std::string("ARKit 6DOF Plane Tracker");
139 }
140 
142 {
143  return DeviceType(deviceTypeTracker6DOF(), TRACKER_VISUAL | SCENE_TRACKER_6DOF);
144 }
145 
146 }
147 
148 }
149 
150 }
151 
152 #endif // META_OCEAN_DEVICES_ARKIT_AK_PLANE_TRACKER_6_DOF_H
This class implements a device for the ARKit library.
Definition: AKDevice.h:48
This class implements a device factory for the ARKit tracking library.
Definition: AKFactory.h:32
This class implements a 6DOF plane tracker based on ARKit.
Definition: AKPlaneTracker6DOF.h:34
bool isObjectTracked(const ObjectId &objectId) const override
Returns whether a specific object is currently actively tracked by this tracker.
bool stop() override
Stops the device.
bool pause() override
Pauses the device.
API_AVAILABLE(ios(11.3)) void onNewSample(const HomogenousMatrix4 &world_T_camera
Event function for a new 6DOF pose.
std::unordered_map< std::string, Index32 > IdentifierMap
Definition of an unordered map mapping anchor identifier strings to unique ids.
Definition: AKPlaneTracker6DOF.h:42
bool start() override
Starts the device.
static DeviceType deviceTypeAKPlaneTracker6DOF()
Returns the device type of this tracker.
Definition: AKPlaneTracker6DOF.h:141
void setInput(Media::FrameMediumRefs &&frameMediums) override
Sets the multi-view visual input of this tracker.
Definition of a class holding the major and minor device type.
Definition: devices/Device.h:62
unsigned int ObjectId
Definition of an object id.
Definition: Measurement.h:46
std::unordered_map< std::string, Value > Metadata
Definition of an unordered map mapping keys to values.
Definition: Measurement.h:61
This class implements the base for all 6-DOF scene trackers.
Definition: SceneTracker6DOF.h:42
std::shared_ptr< SceneElement > SharedSceneElement
Definition of a shared pointer holding a scene element.
Definition: SceneTracker6DOF.h:896
This class is the base class for all tracker using visual input to create the tracking results.
Definition: devices/VisualTracker.h:41
This class implements a timestamp.
Definition: Timestamp.h:36
std::vector< FrameMediumRef > FrameMediumRefs
Definition of a vector holding frame medium reference objects.
Definition: FrameMedium.h:46
const ObjectId invalidObjectId
Definition of an invalid object id.
Definition: rendering/Rendering.h:65
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15