Ocean
AKGeoAnchorsTracker6DOF.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_GEO_ANCHORS_TRACKER_6_DOF_H
9 #define META_OCEAN_DEVICES_ARKIT_AK_GEO_ANCHORS_TRACKER_6_DOF_H
10 
13 
17 
18 namespace Ocean
19 {
20 
21 namespace Devices
22 {
23 
24 namespace ARKit
25 {
26 
27 /**
28  * This class implements ARKit's 6-DOF Geo Anchors tracker.
29  * @ingroup devicesarkit
30  */
31 class OCEAN_DEVICES_ARKIT_EXPORT AKGeoAnchorsTracker6DOF :
32  virtual public AKDevice,
33  virtual public Tracker6DOF,
34  virtual public ObjectTracker,
35  virtual public VisualTracker
36 {
37  friend class AKFactory;
38 
39  public:
40 
41  /**
42  * Definition of an unordered map mapping object ids to transformations.
43  */
44  typedef std::unordered_map<ObjectId, HomogenousMatrix4> TransformationMap;
45 
46  protected:
47 
48  /**
49  * This class stores GPS locations.
50  */
51  class Location
52  {
53  public:
54 
55  /**
56  * Creates a new location object.
57  * @param objectId The object id of the location
58  * @param latitude The location's latitude, in degree, with range [-90, 90]
59  * @param longitude The location's longitude, in degree, with range [-180, 180]
60  * @param altitude The location's altitude, in meters, with range (-infinity, infinity), NumericD::minVaue() if unknown
61  */
62  inline Location(const ObjectId objectId, const double latitude, const double longitude, const double altitude);
63 
64  public:
65 
66  /// The location's latitude, in degree, with range [-90, 90].
67  double latitude_ = NumericD::minValue();
68 
69  /// The location's longitude, in degree, with range [-180, 180].
70  double longitude_ = NumericD::minValue();
71 
72  /// The location's altitude, in meters, with range (-infinity, infinity), NumericD::minVaue() if unknown.
73  double altitude_ = NumericD::minValue();
74 
75  /// The object id of the location.
76  ObjectId objectId_ = invalidObjectId();
77  };
78 
79  /**
80  * Definition of a vector holding locations.
81  */
82  typedef std::vector<Location> Locations;
83 
84  public:
85 
86  /**
87  * Starts the device.
88  * @see Device::start().
89  */
90  bool start() override;
91 
92  /**
93  * Pauses the device.
94  * @see Device::pause().
95  */
96  bool pause() override;
97 
98  /**
99  * Stops the device.
100  * @see Device::stop().
101  */
102  bool stop() override;
103 
104  /**
105  * Sets the multi-view visual input of this tracker.
106  * @see VisualTracker::setInput().
107  */
108  void setInput(Media::FrameMediumRefs&& frameMediums) override;
109 
110  /**
111  * Registers (adds) a new object to be tracked.
112  * @see ObjectTracker::registerObject().
113  */
114  ObjectId registerObject(const std::string& description, const Vector3& dimension) override;
115 
116  /**
117  * Unregisters (removes) a previously registered object.
118  * @see ObjectTracker::unregisterObject().
119  */
120  bool unregisterObject(const ObjectId objectId) override;
121 
122  /**
123  * Returns whether a specific object is currently actively tracked by this tracker.
124  * @see Tracker::isObjectTracked().
125  */
126  bool isObjectTracked(const ObjectId& objectId) const override;
127 
128  /**
129  * Event function for a new 6DOF pose.
130  * @param world_T_camera The transformation between camera and world, invalid if unknown/lost
131  * @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
132  * @param timestamp The timestamp of the new transformation
133  * @param arFrame The current ARFRame object containing additional data for the sample, must be valid
134  */
135  API_AVAILABLE(ios(14.0))
136  void onNewSample(const HomogenousMatrix4& world_T_camera, const HomogenousMatrix4& world_T_rotatedWorld, const Timestamp& timestamp, ARFrame* arFrame);
137 
138  /**
139  * Event function for new 6DOF transformations.
140  * @param anchors_T_camera The transformations of all currently known anchors
141  * @param timestamp The timestamp of the new transformation
142  * @param metadata The metadata of the sample
143  */
144  void onNewSample(const TransformationMap& anchors_T_camera, const Timestamp& timestamp, Metadata&& metadata);
145 
146  /**
147  * Returns the name of this tracker.
148  * @return The trackers's name
149  */
150  static inline std::string deviceNameAKGeoAnchorsTracker6DOF();
151 
152  /**
153  * Returns the device type of this tracker.
154  * @return The tracker's device type
155  */
156  static inline DeviceType deviceTypeAKGeoAnchorsTracker6DOF();
157 
158  protected:
159 
160  /**
161  * Creates a new 6DOF Geo Anchor tracker.
162  */
164 
165  /**
166  * Destructs this tracker.
167  */
169 
170  protected:
171 
172  /// The ids of all objects (including the world object) which are currently tracked.
173  ObjectIdSet trackedObjectIds_;
174 
175  /// True, if the tracker has been started.
176  bool isStarted_ = false;
177 
178  /// Intermediate locations which have been registered before the device have been started.
179  Locations intermediateLocations_;
180 };
181 
182 inline AKGeoAnchorsTracker6DOF::Location::Location(const ObjectId objectId, const double latitude, const double longitude, const double altitude) :
183  latitude_(latitude),
184  longitude_(longitude),
185  altitude_(altitude),
186  objectId_(objectId)
187 {
188  // nothing to do here
189 }
190 
192 {
193  return std::string("ARKit 6DOF Geo Anchors Tracker");
194 }
195 
197 {
198  return DeviceType(deviceTypeTracker6DOF(), TRACKER_VISUAL);
199 }
200 
201 }
202 
203 }
204 
205 }
206 
207 #endif // META_OCEAN_DEVICES_ARKIT_AK_GEO_ANCHORS_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 stores GPS locations.
Definition: AKGeoAnchorsTracker6DOF.h:52
This class implements ARKit's 6-DOF Geo Anchors tracker.
Definition: AKGeoAnchorsTracker6DOF.h:36
static DeviceType deviceTypeAKGeoAnchorsTracker6DOF()
Returns the device type of this tracker.
Definition: AKGeoAnchorsTracker6DOF.h:196
bool isObjectTracked(const ObjectId &objectId) const override
Returns whether a specific object is currently actively tracked by this tracker.
bool unregisterObject(const ObjectId objectId) override
Unregisters (removes) a previously registered object.
static std::string deviceNameAKGeoAnchorsTracker6DOF()
Returns the name of this tracker.
Definition: AKGeoAnchorsTracker6DOF.h:191
bool start() override
Starts the device.
std::vector< Location > Locations
Definition of a vector holding locations.
Definition: AKGeoAnchorsTracker6DOF.h:82
void setInput(Media::FrameMediumRefs &&frameMediums) override
Sets the multi-view visual input of this tracker.
API_AVAILABLE(ios(14.0)) void onNewSample(const HomogenousMatrix4 &world_T_camera
Event function for a new 6DOF pose.
std::unordered_map< ObjectId, HomogenousMatrix4 > TransformationMap
Definition of an unordered map mapping object ids to transformations.
Definition: AKGeoAnchorsTracker6DOF.h:44
ObjectId registerObject(const std::string &description, const Vector3 &dimension) override
Registers (adds) a new object to be tracked.
bool stop() override
Stops the device.
bool pause() override
Pauses the device.
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
std::unordered_set< ObjectId > ObjectIdSet
Definition of an unordered set holding object ids.
Definition: Measurement.h:56
This class is the base class for all tracker allowing to track an object or location.
Definition: ObjectTracker.h:38
This class implements the base for all 6DOF trackers.
Definition: Tracker6DOF.h:39
This class is the base class for all tracker using visual input to create the tracking results.
Definition: devices/VisualTracker.h:41
static constexpr T minValue()
Returns the min scalar value.
Definition: Numeric.h:3250
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