Ocean
AKSceneTracker6DOF.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_SCENE_TRACKER_6_DOF_H
9 #define META_OCEAN_DEVICES_ARKIT_AK_SCENE_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 the 6DOF scene tracker.
28  * @ingroup devicesarkit
29  */
30 class OCEAN_DEVICES_ARKIT_EXPORT AKSceneTracker6DOF :
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  using IdentifierMap = std::unordered_map<std::string, Index32>;
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 world_T_rotatedWorld The optional transformation between ARKit's rotated world and the standard world, should only be identity or the flip matrix around y-axis
80  * @param timestamp The timestamp of the new transformation
81  * @param arFrame The current ARFRame object containing additional data for the sample, must be valid
82  */
83  API_AVAILABLE(ios(11.3))
84  void onNewSample(const HomogenousMatrix4& world_T_camera, const HomogenousMatrix4& world_T_rotatedWorld, const Timestamp& timestamp, ARFrame* arFrame);
85 
86  /**
87  * Event function for a new 6DOF pose.
88  * @param world_T_camera The transformation between camera and world, invalid if unknown/lost
89  * @param sceneElements The scene elements which are part of the sample, at least one
90  * @param timestamp The timestamp of the new transformation
91  * @param metadata The metadata of the sample
92  */
93  void onNewSample(const HomogenousMatrix4& world_T_camera, SharedSceneElements&& sceneElements, const Timestamp& timestamp, Metadata&& metadata);
94 
95  /**
96  * Returns the name of this tracker.
97  * @return The trackers's name
98  */
99  static inline std::string deviceNameAKSceneTracker6DOF();
100 
101  /**
102  * Returns the device type of this tracker.
103  * @return The tracker's device type
104  */
105  static inline DeviceType deviceTypeAKSceneTracker6DOF();
106 
107  protected:
108 
109  /**
110  * Creates a new 6DOF scene tracker.
111  */
112  explicit AKSceneTracker6DOF();
113 
114  /**
115  * Destructs this 6DOF tracker.
116  */
117  ~AKSceneTracker6DOF() override;
118 
119  /**
120  * Exracts the 3D vectors from a geometry source.
121  * @param geometrySource The geometry source from wich all vectors will be extracted
122  * @param vectors The resulting 3D vectors
123  * @return True, if succeeded
124  */
125  API_AVAILABLE(ios(13.4))
126  static bool extractVectors3(ARGeometrySource* geometrySource, Vectors3& vectors);
127 
128  /**
129  * Extracts the indices from a geometry element.
130  * @param geometryElement The geometry elemnt from which the indices will be extracted
131  * @param indices The resulting indices
132  * @return True, if succeeded
133  */
134  API_AVAILABLE(ios(13.4))
135  static bool extractIndices(ARGeometryElement* geometryElement, Indices32& indices);
136 
137  protected:
138 
139  /// The unique id for the world object.
140  ObjectId worldObjectId_ = invalidObjectId();
141 
142  /// True, if the tracker has been started.
143  bool isStarted_ = false;
144 
145  /// True, if the world object is currently tracked.
146  bool worldIsTracked_ = false;
147 
148  /// The map mapping unique plane identifier strings to mesh ids.
149  IdentifierMap identifierMap_;
150 
151  /// The counter for unique mesh ids.
152  unsigned int meshIdCounter_ = 0u;
153 
154  /// The number of triangles each mesh currently has.
155  std::vector<size_t> numberTriangles_;
156 };
157 
158 inline std::string AKSceneTracker6DOF::deviceNameAKSceneTracker6DOF()
159 {
160  return std::string("ARKit 6DOF Scene Tracker");
161 }
162 
164 {
165  return DeviceType(deviceTypeTracker6DOF(), TRACKER_VISUAL | SCENE_TRACKER_6DOF);
166 }
167 
168 }
169 
170 }
171 
172 }
173 
174 #endif // META_OCEAN_DEVICES_ARKIT_AK_SCENE_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 the 6DOF scene tracker.
Definition: AKSceneTracker6DOF.h:34
bool start() override
Starts the device.
std::unordered_map< std::string, Index32 > IdentifierMap
Definition of an unordered map mapping anchor identifier strings to unique ids.
Definition: AKSceneTracker6DOF.h:42
bool pause() override
Pauses the device.
bool stop() override
Stops the device.
static DeviceType deviceTypeAKSceneTracker6DOF()
Returns the device type of this tracker.
Definition: AKSceneTracker6DOF.h:163
API_AVAILABLE(ios(11.3)) void onNewSample(const HomogenousMatrix4 &world_T_camera
Event function for a new 6DOF pose.
void setInput(Media::FrameMediumRefs &&frameMediums) override
Sets the multi-view visual input of this tracker.
bool isObjectTracked(const ObjectId &objectId) const override
Returns whether a specific object is currently actively tracked by 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::vector< SharedSceneElement > SharedSceneElements
Definition of a vector holding scene elements.
Definition: SceneTracker6DOF.h:901
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< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition: Vector3.h:65
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