Ocean
AKDevice.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_DEVICE_H
9 #define META_OCEAN_DEVICES_ARKIT_AK_DEVICE_H
10 
12 
13 #include "ocean/base/Singleton.h"
14 
15 #include "ocean/devices/Device.h"
17 
19 
20 #include <ARKit/ARKit.h>
21 
23 @end
24 
25 namespace Ocean
26 {
27 
28 namespace Devices
29 {
30 
31 namespace ARKit
32 {
33 
34 /// Forward declaration.
35 class AKGeoAnchorsTracker6DOF;
36 
37 /// Forward declaration.
38 class AKSceneTracker6DOF;
39 
40 /// Forward declaration.
41 class AKWorldTracker6DOF;
42 
43 /**
44  * This class implements a device for the ARKit library.
45  * @ingroup devicesarkit
46  */
47 class OCEAN_DEVICES_ARKIT_EXPORT AKDevice : virtual public Device
48 {
49  public:
50 
51  /**
52  * Definition of individual capabilities.
53  */
54  enum TrackerCapabilities : uint32_t
55  {
56  /// An invalid capability.
57  TC_INVALID = 0u,
58  /// The tracker provides basic SLAM.
59  TC_SLAM = 1u << 0u,
60  /// The tracker provides Geo Anchors.
61  TC_GEO_ANCHORS = 1u << 1u,
62  /// The tracker provide plane detection.
63  TC_PLANE_DETECTION = 1u << 2u,
64  /// The tracker provide mesh reconstruction.
65  TC_MESH_RECONSTRUCTION = 1u << 3u,
66  /// The tracker provides depth information.
67  TC_DEPTH = 1u << 4u,
68  /// The tracker is able to track faces.
69  TC_FACE = 1u << 5u
70  };
71 
72  protected:
73 
74  /**
75  * This class implements a wrapper around the actual ARSessionDelegate which may be used by several devices at the same time.
76  */
77  class OCEAN_DEVICES_ARKIT_EXPORT ARSessionManager : public Singleton<ARSessionManager>
78  {
79  friend class Singleton<ARSessionManager>;
80 
81  public:
82 
83  /**
84  * Starts the session for a given tracker.
85  * @param tracker The tracker for which the session will be started, must be valid
86  * @param frameMedium The frame medium the session will use, must be valid
87  * @return True, if succeeded
88  */
89  bool start(AKDevice* tracker, const Media::FrameMediumRef& frameMedium);
90 
91  /**
92  * Pauses the session for a given tracker.
93  * @param tracker The tracker for which the session will be paused, must be valid
94  * @return True, if succeeded
95  */
96  bool pause(AKDevice* tracker);
97 
98  /**
99  * Stops the session for a given tracker.
100  * @param tracker The tracker for which the session will be stopped, must be valid
101  * @return True, if succeeded
102  */
103  bool stop(AKDevice* tracker);
104  /**
105  * Registers a new geo anchor.
106  * @param objectId The id of the object associated with the geo anchor, must be valid
107  * @param latitude The latitude of the geo anchor, with range [-90, 90]
108  * @param longitude The longitude of the geo anchor, with range [-180, 180]
109  * @param altitude The altitude of the geo anchor, with range [-10,000, 30,000], or NumericD::minValue() if unknown
110  * @return True, if succeeded
111  */
112  bool registerGeoAnchor(const Measurement::ObjectId& objectId, const double latitude, const double longitude, const double altitude);
113 
114  /**
115  * Unregisters a geo anchor.
116  * @param objectId The id of the object which is associated with the geo anchor to unregister, must be valid
117  * @return True, if succeeded
118  */
120 
121  protected:
122 
123  /**
124  * Creates a new manager.
125  */
127 
128  protected:
129 
130  /// The delegate of the ARKit Tracker.
131  AKTracker6DOFDelegate* akTracker6DOFDelegate_ = nullptr;
132  };
133 
134  public:
135 
136  /**
137  * Returns the name of the owner library.
138  * @see Device::library().
139  */
140  const std::string& library() const override;
141 
142  /**
143  * Returns the capabilities of the tracker necessary for this device.
144  * @return The tracker capabilities
145  */
146  inline TrackerCapabilities trackerCapabilities() const;
147 
148  /**
149  * Translates the value of an ARGeoTrackingState to a readable string.
150  * @param state The state to translate
151  * @return The readable string
152  */
153  API_AVAILABLE(ios(14.0))
154  static std::string translateGeoTrackingState(const ARGeoTrackingState& state);
155 
156  /**
157  * Translates the value of an ARGeoTrackingStateReason to a readable string.
158  * @param stateReason The state reason to translate
159  * @return The readable string
160  */
161  API_AVAILABLE(ios(14.0))
162  static std::string translateGeoTrackingStateReason(const ARGeoTrackingStateReason& stateReason);
163 
164  /**
165  * Translates the value of an ARGeoTrackingAccuracy to a readable string.
166  * @param accuracy The accuracy to translate
167  * @return The readable string
168  */
169  API_AVAILABLE(ios(14.0))
170  static std::string translateGeoTrackingAccuracy(const ARGeoTrackingAccuracy& accuracy);
171 
172  protected:
173 
174  /**
175  * Creates a new device by is name.
176  * @param trackerCapabilities The capabilities of the tracker necessary for this device
177  * @param name The name of the device
178  * @param type Major and minor device type of the device
179  */
180  AKDevice(const TrackerCapabilities trackerCapabilities, const std::string& name, const DeviceType type);
181 
182  protected:
183 
184  /// The capabilities of the tracker for this device.
185  TrackerCapabilities trackerCapabilities_ = TC_INVALID;
186 };
187 
188 inline AKDevice::TrackerCapabilities AKDevice::trackerCapabilities() const
189 {
190  return trackerCapabilities_;
191 }
192 
193 }
194 
195 }
196 
197 }
198 
199 #endif // META_OCEAN_DEVICES_ARKIT_AK_DEVICE_H
This class implements a wrapper around the actual ARSessionDelegate which may be used by several devi...
Definition: AKDevice.h:78
bool start(AKDevice *tracker, const Media::FrameMediumRef &frameMedium)
Starts the session for a given tracker.
bool pause(AKDevice *tracker)
Pauses the session for a given tracker.
bool stop(AKDevice *tracker)
Stops the session for a given tracker.
bool unregisterGeoAnchor(const Measurement::ObjectId &objectId)
Unregisters a geo anchor.
bool registerGeoAnchor(const Measurement::ObjectId &objectId, const double latitude, const double longitude, const double altitude)
Registers a new geo anchor.
This class implements a device for the ARKit library.
Definition: AKDevice.h:48
const std::string & library() const override
Returns the name of the owner library.
TrackerCapabilities
Definition of individual capabilities.
Definition: AKDevice.h:55
Definition of a class holding the major and minor device type.
Definition: devices/Device.h:62
This class is the base class for all devices of any type.
Definition: devices/Device.h:28
unsigned int ObjectId
Definition of an object id.
Definition: Measurement.h:46
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
SmartMediumRef< FrameMedium > FrameMediumRef
Definition of a smart medium reference holding a frame medium object.
Definition: FrameMedium.h:32
Definition: AKDevice.h:22
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15