Ocean
PlaneFinder.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_PLANE_FINDER_H
9 #define META_OCEAN_TRACKING_PLANE_FINDER_H
10 
13 
14 #include "ocean/geometry/Error.h"
15 
18 #include "ocean/math/Plane3.h"
19 
20 namespace Ocean
21 {
22 
23 namespace Tracking
24 {
25 
26 /**
27  * This class implements a 3D plane finder without any previous knowledge about the plane or the camera poses.
28  * The class takes several correspondences of image points that capture corresponding 3D object points lying on the same 3D plane.<br>
29  * @ingroup tracking
30  */
31 class OCEAN_TRACKING_EXPORT PlaneFinder
32 {
33  protected:
34 
35  /**
36  * Definition of a correspondence set object with handling 2D vectors.
37  */
39 
40  public:
41 
42  /**
43  * Returns the number of stored correspondence sets.
44  * @return Correspondence set size
45  */
46  inline size_t size() const;
47 
48  /**
49  * Returns the number of image points within each individual correspondence set.
50  * @return Number of image points
51  */
52  inline size_t imagePoints() const;
53 
54  /**
55  * Returns the first set of image points.
56  * Beware: Check whether this object holds at least on set of image points before you call this function.
57  * @return Image points
58  */
59  const Vectors2& firstImagePoints() const;
60 
61  /**
62  * Returns the last set of image points.
63  * Beware: Check whether this object holds at least on set of image points before you call this function.
64  * @return Image points
65  */
66  inline const Vectors2& lastImagePoints() const;
67 
68  /**
69  * Calculates the summed square distance between the first image points and the corresponding image points in the most recent set of image points.
70  * @return Resulting summed square distance
71  */
72  inline Scalar sqrDistance() const;
73 
74  /**
75  * Adds new image points as new set of correspondences.
76  * Beware: The number of provided image points must match with the number of already stored image points within each individual set of correspondences.
77  * @param imagePoints Image points to be added
78  * @return True, if succeeded
79  */
80  virtual bool addImagePoint(const Vectors2& imagePoints);
81 
82  /**
83  * Adds new image points as new set of correspondences.
84  * Beware: The number of provided image points must match with the number of already stored image points within each individual set of correspondences.
85  * @param imagePoints Image points to be added (and moved)
86  * @return True, if succeeded
87  */
88  virtual bool addImagePoint(Vectors2&& imagePoints);
89 
90  /**
91  * Adds a new subset of image points that corresponds to a subset of the stored sets of image points.
92  * This function takes a set of indices which define the valid subset of the given image points.<br>
93  * Only valid image points will be added while also the already stored sets of image points will be reduced so that only valid elements are stored finally.<br>
94  * @param imagePoints Large set of image points to be added
95  * @param validIndices Indices that define a valid subset of the given elements, each index must exist at most once and must lie inside the range [0, elements.size())
96  * @return True, if succeeded
97  */
98  virtual bool addImagePoint(const Vectors2& imagePoints, const Indices32& validIndices);
99 
100  /**
101  * Reduces the image points within each set of corresponding image points.
102  * The remaining elements are defined by a set of indices.<br>
103  * @param validIndices Indices that define a valid subset of the already stored elements, each index must exist at most once and must lie inside the range [0, elements())
104  * @return True, if succeeded
105  */
106  inline bool reduce(const Indices32& validIndices);
107 
108  protected:
109 
110  /**
111  * Creates a new plane finder object.
112  */
113  inline PlaneFinder();
114 
115  /**
116  * Destructs this object.
117  */
118  virtual ~PlaneFinder() = default;
119 
120  protected:
121 
122  /// The set of image point correspondences.
124 };
125 
127 {
128  // nothing to do here
129 }
130 
131 inline size_t PlaneFinder::size() const
132 {
134 }
135 
136 inline size_t PlaneFinder::imagePoints() const
137 {
139 }
140 
142 {
143  ocean_assert(!imagePointCorrespondences.correspondences().empty());
145 }
146 
148 {
149  ocean_assert(!imagePointCorrespondences.correspondences().empty());
151 }
152 
154 {
156 
157  if (correspondences.size() <= 1)
158  return 0;
159 
160  return Geometry::Error::determineAverageError(correspondences.front(), correspondences.back());
161 }
162 
163 inline bool PlaneFinder::reduce(const Indices32& validIndices)
164 {
165  return imagePointCorrespondences.reduce(validIndices);
166 }
167 
168 }
169 
170 }
171 
172 #endif // META_OCEAN_TRACKING_PLANE_FINDER_H
static Scalar determineAverageError(const Vectors2 &firstPoints, const Vectors2 &secondPoints, Vector2 *errors=nullptr, Scalar *sqrErrors=nullptr)
Returns the average square error between two sets of 2D positions.
size_t elements() const
Returns the number of corresponding elements.
Definition: CorrespondenceSet.h:251
bool reduce(const Indices32 &validIndices)
Reduces the elements within each set of corresponding elements.
Definition: CorrespondenceSet.h:500
std::vector< Elements > ElementsVector
This class defines a vector storing vectors of elements.
Definition: CorrespondenceSet.h:46
size_t size() const
Returns the number of correspondences.
Definition: CorrespondenceSet.h:244
const ElementsVector & correspondences() const
Returns the set of stored correspondences.
Definition: CorrespondenceSet.h:258
This class implements a 3D plane finder without any previous knowledge about the plane or the camera ...
Definition: PlaneFinder.h:32
virtual ~PlaneFinder()=default
Destructs this object.
Scalar sqrDistance() const
Calculates the summed square distance between the first image points and the corresponding image poin...
Definition: PlaneFinder.h:153
PlaneFinder()
Creates a new plane finder object.
Definition: PlaneFinder.h:126
const Vectors2 & firstImagePoints() const
Returns the first set of image points.
Definition: PlaneFinder.h:141
CorrespondenceSet< Vector2 > ImagePointCorrespondenceSet
Definition of a correspondence set object with handling 2D vectors.
Definition: PlaneFinder.h:38
virtual bool addImagePoint(const Vectors2 &imagePoints, const Indices32 &validIndices)
Adds a new subset of image points that corresponds to a subset of the stored sets of image points.
virtual bool addImagePoint(Vectors2 &&imagePoints)
Adds new image points as new set of correspondences.
size_t size() const
Returns the number of stored correspondence sets.
Definition: PlaneFinder.h:131
bool reduce(const Indices32 &validIndices)
Reduces the image points within each set of corresponding image points.
Definition: PlaneFinder.h:163
virtual bool addImagePoint(const Vectors2 &imagePoints)
Adds new image points as new set of correspondences.
ImagePointCorrespondenceSet imagePointCorrespondences
The set of image point correspondences.
Definition: PlaneFinder.h:123
const Vectors2 & lastImagePoints() const
Returns the last set of image points.
Definition: PlaneFinder.h:147
size_t imagePoints() const
Returns the number of image points within each individual correspondence set.
Definition: PlaneFinder.h:136
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition: base/Utilities.h:1089
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15