Ocean
Loading...
Searching...
No Matches
StaticPatternTracker6DOF.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_PATTERN_STATIC_PATTERN_TRACKER_6DOF_H
9#define META_OCEAN_DEVICES_PATTERN_STATIC_PATTERN_TRACKER_6DOF_H
10
13
17
19
21
22#include <unordered_map>
23
24namespace Ocean
25{
26
27namespace Devices
28{
29
30namespace Pattern
31{
32
33/**
34 * This class implements a static Pattern feature-based tracker.
35 * @ingroup devicespattern
36 */
37class OCEAN_DEVICES_PATTERN_EXPORT StaticPatternTracker6DOF :
38 virtual public PatternDevice,
39 virtual public Tracker6DOF,
40 virtual public ObjectTracker,
41 virtual public VisualTracker
42{
43 friend class PatternFactory;
44
45 protected:
46
47 /**
48 * Definition of a sorted map combining timestamp with transformations.
49 */
50 typedef std::map<Timestamp, HomogenousMatrix4> TransformationMap;
51
52 /**
53 * This class stores necessary information for one pattern.
54 */
56 {
57 public:
58
59 /**
60 * Creates a new object.
61 * @param maximalDistance The distance between pattern and camera in which the Pattern tracker can be trusted, in meter, with range (0, infinity)
62 */
63 explicit inline PatternTransformations(const Scalar maximalDistance);
64
65 /**
66 * Adds a new transformation between camera and pattern.
67 * @param pattern_T_camera The new transformation to be added, must be valid
68 * @param timestamp The timestamp of the transformation
69 * @param maximalNumberForAlignment The maximal number of transformations that kept stored to determine the aligned transformation between world and pattern, with range [1, infinity)
70 * @param maximalIntervalForAlignment The maximal time interval of transformations that kept stored to determine the aligned transformation between world and pattern, in seconds, with range (0, infinity)
71 * @return True, if the transformation has been added; False, if the transformation was not trusted
72 */
73 bool addTransformation(const HomogenousMatrix4& pattern_T_camera, const Timestamp& timestamp, const size_t maximalNumberForAlignment, const double maximalIntervalForAlignment);
74
75 /**
76 * Returns the current transformation between world and pattern, may be invalid.
77 * @return Current transformation
78 */
79 inline HomogenousMatrix4& pattern_T_world();
80
81 /**
82 * Returns the transformations associated with this pattern.
83 * @return The transformations
84 */
85 inline TransformationMap& transformations();
86
87 protected:
88
89 /// The distance between pattern and camera in which the Pattern tracker can be trusted, in meter, with range (0, infinity).
91
92 /// The most current transformation between world and pattern, invalid if unknown.
94
95 /// The recent transformations associated with this pattern.
97 };
98
99 /**
100 * Definition of an unsorted map combining object ids with pattern transformations.
101 */
102 typedef std::unordered_map<ObjectId, PatternTransformations> PatternTransformationsMap;
103
104 public:
105
106 /**
107 * Sets the multi-view visual input of this tracker.
108 * @see VisualTracker::setInput().
109 */
110 void setInput(Media::FrameMediumRefs&& frameMediums) override;
111
112 /**
113 * Adds a new tracking pattern.
114 * For this pattern feature based tracker the pattern must be the url of an image.
115 * @see ObjectTracker::registerObject().
116 */
117 ObjectId registerObject(const std::string& description, const Vector3& dimension) override;
118
119 /**
120 * Returns whether this device is active.
121 * @see Devices::isStarted().
122 */
123 bool isStarted() const override;
124
125 /**
126 * Starts the device.
127 * @see Device::start().
128 */
129 bool start() override;
130
131 /**
132 * Stops the device.
133 * @see Device::stop().
134 */
135 bool stop() override;
136
137 /**
138 * Returns the name of this tracker.
139 * @return Tracker name
140 */
141 static inline std::string deviceNameStaticPatternTracker6DOF();
142
143 /**
144 * Returns the type of this tracker.
145 * @return Tracker type
146 */
147 static inline DeviceType deviceTypeStaticPatternTracker6DOF();
148
149 private:
150
151 /**
152 * Creates a new Static Pattern feature based 6DOF tracker object.
153 */
155
156 /**
157 * Destructs an Static Pattern feature based 6DOF tracker object.
158 */
160
161 /**
162 * Event function for new tracking samples from the pattern tracker.
163 * @param measurement The measurement object sending the sample
164 * @param sample The new samples with resulting from pattern tracker
165 */
166 void onPatternTrackerSample(const Measurement* measurement, const SampleRef& sample);
167
168 /**
169 * Event function for new tracking samples from the world tracker.
170 * @param measurement The measurement object sending the sample
171 * @param sample The new samples with resulting from world tracker
172 */
173 void onWorldTrackerSample(const Measurement* measurement, const SampleRef& sample);
174
175 /**
176 * Event function for new tracking object event from the pattern tracker.
177 * @param tracker The sender of the event, must be valid
178 * @param found True, if the object ids were found; False if the object ids were lost
179 * @param objectIds The ids of the object which are found or lost, at least one
180 * @param timestamp The timestamp of the event
181 */
182 void onPatternTrackerObject(const Tracker* tracker, const bool found, const ObjectIdSet& objectIds, const Timestamp& timestamp);
183
184 /**
185 * Event function for new tracking object event from the world tracker.
186 * @param tracker The sender of the event, must be valid
187 * @param found True, if the object ids were found; False if the object ids were lost
188 * @param objectIds The ids of the object which are found or lost, at least one
189 * @param timestamp The timestamp of the event
190 */
191 void onWorldTrackerObject(const Tracker* tracker, const bool found, const ObjectIdSet& objectIds, const Timestamp& timestamp);
192
193 /**
194 * Reports all pattern poses without aligning the poses with the world tracker.
195 * @param timestamp The current timestamp
196 */
197 void reportNotAlignedPoses(const Timestamp& timestamp);
198
199 /**
200 * Reports all pattern poses by aligning them with the world tracker.
201 * @param timestamp The current timestamp
202 */
203 void reportAlignedPoses(const Timestamp& timestamp);
204
205 private:
206
207 /// The 6-DOF pattern tracker.
209
210 /// The 6-DOF world tracker.
212
213 /// The subscription object for samples events from the pattern tracker.
215
216 /// The subscription object for samples events from the world tracker.
218
219 /// The subscription object for tracker object events from the pattern tracker.
221
222 /// The subscription object for tracker object events from the world tracker.
224
225 /// The ids of all objects currently connected with a world pose.
227
228 /// The ids of all objects detected and currently actively tracked.
230
231 /// The ids of all objects currently not actively tracked.
233
234 /// Individual transformations (the history of recent poses) of all (pattern) objects.
236
237 /// The transformation map (the history of recent poses) of the world tracker.
239
240 /// The look for all transformation maps.
242
243 /// The maximal number of transformations that kept stored to determine the aligned transformation between world and pattern, with range [1, infinity)
244 size_t maximalNumberForAlignment_ = 5;
245
246 /// The maximal time interval of transformations that kept stored to determine the aligned transformation between world and pattern, in seconds, with range (0, infinity)
247 double maximalIntervalForAlignment_ = 10.0;
248
249 /// The mapper between internal and external object ids.
251};
252
254 maximalDistance_(maximalDistance),
255 pattern_T_world_(false)
256{
257 ocean_assert(maximalDistance_ > Numeric::eps());
258}
259
264
269
271{
272 return std::string("Static Pattern 6DOF Tracker");
273}
274
279
280}
281
282}
283
284}
285
286#endif // META_OCEAN_DEVICES_PATTERN_STATIC_PATTERN_TRACKER_6DOF_H
Definition of a class holding the major and minor device type.
Definition devices/Device.h:62
This class implements a helper class to simplify the mapping between internal object ids (of the actu...
Definition Measurement.h:239
This class manages the lifetime of an event subscription for sample events.
Definition Measurement.h:154
This class implements the base class for all devices providing measurement samples.
Definition Measurement.h:40
unsigned int ObjectId
Definition of an object id.
Definition Measurement.h:46
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 a base class for all devices of the Pattern library.
Definition PatternDevice.h:29
This class implements a device factory for the Pattern feature based tracking system.
Definition PatternFactory.h:29
This class stores necessary information for one pattern.
Definition StaticPatternTracker6DOF.h:56
PatternTransformations(const Scalar maximalDistance)
Creates a new object.
Definition StaticPatternTracker6DOF.h:253
Scalar maximalDistance_
The distance between pattern and camera in which the Pattern tracker can be trusted,...
Definition StaticPatternTracker6DOF.h:90
bool addTransformation(const HomogenousMatrix4 &pattern_T_camera, const Timestamp &timestamp, const size_t maximalNumberForAlignment, const double maximalIntervalForAlignment)
Adds a new transformation between camera and pattern.
TransformationMap transformationMap_
The recent transformations associated with this pattern.
Definition StaticPatternTracker6DOF.h:96
HomogenousMatrix4 pattern_T_world_
The most current transformation between world and pattern, invalid if unknown.
Definition StaticPatternTracker6DOF.h:93
HomogenousMatrix4 & pattern_T_world()
Returns the current transformation between world and pattern, may be invalid.
Definition StaticPatternTracker6DOF.h:260
TransformationMap & transformations()
Returns the transformations associated with this pattern.
Definition StaticPatternTracker6DOF.h:265
This class implements a static Pattern feature-based tracker.
Definition StaticPatternTracker6DOF.h:42
ObjectMapper< ObjectId > objectIdMapper_
The mapper between internal and external object ids.
Definition StaticPatternTracker6DOF.h:250
SampleEventSubscription worldTrackerSampleEventSubscription_
The subscription object for samples events from the world tracker.
Definition StaticPatternTracker6DOF.h:217
bool isStarted() const override
Returns whether this device is active.
ObjectId registerObject(const std::string &description, const Vector3 &dimension) override
Adds a new tracking pattern.
static std::string deviceNameStaticPatternTracker6DOF()
Returns the name of this tracker.
Definition StaticPatternTracker6DOF.h:270
bool start() override
Starts the device.
static DeviceType deviceTypeStaticPatternTracker6DOF()
Returns the type of this tracker.
Definition StaticPatternTracker6DOF.h:275
void reportNotAlignedPoses(const Timestamp &timestamp)
Reports all pattern poses without aligning the poses with the world tracker.
Lock sampleMapLock_
The look for all transformation maps.
Definition StaticPatternTracker6DOF.h:241
TrackerObjectEventSubscription worldTrackerObjectSubscription_
The subscription object for tracker object events from the world tracker.
Definition StaticPatternTracker6DOF.h:223
void setInput(Media::FrameMediumRefs &&frameMediums) override
Sets the multi-view visual input of this tracker.
void reportAlignedPoses(const Timestamp &timestamp)
Reports all pattern poses by aligning them with the world tracker.
Tracker6DOFRef worldTracker_
The 6-DOF world tracker.
Definition StaticPatternTracker6DOF.h:211
ObjectIdSet lostPatternTrackerObjects_
The ids of all objects currently not actively tracked.
Definition StaticPatternTracker6DOF.h:232
std::map< Timestamp, HomogenousMatrix4 > TransformationMap
Definition of a sorted map combining timestamp with transformations.
Definition StaticPatternTracker6DOF.h:50
bool stop() override
Stops the device.
ObjectIdSet worldTrackedPatternObjects_
The ids of all objects currently connected with a world pose.
Definition StaticPatternTracker6DOF.h:226
Tracker6DOFRef patternTracker_
The 6-DOF pattern tracker.
Definition StaticPatternTracker6DOF.h:208
StaticPatternTracker6DOF()
Creates a new Static Pattern feature based 6DOF tracker object.
void onPatternTrackerObject(const Tracker *tracker, const bool found, const ObjectIdSet &objectIds, const Timestamp &timestamp)
Event function for new tracking object event from the pattern tracker.
void onWorldTrackerSample(const Measurement *measurement, const SampleRef &sample)
Event function for new tracking samples from the world tracker.
~StaticPatternTracker6DOF() override
Destructs an Static Pattern feature based 6DOF tracker object.
SampleEventSubscription patternTrackerSampleEventSubscription_
The subscription object for samples events from the pattern tracker.
Definition StaticPatternTracker6DOF.h:214
void onWorldTrackerObject(const Tracker *tracker, const bool found, const ObjectIdSet &objectIds, const Timestamp &timestamp)
Event function for new tracking object event from the world tracker.
std::unordered_map< ObjectId, PatternTransformations > PatternTransformationsMap
Definition of an unsorted map combining object ids with pattern transformations.
Definition StaticPatternTracker6DOF.h:102
ObjectIdSet foundPatternTrackerObjects_
The ids of all objects detected and currently actively tracked.
Definition StaticPatternTracker6DOF.h:229
PatternTransformationsMap patternTrackerTransformationsMap_
Individual transformations (the history of recent poses) of all (pattern) objects.
Definition StaticPatternTracker6DOF.h:235
void onPatternTrackerSample(const Measurement *measurement, const SampleRef &sample)
Event function for new tracking samples from the pattern tracker.
TrackerObjectEventSubscription patternTrackerObjectSubscription_
The subscription object for tracker object events from the pattern tracker.
Definition StaticPatternTracker6DOF.h:220
TransformationMap worldTrackerTransformationMap_
The transformation map (the history of recent poses) of the world tracker.
Definition StaticPatternTracker6DOF.h:238
This class implements the base for all 6DOF trackers.
Definition Tracker6DOF.h:39
static DeviceType deviceTypeTracker6DOF()
Definition of this device type.
Definition Tracker6DOF.h:100
This class manages the lifetime of an event subscription for tracker object events.
Definition devices/Tracker.h:141
This class implements the base class for all tracker devices.
Definition devices/Tracker.h:39
@ TRACKER_VISUAL
Tracker using a visual input for their measurements.
Definition devices/Tracker.h:62
@ TRACKER_OBJECT
Tracker allowing to register tracking objects at runtime.
Definition devices/Tracker.h:64
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 recursive lock object.
Definition Lock.h:31
static constexpr T eps()
Returns a small epsilon.
This template class implements a object reference with an internal reference counter.
Definition base/ObjectRef.h:58
This class implements a timestamp.
Definition Timestamp.h:36
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< FrameMediumRef > FrameMediumRefs
Definition of a vector holding frame medium reference objects.
Definition FrameMedium.h:46
The namespace covering the entire Ocean framework.
Definition Accessor.h:15