Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 53 additions & 2 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<StreamProfileList, crate::error::OrbbecError> {
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
Expand Down
28 changes: 28 additions & 0 deletions src/sys/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
60 changes: 59 additions & 1 deletion src/sys/pipeline.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<OBStreamProfileList, OBError> {
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();
Expand Down