realsense_rust/kind/
extension.rs

1//! Possible interface extensions as an enumeration.
2use num_derive::{FromPrimitive, ToPrimitive};
3use realsense_sys as sys;
4
5/// Enumeration of interface extensions
6///
7/// `Rs2Extension` is an enumeration type that lists all the possible underlying interfaces that
8/// librealsense2 types can be extended to. Most of the types in librealsense2 are pointers to
9/// opaque structs, and there is little in the way of type variety or distinction.
10///
11/// Instead, generic types are effectively type-tagged through the use of an extension enums which
12/// represent the true ontological distinction between e.g. two frames or two sensors.
13///
14/// Here, rather than try to separate these into different types at the Rust level, we do a simple
15/// mapping to the underlying C-enum values. The API does not try to expose these where possible
16/// and attempts to hide this behind traits.
17///
18/// Extensions as listed are effectively the "types" of underlying data in the librealsense2
19/// system. However, there is only one extension enum, whereas there are plenty of categories of
20/// types available. We try to split these into sets of categories:
21///
22/// # Sensor extensions:
23///
24/// * [`Rs2Extension::ColorSensor`]
25/// * [`Rs2Extension::MotionSensor`]
26/// * [`Rs2Extension::FishEyeSensor`]
27/// * [`Rs2Extension::DepthSensor`]
28/// * [`Rs2Extension::DepthStereoSensor`]
29/// * [`Rs2Extension::SoftwareSensor`]
30/// * [`Rs2Extension::PoseSensor`]
31/// * [`Rs2Extension::L500DepthSensor`]
32/// * [`Rs2Extension::Tm2Sensor`]
33/// * [`Rs2Extension::CalibratedSensor`]
34/// * [`Rs2Extension::MaxUsableRangeSensor`]
35/// * [`Rs2Extension::DebugStreamSensor`]
36///
37/// # Frame extensions:
38///
39/// * [`Rs2Extension::VideoFrame`]
40/// * [`Rs2Extension::MotionFrame`]
41/// * [`Rs2Extension::CompositeFrame`]
42/// * [`Rs2Extension::DepthFrame`]
43/// * [`Rs2Extension::DisparityFrame`]
44/// * [`Rs2Extension::PoseFrame`]
45/// * [`Rs2Extension::Points`]
46///
47/// # Filter (processing block) extensions:
48///
49/// * [`Rs2Extension::DecimationFilter`]
50/// * [`Rs2Extension::ThresholdFilter`]
51/// * [`Rs2Extension::DisparityFilter`]
52/// * [`Rs2Extension::SpatialFilter`]
53/// * [`Rs2Extension::TemporalFilter`]
54/// * [`Rs2Extension::HoleFillingFilter`]
55/// * [`Rs2Extension::ZeroOrderFilter`]
56/// * [`Rs2Extension::RecommendedFilters`]
57/// * [`Rs2Extension::AutoCalibrationFilter`]
58/// * [`Rs2Extension::SequenceIdFilter`]
59///
60/// # Profile extensions:
61///
62/// * [`Rs2Extension::VideoProfile`]
63/// * [`Rs2Extension::MotionProfile`]
64/// * [`Rs2Extension::PoseProfile`]
65///
66/// # Device extensions:
67///
68/// * [`Rs2Extension::SoftwareDevice`]
69/// * [`Rs2Extension::UpdateDevice`]
70/// * [`Rs2Extension::AutoCalibratedDevice`]
71/// * [`Rs2Extension::CalibrationChangeDevice`]
72///
73/// # Miscellaneous extensions:
74///
75/// * [`Rs2Extension::AdvancedMode`]
76/// * [`Rs2Extension::Record`]
77/// * [`Rs2Extension::Playback`]
78/// * [`Rs2Extension::Pose`]
79/// * [`Rs2Extension::WheelOdometer`]
80/// * [`Rs2Extension::GlobalTimer`]
81/// * [`Rs2Extension::Updatable`]
82/// * [`Rs2Extension::Tm2`]
83/// * [`Rs2Extension::Unknown`]
84/// * [`Rs2Extension::Debug`]
85/// * [`Rs2Extension::Info`]
86/// * [`Rs2Extension::Motion`]
87/// * [`Rs2Extension::Options`]
88/// * [`Rs2Extension::Video`]
89/// * [`Rs2Extension::Roi`]
90#[allow(missing_docs)]
91#[repr(i32)]
92#[derive(FromPrimitive, ToPrimitive, Debug, Clone, Copy, PartialEq, Eq, Hash)]
93pub enum Rs2Extension {
94    // sensor
95    /// Color sensor
96    ColorSensor = sys::rs2_extension_RS2_EXTENSION_COLOR_SENSOR as i32,
97    /// Motion sensor
98    MotionSensor = sys::rs2_extension_RS2_EXTENSION_MOTION_SENSOR as i32,
99    /// Fisheye sensor
100    FishEyeSensor = sys::rs2_extension_RS2_EXTENSION_FISHEYE_SENSOR as i32,
101    /// Depth sensor
102    DepthSensor = sys::rs2_extension_RS2_EXTENSION_DEPTH_SENSOR as i32,
103    /// Depth stereo sensor
104    DepthStereoSensor = sys::rs2_extension_RS2_EXTENSION_DEPTH_STEREO_SENSOR as i32,
105    /// Software sensor
106    SoftwareSensor = sys::rs2_extension_RS2_EXTENSION_SOFTWARE_SENSOR as i32,
107    /// Pose sensor
108    PoseSensor = sys::rs2_extension_RS2_EXTENSION_POSE_SENSOR as i32,
109    /// L500 depth sensor
110    L500DepthSensor = sys::rs2_extension_RS2_EXTENSION_L500_DEPTH_SENSOR as i32,
111    /// TM2 sensor
112    Tm2Sensor = sys::rs2_extension_RS2_EXTENSION_TM2_SENSOR as i32,
113    /// Calibrated sensor
114    CalibratedSensor = sys::rs2_extension_RS2_EXTENSION_CALIBRATED_SENSOR as i32,
115    /// Max usable range sensor
116    MaxUsableRangeSensor = sys::rs2_extension_RS2_EXTENSION_MAX_USABLE_RANGE_SENSOR as i32,
117    /// Debug stream sensor
118    DebugStreamSensor = sys::rs2_extension_RS2_EXTENSION_DEBUG_STREAM_SENSOR as i32,
119
120    // frame
121    /// Video frame
122    VideoFrame = sys::rs2_extension_RS2_EXTENSION_VIDEO_FRAME as i32,
123    /// Motion frame
124    MotionFrame = sys::rs2_extension_RS2_EXTENSION_MOTION_FRAME as i32,
125    /// Composite frame
126    CompositeFrame = sys::rs2_extension_RS2_EXTENSION_COMPOSITE_FRAME as i32,
127    /// Depth frame
128    DepthFrame = sys::rs2_extension_RS2_EXTENSION_DEPTH_FRAME as i32,
129    /// Disparity frame
130    DisparityFrame = sys::rs2_extension_RS2_EXTENSION_DISPARITY_FRAME as i32,
131    /// Pose frame
132    PoseFrame = sys::rs2_extension_RS2_EXTENSION_POSE_FRAME as i32,
133    /// Points
134    Points = sys::rs2_extension_RS2_EXTENSION_POINTS as i32,
135
136    // filter
137    /// Decimation filter
138    DecimationFilter = sys::rs2_extension_RS2_EXTENSION_DECIMATION_FILTER as i32,
139    /// Threshold filter
140    ThresholdFilter = sys::rs2_extension_RS2_EXTENSION_THRESHOLD_FILTER as i32,
141    /// Disparity filter
142    DisparityFilter = sys::rs2_extension_RS2_EXTENSION_DISPARITY_FILTER as i32,
143    /// Spatial filter
144    SpatialFilter = sys::rs2_extension_RS2_EXTENSION_SPATIAL_FILTER as i32,
145    /// Temporal filter
146    TemporalFilter = sys::rs2_extension_RS2_EXTENSION_TEMPORAL_FILTER as i32,
147    /// Hole filling filter
148    HoleFillingFilter = sys::rs2_extension_RS2_EXTENSION_HOLE_FILLING_FILTER as i32,
149    /// Zero order filter
150    ZeroOrderFilter = sys::rs2_extension_RS2_EXTENSION_ZERO_ORDER_FILTER as i32,
151    /// Recommended filters
152    RecommendedFilters = sys::rs2_extension_RS2_EXTENSION_RECOMMENDED_FILTERS as i32,
153    /// Auto-calibration filter
154    AutoCalibrationFilter = sys::rs2_extension_RS2_EXTENSION_AUTO_CALIBRATION_FILTER as i32,
155    /// Sequence ID filter
156    SequenceIdFilter = sys::rs2_extension_RS2_EXTENSION_SEQUENCE_ID_FILTER as i32,
157
158    // profile
159    /// Video profile
160    VideoProfile = sys::rs2_extension_RS2_EXTENSION_VIDEO_PROFILE as i32,
161    /// Motion profile
162    MotionProfile = sys::rs2_extension_RS2_EXTENSION_MOTION_PROFILE as i32,
163    /// Pose profile
164    PoseProfile = sys::rs2_extension_RS2_EXTENSION_POSE_PROFILE as i32,
165
166    // device
167    /// Software device
168    SoftwareDevice = sys::rs2_extension_RS2_EXTENSION_SOFTWARE_DEVICE as i32,
169    /// Update device
170    UpdateDevice = sys::rs2_extension_RS2_EXTENSION_UPDATE_DEVICE as i32,
171    /// Auto-calibration device
172    AutoCalibratedDevice = sys::rs2_extension_RS2_EXTENSION_AUTO_CALIBRATED_DEVICE as i32,
173    /// Calibration change device
174    CalibrationChangeDevice = sys::rs2_extension_RS2_EXTENSION_CALIBRATION_CHANGE_DEVICE as i32,
175
176    // misc
177    /// Advanced mode
178    AdvancedMode = sys::rs2_extension_RS2_EXTENSION_ADVANCED_MODE as i32,
179    /// Record
180    Record = sys::rs2_extension_RS2_EXTENSION_RECORD as i32,
181    /// Playback
182    Playback = sys::rs2_extension_RS2_EXTENSION_PLAYBACK as i32,
183    /// Pose
184    Pose = sys::rs2_extension_RS2_EXTENSION_POSE as i32,
185    /// Wheel odometer
186    WheelOdometer = sys::rs2_extension_RS2_EXTENSION_WHEEL_ODOMETER as i32,
187    /// Global timer
188    GlobalTimer = sys::rs2_extension_RS2_EXTENSION_GLOBAL_TIMER as i32,
189    /// Updatable
190    Updatable = sys::rs2_extension_RS2_EXTENSION_UPDATABLE as i32,
191    /// TM2
192    Tm2 = sys::rs2_extension_RS2_EXTENSION_TM2 as i32,
193    /// Unknown
194    Unknown = sys::rs2_extension_RS2_EXTENSION_UNKNOWN as i32,
195    /// Debug
196    Debug = sys::rs2_extension_RS2_EXTENSION_DEBUG as i32,
197    /// Info
198    Info = sys::rs2_extension_RS2_EXTENSION_INFO as i32,
199    /// Motion
200    Motion = sys::rs2_extension_RS2_EXTENSION_MOTION as i32,
201    /// Options
202    Options = sys::rs2_extension_RS2_EXTENSION_OPTIONS as i32,
203    /// Video
204    Video = sys::rs2_extension_RS2_EXTENSION_VIDEO as i32,
205    /// ROI
206    Roi = sys::rs2_extension_RS2_EXTENSION_ROI as i32,
207    /// Depth Huffman decoder
208    DepthHuffmanDecoder = sys::rs2_extension_RS2_EXTENSION_DEPTH_HUFFMAN_DECODER as i32,
209    /// Serializable
210    Serializable = sys::rs2_extension_RS2_EXTENSION_SERIALIZABLE as i32,
211    /// Firmware logger
212    FirmwareLogger = sys::rs2_extension_RS2_EXTENSION_FW_LOGGER as i32,
213    /// Device calibration
214    DeviceCalibration = sys::rs2_extension_RS2_EXTENSION_DEVICE_CALIBRATION as i32,
215    /// HDR merge
216    HdrMerge = sys::rs2_extension_RS2_EXTENSION_HDR_MERGE as i32,
217    // Not included since this just tells us the total number of extensions
218    //
219    // Count = sys::rs2_extension_RS2_EXTENSION_COUNT,
220}
221
222/// A collection of the various rs2 sensor extensions
223pub const SENSOR_EXTENSIONS: [Rs2Extension; 12] = [
224    Rs2Extension::ColorSensor,
225    Rs2Extension::MotionSensor,
226    Rs2Extension::FishEyeSensor,
227    Rs2Extension::DepthSensor,
228    Rs2Extension::DepthStereoSensor,
229    Rs2Extension::SoftwareSensor,
230    Rs2Extension::PoseSensor,
231    Rs2Extension::L500DepthSensor,
232    Rs2Extension::Tm2Sensor,
233    Rs2Extension::CalibratedSensor,
234    Rs2Extension::MaxUsableRangeSensor,
235    Rs2Extension::DebugStreamSensor,
236];
237
238/// A collection of the various rs2 frame extensions
239pub const FRAME_EXTENSIONS: [Rs2Extension; 7] = [
240    Rs2Extension::VideoFrame,
241    Rs2Extension::MotionFrame,
242    Rs2Extension::CompositeFrame,
243    Rs2Extension::DepthFrame,
244    Rs2Extension::DisparityFrame,
245    Rs2Extension::PoseFrame,
246    Rs2Extension::Points,
247];
248
249/// A collection of the various rs2 filter extensions
250pub const FILTER_EXTENSIONS: [Rs2Extension; 9] = [
251    Rs2Extension::DecimationFilter,
252    Rs2Extension::ThresholdFilter,
253    Rs2Extension::DisparityFilter,
254    Rs2Extension::SpatialFilter,
255    Rs2Extension::TemporalFilter,
256    Rs2Extension::HoleFillingFilter,
257    Rs2Extension::ZeroOrderFilter,
258    Rs2Extension::RecommendedFilters,
259    Rs2Extension::AutoCalibrationFilter,
260];
261
262/// A collection of the various rs2 profile extensions
263pub const PROFILE_EXTENSIONS: [Rs2Extension; 3] = [
264    Rs2Extension::VideoProfile,
265    Rs2Extension::MotionProfile,
266    Rs2Extension::PoseProfile,
267];
268
269/// A collection of the various rs2 device extensions
270pub const DEVICE_EXTENSIONS: [Rs2Extension; 4] = [
271    Rs2Extension::SoftwareDevice,
272    Rs2Extension::UpdateDevice,
273    Rs2Extension::AutoCalibratedDevice,
274    Rs2Extension::CalibrationChangeDevice,
275];
276
277/// A collection of the various rs2 miscellaneous extensions
278pub const MISC_EXTENSIONS: [Rs2Extension; 15] = [
279    Rs2Extension::AdvancedMode,
280    Rs2Extension::Record,
281    Rs2Extension::Playback,
282    Rs2Extension::Pose,
283    Rs2Extension::WheelOdometer,
284    Rs2Extension::GlobalTimer,
285    Rs2Extension::Updatable,
286    Rs2Extension::Tm2,
287    Rs2Extension::Unknown,
288    Rs2Extension::Debug,
289    Rs2Extension::Info,
290    Rs2Extension::Motion,
291    Rs2Extension::Options,
292    Rs2Extension::Video,
293    Rs2Extension::Roi,
294];
295
296#[cfg(test)]
297mod tests {
298    use super::*;
299    use num_traits::FromPrimitive;
300
301    #[test]
302    fn all_variants_exist() {
303        for i in 0..sys::rs2_extension_RS2_EXTENSION_COUNT as i32 {
304            assert!(
305                Rs2Extension::from_i32(i).is_some(),
306                "Rs2Extension variant for ordinal {} does not exist.",
307                i,
308            );
309        }
310    }
311}