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  /**
73  * Definition of a vector holding ARAnchors.
74  */
75  using ARAnchors = std::vector<ARAnchor*>;
76 
77  /**
78  * Definition of an unordered map mapping devices to usage counters.
79  */
80  using DeviceMap = std::unordered_map<AKDevice*, unsigned int>;
81 
82  protected:
83 
84  /**
85  * This class implements a wrapper around the actual ARSessionDelegate which may be used by several devices at the same time.
86  */
87  class OCEAN_DEVICES_ARKIT_EXPORT ARSessionManager : public Singleton<ARSessionManager>
88  {
89  friend class Singleton<ARSessionManager>;
90 
91  public:
92 
93  /**
94  * Starts the session for a given tracker.
95  * @param tracker The tracker for which the session will be started, must be valid
96  * @param frameMedium The frame medium the session will use, must be valid
97  * @return True, if succeeded
98  */
99  bool start(AKDevice* tracker, const Media::FrameMediumRef& frameMedium);
100 
101  /**
102  * Pauses the session for a given tracker.
103  * @param tracker The tracker for which the session will be paused, must be valid
104  * @return True, if succeeded
105  */
106  bool pause(AKDevice* tracker);
107 
108  /**
109  * Stops the session for a given tracker.
110  * @param tracker The tracker for which the session will be stopped, must be valid
111  * @return True, if succeeded
112  */
113  bool stop(AKDevice* tracker);
114  /**
115  * Registers a new geo anchor.
116  * @param objectId The id of the object associated with the geo anchor, must be valid
117  * @param latitude The latitude of the geo anchor, with range [-90, 90]
118  * @param longitude The longitude of the geo anchor, with range [-180, 180]
119  * @param altitude The altitude of the geo anchor, with range [-10,000, 30,000], or NumericD::minValue() if unknown
120  * @return True, if succeeded
121  */
122  bool registerGeoAnchor(const Measurement::ObjectId& objectId, const double latitude, const double longitude, const double altitude);
123 
124  /**
125  * Unregisters a geo anchor.
126  * @param objectId The id of the object which is associated with the geo anchor to unregister, must be valid
127  * @return True, if succeeded
128  */
130 
131  protected:
132 
133  /**
134  * Creates a new manager.
135  */
137 
138  protected:
139 
140  /// The delegate of the ARKit Tracker.
141  AKTracker6DOFDelegate* akTracker6DOFDelegate_ = nullptr;
142  };
143 
144  public:
145 
146  /**
147  * Returns the name of the owner library.
148  * @see Device::library().
149  */
150  const std::string& library() const override;
151 
152  /**
153  * Returns the capabilities of the tracker necessary for this device.
154  * @return The tracker capabilities
155  */
156  inline TrackerCapabilities trackerCapabilities() const;
157 
158  /**
159  * Event function for added anchors.
160  * @param anchors The added anchors, at least one
161  */
162  virtual void onAddedAnchors(const ARAnchors& anchors);
163 
164  /**
165  * Event function for updated anchors.
166  * @param anchors The updated anchors, at least one
167  */
168  virtual void onUpdateAnchors(const ARAnchors& anchors);
169 
170  /**
171  * Event function for removed anchors.
172  * @param anchors The removed anchors, at least one
173  */
174  virtual void onRemovedAnchors(const ARAnchors& anchors);
175 
176  /**
177  * Translates the value of an ARGeoTrackingState to a readable string.
178  * @param state The state to translate
179  * @return The readable string
180  */
181  API_AVAILABLE(ios(14.0))
182  static std::string translateGeoTrackingState(const ARGeoTrackingState& state);
183 
184  /**
185  * Translates the value of an ARGeoTrackingStateReason to a readable string.
186  * @param stateReason The state reason to translate
187  * @return The readable string
188  */
189  API_AVAILABLE(ios(14.0))
190  static std::string translateGeoTrackingStateReason(const ARGeoTrackingStateReason& stateReason);
191 
192  /**
193  * Translates the value of an ARGeoTrackingAccuracy to a readable string.
194  * @param accuracy The accuracy to translate
195  * @return The readable string
196  */
197  API_AVAILABLE(ios(14.0))
198  static std::string translateGeoTrackingAccuracy(const ARGeoTrackingAccuracy& accuracy);
199 
200  protected:
201 
202  /**
203  * Creates a new device by is name.
204  * @param trackerCapabilities The capabilities of the tracker necessary for this device
205  * @param name The name of the device
206  * @param type Major and minor device type of the device
207  */
208  AKDevice(const TrackerCapabilities trackerCapabilities, const std::string& name, const DeviceType type);
209 
210  protected:
211 
212  /// The capabilities of the tracker for this device.
213  TrackerCapabilities trackerCapabilities_ = TC_INVALID;
214 };
215 
216 inline AKDevice::TrackerCapabilities AKDevice::trackerCapabilities() const
217 {
218  return trackerCapabilities_;
219 }
220 
221 }
222 
223 }
224 
225 }
226 
227 #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:88
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
virtual void onRemovedAnchors(const ARAnchors &anchors)
Event function for removed anchors.
const std::string & library() const override
Returns the name of the owner library.
std::unordered_map< AKDevice *, unsigned int > DeviceMap
Definition of an unordered map mapping devices to usage counters.
Definition: AKDevice.h:80
virtual void onAddedAnchors(const ARAnchors &anchors)
Event function for added anchors.
std::vector< ARAnchor * > ARAnchors
Definition of a vector holding ARAnchors.
Definition: AKDevice.h:75
virtual void onUpdateAnchors(const ARAnchors &anchors)
Event function for updated anchors.
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