Ocean
RandomizedPose.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_RMV_RANDOMIZED_POSE_H
9 #define META_OCEAN_TRACKING_RMV_RANDOMIZED_POSE_H
10 
11 #include "ocean/tracking/rmv/RMV.h"
12 
14 #include "ocean/base/Worker.h"
15 
16 #include "ocean/math/Box3.h"
19 
20 namespace Ocean
21 {
22 
23 namespace Tracking
24 {
25 
26 namespace RMV
27 {
28 
29 /**
30  * This class implements functions for randomized poses.
31  * @ingroup trackingrmv
32  */
33 class OCEAN_TRACKING_RMV_EXPORT RandomizedPose
34 {
35  public:
36 
37  /**
38  * Determines several random camera poses close to a hemisphere, separated at individual location but slightly randomized.
39  * First, 'rollSteps' randomized poses are scattered around the north pole.<br>
40  * Second, a ring of poses around the hemisphere will be created at 'longitudeSteps' individual locations with mainly 'rollSteps' individual orientations (but all slightly randomized).
41  * @param box The bounding box of the object to be observed, must be valid
42  * @param randomGenerator Random number generator to be used
43  * @param distance The radius of the sphere around the center of the bounding box
44  * @param longitudeSteps The number of longitude steps, with range [1, infinity)
45  * @param rollSteps The number of roll steps, with range [1, infinity)
46  * @return The resulting camera poses slightly randomized but scattered around the hemisphere
47  */
48  static HomogenousMatrices4 hemispherePoses(const Box3& box, RandomGenerator& randomGenerator, const Scalar distance, const unsigned int longitudeSteps = 12u, const unsigned int rollSteps = 12u);
49 
50  /**
51  * Returns a randomized pose looking at a box.
52  * The pose points to the box center (in a hemisphere with positive y-axis as up vector).
53  * @param box Box to be looked at
54  * @param distance Pose distance to the box center
55  * @param minYFactor Minimal y translation value of the pose in relation to the distance, with range [0, 1)
56  * @return Resulting randomized pose
57  */
58  static HomogenousMatrix4 constantDistance(const Box3& box, const Scalar distance, const Scalar minYFactor);
59 
60  /**
61  * Returns a set of random pose looking at a box.
62  * The poses points to the box center (in a hemisphere with positive y-axis as up vector).
63  * @param box Box to be locked at
64  * @param distance Pose distance to the box center
65  * @param minYFactor Minimal y translation value of the pose in relation to the distance, with range [0, 1)
66  * @param number Number of random poses to return
67  * @param maximalIterations Number of maximal iterations with no new found pose, with range [10, infinity)
68  * @param angleOffset Minimal angle offset between each now pose, in radian with range (0, PI)
69  * @param poses Resulting poses, must provide enough space for all requested poses
70  */
71  static void constantDistance(const Box3& box, const Scalar distance, const Scalar minYFactor, const unsigned int number, const unsigned int maximalIterations, const Scalar angleOffset, HomogenousMatrix4* poses);
72 
73  /**
74  * Returns a randomized pose looking at a box.
75  * The pose points to the box with positive y-axis as up vector.
76  * @param pinholeCamera The pinhole camera object to be used for tracking, must be valid
77  * @param box Box to be looked at, must be valid
78  * @param randomGenerator Random generator to be used
79  * @param minDistance Minimal distance to the box's center, with range (0, infinity)
80  * @param maxDistance Maximal distance to the box's center, with range (minDistance, infinity)
81  * @param visibleRatio Defines the minimal ratio between projected box and image size (1 - visibleRatio), and the maximal ratio between projected box and image size (1 + visibleRatio), with range [0, 1)
82  * @return Resulting randomized pose
83  */
84  static HomogenousMatrix4 randomPose(const PinholeCamera& pinholeCamera, const Box3& box, RandomGenerator& randomGenerator, const Scalar minDistance, const Scalar maxDistance, const Scalar visibleRatio = Scalar(0.25));
85 
86  /**
87  * Returns a set of randomized pose looking at a box.
88  * The pose points to the box with positive y-axis as up vector.
89  * @param pinholeCamera The pinhole camera object defining the projection, must be valid
90  * @param box Box to be looked at, must be valid
91  * @param randomGenerator Random generator to be used
92  * @param minDistance Minimal distance to the box's center, with range (0, infinity)
93  * @param maxDistance Maximal distance to the box's center, with range (minDistance, infinity)
94  * @param visibleRatio Defines the minimal ratio between projected box and image size (1 - visibleRatio), and the maximal ratio between projected box and image size (1 + visibleRatio), with range [0, 1)
95  * @param number Number of random poses to return, with range [1, infinity)
96  * @param poses Resulting poses, must provide enough space for all requested poses
97  * @param worker Optional worker object to distribute the computation
98  */
99  static void randomPoses(const PinholeCamera& pinholeCamera, const Box3& box, RandomGenerator& randomGenerator, const Scalar minDistance, const Scalar maxDistance, const Scalar visibleRatio, const size_t number, HomogenousMatrix4* poses, Worker* worker = nullptr);
100 
101  private:
102 
103  /**
104  * Returns a subset of randomized pose looking at a box.
105  * The pose points to the box with positive y-axis as up vector.
106  * @param pinholeCamera The pinhole camera object defining the projection, must be valid
107  * @param box Box to be looked at, must be valid
108  * @param randomGenerator Random generator to be used
109  * @param minDistance Minimal distance to the box's center, with range (0, infinity)
110  * @param maxDistance Maximal distance to the box's center, with range (minDistance, infinity)
111  * @param visibleRatio Defines the minimal ratio between projected box and image size (1 - visibleRatio), and the maximal ratio between projected box and image size (1 + visibleRatio), with range [0, 1)
112  * @param poses Resulting poses, must provide enough space for all requested poses
113  * @param firstPose First pose to be handled, with range [0, numberPoses)
114  * @param numberPoses Number of poses to be generated, with range [1, numberPoses]
115  */
116  static void randomPoseSubset(const PinholeCamera* pinholeCamera, const Box3* box, RandomGenerator* randomGenerator, const Scalar minDistance, const Scalar maxDistance, const Scalar visibleRatio, HomogenousMatrix4* poses, const unsigned int firstPose, const unsigned int numberPoses);
117 };
118 
119 }
120 
121 }
122 
123 }
124 
125 #endif // META_OCEAN_TRACKING_RMV_RANDOMIZED_POSE_H
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
This class implements functions for randomized poses.
Definition: RandomizedPose.h:34
static void randomPoseSubset(const PinholeCamera *pinholeCamera, const Box3 *box, RandomGenerator *randomGenerator, const Scalar minDistance, const Scalar maxDistance, const Scalar visibleRatio, HomogenousMatrix4 *poses, const unsigned int firstPose, const unsigned int numberPoses)
Returns a subset of randomized pose looking at a box.
static HomogenousMatrices4 hemispherePoses(const Box3 &box, RandomGenerator &randomGenerator, const Scalar distance, const unsigned int longitudeSteps=12u, const unsigned int rollSteps=12u)
Determines several random camera poses close to a hemisphere, separated at individual location but sl...
static HomogenousMatrix4 constantDistance(const Box3 &box, const Scalar distance, const Scalar minYFactor)
Returns a randomized pose looking at a box.
static void randomPoses(const PinholeCamera &pinholeCamera, const Box3 &box, RandomGenerator &randomGenerator, const Scalar minDistance, const Scalar maxDistance, const Scalar visibleRatio, const size_t number, HomogenousMatrix4 *poses, Worker *worker=nullptr)
Returns a set of randomized pose looking at a box.
static HomogenousMatrix4 randomPose(const PinholeCamera &pinholeCamera, const Box3 &box, RandomGenerator &randomGenerator, const Scalar minDistance, const Scalar maxDistance, const Scalar visibleRatio=Scalar(0.25))
Returns a randomized pose looking at a box.
static void constantDistance(const Box3 &box, const Scalar distance, const Scalar minYFactor, const unsigned int number, const unsigned int maximalIterations, const Scalar angleOffset, HomogenousMatrix4 *poses)
Returns a set of random pose looking at a box.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition: HomogenousMatrix4.h:73
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15