Ocean
Loading...
Searching...
No Matches
TestVocabularyTree.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_TEST_TESTTACKING_TEST_VOCABULARY_TREE_H
9#define META_OCEAN_TEST_TESTTACKING_TEST_VOCABULARY_TREE_H
10
12
14
16
18
19#include <array>
20
21namespace Ocean
22{
23
24namespace Test
25{
26
27namespace TestTracking
28{
29
30/**
31 * This class implements a test for the VocabularyTree class.
32 * @ingroup testtracking
33 */
34class OCEAN_TEST_TRACKING_EXPORT TestVocabularyTree
35{
36 public:
37
38 /**
39 * Definition of individual descriptor types.
40 */
42 {
43 /// Descriptor based on binary data.
45 /// Descriptor based on floats.
46 DT_FLOAT
47 };
48
49 protected:
50
51 /// The number of elements/bytes of a binary descriptor.
52 static constexpr unsigned int binaryDescriptorElements_ = 32u;
53
54 /// The number of elements of a float descriptor.
55 static constexpr unsigned int floatDescriptorElements_ = 128u;
56
57 /**
58 * Definition of a binary descriptor.
59 */
60 using BinaryDescriptor = std::array<uint8_t, binaryDescriptorElements_>;
61
62 /**
63 * Definition of a float descriptor.
64 */
65 using FloatDescriptor = std::array<float, floatDescriptorElements_>;
66
67 /**
68 * Helper class to determine data types for individual descriptor types.
69 * @tparam tDescriptorType The type of the descriptor to be sued
70 */
71 template <DescriptorType tDescriptorType>
73 {
74 // nothing to do here
75 };
76
77 public:
78
79 /**
80 * Invokes all existing tests for VocabularyTree.
81 * @param testDuration Number of seconds for each test, with range (0, infinity)
82 * @param worker The worker object to distribute the computation
83 * @param selector The test selector
84 * @return True, if succeeded
85 */
86 static bool test(const double testDuration, Worker& worker, const TestSelector& selector);
87
88 /**
89 * Tests the function determining the means for clusters of binary descriptors.
90 * @param testDuration Number of seconds for each test, with range (0, infinity)
91 * @param worker The worker object to distribute the computation
92 * @return True, if succeeded
93 */
94 static bool testDetermineClustersMeanForBinaryDescriptor(const double testDuration, Worker& worker);
95
96 /**
97 * Tests the function determining the means for clusters of float descriptors.
98 * @param testDuration Number of seconds for each test, with range (0, infinity)
99 * @param worker The worker object to distribute the computation
100 * @return True, if succeeded
101 */
102 static bool testDetermineClustersMeanForFloatDescriptor(const double testDuration, Worker& worker);
103
104 /**
105 * Tests the constructor.
106 * @param testDuration Number of seconds for each test, with range (0, infinity)
107 * @param worker The worker object to distribute the computation
108 * @return True, if succeeded
109 * @tparam tDescriptorType The descriptor type to be used
110 */
111 template <DescriptorType tDescriptorType>
112 static bool testConstructor(const double testDuration, Worker& worker);
113
114 /**
115 * Tests manual matching accessing the leaves.
116 * @param testDuration Number of seconds for each test, with range (0, infinity)
117 * @param worker The worker object to distribute the computation
118 * @return True, if succeeded
119 * @tparam tDescriptorType The descriptor type to be used
120 */
121 template <DescriptorType tDescriptorType>
122 static bool testMatchingViaLeaves(const double testDuration, Worker& worker);
123
124 /**
125 * Tests descriptor matching.
126 * @param testDuration Number of seconds for each test, with range (0, infinity)
127 * @param worker The worker object to distribute the computation
128 * @return True, if succeeded
129 * @tparam tDescriptorType The descriptor type to be used
130 */
131 template <DescriptorType tDescriptorType>
132 static bool testMatchingDescriptors(const double testDuration, Worker& worker);
133
134 /**
135 * Tests descriptor matching with forest.
136 * @param testDuration Number of seconds for each test, with range (0, infinity)
137 * @param worker The worker object to distribute the computation
138 * @return True, if succeeded
139 * @tparam tDescriptorType The descriptor type to be used
140 */
141 template <DescriptorType tDescriptorType>
142 static bool testMatchingDescriptorsWithForest(const double testDuration, Worker& worker);
143
144 protected:
145
146 /**
147 * Separates the individual bits of binary descriptor into individual integer values.
148 * @param descriptor The binary descriptor to be separated
149 * @return The resulting integer values, one for each bit
150 */
152};
153
154template <>
155class OCEAN_TEST_TRACKING_EXPORT TestVocabularyTree::TypeHelper<TestVocabularyTree::DT_BINARY>
156{
157 public:
158
159 /**
160 * The readable name of the descriptor type.
161 */
162 static constexpr const char* name_ = "Binary";
163
164 /**
165 * Definition of a descriptor data type.
166 */
168
169 /**
170 * Definition of a vector holding descriptors.
171 */
172 using Descriptors = std::vector<Descriptor>;
173
174 /**
175 * Definition of the data type for the distance between two descriptors.
176 */
177 using DistanceType = unsigned int;
178
179 /**
180 * Determines the (hamming) distance between two binary descriptors.
181 * @param descriptorA The first descriptor
182 * @param descriptorB The second descriptor
183 * @return The resulting distance
184 */
185 static DistanceType determineDistance(const BinaryDescriptor& descriptorA, const BinaryDescriptor& descriptorB);
186
187 /**
188 * Randomizes a descriptor.
189 * @param descriptor The descriptor to be randomized
190 * @param randomGenerator The random generator object to be used
191 */
192 static void randomizeDescriptor(BinaryDescriptor& descriptor, RandomGenerator& randomGenerator);
193
194 /**
195 * Applies a minor random modification to a given descriptor.
196 * @param descriptor The descriptor to modify
197 * @param randomGenerator The random generator object to be used
198 * @return The modified descriptor
199 */
200 static BinaryDescriptor modifyDescriptor(const BinaryDescriptor& descriptor, RandomGenerator& randomGenerator);
201
202 /**
203 * Returns a bunch of descriptor epsilons which can be used for testing.
204 * @param numberEpsilons The number of epsilon value to return, with range [2, numberBits]
205 * @return The descriptor epsilons
206 */
207 static std::vector<DistanceType> descriptorEpsilons(const unsigned int numberEpsilons);
208
209 /**
210 * Definition of the vocabulary tree data type.
211 */
213
214 /**
215 * The function pointer to the cluster mean function.
216 */
217 static constexpr const VocabularyTree::ClustersMeanFunction clusterMeanFunction_ = &VocabularyTree::determineClustersMeanForBinaryDescriptor<binaryDescriptorElements_ * 8u>;
218};
219
220template <>
221class OCEAN_TEST_TRACKING_EXPORT TestVocabularyTree::TypeHelper<TestVocabularyTree::DT_FLOAT>
222{
223 public:
224
225 /**
226 * The readable name of the descriptor type.
227 */
228 static constexpr const char* name_ = "Float";
229
230 /**
231 * Definition of a descriptor data type.
232 */
234
235 /**
236 * Definition of a vector holding descriptors.
237 */
238 using Descriptors = std::vector<Descriptor>;
239
240 /**
241 * Definition of the data type for the distance between two descriptors.
242 */
243 using DistanceType = float;
244
245 /**
246 * Determines the square distance between two float descriptors.
247 * @param descriptorA The first descriptor
248 * @param descriptorB The second descriptor
249 * @return The resulting square distance
250 */
251 static float determineDistance(const FloatDescriptor& descriptorA, const FloatDescriptor& descriptorB);
252
253 /**
254 * Randomizes a descriptor.
255 * @param descriptor The descriptor to be randomized
256 * @param randomGenerator The random generator object to be used
257 */
258 static void randomizeDescriptor(FloatDescriptor& descriptor, RandomGenerator& randomGenerator);
259
260 /**
261 * Applies a minor random modification to a given descriptor.
262 * @param descriptor The descriptor to modify
263 * @param randomGenerator The random generator object to be used
264 * @return The modified descriptor
265 */
266 static FloatDescriptor modifyDescriptor(const FloatDescriptor& descriptor, RandomGenerator& randomGenerator);
267
268 /**
269 * Returns a bunch of descriptor epsilons which can be used for testing.
270 * @param numberEpsilons The number of epsilon value to return, with range [2, numberBits]
271 * @return The descriptor epsilons
272 */
273 static std::vector<DistanceType> descriptorEpsilons(const unsigned int numberEpsilons);
274
275 /**
276 * Definition of the vocabulary tree data type.
277 */
279
280 /**
281 * The function pointer to the cluster mean function.
282 */
283 static constexpr const VocabularyTree::ClustersMeanFunction clusterMeanFunction_ = &VocabularyTree::determineClustersMeanForFloatDescriptor<floatDescriptorElements_>;
284};
285
286}
287
288}
289
290}
291
292#endif // META_OCEAN_TEST_TESTTACKING_TEST_VOCABULARY_TREE_H
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
Helper class to determine data types for individual descriptor types.
Definition TestVocabularyTree.h:73
This class implements a test for the VocabularyTree class.
Definition TestVocabularyTree.h:35
std::vector< Descriptor > Descriptors
Definition of a vector holding descriptors.
Definition TestVocabularyTree.h:172
static bool testDetermineClustersMeanForFloatDescriptor(const double testDuration, Worker &worker)
Tests the function determining the means for clusters of float descriptors.
static float determineDistance(const FloatDescriptor &descriptorA, const FloatDescriptor &descriptorB)
Determines the square distance between two float descriptors.
static FloatDescriptor modifyDescriptor(const FloatDescriptor &descriptor, RandomGenerator &randomGenerator)
Applies a minor random modification to a given descriptor.
static bool testMatchingDescriptors(const double testDuration, Worker &worker)
Tests descriptor matching.
static std::vector< DistanceType > descriptorEpsilons(const unsigned int numberEpsilons)
Returns a bunch of descriptor epsilons which can be used for testing.
static bool testConstructor(const double testDuration, Worker &worker)
Tests the constructor.
static void randomizeDescriptor(BinaryDescriptor &descriptor, RandomGenerator &randomGenerator)
Randomizes a descriptor.
std::array< float, floatDescriptorElements_ > FloatDescriptor
Definition of a float descriptor.
Definition TestVocabularyTree.h:65
static BinaryDescriptor modifyDescriptor(const BinaryDescriptor &descriptor, RandomGenerator &randomGenerator)
Applies a minor random modification to a given descriptor.
static bool testMatchingDescriptorsWithForest(const double testDuration, Worker &worker)
Tests descriptor matching with forest.
static Indices32 separateBinaryDescriptor(const BinaryDescriptor &descriptor)
Separates the individual bits of binary descriptor into individual integer values.
static DistanceType determineDistance(const BinaryDescriptor &descriptorA, const BinaryDescriptor &descriptorB)
Determines the (hamming) distance between two binary descriptors.
std::array< uint8_t, binaryDescriptorElements_ > BinaryDescriptor
Definition of a binary descriptor.
Definition TestVocabularyTree.h:60
static bool test(const double testDuration, Worker &worker, const TestSelector &selector)
Invokes all existing tests for VocabularyTree.
static bool testDetermineClustersMeanForBinaryDescriptor(const double testDuration, Worker &worker)
Tests the function determining the means for clusters of binary descriptors.
unsigned int DistanceType
Definition of the data type for the distance between two descriptors.
Definition TestVocabularyTree.h:177
DescriptorType
Definition of individual descriptor types.
Definition TestVocabularyTree.h:42
@ DT_BINARY
Descriptor based on binary data.
Definition TestVocabularyTree.h:44
BinaryDescriptor Descriptor
Definition of a descriptor data type.
Definition TestVocabularyTree.h:167
static bool testMatchingViaLeaves(const double testDuration, Worker &worker)
Tests manual matching accessing the leaves.
static void randomizeDescriptor(FloatDescriptor &descriptor, RandomGenerator &randomGenerator)
Randomizes a descriptor.
This class implements a Vocabulary Tree for feature descriptors.
Definition VocabularyTree.h:223
TDescriptors(*)(const unsigned int numberClusters, const TDescriptor *treeDescriptors, const Index32 *descriptorIndices, const Index32 *clusterIndicesForDescriptors, const size_t numberDescriptorIndices, Worker *worker) ClustersMeanFunction
Definition of a function pointer allowing to determine the mean descriptors for individual clusters.
Definition VocabularyTree.h:285
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
The namespace covering the entire Ocean framework.
Definition Accessor.h:15