Chromium Code Reviews| 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 |
| 35 // Returns the minimum distance between any two Points in the given | 40 // Returns the minimum distance between any two Points in the given |
| 36 // |array_geometry|. | 41 // |array_geometry|. |
| 37 float GetMinimumSpacing(const std::vector<Point>& array_geometry); | 42 float GetMinimumSpacing(const std::vector<Point>& array_geometry); |
| 38 | 43 |
| 39 template<typename T> | 44 template<typename T> |
| 40 float Distance(CartesianPoint<T> a, CartesianPoint<T> b) { | 45 float Distance(CartesianPoint<T> a, CartesianPoint<T> b) { |
| 41 return std::sqrt((a.x() - b.x()) * (a.x() - b.x()) + | 46 return std::sqrt((a.x() - b.x()) * (a.x() - b.x()) + |
| 42 (a.y() - b.y()) * (a.y() - b.y()) + | 47 (a.y() - b.y()) * (a.y() - b.y()) + |
| 43 (a.z() - b.z()) * (a.z() - b.z())); | 48 (a.z() - b.z()) * (a.z() - b.z())); |
| 44 } | 49 } |
| 45 | 50 |
| 51 // The convention used: | |
| 52 // azimuth: zero is to the right from the camera's perspective, with positive | |
| 53 // angles in radians counter-clockwise. | |
| 54 // elevation: zero is horizontal, with positive angles in radians upwards. | |
| 55 // radius: distance from the camera in meters. | |
| 46 template <typename T> | 56 template <typename T> |
| 47 struct SphericalPoint { | 57 struct SphericalPoint { |
| 48 SphericalPoint(T azimuth, T elevation, T radius) { | 58 SphericalPoint(T azimuth, T elevation, T radius) { |
| 49 s[0] = azimuth; | 59 s[0] = azimuth; |
| 50 s[1] = elevation; | 60 s[1] = elevation; |
| 51 s[2] = radius; | 61 s[2] = radius; |
| 52 } | 62 } |
| 53 T azimuth() const { return s[0]; } | 63 T azimuth() const { return s[0]; } |
| 54 T elevation() const { return s[1]; } | 64 T elevation() const { return s[1]; } |
| 55 T distance() const { return s[2]; } | 65 T distance() const { return s[2]; } |
| 56 T s[3]; | 66 T s[3]; |
| 57 }; | 67 }; |
| 58 | 68 |
| 59 using SphericalPointf = SphericalPoint<float>; | 69 using SphericalPointf = SphericalPoint<float>; |
| 60 | 70 |
| 71 // Helper functions to transform degrees to radians and the inverse. | |
| 72 float DegreesToRadians(float angle_degrees); | |
|
Andrew MacDonald
2015/10/21 03:27:43
Probably reasonable to make these templates.
aluebs-webrtc
2015/10/27 18:08:15
Done.
| |
| 73 float RadiansToDegrees(float angle_radians); | |
| 74 | |
| 61 } // namespace webrtc | 75 } // namespace webrtc |
| 62 | 76 |
| 63 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ | 77 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ |
| OLD | NEW |