Ocean
UnifiedDescriptorMap.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_MAPBUILDING_UNIFIED_DESCRIPTOR_MAP_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_UNIFIED_DESCRIPTOR_MAP_H
10 
13 
14 namespace Ocean
15 {
16 
17 namespace Tracking
18 {
19 
20 namespace MapBuilding
21 {
22 
23 // Forward declaration.
24 class UnifiedDescriptorMap;
25 
26 /**
27  * Definition of a shared pointer holding a UnifiedDescriptorMap object.
28  * @ingroup trackingmapbuilding
29  */
30 using SharedUnifiedDescriptorMap = std::shared_ptr<UnifiedDescriptorMap>;
31 
32 /**
33  * This class implements the base class for all unified descriptor maps in which ids are mapped to descriptors.
34  * @see UnifiedDescriptors.
35  * @ingroup trackingmapbuilding
36  */
38 {
39  public:
40 
41  /**
42  * Disposes the object.
43  */
44  virtual ~UnifiedDescriptorMap() = default;
45 
46  /**
47  * Returns the number of object points.
48  * @return The map's number of object points
49  */
50  virtual size_t numberObjectPoints() const = 0;
51 
52  /**
53  * Returns the ids of all object points.
54  * @return The object ids of all 3D object points this map holds
55  */
56  virtual Indices32 objectPointIds() const = 0;
57 
58  /**
59  * Returns the number of descriptors associated with a specified object point id.
60  * @param objectPointId The id of the object point
61  * @return The number of descriptors
62  */
63  virtual size_t numberDescriptors(const Index32& objectPointId) const = 0;
64 
65  /**
66  * Removes the descriptors for a specified object point id.
67  * @param objectPointId The id of the object point to be removed
68  * @return True, if the map contained the specified object point and if the descriptors were removed; False, if the map does not contain the specified object point
69  */
70  virtual bool removeDescriptors(const Index32& objectPointId) = 0;
71 
72  /**
73  * Returns a clone of this map.
74  * @return The map's clone
75  */
76  virtual std::unique_ptr<UnifiedDescriptorMap> clone() const = 0;
77 
78  protected:
79 
80  /**
81  * Creates a new descriptors object.
82  * @param descriptorType The type of the descriptors
83  */
84  explicit inline UnifiedDescriptorMap(const DescriptorType descriptorType);
85 };
86 
87 /**
88  * This class implements the descriptor map for arbitrary descriptors.
89  * @tparam TDescriptor The data type of the descriptor to be used (can also be a multi-view descriptor - e.g., a vector with descriptors)
90  * @ingroup trackingmapbuilding
91  */
92 template <typename TDescriptor>
94 {
95  public:
96 
97  /**
98  * Definition of the descriptors this map is using.
99  */
100  using Descriptor = TDescriptor;
101 
102  /**
103  * Definition of an unordered map mapping object point ids to multi-view float descriptors.
104  */
105  using DescriptorMap = std::unordered_map<Index32, Descriptor>;
106 
107  public:
108 
109  /**
110  * Default constructor.
111  */
112  inline UnifiedDescriptorMapT();
113 
114  /**
115  * Creates a new descriptor map object.
116  * @param descriptorMap The actual internal descriptor map to be moved into the new object
117  */
119 
120  /**
121  * Returns the number of object points.
122  * @see UnifiedDescriptorMap::numberObjectPoints().
123  */
124  size_t numberObjectPoints() const override;
125 
126  /**
127  * Returns the ids of all object points.
128  * @return The object ids of all 3D object points this map holds
129  */
130  Indices32 objectPointIds() const override;
131 
132  /**
133  * Returns the number of descriptors associated with a specified object point id.
134  * @see UnifiedDescriptorMap::numberDescriptors().
135  */
136  size_t numberDescriptors(const Index32& objectPointId) const override;
137 
138  /**
139  * Removes the descriptors for a specified object point id.
140  * @see UnifiedDescriptorMap::removeDescriptors().
141  */
142  bool removeDescriptors(const Index32& objectPointId) override;
143 
144  /**
145  * Returns a clone of this map.
146  * @see UnifiedDescriptorMap::clone().
147  */
148  std::unique_ptr<UnifiedDescriptorMap> clone() const override;
149 
150  /**
151  * Returns the actual underlying descriptor map.
152  * @return Internal descriptor map
153  */
154  inline const DescriptorMap& descriptorMap() const;
155 
156  /**
157  * Returns the actual underlying descriptor map.
158  * @return Internal descriptor map
159  */
161 
162  protected:
163 
164  /// The internal descriptor map.
166 };
167 
168 /**
169  * Definition of a UnifiedDescriptorMapT object for FREAK multi-view, multi-level descriptors with 256 bits.
170  * @ingroup trackingmapbuilding
171  */
173 
174 /**
175  * Definition of a UnifiedDescriptorMapT object for float multi-view, single-level descriptors.
176  * @tparam tElements The number of float elements each float descriptor has, with range [1, infinity)
177  * @ingroup trackingmapbuilding
178  */
179 template <uint16_t tElements>
181 
183  UnifiedDescriptor(descriptorType)
184 {
185  // nothing to do here
186 }
187 
188 template <typename TDescriptor>
190  UnifiedDescriptorMap(DescriptorTyper<TDescriptor>::type())
191 {
192  ocean_assert(descriptorType() != DescriptorType::DT_INVALID);
193 }
194 
195 template <typename TDescriptor>
197  UnifiedDescriptorMap(DescriptorTyper<TDescriptor>::type()),
198  descriptorMap_(std::move(descriptorMap))
199 {
200  ocean_assert(descriptorType() != DescriptorType::DT_INVALID);
201 }
202 
203 template <typename TDescriptor>
205 {
206  return descriptorMap_;
207 }
208 
209 template <typename TDescriptor>
211 {
212  return descriptorMap_;
213 }
214 
215 template <typename TDescriptor>
217 {
218  return descriptorMap_.size();
219 }
220 
221 template <typename TDescriptor>
223 {
224  Indices32 ids;
225  ids.reserve(descriptorMap_.size());
226 
227  for (const typename DescriptorMap::value_type& descriptorPair : descriptorMap_)
228  {
229  ids.emplace_back(descriptorPair.first);
230  }
231 
232  return ids;
233 }
234 
235 template <typename TDescriptor>
237 {
238  const typename DescriptorMap::const_iterator i = descriptorMap_.find(objectPointId);
239 
240  if (i == descriptorMap_.cend())
241  {
242  return 0;
243  }
244 
245  return i->second.size();
246 }
247 
248 template <typename TDescriptor>
250 {
251  const typename DescriptorMap::iterator i = descriptorMap_.find(objectPointId);
252 
253  if (i == descriptorMap_.cend())
254  {
255  return false;
256  }
257 
258  descriptorMap_.erase(i);
259 
260  return true;
261 }
262 
263 template <typename TDescriptor>
264 std::unique_ptr<UnifiedDescriptorMap> UnifiedDescriptorMapT<TDescriptor>::clone() const
265 {
266  return std::make_unique<UnifiedDescriptorMapT<TDescriptor>>(DescriptorMap(descriptorMap_));
267 }
268 
269 }
270 
271 }
272 
273 }
274 
275 #endif // META_OCEAN_TRACKING_MAPBUILDING_UNIFIED_DESCRIPTOR_H
This class implements a helper class allowing to determine the descriptor type value for a descriptor...
Definition: UnifiedDescriptor.h:177
This class implements the base class for all unified descriptor objects.
Definition: UnifiedDescriptor.h:31
DescriptorType descriptorType() const
Returns the descriptor type of all descriptors hold in this object.
Definition: UnifiedDescriptor.h:492
DescriptorType
Definition of descriptor types.
Definition: UnifiedDescriptor.h:49
This class implements the base class for all unified descriptor maps in which ids are mapped to descr...
Definition: UnifiedDescriptorMap.h:38
virtual size_t numberDescriptors(const Index32 &objectPointId) const =0
Returns the number of descriptors associated with a specified object point id.
virtual std::unique_ptr< UnifiedDescriptorMap > clone() const =0
Returns a clone of this map.
virtual size_t numberObjectPoints() const =0
Returns the number of object points.
UnifiedDescriptorMap(const DescriptorType descriptorType)
Creates a new descriptors object.
Definition: UnifiedDescriptorMap.h:182
virtual Indices32 objectPointIds() const =0
Returns the ids of all object points.
virtual bool removeDescriptors(const Index32 &objectPointId)=0
Removes the descriptors for a specified object point id.
virtual ~UnifiedDescriptorMap()=default
Disposes the object.
This class implements the descriptor map for arbitrary descriptors.
Definition: UnifiedDescriptorMap.h:94
std::unordered_map< Index32, Descriptor > DescriptorMap
Definition of an unordered map mapping object point ids to multi-view float descriptors.
Definition: UnifiedDescriptorMap.h:105
bool removeDescriptors(const Index32 &objectPointId) override
Removes the descriptors for a specified object point id.
Definition: UnifiedDescriptorMap.h:249
DescriptorMap & descriptorMap()
Returns the actual underlying descriptor map.
size_t numberObjectPoints() const override
Returns the number of object points.
Definition: UnifiedDescriptorMap.h:216
TDescriptor Descriptor
Definition of the descriptors this map is using.
Definition: UnifiedDescriptorMap.h:100
std::unique_ptr< UnifiedDescriptorMap > clone() const override
Returns a clone of this map.
Definition: UnifiedDescriptorMap.h:264
size_t numberDescriptors(const Index32 &objectPointId) const override
Returns the number of descriptors associated with a specified object point id.
Definition: UnifiedDescriptorMap.h:236
const DescriptorMap & descriptorMap() const
Returns the actual underlying descriptor map.
Definition: UnifiedDescriptorMap.h:204
DescriptorMap descriptorMap_
The internal descriptor map.
Definition: UnifiedDescriptorMap.h:165
UnifiedDescriptorMapT()
Default constructor.
Definition: UnifiedDescriptorMap.h:189
Indices32 objectPointIds() const override
Returns the ids of all object points.
Definition: UnifiedDescriptorMap.h:222
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
std::shared_ptr< UnifiedDescriptorMap > SharedUnifiedDescriptorMap
Definition of a shared pointer holding a UnifiedDescriptorMap object.
Definition: UnifiedDescriptorMap.h:30
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15