diff --git a/src/lib.rs b/src/lib.rs index 2243d9d..00b0528 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,6 +37,12 @@ pub use crate::sys::enums::OBConvertFormat as ConvertType; #[doc(inline)] pub use crate::sys::enums::OBCoordinateSystem as CoordinateSystem; +#[doc(inline)] +pub use crate::sys::enums::OBAlignMode as AlignMode; + +#[doc(inline)] +pub use crate::sys::enums::OBFrameAggregateOutputMode as FrameAggregateOutputMode; + /// There can only be a single context at a time /// C API does not enforce this, but having multiple contexts /// will lead to crashes and undefined behavior diff --git a/src/pipeline.rs b/src/pipeline.rs index 0b10ee3..b701117 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -2,10 +2,10 @@ use std::time::Duration; use crate::{ - SensorType, + AlignMode, FrameAggregateOutputMode, SensorType, device::Device, frame::FrameSet, - stream::{StreamProfile, StreamProfileList}, + stream::{StreamProfile, StreamProfileList, VideoStreamProfile}, sys::pipeline::{OBConfig, OBPipeline}, }; @@ -33,6 +33,39 @@ impl Config { .enable_stream_with_profile(profile.as_ref()) .map_err(crate::error::OrbbecError::from) } + + /// Set the alignment mode for the pipeline configuration + /// ### Arguments + /// * `mode` - Alignment mode to set + pub fn set_align_mode(&mut self, mode: AlignMode) -> Result<(), crate::error::OrbbecError> { + self.inner + .set_align_mode(mode) + .map_err(crate::error::OrbbecError::from) + } + + /// Set whether depth scaling is required after enable depth to color alignment + /// ### Arguments + /// * `enable` - `true` to enable depth scaling, `false` to disable it + pub fn set_depth_scale_after_align_require( + &mut self, + enable: bool, + ) -> Result<(), crate::error::OrbbecError> { + self.inner + .set_depth_scale_after_align_require(enable) + .map_err(crate::error::OrbbecError::from) + } + + /// Set the frame aggregation output mode for the pipeline configuration + /// ### Arguments + /// * `mode` - Frame aggregation output mode to set + pub fn set_frame_aggregate_output_mode( + &mut self, + mode: FrameAggregateOutputMode, + ) -> Result<(), crate::error::OrbbecError> { + self.inner + .set_frame_aggregate_output_mode(mode) + .map_err(crate::error::OrbbecError::from) + } } /// Pipeline @@ -76,6 +109,24 @@ impl Pipeline { Ok(profile_list) } + /// Get the list of D2C-enabled depth sensor resolutions corresponding to the input color sensor resolution + /// ### Arguments + /// * `color_profile` - Color sensor profile + /// * `align_mode` - Depth alignment mode + pub fn get_d2c_depth_profiles( + &mut self, + color_profile: &VideoStreamProfile, + align_mode: AlignMode, + ) -> Result { + let profile_list = self + .inner + .get_d2c_depth_profile_list(color_profile.as_ref(), align_mode) + .map(StreamProfileList::new) + .map_err(crate::error::OrbbecError::from)?; + + Ok(profile_list) + } + /// Start the pipeline with the given configuration /// ### Arguments /// * `config` - Configuration to use for the pipeline diff --git a/src/sys/enums.rs b/src/sys/enums.rs index 90c171d..c91b6d0 100644 --- a/src/sys/enums.rs +++ b/src/sys/enums.rs @@ -690,3 +690,31 @@ pub enum OBCoordinateSystem { /// Right Handed Coordinate System RightHanded = orb::OB_COORDINATE_SYSTEM_TYPE_OB_RIGHT_HAND_COORDINATE_SYSTEM as isize, } + +/// Align Mode +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum OBAlignMode { + /// Turn off alignment + Disable = orb::OBAlignMode_ALIGN_DISABLE as isize, + /// Hardware D2C alignment mode + Hardware = orb::OBAlignMode_ALIGN_D2C_HW_MODE as isize, + /// Software D2C alignment mode + Software = orb::OBAlignMode_ALIGN_D2C_SW_MODE as isize, +} + +/// Frame Aggregate Output Mode +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum OBFrameAggregateOutputMode { + /// Only FrameSet that contains all types of data frames will be output + AllTypeFrameRequire = + orb::OB_FRAME_AGGREGATE_OUTPUT_MODE_OB_FRAME_AGGREGATE_OUTPUT_ALL_TYPE_FRAME_REQUIRE + as isize, + /// Color Frame Require output mode + ColorFrameRequire = + orb::OB_FRAME_AGGREGATE_OUTPUT_MODE_OB_FRAME_AGGREGATE_OUTPUT_COLOR_FRAME_REQUIRE as isize, + /// FrameSet for any case will be output + AnySituation = + orb::OB_FRAME_AGGREGATE_OUTPUT_MODE_OB_FRAME_AGGREGATE_OUTPUT_ANY_SITUATION as isize, + /// Disable Frame Aggreate + Disable = orb::OB_FRAME_AGGREGATE_OUTPUT_MODE_OB_FRAME_AGGREGATE_OUTPUT_DISABLE as isize, +} diff --git a/src/sys/pipeline.rs b/src/sys/pipeline.rs index 3824139..5bb8f6f 100644 --- a/src/sys/pipeline.rs +++ b/src/sys/pipeline.rs @@ -1,6 +1,8 @@ //! Pipeline configuration and management +use crate::sys::enums::OBFrameAggregateOutputMode; + use super::device::OBDevice; -use super::enums::OBSensorType; +use super::enums::{OBAlignMode, OBSensorType}; use super::frame::OBFrame; use super::stream::{OBStreamProfile, OBStreamProfileList}; use super::{OBError, drop_ob_object, orb}; @@ -38,6 +40,40 @@ impl OBConfig { OBError::consume(err_ptr) } + + /// Set the alignment mode for the pipeline configuration + pub fn set_align_mode(&self, mode: OBAlignMode) -> Result<(), OBError> { + let mut err_ptr = std::ptr::null_mut(); + + unsafe { orb::ob_config_set_align_mode(self.inner, mode as i32, &mut err_ptr) }; + + OBError::consume(err_ptr) + } + + /// Set whether depth scaling is required after enable depth to color alignment + pub fn set_depth_scale_after_align_require(&self, enable: bool) -> Result<(), OBError> { + let mut err_ptr = std::ptr::null_mut(); + + unsafe { + orb::ob_config_set_depth_scale_after_align_require(self.inner, enable, &mut err_ptr) + }; + + OBError::consume(err_ptr) + } + + /// Set the frame aggregation output mode for the pipeline configuration + pub fn set_frame_aggregate_output_mode( + &self, + mode: OBFrameAggregateOutputMode, + ) -> Result<(), OBError> { + let mut err_ptr = std::ptr::null_mut(); + + unsafe { + orb::ob_config_set_frame_aggregate_output_mode(self.inner, mode as i32, &mut err_ptr) + }; + + OBError::consume(err_ptr) + } } /// Camera pipeline class @@ -85,6 +121,28 @@ impl OBPipeline { Ok(OBStreamProfileList::new(profile_list)) } + /// Get the list of D2C-enabled depth sensor resolutions corresponding to the input color sensor resolution + pub fn get_d2c_depth_profile_list( + &self, + color_profile: &OBStreamProfile, + align_mode: OBAlignMode, + ) -> Result { + let mut err_ptr = std::ptr::null_mut(); + + let profile_list = unsafe { + orb::ob_get_d2c_depth_profile_list( + self.inner, + color_profile.inner(), + align_mode as i32, + &mut err_ptr, + ) + }; + + OBError::consume(err_ptr)?; + + Ok(OBStreamProfileList::new(profile_list)) + } + /// Enable frame synchronization pub fn enable_frame_sync(&self) -> Result<(), OBError> { let mut err_ptr = std::ptr::null_mut();