Ocean
geometry/Geometry.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_GEOMETRY_GEOMETRY_H
9 #define META_OCEAN_GEOMETRY_GEOMETRY_H
10 
11 #include "ocean/base/Base.h"
12 
14 #include "ocean/math/Vector2.h"
15 #include "ocean/math/Vector3.h"
16 
17 #include <set>
18 #include <vector>
19 
20 namespace Ocean
21 {
22 
23 namespace Geometry
24 {
25 
26 /**
27  * @defgroup geometry Ocean Geometry Library
28  * @{
29  * The Ocean Geometry Library provides geometry functionalities e.g., projective algorithms, optimization approaches or support for advanced transformations.
30  * The library is platform independent.
31  *
32  * In general, the Geometry library is an direct extension to the Math library offering a wide variety of mathematic functions mostly related with geometric tasks.<br>
33  * The entire framework is using a right-handed coordinate system (as long as not explicitly documented differently).<br>
34  * Please be aware that often coordinate systems are defined in different ways depending on the area of expertise or traditional decisions.<br>
35  * In Computer Graphics, most coordinate systems are defined/interpreted in a way that the observer/camera is looking into the negative z-space.<br>
36  * In such a case, the x-axis points to the right of the camera, and the y-axis is identical to the up vector of the camera (as long as the camera is located in the origin of the coordinate system).<br>
37  * In the following, such a coordinate system is depicted:
38  * <pre>
39  * ^
40  * Y |
41  * |
42  * |
43  * O --------->
44  * / X
45  * / Z
46  * v
47  * </pre>
48  * Therefore, each 3D object point lying in front of the camera has a negative z-value (as long as the camera is located in the origin of the coordinate system).<br>
49  * On the contrary, each object point lying behind the camera then has a positive z-value.<br>
50  * By default, the Ocean framework uses this kind of representation/interpretation for !any! coordinate system and for any algorithm as long as not explicitly stated/documented differently.
51  *
52  * In Computer Vision, often a slightly different representation/interpretation is used.<br>
53  * Computer Vision algorithms or/and equations are mostly defined in relation to a coordinate system in which the observer/camera is looking into the positive z-space.<br>
54  * While the x-axis is still pointing to the right of the camera, the y-axis is equivalent to the down vector of the camera.<br>
55  * In the following, such a coordinate system is depicted:
56  * <pre>
57  * ^
58  * Z /
59  * /
60  * O --------->
61  * | X
62  * |
63  * | Y
64  * v
65  * </pre>
66  * In such a coordinate system, 3D object points lying in front of the camera have a positive z-value (as long as the camera is located in the origin of the coordinate system).<br>
67  * The reason (at least one of several other) for this coordinate system is that an image/frame quite often is defined to have the origin in the upper left corner of the image/frame (while the x-axis is pointing horizontally to the right and the y-axis is pointing vertically to the bottom of the image/frame).
68  *
69  * Obviously, both coordinate systems can simply be transformed from one to the other and vice versa (by simply rotating around the x-axis).<br>
70  * However, it is crucial to understand that mixing up both coordinate systems can result in totally different results (sometimes not directly noticeable - depending on the situation etc.).<br>
71  * As the Ocean framework offers Computer Graphics as well as Computer Vision functionalities it was important to define one coordinate system as default coordinate system.<br>
72  * Without specific reasons, the Computer Graphics coordinate system (camera is looking into the negative z-space) is the default coordinate system while the Computer Vision coordinate system (camera is looking into the positive z-space) is the non-default case.<br>
73  * Therefore, the Computer Vision coordinate system is called the 'flipped' coordinate system as (compared to the default coordinate system) the Computer Vision coordinate system is flipped around the x-axis by 180 degrees.
74  *
75  * Whenever a coordinate system is defined, e.g., for a camera pose the name of this parameter contains the information in which coordinate system the transformation is defined.<br>
76  * The parameter name for a default camera pose (defined in the default coordinate system) can be e.g., "cameraPose", 'extrinsicMatrix', 'pose', 'transformation', and so on.<br>
77  * While the camera pose defined in the flipped coordinate system (the Computer Vision coordinate system) can be e.g., 'cameraPoseFlipped', 'flippedPose', 'flippedTransformation', 'cameraPoseF', 'transformationF', and so on.<br>
78  * Either the prefix or suffix 'flipped/Flipped' or 'f/F' is used to identify a transformation defined in the flipped coordinate system.<br>
79  * Similar to this naming convention every function expecting (or returning) a transformation defined in the flipped coordinate system will contain the suffix 'F' like e.g., determineCameraPoseF(), projectPointF().<br>
80  * As long as this naming convention is preserved within the entire Framework no issues regarding mixed coordinate system can happen and a lot of time can be saved for debugging.<br>
81  * The framework has a lot of helper functions allowing to transform coordinate systems from one interpretation to the other.<br>
82  * Further, for reasons of convenience often a function is implemented twice (one function holds the actual implementation e.g., for the Computer Vision coordinate system, while the other function is implemented for the Computer Graphic coordinate system and simply transforms input and output).<br>
83  * For better understanding take a look on NonLinearOptimizationPose::optimizePose() and NonLinearOptimizationPose::optimizePoseIF().
84  *
85  * Another decision has been made that a camera pose (the coordinate system respectively), in general, can be located at any position and can have any orientation compared to the world coordinate system.<br>
86  * That means that camera poses must not necessarily be located in the origin of the world coordinate system which offers a lot of flexibilities.<br>
87  * In this framework, a camera pose (the extrinsic camera matrix) transforms 3D object points, defined in the coordinate system of the camera, into 3D object points defined in the world coordinate system.<br>
88  * In Computer Graphics, the well known Model-View-Matrix is often defined in the opposite way (the matrix is simply inverted) - here 3D object points defined in the world coordinate system would be transformed into the camera coordinate system.<br>
89  * However, as a wide variety of functions in this framework also expect the inverted camera pose as input, another naming convention exists adding an 'inverted/Inverted' or 'i/I' to any parameter name of function name if the inverted matrix/transformation is expected.<br>
90  * For better understanding take a look on PinholeCamera::projectToImage() and PinholeCamera::projectToImageIF().
91  *
92  * As coordinate systems (and their transformations between each) are very often the reason for bugs, errors and time consuming debugging sessions it is highly recommended to follow the above described rules and to document which kind of transformation is expected in every function.<br>
93  * In this framework, the documentation often provides equations showing which kind of transformations are expected or returned e.g., like:
94  * <pre>
95  * Pw = wTc * Pc, or wP = wTc * cP
96  * </pre>
97  * For a transformation wTc (e.g., a 3x3 or 4x4 square matrix) transforming a point 'Pc/cP' defined in the coordinate system of the camera (c) into the coordinate system of the world (w) - as long as points are multiplied on the right side of the transformation.<br>
98  * Due to the notation of the subscripts 'w' and 'c' it's obvious how the transformation is to be interpreted and in which coordinate system a point must be defined so that the transformation can be applied.
99  * @}
100  */
101 
102 /**
103  * @namespace Ocean::Geometry Namespace of the Geometry library.<p>
104  * The Namespace Ocean::Geometry is used in the entire Ocean Geometry Library.
105  */
106 
107 /**
108  * Definition of a 2D image point.
109  * @ingroup geometry
110  */
112 
113 /**
114  * Definition of a 3D object point.
115  * @ingroup geometry
116  */
118 
119 /**
120  * Definition of a vector holding 2D image points.
121  * @ingroup geometry
122  */
123 typedef std::vector<ImagePoint> ImagePoints;
124 
125 /**
126  * Definition of a vector holding 3D object points.
127  * @ingroup geometry
128  */
129 typedef std::vector<ObjectPoint> ObjectPoints;
130 
131 /**
132  * Definition of a vector holding object points, so we have groups of object points.
133  * @ingroup geometry
134  */
135 typedef std::vector<ObjectPoints> ObjectPointGroups;
136 
137 /**
138  * Definition of a vector holding image points, so we have groups of image points.
139  * @ingroup geometry
140  */
141 typedef std::vector<ImagePoints> ImagePointGroups;
142 
143 
144 // Defines OCEAN_GEOMETRY_EXPORT for dll export and import.
145 #if defined(_WINDOWS) && defined(OCEAN_RUNTIME_SHARED)
146  #ifdef USE_OCEAN_GEOMETRY_EXPORT
147  #define OCEAN_GEOMETRY_EXPORT __declspec(dllexport)
148  #else
149  #define OCEAN_GEOMETRY_EXPORT __declspec(dllimport)
150  #endif
151 #else
152  #define OCEAN_GEOMETRY_EXPORT
153 #endif
154 
155 }
156 
157 }
158 
159 #endif // META_OCEAN_GEOMETRY_GEOMETRY_H
std::vector< ObjectPoint > ObjectPoints
Definition of a vector holding 3D object points.
Definition: geometry/Geometry.h:129
std::vector< ObjectPoints > ObjectPointGroups
Definition of a vector holding object points, so we have groups of object points.
Definition: geometry/Geometry.h:135
Vector3 ObjectPoint
Definition of a 3D object point.
Definition: geometry/Geometry.h:117
std::vector< ImagePoint > ImagePoints
Definition of a vector holding 2D image points.
Definition: geometry/Geometry.h:123
std::vector< ImagePoints > ImagePointGroups
Definition of a vector holding image points, so we have groups of image points.
Definition: geometry/Geometry.h:141
Vector2 ImagePoint
Definition of a 2D image point.
Definition: geometry/Geometry.h:111
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15