Ocean
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 
19 namespace Ocean
20 {
21 
22 namespace Tracking
23 {
24 
25 namespace Point
26 {
27 
28 // Forward declaration.
29 class PosePointPair;
30 
31 /**
32  * Definition of a vector holding pose point pairs.
33  * @ingroup trackingpoint
34  */
35 typedef std::vector<PosePointPair> PosePointPairs;
36 
37 // Forward declaration.
39 
40 /**
41  * Definition of a vector holding pose objects.
42  * @ingroup trackingpoint
43  */
44 typedef std::vector<PosePointPairsObject> PosePointPairsObjects;
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;
90 
91  /// Id of th point.
92  unsigned int pairImagePointId;
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  */
99 class 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;
259 
260  /// Pose point pairs.
262 
263  /// Failure counter.
264  unsigned int dataFailureCounter;
265 };
266 
268  pairPoseId((unsigned int)(-1)),
269  pairImagePointId((unsigned int)(-1))
270 {
271  // nothing to do here
272 }
273 
274 inline PosePointPair::PosePointPair(const unsigned int poseId, const unsigned int imagePointId) :
275  pairPoseId(poseId),
276  pairImagePointId(imagePointId)
277 {
278  // nothing to do here
279 }
280 
281 inline unsigned int PosePointPair::poseId() const
282 {
283  return pairPoseId;
284 }
285 
286 inline unsigned int PosePointPair::imagePointId() const
287 {
288  return pairImagePointId;
289 }
290 
291 inline void PosePointPair::extractPair(const Database& database, HomogenousMatrix4& pose, Vector2& imagePoint) const
292 {
293  ocean_assert(database.hasPose<false>(pairPoseId));
294 
295  pose = database.pose<false>(pairPoseId);
296  imagePoint = database.imagePoint<false>(pairImagePointId);
297 }
298 
300  dataObjectId((unsigned int)(-1)),
301  dataFailureCounter(0u)
302 {
303  // nothing to do here
304 }
305 
306 inline PosePointPairsObject::PosePointPairsObject(const unsigned int objectId, const PosePointPairs& posePointPairs) :
307  dataObjectId(objectId),
308  dataPosePointPairs(posePointPairs),
309  dataFailureCounter(0u)
310 {
311  // nothing to do here
312 }
313 
315  dataObjectId(object.dataObjectId),
316  dataPosePointPairs(std::move(object.dataPosePointPairs)),
317  dataFailureCounter(object.dataFailureCounter)
318 {
319  object.dataObjectId = (unsigned int)(-1);
320 }
321 
322 inline PosePointPairsObject::PosePointPairsObject(const unsigned int newObjectId, PosePointPairs&& newPosePointPairs) :
323  dataObjectId(newObjectId),
324  dataPosePointPairs(newPosePointPairs),
325  dataFailureCounter(0u)
326 {
327  // nothing to do here
328 }
329 
330 inline unsigned int PosePointPairsObject::objectId() const
331 {
332  return dataObjectId;
333 }
334 
335 inline unsigned int PosePointPairsObject::size() const
336 {
337  return (unsigned int)dataPosePointPairs.size();
338 }
339 
340 inline unsigned int PosePointPairsObject::failureCounter() const
341 {
342  return dataFailureCounter;
343 }
344 
346 {
348 }
349 
351 {
352  dataFailureCounter = 0u;
353 }
354 
356 {
357  return dataPosePointPairs;
358 }
359 
360 void inline PosePointPairsObject::addPosePointPair(const PosePointPair& posePointPair)
361 {
362  dataPosePointPairs.push_back(posePointPair);
363 }
364 
365 void inline PosePointPairsObject::addPosePointPair(const unsigned int poseId, const unsigned int imagePointId)
366 {
367  dataPosePointPairs.push_back(PosePointPair(poseId, imagePointId));
368 }
369 
371 {
372  HomogenousMatrices4 result;
373  result.reserve(dataPosePointPairs.size());
374 
375  for (PosePointPairs::const_iterator i = dataPosePointPairs.begin(); i != dataPosePointPairs.end(); ++i)
376  result.push_back(database.pose<false>(i->poseId()));
377 
378  return result;
379 }
380 
382 {
384 }
385 
387 {
388  Vectors2 result;
389  result.reserve(dataPosePointPairs.size());
390 
391  for (PosePointPairs::const_iterator i = dataPosePointPairs.begin(); i != dataPosePointPairs.end(); ++i)
392  result.push_back(database.imagePoint<false>(i->imagePointId()));
393 
394  return result;
395 }
396 
398 {
399  return database.objectPoint<true>(dataObjectId);
400 }
401 
402 inline void PosePointPairsObject::extractObject(const Database& database, HomogenousMatrices4& poses, Vectors2& imagePoints, Vector3& objectPoint)
403 {
404  ocean_assert(poses.empty());
405  ocean_assert(imagePoints.empty());
406 
407  poses.reserve(dataPosePointPairs.size());
408  for (PosePointPairs::const_iterator i = dataPosePointPairs.begin(); i != dataPosePointPairs.end(); ++i)
409  poses.push_back(database.pose<false>(i->poseId()));
410 
411  imagePoints.reserve(dataPosePointPairs.size());
412  for (PosePointPairs::const_iterator i = dataPosePointPairs.begin(); i != dataPosePointPairs.end(); ++i)
413  imagePoints.push_back(database.imagePoint<false>(i->imagePointId()));
414 
415  objectPoint = database.objectPoint<true>(dataObjectId);
416 }
417 
418 inline void PosePointPairsObject::extractObjectIF(const Database& database, HomogenousMatrices4& posesIF, Vectors2& imagePoints, Vector3& objectPoint)
419 {
420  ocean_assert(posesIF.empty());
421  ocean_assert(imagePoints.empty());
422 
424 
425  imagePoints.reserve(dataPosePointPairs.size());
426  for (PosePointPairs::const_iterator i = dataPosePointPairs.begin(); i != dataPosePointPairs.end(); ++i)
427  imagePoints.push_back(database.imagePoint<false>(i->imagePointId()));
428 
429  objectPoint = database.objectPoint<true>(dataObjectId);
430 }
431 
433 {
434  dataObjectId = (unsigned int)(-1);
435 }
436 
437 inline bool PosePointPairsObject::isValid() const
438 {
439  return dataObjectId != (unsigned int)(-1);
440 }
441 
443 {
444  if (this != &object)
445  {
446  dataObjectId = object.dataObjectId;
447  dataPosePointPairs = std::move(object.dataPosePointPairs);
448  dataFailureCounter = object.dataFailureCounter;
449 
450  object.dataObjectId = (unsigned int)(-1);
451  }
452 
453  return *this;
454 }
455 
456 inline PosePointPairsObject::operator bool() const
457 {
458  return isValid();
459 }
460 
461 }
462 
463 }
464 
465 }
466 
467 #endif // META_OCEAN_TRACKING_POINT_POSE_POINT_PAIR_H
static HomogenousMatrixT4< U > standard2InvertedFlipped(const HomogenousMatrixT4< U > &world_T_camera)
Transforms a standard homogenous 4x4 viewing (extrinsic camera) matrix into an inverted and flipped c...
Definition: Camera.h:734
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:2267
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:3276
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:2343
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:291
PosePointPair()
Creates an invalid pair.
Definition: PosePointPair.h:267
unsigned int imagePointId() const
Returns the image point id of this pair.
Definition: PosePointPair.h:286
unsigned int poseId() const
Returns the pose id of this pair.
Definition: PosePointPair.h:281
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:381
const PosePointPairs & posePointPairs() const
Returns the pose point pairs of this objects.
Definition: PosePointPair.h:355
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:402
void addPosePointPair(const PosePointPair &posePointPair)
Adds a new pose point pair to this object.
Definition: PosePointPair.h:360
unsigned int size() const
Returns the number of poses and corresponding image points that object covers.
Definition: PosePointPair.h:335
void incrementFailure()
Increments the failure counter by one.
Definition: PosePointPair.h:345
void invalidate()
Invalidates this object.
Definition: PosePointPair.h:432
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:418
unsigned int objectId() const
Returns the id of the object point of this object.
Definition: PosePointPair.h:330
bool isValid() const
Returns whether this object holds a valid id of an object point.
Definition: PosePointPair.h:437
PosePointPairs dataPosePointPairs
Pose point pairs.
Definition: PosePointPair.h:261
unsigned int failureCounter() const
Returns the failure counter.
Definition: PosePointPair.h:340
PosePointPairsObject()
Creates an invalid object.
Definition: PosePointPair.h:299
unsigned int dataFailureCounter
Failure counter.
Definition: PosePointPair.h:264
HomogenousMatrices4 poses(const Database &database) const
Returns the poses of this object.
Definition: PosePointPair.h:370
PosePointPairsObject & operator=(PosePointPairsObject &&object)
Assign operator.
Definition: PosePointPair.h:442
unsigned int dataObjectId
Id of the object.
Definition: PosePointPair.h:258
void resetFailure()
Resets the failure counter to zero.
Definition: PosePointPair.h:350
Vectors2 imagePoints(const Database &database) const
Returns the image points of this object.
Definition: PosePointPair.h:386
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:397
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition: HomogenousMatrix4.h:73
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
std::vector< PosePointPair > PosePointPairs
Definition of a vector holding pose point pairs.
Definition: PosePointPair.h:29
std::vector< PosePointPairsObject > PosePointPairsObjects
Definition of a vector holding pose objects.
Definition: PosePointPair.h:38
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15