Ocean
Loading...
Searching...
No Matches
PosePointPair.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_POINT_POSE_POINT_PAIR_H
9#define META_OCEAN_TRACKING_POINT_POSE_POINT_PAIR_H
10
12
14
16
17#include <vector>
18
19namespace Ocean
20{
21
22namespace Tracking
23{
24
25namespace Point
26{
27
28// Forward declaration.
29class PosePointPair;
30
31/**
32 * Definition of a vector holding pose point pairs.
33 * @ingroup trackingpoint
34 */
35using PosePointPairs = std::vector<PosePointPair>;
36
37// Forward declaration.
39
40/**
41 * Definition of a vector holding pose objects.
42 * @ingroup trackingpoint
43 */
44using PosePointPairsObjects = std::vector<PosePointPairsObject>;
45
46/**
47 * Definition of a simple struct combining a pose and an image point id.
48 * @ingroup trackingpoint
49 */
51{
52 public:
53
54 /**
55 * Creates an invalid pair.
56 */
57 inline PosePointPair();
58
59 /**
60 * Creates a new pair.
61 * @param poseId Id of the pose
62 * @param imagePointId Id of the image point
63 */
64 inline PosePointPair(const unsigned int poseId, const unsigned int imagePointId);
65
66 /**
67 * Returns the pose id of this pair.
68 * @return Pose id
69 */
70 inline unsigned int poseId() const;
71
72 /**
73 * Returns the image point id of this pair.
74 * @return Point id
75 */
76 inline unsigned int imagePointId() const;
77
78 /**
79 * Extracts the pose and the image point of this pair.
80 * @param database The database holding the entire tracking information
81 * @param pose Resulting pose of this pair
82 * @param imagePoint Resulting image points of this pair
83 */
84 inline void extractPair(const Database& database, HomogenousMatrix4& pose, Vector2& imagePoint) const;
85
86 private:
87
88 /// Id of the pose.
89 unsigned int pairPoseId = (unsigned int)(-1);
90
91 /// Id of th point.
92 unsigned int pairImagePointId = (unsigned int)(-1);
93};
94
95/**
96 * Definition of an object that combines an object id with the pairs of poses and image points.
97 * @ingroup trackingpoint
98 */
99class OCEAN_TRACKING_POINT_EXPORT PosePointPairsObject
100{
101 public:
102
103 /**
104 * Creates an invalid object.
105 */
106 inline PosePointPairsObject();
107
108 /**
109 * Creates a new object.
110 * @param objectId Id of the object
111 * @param posePointPairs Pose point pairs
112 */
113 inline PosePointPairsObject(const unsigned int objectId, const PosePointPairs& posePointPairs);
114
115 /**
116 * Move constructor.
117 * @param object Object to be moved
118 */
120
121 /**
122 * Creates a new object.
123 * @param objectId Id of the object
124 * @param posePointPairs Pose point pairs
125 */
126 inline PosePointPairsObject(const unsigned int objectId, PosePointPairs&& posePointPairs);
127
128 /**
129 * Returns the id of the object point of this object.
130 * @return Object point id
131 */
132 inline unsigned int objectId() const;
133
134 /**
135 * Returns the number of poses and corresponding image points that object covers.
136 * @return Number of poses and corresponding image points
137 */
138 inline unsigned int size() const;
139
140 /**
141 * Returns the failure counter.
142 * @return Failure counter
143 */
144 inline unsigned int failureCounter() const;
145
146 /**
147 * Increments the failure counter by one.
148 */
149 inline void incrementFailure();
150
151 /**
152 * Resets the failure counter to zero.
153 */
154 inline void resetFailure();
155
156 /**
157 * Returns the pose point pairs of this objects.
158 * @return Pose point pairs
159 */
160 inline const PosePointPairs& posePointPairs() const;
161
162 /**
163 * Adds a new pose point pair to this object.
164 * @param posePointPair Pose point pair to be added
165 */
166 inline void addPosePointPair(const PosePointPair& posePointPair);
167
168 /**
169 * Adds a new pose point pair to this object.
170 * @param poseId Id of the pose to be added
171 * @param imagePointId Id of the image point to be added
172 */
173 inline void addPosePointPair(const unsigned int poseId, const unsigned int imagePointId);
174
175 /**
176 * Returns the poses of this object.
177 * @param database The database holding the entire tracking information
178 * @return Object poses
179 */
180 inline HomogenousMatrices4 poses(const Database& database) const;
181
182 /**
183 * Returns the inverted and flipped poses of this object.
184 * @param database The database holding the entire tracking information
185 * @return Inverted and flipped poses
186 */
187 inline HomogenousMatrices4 posesIF(const Database& database) const;
188
189 /**
190 * Returns the image points of this object.
191 * @param database The database holding the entire tracking information
192 * @return Image points
193 */
194 inline Vectors2 imagePoints(const Database& database) const;
195
196 /**
197 * Returns the object point of this object.
198 * @param database The database holding the entire tracking information
199 * @return Object point
200 */
201 inline Vector3 objectPoint(const Database& database) const;
202
203 /**
204 * Extracts the poses, the image points and the object point of this object.
205 * @param database The database holding the entire tracking information
206 * @param poses Resulting poses
207 * @param imagePoints Resulting image points
208 * @param objectPoint Resulting object point
209 */
210 inline void extractObject(const Database& database, HomogenousMatrices4& poses, Vectors2& imagePoints, Vector3& objectPoint);
211
212 /**
213 * Extracts the poses, the image points and the object point of this object.
214 * @param database The database holding the entire tracking information
215 * @param posesIF Resulting inverted and flipped poses
216 * @param imagePoints Resulting image points
217 * @param objectPoint Resulting object point
218 */
219 inline void extractObjectIF(const Database& database, HomogenousMatrices4& posesIF, Vectors2& imagePoints, Vector3& objectPoint);
220
221 /**
222 * Optimizes the object point according to the pose and image points of this object
223 * @param database The database holding the entire tracking information
224 * @param pinholeCamera The pinhole camera object
225 * @param useCameraDistortionParameters True, to apply the camera distortion parameters
226 * @return True, if succeeded
227 */
228 bool optimizeObjectPoint(Database& database, const PinholeCamera& pinholeCamera , const bool useCameraDistortionParameters);
229
230 /**
231 * Invalidates this object.
232 * The object id is invalidated.
233 */
234 inline void invalidate();
235
236 /**
237 * Returns whether this object holds a valid id of an object point.
238 * @return True, if so
239 */
240 inline bool isValid() const;
241
242 /**
243 * Assign operator.
244 * @param object Object to be moved
245 * @return Reference to this object
246 */
247 inline PosePointPairsObject& operator=(PosePointPairsObject&& object);
248
249 /**
250 * Returns whether this object holds a valid id of an object point.
251 * @return True, if so
252 */
253 explicit inline operator bool() const;
254
255 private:
256
257 /// Id of the object.
258 unsigned int dataObjectId = (unsigned int)(-1);
259
260 /// Pose point pairs.
262
263 /// Failure counter.
264 unsigned int dataFailureCounter = 0u;
265};
266
268{
269 // nothing to do here
270}
271
272inline PosePointPair::PosePointPair(const unsigned int poseId, const unsigned int imagePointId) :
273 pairPoseId(poseId),
274 pairImagePointId(imagePointId)
275{
276 // nothing to do here
277}
278
279inline unsigned int PosePointPair::poseId() const
280{
281 return pairPoseId;
282}
283
284inline unsigned int PosePointPair::imagePointId() const
285{
286 return pairImagePointId;
287}
288
289inline void PosePointPair::extractPair(const Database& database, HomogenousMatrix4& pose, Vector2& imagePoint) const
290{
291 ocean_assert(database.hasPose<false>(pairPoseId));
292
293 pose = database.pose<false>(pairPoseId);
294 imagePoint = database.imagePoint<false>(pairImagePointId);
295}
296
298{
299 // nothing to do here
300}
301
302inline PosePointPairsObject::PosePointPairsObject(const unsigned int objectId, const PosePointPairs& posePointPairs) :
303 dataObjectId(objectId),
304 dataPosePointPairs(posePointPairs)
305{
306 // nothing to do here
307}
308
310 dataObjectId(object.dataObjectId),
311 dataPosePointPairs(std::move(object.dataPosePointPairs)),
312 dataFailureCounter(object.dataFailureCounter)
313{
314 object.dataObjectId = (unsigned int)(-1);
315}
316
317inline PosePointPairsObject::PosePointPairsObject(const unsigned int newObjectId, PosePointPairs&& newPosePointPairs) :
318 dataObjectId(newObjectId),
319 dataPosePointPairs(newPosePointPairs)
320{
321 // nothing to do here
322}
323
324inline unsigned int PosePointPairsObject::objectId() const
325{
326 return dataObjectId;
327}
328
329inline unsigned int PosePointPairsObject::size() const
330{
331 return (unsigned int)dataPosePointPairs.size();
332}
333
334inline unsigned int PosePointPairsObject::failureCounter() const
335{
336 return dataFailureCounter;
337}
338
343
348
353
355{
356 dataPosePointPairs.push_back(posePointPair);
357}
358
359void inline PosePointPairsObject::addPosePointPair(const unsigned int poseId, const unsigned int imagePointId)
360{
361 dataPosePointPairs.emplace_back(poseId, imagePointId);
362}
363
365{
366 HomogenousMatrices4 result;
367 result.reserve(dataPosePointPairs.size());
368
369 for (const PosePointPair& dataPosePointPair : dataPosePointPairs)
370 {
371 result.push_back(database.pose<false>(dataPosePointPair.poseId()));
372 }
373
374 return result;
375}
376
378{
379 return PinholeCamera ::standard2InvertedFlipped(poses(database));
380}
381
383{
384 Vectors2 result;
385 result.reserve(dataPosePointPairs.size());
386
387 for (const PosePointPair& dataPosePointPair : dataPosePointPairs)
388 {
389 result.push_back(database.imagePoint<false>(dataPosePointPair.imagePointId()));
390 }
391
392 return result;
393}
394
396{
397 return database.objectPoint<true>(dataObjectId);
398}
399
400inline void PosePointPairsObject::extractObject(const Database& database, HomogenousMatrices4& poses, Vectors2& imagePoints, Vector3& objectPoint)
401{
402 ocean_assert(poses.empty());
403 ocean_assert(imagePoints.empty());
404
405 poses.reserve(dataPosePointPairs.size());
406 for (const PosePointPair& dataPosePointPair : dataPosePointPairs)
407 {
408 poses.push_back(database.pose<false>(dataPosePointPair.poseId()));
409 }
410
411 imagePoints.reserve(dataPosePointPairs.size());
412 for (const PosePointPair& dataPosePointPair : dataPosePointPairs)
413 {
414 imagePoints.push_back(database.imagePoint<false>(dataPosePointPair.imagePointId()));
415 }
416
417 objectPoint = database.objectPoint<true>(dataObjectId);
418}
419
420inline void PosePointPairsObject::extractObjectIF(const Database& database, HomogenousMatrices4& posesIF, Vectors2& imagePoints, Vector3& objectPoint)
421{
422 ocean_assert(posesIF.empty());
423 ocean_assert(imagePoints.empty());
424
425 posesIF = PinholeCamera ::standard2InvertedFlipped(poses(database));
426
427 imagePoints.reserve(dataPosePointPairs.size());
428 for (const PosePointPair& dataPosePointPair : dataPosePointPairs)
429 {
430 imagePoints.push_back(database.imagePoint<false>(dataPosePointPair.imagePointId()));
431 }
432
433 objectPoint = database.objectPoint<true>(dataObjectId);
434}
435
437{
438 dataObjectId = (unsigned int)(-1);
439}
440
442{
443 return dataObjectId != (unsigned int)(-1);
444}
445
447{
448 if (this != &object)
449 {
450 dataObjectId = object.dataObjectId;
451 dataPosePointPairs = std::move(object.dataPosePointPairs);
452 dataFailureCounter = object.dataFailureCounter;
453
454 object.dataObjectId = (unsigned int)(-1);
455 }
456
457 return *this;
458}
459
460inline PosePointPairsObject::operator bool() const
461{
462 return isValid();
463}
464
465}
466
467}
468
469}
470
471#endif // META_OCEAN_TRACKING_POINT_POSE_POINT_PAIR_H
This class implements a database for 3D object points, 2D image points and 6DOF camera poses.
Definition Database.h:67
const Vector2 & imagePoint(const Index32 imagePointId) const
Returns the location of an image point which is specified by the id of the image point.
Definition Database.h:2251
const HomogenousMatrix4 & pose(const Index32 poseId) const
Returns the 6DOF pose of a camera frame which is specified by the id of the pose.
Definition Database.h:2444
bool hasPose(const Index32 poseId, HomogenousMatrix4 *pose=nullptr) const
Returns whether this database holds a specified camera pose.
Definition Database.h:3369
const Vector3 & objectPoint(const Index32 objectPointId) const
Returns the location of an object point which is specified by the id of the object point.
Definition Database.h:2335
Definition of a simple struct combining a pose and an image point id.
Definition PosePointPair.h:51
void extractPair(const Database &database, HomogenousMatrix4 &pose, Vector2 &imagePoint) const
Extracts the pose and the image point of this pair.
Definition PosePointPair.h:289
PosePointPair()
Creates an invalid pair.
Definition PosePointPair.h:267
unsigned int imagePointId() const
Returns the image point id of this pair.
Definition PosePointPair.h:284
unsigned int poseId() const
Returns the pose id of this pair.
Definition PosePointPair.h:279
unsigned int pairPoseId
Id of the pose.
Definition PosePointPair.h:89
unsigned int pairImagePointId
Id of th point.
Definition PosePointPair.h:92
Definition of an object that combines an object id with the pairs of poses and image points.
Definition PosePointPair.h:100
HomogenousMatrices4 posesIF(const Database &database) const
Returns the inverted and flipped poses of this object.
Definition PosePointPair.h:377
const PosePointPairs & posePointPairs() const
Returns the pose point pairs of this objects.
Definition PosePointPair.h:349
void extractObject(const Database &database, HomogenousMatrices4 &poses, Vectors2 &imagePoints, Vector3 &objectPoint)
Extracts the poses, the image points and the object point of this object.
Definition PosePointPair.h:400
void addPosePointPair(const PosePointPair &posePointPair)
Adds a new pose point pair to this object.
Definition PosePointPair.h:354
unsigned int size() const
Returns the number of poses and corresponding image points that object covers.
Definition PosePointPair.h:329
void incrementFailure()
Increments the failure counter by one.
Definition PosePointPair.h:339
void invalidate()
Invalidates this object.
Definition PosePointPair.h:436
void extractObjectIF(const Database &database, HomogenousMatrices4 &posesIF, Vectors2 &imagePoints, Vector3 &objectPoint)
Extracts the poses, the image points and the object point of this object.
Definition PosePointPair.h:420
unsigned int objectId() const
Returns the id of the object point of this object.
Definition PosePointPair.h:324
bool isValid() const
Returns whether this object holds a valid id of an object point.
Definition PosePointPair.h:441
PosePointPairs dataPosePointPairs
Pose point pairs.
Definition PosePointPair.h:261
unsigned int failureCounter() const
Returns the failure counter.
Definition PosePointPair.h:334
PosePointPairsObject()
Creates an invalid object.
Definition PosePointPair.h:297
unsigned int dataFailureCounter
Failure counter.
Definition PosePointPair.h:264
HomogenousMatrices4 poses(const Database &database) const
Returns the poses of this object.
Definition PosePointPair.h:364
PosePointPairsObject & operator=(PosePointPairsObject &&object)
Assign operator.
Definition PosePointPair.h:446
unsigned int dataObjectId
Id of the object.
Definition PosePointPair.h:258
void resetFailure()
Resets the failure counter to zero.
Definition PosePointPair.h:344
Vectors2 imagePoints(const Database &database) const
Returns the image points of this object.
Definition PosePointPair.h:382
bool optimizeObjectPoint(Database &database, const PinholeCamera &pinholeCamera, const bool useCameraDistortionParameters)
Optimizes the object point according to the pose and image points of this object.
Vector3 objectPoint(const Database &database) const
Returns the object point of this object.
Definition PosePointPair.h:395
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition HomogenousMatrix4.h:73
std::vector< PosePointPair > PosePointPairs
Definition of a vector holding pose point pairs.
Definition PosePointPair.h:35
std::vector< PosePointPairsObject > PosePointPairsObjects
Definition of a vector holding pose objects.
Definition PosePointPair.h:44
The namespace covering the entire Ocean framework.
Definition Accessor.h:15