OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ |
13 | 13 |
14 #include <cmath> | 14 #include <cmath> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 | 18 |
19 // Coordinates in meters. | 19 // Coordinates in meters. The convention used is: |
20 // x: the horizontal dimension, with positive to the right from the camera's | |
21 // perspective. | |
22 // y: the depth dimension, with positive forward from the camera's | |
23 // perspective. | |
24 // z: the vertical dimension, with positive upwards. | |
20 template<typename T> | 25 template<typename T> |
21 struct CartesianPoint { | 26 struct CartesianPoint { |
22 CartesianPoint(T x, T y, T z) { | 27 CartesianPoint(T x, T y, T z) { |
23 c[0] = x; | 28 c[0] = x; |
24 c[1] = y; | 29 c[1] = y; |
25 c[2] = z; | 30 c[2] = z; |
26 } | 31 } |
27 T x() const { return c[0]; } | 32 T x() const { return c[0]; } |
28 T y() const { return c[1]; } | 33 T y() const { return c[1]; } |
29 T z() const { return c[2]; } | 34 T z() const { return c[2]; } |
30 T c[3]; | 35 T c[3]; |
31 }; | 36 }; |
32 | 37 |
33 using Point = CartesianPoint<float>; | 38 using Point = CartesianPoint<float>; |
34 | 39 |
40 // Calculates the direction given a pair of Points. | |
Andrew MacDonald
2015/10/28 01:57:56
Be more specific: Calculates the direction from a
aluebs-webrtc
2015/10/29 00:34:21
Done.
| |
41 Point PairDirection(const Point& a, const Point& b); | |
42 | |
43 float DotProduct(const Point& a, const Point& b); | |
44 Point CrossProduct(const Point& a, const Point& b); | |
45 | |
46 bool AreParallel(const Point& a, const Point& b); | |
47 bool ArePerpendicular(const Point& a, const Point& b); | |
48 | |
35 // Returns the minimum distance between any two Points in the given | 49 // Returns the minimum distance between any two Points in the given |
36 // |array_geometry|. | 50 // |array_geometry|. |
37 float GetMinimumSpacing(const std::vector<Point>& array_geometry); | 51 float GetMinimumSpacing(const std::vector<Point>& array_geometry); |
38 | 52 |
53 // If the given array geometry is linear it returns the direction without | |
54 // normalizing. If it is not linear it returns a null Point. | |
Andrew MacDonald
2015/10/28 01:57:56
I would say the origin (or zero) rather than null?
aluebs-webrtc
2015/10/29 00:34:21
Changed to use Maybe and renamed function.
| |
55 Point IsGeometryLinear(const std::vector<Point>& array_geometry); | |
56 | |
57 // If the given array geometry is planar it returns the normal without | |
58 // normalizing. If it is not planar it returns a null Point. | |
59 Point IsGeometryPlanar(const std::vector<Point>& array_geometry); | |
Andrew MacDonald
2015/10/28 01:57:56
GetNormalIfPlanar
aluebs-webrtc
2015/10/29 00:34:21
Done.
| |
60 | |
61 // Returns the normal of an array in the xy-plane. If the array has no normal or | |
62 // the normal is not in the xy-plane it returns a null Point. | |
Andrew MacDonald
2015/10/28 01:57:57
zero or origin
aluebs-webrtc
2015/10/29 00:34:21
No need since using Maybe.
| |
63 Point GetArrayNormal(const std::vector<Point>& array_geometry); | |
Andrew MacDonald
2015/10/28 01:57:56
GetArrayNormalIfExists
aluebs-webrtc
2015/10/29 00:34:21
Done.
| |
64 | |
65 Point AzimuthToPoint(float azimuth); | |
Andrew MacDonald
2015/10/28 01:57:56
Might be worth documenting that the point will be
aluebs-webrtc
2015/10/29 00:34:21
Good point. Added documentation.
| |
66 | |
39 template<typename T> | 67 template<typename T> |
40 float Distance(CartesianPoint<T> a, CartesianPoint<T> b) { | 68 float Distance(CartesianPoint<T> a, CartesianPoint<T> b) { |
41 return std::sqrt((a.x() - b.x()) * (a.x() - b.x()) + | 69 return std::sqrt((a.x() - b.x()) * (a.x() - b.x()) + |
42 (a.y() - b.y()) * (a.y() - b.y()) + | 70 (a.y() - b.y()) * (a.y() - b.y()) + |
43 (a.z() - b.z()) * (a.z() - b.z())); | 71 (a.z() - b.z()) * (a.z() - b.z())); |
44 } | 72 } |
45 | 73 |
74 // The convention used: | |
75 // azimuth: zero is to the right from the camera's perspective, with positive | |
76 // angles in radians counter-clockwise. | |
77 // elevation: zero is horizontal, with positive angles in radians upwards. | |
78 // radius: distance from the camera in meters. | |
46 template <typename T> | 79 template <typename T> |
47 struct SphericalPoint { | 80 struct SphericalPoint { |
48 SphericalPoint(T azimuth, T elevation, T radius) { | 81 SphericalPoint(T azimuth, T elevation, T radius) { |
49 s[0] = azimuth; | 82 s[0] = azimuth; |
50 s[1] = elevation; | 83 s[1] = elevation; |
51 s[2] = radius; | 84 s[2] = radius; |
52 } | 85 } |
53 T azimuth() const { return s[0]; } | 86 T azimuth() const { return s[0]; } |
54 T elevation() const { return s[1]; } | 87 T elevation() const { return s[1]; } |
55 T distance() const { return s[2]; } | 88 T distance() const { return s[2]; } |
56 T s[3]; | 89 T s[3]; |
57 }; | 90 }; |
58 | 91 |
59 using SphericalPointf = SphericalPoint<float>; | 92 using SphericalPointf = SphericalPoint<float>; |
60 | 93 |
94 // Helper functions to transform degrees to radians and the inverse. | |
95 template <typename T> | |
96 T DegreesToRadians(T angle_degrees) { | |
97 return M_PI * angle_degrees / 180; | |
98 } | |
99 | |
100 template <typename T> | |
101 T RadiansToDegrees(T angle_radians) { | |
102 return 180 * angle_radians / M_PI; | |
103 } | |
104 | |
61 } // namespace webrtc | 105 } // namespace webrtc |
62 | 106 |
63 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ | 107 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ |
OLD | NEW |