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 #include "webrtc/base/maybe.h" |
| 18 |
17 namespace webrtc { | 19 namespace webrtc { |
18 | 20 |
19 // Coordinates in meters. | 21 // Coordinates in meters. The convention used is: |
| 22 // x: the horizontal dimension, with positive to the right from the camera's |
| 23 // perspective. |
| 24 // y: the depth dimension, with positive forward from the camera's |
| 25 // perspective. |
| 26 // z: the vertical dimension, with positive upwards. |
20 template<typename T> | 27 template<typename T> |
21 struct CartesianPoint { | 28 struct CartesianPoint { |
| 29 CartesianPoint() { |
| 30 c[0] = 0; |
| 31 c[1] = 0; |
| 32 c[2] = 0; |
| 33 } |
22 CartesianPoint(T x, T y, T z) { | 34 CartesianPoint(T x, T y, T z) { |
23 c[0] = x; | 35 c[0] = x; |
24 c[1] = y; | 36 c[1] = y; |
25 c[2] = z; | 37 c[2] = z; |
26 } | 38 } |
27 T x() const { return c[0]; } | 39 T x() const { return c[0]; } |
28 T y() const { return c[1]; } | 40 T y() const { return c[1]; } |
29 T z() const { return c[2]; } | 41 T z() const { return c[2]; } |
30 T c[3]; | 42 T c[3]; |
31 }; | 43 }; |
32 | 44 |
33 using Point = CartesianPoint<float>; | 45 using Point = CartesianPoint<float>; |
34 | 46 |
| 47 // Calculates the direction from a to b. |
| 48 Point PairDirection(const Point& a, const Point& b); |
| 49 |
| 50 float DotProduct(const Point& a, const Point& b); |
| 51 Point CrossProduct(const Point& a, const Point& b); |
| 52 |
| 53 bool AreParallel(const Point& a, const Point& b); |
| 54 bool ArePerpendicular(const Point& a, const Point& b); |
| 55 |
35 // Returns the minimum distance between any two Points in the given | 56 // Returns the minimum distance between any two Points in the given |
36 // |array_geometry|. | 57 // |array_geometry|. |
37 float GetMinimumSpacing(const std::vector<Point>& array_geometry); | 58 float GetMinimumSpacing(const std::vector<Point>& array_geometry); |
38 | 59 |
| 60 // If the given array geometry is linear it returns the direction without |
| 61 // normalizing. |
| 62 rtc::Maybe<Point> GetDirectionIfLinear( |
| 63 const std::vector<Point>& array_geometry); |
| 64 |
| 65 // If the given array geometry is planar it returns the normal without |
| 66 // normalizing. |
| 67 rtc::Maybe<Point> GetNormalIfPlanar(const std::vector<Point>& array_geometry); |
| 68 |
| 69 // Returns the normal of an array if it has one and it is in the xy-plane. |
| 70 rtc::Maybe<Point> GetArrayNormalIfExists( |
| 71 const std::vector<Point>& array_geometry); |
| 72 |
| 73 // The resulting Point will be in the xy-plane. |
| 74 Point AzimuthToPoint(float azimuth); |
| 75 |
39 template<typename T> | 76 template<typename T> |
40 float Distance(CartesianPoint<T> a, CartesianPoint<T> b) { | 77 float Distance(CartesianPoint<T> a, CartesianPoint<T> b) { |
41 return std::sqrt((a.x() - b.x()) * (a.x() - b.x()) + | 78 return std::sqrt((a.x() - b.x()) * (a.x() - b.x()) + |
42 (a.y() - b.y()) * (a.y() - b.y()) + | 79 (a.y() - b.y()) * (a.y() - b.y()) + |
43 (a.z() - b.z()) * (a.z() - b.z())); | 80 (a.z() - b.z()) * (a.z() - b.z())); |
44 } | 81 } |
45 | 82 |
| 83 // The convention used: |
| 84 // azimuth: zero is to the right from the camera's perspective, with positive |
| 85 // angles in radians counter-clockwise. |
| 86 // elevation: zero is horizontal, with positive angles in radians upwards. |
| 87 // radius: distance from the camera in meters. |
46 template <typename T> | 88 template <typename T> |
47 struct SphericalPoint { | 89 struct SphericalPoint { |
48 SphericalPoint(T azimuth, T elevation, T radius) { | 90 SphericalPoint(T azimuth, T elevation, T radius) { |
49 s[0] = azimuth; | 91 s[0] = azimuth; |
50 s[1] = elevation; | 92 s[1] = elevation; |
51 s[2] = radius; | 93 s[2] = radius; |
52 } | 94 } |
53 T azimuth() const { return s[0]; } | 95 T azimuth() const { return s[0]; } |
54 T elevation() const { return s[1]; } | 96 T elevation() const { return s[1]; } |
55 T distance() const { return s[2]; } | 97 T distance() const { return s[2]; } |
56 T s[3]; | 98 T s[3]; |
57 }; | 99 }; |
58 | 100 |
59 using SphericalPointf = SphericalPoint<float>; | 101 using SphericalPointf = SphericalPoint<float>; |
60 | 102 |
| 103 // Helper functions to transform degrees to radians and the inverse. |
| 104 template <typename T> |
| 105 T DegreesToRadians(T angle_degrees) { |
| 106 return M_PI * angle_degrees / 180; |
| 107 } |
| 108 |
| 109 template <typename T> |
| 110 T RadiansToDegrees(T angle_radians) { |
| 111 return 180 * angle_radians / M_PI; |
| 112 } |
| 113 |
61 } // namespace webrtc | 114 } // namespace webrtc |
62 | 115 |
63 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ | 116 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ |
OLD | NEW |