Ocean
Loading...
Searching...
No Matches
Math.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_MATH_MATH_H
9#define META_OCEAN_MATH_MATH_H
10
11#include "ocean/base/Base.h"
13
14#include <vector>
15
16#if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
17 // SSE2 include files
18 #include <emmintrin.h>
19 #include <mmintrin.h>
20
21 // SSE3 include files
22 #include <pmmintrin.h>
23 #include <mmintrin.h>
24
25 // SSE4 include files
26 #include <smmintrin.h>
27
28 #if defined(OCEAN_HARDWARE_AVX_VERSION) && OCEAN_HARDWARE_AVX_VERSION > 0
29 // AVX include files
30 #include <immintrin.h>
31 #endif
32#endif
33
34#if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
35 #if defined(__ARM_NEON__) || defined(__ARM_NEON)
36 #include <arm_neon.h>
37 #endif // __ARM_NEON__
38#endif
39
40namespace Ocean
41{
42
43/**
44 * @defgroup math Ocean Math Library
45 * @{
46 * The Ocean Math Library provides basic numerical and algebraic functionalities.
47 * The library is platform independent.<br>
48 *
49 * The Math Library supports floating point numbers with single (32bit) and double (64bit) precision.<br>
50 * The library defines an own type for floating point numbers allowing to compile the entire library for a specific default type of floating point numbers (either float or double).<br>
51 * Thus, use the Scalar type to implement code for either 32bit or 64bit floating point values.<br>
52 * The preprocessor define 'OCEAN_MATH_USE_SINGLE_PRECISION' distinguishes whether single or double precision is used as default floating point numbers.<br>
53 * @see Scalar.
54 *
55 * The library implements template-based classes allowing the explicit application of single or double precision floating point numbers.<br>
56 * The template-based classes are necessary to store or convert mathematical data between the Ocean framework and 3rd party libraries which rely either on 32bit or 64bit floating point numbers.<br>
57 * Further, the library implements classes that consistently applies the Scalar default floating point type avoiding a template-based implementation.<br>
58 * All template-based class names end with a 'T' identifying the template implementation.<br>
59 * However, for each template class three typedef definitions exist: a single,a double and a default precision version.<br>
60 * The single precision version ends with a 'F' (for float), the double precision version ends with a 'D' (for double).<br>
61 * The name of the default precision version is the normal class name without 'T', 'F' or 'D'.<br>
62 * @see VectorT3, VectorF3, VectorD3, Vector3.
63 * @see PlaneT3, PlaneF3, PlaneD3, Plane3.
64 * @see VarianceT, VarianceF, VarianceD, Variance.
65 *
66 * The NumericT class provides template-based access to numerical functions for single (NumericF) and double (NumericD) precision floating point numbers.<br>
67 * Use the default Numeric class to access the numerical functions with default floating point number type.<br>
68 * @see NumericT, NumericF, NumericD, Numeric.
69 *
70 * The Math Library provides 2D, 3D and 4D vector classes with a wide variety of functions necessary for linear algebra tasks.<br>
71 * @see VectorT2, VectorT3, VectorT4.
72 *
73 * The SquareMatrix2, SquareMatrix3 and SquareMatrix4 classes can be used for e.g., matrix-matrix or matrix-vector multipliations.<br>
74 * Each of the three matrix classes implement a square matrix with either 2, 3 or 4 rows and columns.<br>
75 * @see SquareMatrixT2, SquareMatrixT3, SquareMatrixT4.
76 *
77 * The HomogenousMatrix4 is comparable to the SquareMatrix4 class.<br>
78 * However, the homogenous matrix is designed to store homogenous transformations in 3D space like e.g., camera poses or coordinate system transformations.<br>
79 * @see HomogenousMatrix4.
80 *
81 * Matrix object with arbitrary (dynamic or static dimensions) are implemented by the classes Matrix and StaticMatrix.<br>
82 * A sparse matrix is realized in the SparseMatrix class.<br>
83 * @see Matrix, StaticMatrix, SparseMatrix.<br>
84 *
85 * Rotation in 3D space can be expressed by the Euler, ExponentialMap, Quaternion, Rotation, SquareMatrix3 classes.<br>
86 * @see EulerT, ExponentialMap, QuaternionT, RotationT, SquareMatrixT3.
87 *
88 * An extrinsic camera matrix (a camera pose) can be represented by an HomogenousMatrix4 object or by a Pose object.<br>
89 * An intrinsic camera matrix (camera profile) is implemented by the PinholeCamera class further supporting camera distortion profiles.<br>
90 * @see HomogenousMatrix4, Pose.
91 *
92 * Further, the library supports 2D and 3D finite and infinite lines (rays) and 2D and 3D triangles.<br>
93 * @see Line2, Line3, FiniteLine2, FiniteLine3, Triangle2, Triangle3.<br>
94 *
95 * The Plane3 class implements an infinite 3D plane.<br>
96 * @see Plane3.<br>
97 *
98 * 2D rectangles, 3D boxes and sphere as well as bounding volumes are realized by the Box2, Box3, Sphere3, BoundingBox and BoundingSphere classes.<br>
99 * @see Box2, Box3, Sphere3, BoundingBox, BoundingSphere.
100 *
101 * A Fourier transformation and a discrete cosine transformation can be accessed by the FourierTransformation and DiscreteCosineTransformation classes.<br>
102 * @see FourierTransformation, DiscreteCosineTransformation.<br>
103 *
104 * However, the Math Library provides several further classes and functions.
105 *
106 * In general, the Math library (but also the remaining entire framework) is using a right-handed coordinate system (as long as not explicitly documented differently).<br>
107 * Please refer to the Geometry library regarding a more detailed overview of the individual coordinate systems and how the framework handles transformations by default.
108 * @}
109 */
110
111// @cond
112// Selection of the scalar floating precision.
113// Define OCEAN_MATH_USE_SINGLE_PRECISION to use 32bit floating point values.
114#ifdef OCEAN_HARDWARE_REDUCED_PERFORMANCE
115 #ifndef OCEAN_MATH_USE_SINGLE_PRECISION
116 #define OCEAN_MATH_USE_SINGLE_PRECISION
117 #endif
118#else
119 //#define OCEAN_MATH_USE_SINGLE_PRECISION
120#endif
121// @endcond
122
123#ifdef OCEAN_MATH_USE_SINGLE_PRECISION
124
125 /**
126 * Definition of a scalar type.
127 * @ingroup math
128 */
129 typedef float Scalar;
130
131#else
132
133 /**
134 * Definition of a scalar type.
135 * @ingroup math
136 */
137 typedef double Scalar;
138
139#endif
140
141/**
142 * Definition of a vector holding Scalar objects.
143 * @ingroup math
144 */
145typedef std::vector<Scalar> Scalars;
146
147// Defines OCEAN_MATH_EXPORT for dll export and import.
148#if defined(_WINDOWS) && defined(OCEAN_RUNTIME_SHARED)
149 #ifdef USE_OCEAN_MATH_EXPORT
150 #define OCEAN_MATH_EXPORT __declspec(dllexport)
151 #else
152 #define OCEAN_MATH_EXPORT __declspec(dllimport)
153 #endif
154#else
155 #define OCEAN_MATH_EXPORT
156#endif
157
158}
159
160#endif // META_OCEAN_MATH_MATH_H
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition Math.h:145
The namespace covering the entire Ocean framework.
Definition Accessor.h:15