Ocean
UnifiedDescriptors.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_DESCRIPTORS_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_UNIFIED_DESCRIPTORS_H
10 
13 
14 namespace Ocean
15 {
16 
17 namespace Tracking
18 {
19 
20 namespace MapBuilding
21 {
22 
23 /**
24  * This class implements the base class for all unified descriptor buffers stored in a continuous memory like a vector.
25  * @see UnifiedDescriptorMap
26  * @ingroup trackingmapbuilding
27  */
29 {
30  public:
31 
32  /**
33  * Disposes this object.
34  */
35  virtual ~UnifiedDescriptors() = default;
36 
37  /**
38  * Returns the number of descriptors this object holds.
39  * @return The number of descriptors, with range [0, infinity)
40  */
41  virtual size_t numberDescriptors() const = 0;
42 
43  /**
44  * Returns whether this object holds at least one descriptor.
45  * @return True, if so
46  */
47  virtual bool isValid() const = 0;
48 
49  protected:
50 
51  /**
52  * Creates a new descriptors object.
53  * @param descriptorType The type of the descriptors
54  */
55  explicit inline UnifiedDescriptors(const DescriptorType descriptorType);
56 };
57 
58 /**
59  * Definition of a shared pointer holding a UnifiedDescriptors object.
60  * @see UnifiedDescriptors
61  * @ingroup trackingmapbuilding
62  */
63 using SharedUnifiedDescriptors = std::shared_ptr<UnifiedDescriptors>;
64 
65 /**
66  * This class implements a type-based container for descriptors stored in a continuous memory like a vector.
67  * @tparam TDescriptor The data type of each individual descriptor this object will store
68  */
69 template <typename TDescriptor>
71 {
72  public:
73 
74  /// The data type of the descriptor.
75  using Descriptor = TDescriptor;
76 
77  public:
78 
79  /**
80  * Default constructor creating an object without any descriptors.
81  */
82  inline UnifiedDescriptorsT();
83 
84  /**
85  * Creates a new object with new descriptors.
86  * @param descriptors The descriptors which will be moved into this object
87  */
88  explicit UnifiedDescriptorsT(std::vector<TDescriptor>&& descriptors);
89 
90  /**
91  * Returns the pointer to the memory holding all descriptors of this object.
92  * @return The memory with all descriptors if 'isValid() == true'
93  */
94  inline const TDescriptor* descriptors() const;
95 
96  /**
97  * Returns the number of descriptors this object holds.
98  * @see UnifiedDescriptors::numberDescriptors().
99  */
100  size_t numberDescriptors() const override;
101 
102  /**
103  * Returns whether this object holds at least one descriptor.
104  * @see UnifiedDescriptors::isValid().
105  */
106  bool isValid() const override;
107 
108  protected:
109 
110  /// The object's descriptors.
111  std::vector<TDescriptor> descriptors_;
112 };
113 
115 
117 
118 template <unsigned int tNumberBits>
120 
121 template <unsigned int tNumberElements>
123 
124 template <unsigned int tNumberElements>
126 
128  UnifiedDescriptor(descriptorType)
129 {
130  // nothing to do here
131 }
132 
133 template <typename TDescriptor>
135  UnifiedDescriptors(DescriptorTyper<TDescriptor>::type())
136 {
137  ocean_assert(descriptorType() != DescriptorType::DT_INVALID);
138 }
139 
140 template <typename TDescriptor>
141 UnifiedDescriptorsT<TDescriptor>::UnifiedDescriptorsT(std::vector<TDescriptor>&& descriptors) :
142  UnifiedDescriptors(DescriptorTyper<TDescriptor>::type()),
143  descriptors_(std::move(descriptors))
144 {
145  ocean_assert(descriptorType() != DescriptorType::DT_INVALID);
146 }
147 
148 template <typename TDescriptor>
149 inline const TDescriptor* UnifiedDescriptorsT<TDescriptor>::descriptors() const
150 {
151  return descriptors_.data();
152 }
153 
154 template <typename TDescriptor>
156 {
157  return descriptors_.size();
158 }
159 
160 template <typename TDescriptor>
162 {
163  return !descriptors_.empty();
164 }
165 
166 }
167 
168 }
169 
170 }
171 
172 #endif // META_OCEAN_TRACKING_MAPBUILDING_UNIFIED_DESCRIPTORS_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 buffers stored in a continuous memory...
Definition: UnifiedDescriptors.h:29
virtual ~UnifiedDescriptors()=default
Disposes this object.
UnifiedDescriptors(const DescriptorType descriptorType)
Creates a new descriptors object.
Definition: UnifiedDescriptors.h:127
virtual bool isValid() const =0
Returns whether this object holds at least one descriptor.
virtual size_t numberDescriptors() const =0
Returns the number of descriptors this object holds.
This class implements a type-based container for descriptors stored in a continuous memory like a vec...
Definition: UnifiedDescriptors.h:71
bool isValid() const override
Returns whether this object holds at least one descriptor.
Definition: UnifiedDescriptors.h:161
UnifiedDescriptorsT()
Default constructor creating an object without any descriptors.
Definition: UnifiedDescriptors.h:134
std::vector< TDescriptor > descriptors_
The object's descriptors.
Definition: UnifiedDescriptors.h:111
const TDescriptor * descriptors() const
Returns the pointer to the memory holding all descriptors of this object.
Definition: UnifiedDescriptors.h:149
TDescriptor Descriptor
The data type of the descriptor.
Definition: UnifiedDescriptors.h:75
size_t numberDescriptors() const override
Returns the number of descriptors this object holds.
Definition: UnifiedDescriptors.h:155
std::shared_ptr< UnifiedDescriptors > SharedUnifiedDescriptors
Definition of a shared pointer holding a UnifiedDescriptors object.
Definition: UnifiedDescriptors.h:63
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15