Ocean
Loading...
Searching...
No Matches
OculusTag.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_TRACKING_OCULUSTAGS_OCULUSTAG_H
9#define META_OCEAN_TRACKING_OCULUSTAGS_OCULUSTAG_H
10
12
13namespace Ocean
14{
15
16namespace Tracking
17{
18
19namespace OculusTags
20{
21
22/**
23 * This class implements a Oculus tag.
24 * @ingroup trackingoculustags
25 */
26class OCEAN_TRACKING_OCULUSTAGS_EXPORT OculusTag
27{
28 public:
29
30 /**
31 * Reflectance types that the tag can have
32 */
33 enum ReflectanceType : uint8_t
34 {
35 /// Normal reflectance: '1' - dark intensity, '0' - light intensity
36 RT_REFLECTANCE_NORMAL = 0u,
37
38 /// Inverted reflectance: '1' - light intensity, '0' - dark intensity
40
41 /// Used if the reflectance type is unknown or invalid
42 RT_REFLECTANCE_UNDEFINED
43 };
44
45 /// Data structure for the payload of the code: 4 x 4 = 16 bits
46 typedef uint16_t DataMatrix;
47
48 public:
49
50 /**
51 * Creates an empty Oculus Tag instance with normal reflectance
52 */
54
55 /**
56 * Creates an Oculus Tag instance
57 * @param tagID The ID of the tag, range: [0, 1024)
58 * @param reflectanceType The reflectance type of the tag; can be normal or inverted (but not undefined)
59 * @param intensityThreshold The intensity value that was used to threshold foreground and background pixel values, range: [0, 256)
60 * @param world_T_tag The 6DOF pose of the tag in the world such that `worldCoord = world_T_tag * tagCoord`, must be valid
61 * @param tagSize The edge length of the tag in 3D object space, range: (0, infinity)
62 */
63 OculusTag(const uint32_t& tagID, const ReflectanceType& reflectanceType, const uint8_t& intensityThreshold, const HomogenousMatrix4& world_T_tag, const Scalar tagSize);
64
65 /**
66 * Returns true if the tag is valid
67 * @return True, if the tag is valid, otherwise false
68 */
69 bool isValid() const;
70
71 /**
72 * Return the ID of this tag
73 * @return The ID of this tag, range: [0, 1024)
74 */
75 inline uint32_t tagID() const;
76
77 /**
78 * Returns the reflectance type of this tag
79 * @return The reflectance type
80 */
81 inline ReflectanceType reflectanceType() const;
82
83 /**
84 * Returns the grayscale intensity that was used for binary separation of foreground and background
85 * @return The value of the threshold
86 */
87 inline uint8_t intensityThreshold() const;
88
89 /**
90 * Returns the transformation to map tag coordinates into world coordinates
91 * @return The pose such that `deviceCoord = world_T_device() * tagCoord`
92 * @tparam tOriginInCenter If true, the center of the tag is defined as its origin, otherwise its top-left corner is its origin
93 */
94 template <bool tOriginInCenter = false>
95 inline const HomogenousMatrix4 world_T_tag() const;
96
97 /**
98 * Updates the 6DOF pose of the tag
99 * @param world_T_tag The 6DOF pose of the tag in the world such that `worldCoord = world_T_tag * tagCoord`, must be valid
100 */
101 inline void setWorld_T_tag(const HomogenousMatrix4& world_T_tag);
102
103 /**
104 * Return the size of the tag
105 * @return The size of the tag
106 */
107 inline Scalar tagSize() const;
108
109 public:
110
111 /// Number of modules along the vertical and horizontal directions
112 static constexpr uint32_t numberOfModules = 8u;
113
114 protected:
115
116 /// The ID of this tag
117 uint32_t tagID_;
118
119 /// The reflectance type of this tag instance
121
122 /// The grayscale intensity that was used binary separation of foreground and background
124
125 /// The 6DOF pose of the tag relative to the world
127
128 /// The edge length of the tag in 3D object space
130};
131
132/**
133 * A vector of Oculus tags.
134 * @ingroup trackingoculustags
135 */
136typedef std::vector<OculusTag> OculusTags;
137
138/**
139 * A data structure to map tag IDs to tag sizes.
140 * @ingroup trackingoculustags
141 */
142typedef std::unordered_map<uint32_t, Scalar> TagSizeMap;
143
144inline uint32_t OculusTag::tagID() const
145{
146 return tagID_;
147}
148
153
154inline uint8_t OculusTag::intensityThreshold() const
155{
156 return intensityThreshold_;
157}
158
159template <bool tOriginInCenter>
161{
162 if constexpr (tOriginInCenter)
163 {
164 return world_T_tag_ * HomogenousMatrix4(Vector3(Scalar(0.5) * tagSize(), Scalar(-0.5) * tagSize(), 0));
165 }
166
167 return world_T_tag_; // Returned this as `const HomogenousMatrix4&` again once possible
168}
169
170inline void OculusTag::setWorld_T_tag(const HomogenousMatrix4& world_T_tag)
171{
172 ocean_assert(world_T_tag.isValid());
174}
175
177{
178 return tagSize_;
179}
180
181} // namespace OculusTags
182
183} // namespace Tracking
184
185} // namespace Ocean
186
187#endif // META_OCEAN_TRACKING_OCULUSTAGS_OCULUSTAG_H
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
This class implements a Oculus tag.
Definition OculusTag.h:27
HomogenousMatrix4 world_T_tag_
The 6DOF pose of the tag relative to the world.
Definition OculusTag.h:126
Scalar tagSize_
The edge length of the tag in 3D object space.
Definition OculusTag.h:129
Scalar tagSize() const
Return the size of the tag.
Definition OculusTag.h:176
uint8_t intensityThreshold() const
Returns the grayscale intensity that was used for binary separation of foreground and background.
Definition OculusTag.h:154
bool isValid() const
Returns true if the tag is valid.
ReflectanceType reflectanceType_
The reflectance type of this tag instance.
Definition OculusTag.h:120
const HomogenousMatrix4 world_T_tag() const
Returns the transformation to map tag coordinates into world coordinates.
Definition OculusTag.h:160
OculusTag(const uint32_t &tagID, const ReflectanceType &reflectanceType, const uint8_t &intensityThreshold, const HomogenousMatrix4 &world_T_tag, const Scalar tagSize)
Creates an Oculus Tag instance.
uint16_t DataMatrix
Data structure for the payload of the code: 4 x 4 = 16 bits.
Definition OculusTag.h:46
ReflectanceType
Reflectance types that the tag can have.
Definition OculusTag.h:34
@ RT_REFLECTANCE_INVERTED
Inverted reflectance: '1' - light intensity, '0' - dark intensity.
Definition OculusTag.h:39
uint32_t tagID_
The ID of this tag.
Definition OculusTag.h:117
ReflectanceType reflectanceType() const
Returns the reflectance type of this tag.
Definition OculusTag.h:149
void setWorld_T_tag(const HomogenousMatrix4 &world_T_tag)
Updates the 6DOF pose of the tag.
Definition OculusTag.h:170
uint8_t intensityThreshold_
The grayscale intensity that was used binary separation of foreground and background.
Definition OculusTag.h:123
OculusTag()
Creates an empty Oculus Tag instance with normal reflectance.
uint32_t tagID() const
Return the ID of this tag.
Definition OculusTag.h:144
float Scalar
Definition of a scalar type.
Definition Math.h:129
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition Vector3.h:29
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition HomogenousMatrix4.h:44
std::unordered_map< uint32_t, Scalar > TagSizeMap
A data structure to map tag IDs to tag sizes.
Definition OculusTag.h:142
std::vector< OculusTag > OculusTags
A vector of Oculus tags.
Definition OculusTag.h:136
The namespace covering the entire Ocean framework.
Definition Accessor.h:15