Ocean
Loading...
Searching...
No Matches
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
14
17
19
20#include <ARKit/ARKit.h>
21
23@end
24
25namespace Ocean
26{
27
28namespace Devices
29{
30
31namespace ARKit
32{
33
34/// Forward declaration.
35class AKGeoAnchorsTracker6DOF;
36
37/// Forward declaration.
38class AKSceneTracker6DOF;
39
40/// Forward declaration.
41class AKWorldTracker6DOF;
42
43/**
44 * This class implements a device for the ARKit library.
45 * @ingroup devicesarkit
46 */
47class 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 /**
145 * Definition of an unordered map mapping names to values.
146 */
147 using ParameterMap = std::unordered_map<std::string, Value>;
148
149 public:
150
151 /**
152 * Returns the name of the owner library.
153 * @see Device::library().
154 */
155 const std::string& library() const override;
156
157 /**
158 * Returns the capabilities of the tracker necessary for this device.
159 * @return The tracker capabilities
160 */
161 inline TrackerCapabilities trackerCapabilities() const;
162
163 /**
164 * Event function for added anchors.
165 * @param anchors The added anchors, at least one
166 */
167 virtual void onAddedAnchors(const ARAnchors& anchors);
168
169 /**
170 * Event function for updated anchors.
171 * @param anchors The updated anchors, at least one
172 */
173 virtual void onUpdateAnchors(const ARAnchors& anchors);
174
175 /**
176 * Event function for removed anchors.
177 * @param anchors The removed anchors, at least one
178 */
179 virtual void onRemovedAnchors(const ARAnchors& anchors);
180
181 /**
182 * Sets a parameter for this tracker.
183 * Supprted parameters 'noFrameToFrameTracking', 'noDownsamplingOnAndroid'.
184 * @see Device::setParameter().
185 */
186 bool setParameter(const std::string& parameter, const Value& value) override;
187
188 /**
189 * Returns a parameter of this device.
190 * Supprted parameters 'noFrameToFrameTracking', 'noDownsamplingOnAndroid'.
191 * @see Device::parameter().
192 */
193 bool parameter(const std::string& parameter, Value& value) override;
194
195 /**
196 * Translates the value of an ARTrackingState to a readable string.
197 * @param state The state to translate
198 * @return The readable string
199 */
200 static std::string translateTrackingState(const ARTrackingState& state);
201
202 /**
203 * Translates the value of an ARGeoTrackingState to a readable string.
204 * @param state The state to translate
205 * @return The readable string
206 */
207 API_AVAILABLE(ios(14.0))
208 static std::string translateGeoTrackingState(const ARGeoTrackingState& state);
209
210 /**
211 * Translates the value of an ARGeoTrackingStateReason to a readable string.
212 * @param stateReason The state reason to translate
213 * @return The readable string
214 */
215 API_AVAILABLE(ios(14.0))
216 static std::string translateGeoTrackingStateReason(const ARGeoTrackingStateReason& stateReason);
217
218 /**
219 * Translates the value of an ARGeoTrackingAccuracy to a readable string.
220 * @param accuracy The accuracy to translate
221 * @return The readable string
222 */
223 API_AVAILABLE(ios(14.0))
224 static std::string translateGeoTrackingAccuracy(const ARGeoTrackingAccuracy& accuracy);
225
226 protected:
227
228 /**
229 * Creates a new device by is name.
230 * @param trackerCapabilities The capabilities of the tracker necessary for this device
231 * @param name The name of the device
232 * @param type Major and minor device type of the device
233 */
234 AKDevice(const TrackerCapabilities trackerCapabilities, const std::string& name, const DeviceType type);
235
236 protected:
237
238 /// The capabilities of the tracker for this device.
239 TrackerCapabilities trackerCapabilities_ = TC_INVALID;
240
241 /// The map with optional parameters.
242 ParameterMap parameterMap_;
243};
244
245inline AKDevice::TrackerCapabilities AKDevice::trackerCapabilities() const
246{
247 return trackerCapabilities_;
248}
249
250}
251
252}
253
254}
255
256#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
bool setParameter(const std::string &parameter, const Value &value) override
Sets a parameter for this tracker.
virtual void onRemovedAnchors(const ARAnchors &anchors)
Event function for removed anchors.
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
static std::string translateTrackingState(const ARTrackingState &state)
Translates the value of an ARTrackingState to a readable string.
bool parameter(const std::string &parameter, Value &value) override
Returns a parameter of this device.
std::unordered_map< std::string, Value > ParameterMap
Definition of an unordered map mapping names to values.
Definition AKDevice.h:147
virtual void onUpdateAnchors(const ARAnchors &anchors)
Event function for updated anchors.
TrackerCapabilities
Definition of individual capabilities.
Definition AKDevice.h:55
const std::string & library() const override
Returns the name of the owner library.
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
This class implements a type independent value.
Definition Value.h:23
SmartMediumRef< FrameMedium > FrameMediumRef
Definition of a smart medium reference holding a frame medium object.
Definition FrameMedium.h:39
Definition AKDevice.h:22
The namespace covering the entire Ocean framework.
Definition Accessor.h:15