realsense_rust/kind/
distortion_model.rs

1//! Enumeration describing the possible kinds of distortions present in a stream profile.
2//!
3//! Different RealSense devices use different distortion models to describe their intrinsics. For instance, the D415
4//! uses the Modified Brown Conrady distortion model on its color camera, while the SR300 uses the Inverse Brown
5//! Conrady. Ultimately, the user will need to interrogate a Stream's intrinsics directly using `.intrinsics()` to be
6//! sure about the model being used.
7//!
8//! See the Intel docs about [Projection in RealSense SDK
9//! 2.0](https://dev.intelrealsense.com/docs/projection-in-intel-realsense-sdk-20) for more information.
10
11use num_derive::{FromPrimitive, ToPrimitive};
12use realsense_sys as sys;
13
14/// An enum for the various kinds of distortion models provided by librealsense2.
15#[repr(i32)]
16#[derive(FromPrimitive, ToPrimitive, Debug, Clone, Copy, PartialEq, Eq, Hash)]
17pub enum Rs2DistortionModel {
18    /// Rectilinear images. No distortion compensation required.
19    None = sys::rs2_distortion_RS2_DISTORTION_NONE as i32,
20    /// Unmodified Brown-Conrady distortion model
21    BrownConrady = sys::rs2_distortion_RS2_DISTORTION_BROWN_CONRADY as i32,
22    /// Equivalent to Brown-Conrady distortion, except that tangential distortion is applied to
23    /// radially distorted points
24    BrownConradyModified = sys::rs2_distortion_RS2_DISTORTION_MODIFIED_BROWN_CONRADY as i32,
25    /// Equivalent to Brown-Conrady distortion, except undistorts image instead of distorting it
26    BrownConradyInverse = sys::rs2_distortion_RS2_DISTORTION_INVERSE_BROWN_CONRADY as i32,
27    /// F-Theta fish-eye distortion model
28    FThetaFisheye = sys::rs2_distortion_RS2_DISTORTION_FTHETA as i32,
29    /// Four parameter Kannala Brandt distortion model
30    KannalaBrandt = sys::rs2_distortion_RS2_DISTORTION_KANNALA_BRANDT4 as i32,
31    // Number of enumeration values. Not included.
32    //
33    // Count = sys::rs2_distortion_RS2_DISTORTION_COUNT
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39    use num_traits::FromPrimitive;
40
41    #[test]
42    fn all_variants_exist() {
43        for i in 0..sys::rs2_distortion_RS2_DISTORTION_COUNT as i32 {
44            assert!(
45                Rs2DistortionModel::from_i32(i).is_some(),
46                "DistortionModel variant for ordinal {} does not exist.",
47                i,
48            );
49        }
50    }
51}