Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into UIChanges
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomáš Kubíček committed Dec 7, 2023
2 parents b677149 + 32c3f49 commit 1b044e8
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 182 deletions.
74 changes: 37 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 25 additions & 22 deletions crates/re_viewer/src/depthai/depthai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub enum CameraSensorResolution {
THE_1440X1080,
THE_1080_P,
THE_1200_P,
THE_1280_P,
THE_4_K,
THE_4000X3000,
THE_12_MP,
Expand All @@ -149,6 +150,7 @@ impl fmt::Display for CameraSensorResolution {
Self::THE_1440X1080 => write!(f, "1440x1080"),
Self::THE_1080_P => write!(f, "1080p"),
Self::THE_1200_P => write!(f, "1200p"),
Self::THE_1280_P => write!(f, "1280p"),
Self::THE_4_K => write!(f, "4k"),
Self::THE_4000X3000 => write!(f, "4000x3000"),
Self::THE_12_MP => write!(f, "12MP"),
Expand Down Expand Up @@ -243,8 +245,8 @@ impl Default for DepthMedianFilter {
}
}

#[derive(serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq, Debug)]
pub struct DepthConfig {
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq, Debug)]
pub struct StereoDepthConfig {
pub median: DepthMedianFilter,
pub lr_check: bool,
pub lrc_threshold: u64,
Expand All @@ -256,7 +258,7 @@ pub struct DepthConfig {
pub stereo_pair: (CameraBoardSocket, CameraBoardSocket),
}

impl Default for DepthConfig {
impl Default for StereoDepthConfig {
fn default() -> Self {
Self {
median: DepthMedianFilter::default(),
Expand All @@ -267,17 +269,17 @@ impl Default for DepthConfig {
sigma: 0,
confidence: 230,
align: CameraBoardSocket::RGB,
stereo_pair: (CameraBoardSocket::CAM_A, CameraBoardSocket::CAM_C),
stereo_pair: (CameraBoardSocket::CAM_B, CameraBoardSocket::CAM_C),
}
}
}

impl DepthConfig {
impl StereoDepthConfig {
pub fn default_as_option() -> Option<Self> {
Some(Self::default())
}

pub fn only_runtime_configs_differ(&self, other: &DepthConfig) -> bool {
pub fn only_runtime_configs_differ(&self, other: &StereoDepthConfig) -> bool {
self.lr_check == other.lr_check
&& self.align == other.align
&& self.extended_disparity == other.extended_disparity
Expand All @@ -286,12 +288,14 @@ impl DepthConfig {
}
}

impl From<&DeviceProperties> for Option<DepthConfig> {
impl From<&DeviceProperties> for Option<StereoDepthConfig> {
fn from(props: &DeviceProperties) -> Self {
let mut config = DepthConfig::default();
let Some(cam_with_stereo_pair) = props.cameras
let mut config = StereoDepthConfig::default();
let Some(cam_with_stereo_pair) = props
.cameras
.iter()
.find(|feat| !feat.stereo_pairs.is_empty()) else {
.find(|feat| !feat.stereo_pairs.is_empty())
else {
return None;
};
if let Some((cam_a, cam_b)) = props.default_stereo_pair {
Expand All @@ -316,8 +320,8 @@ pub struct DeviceConfig {
pub cameras: Vec<CameraConfig>,
#[serde(default = "bool_true")]
pub depth_enabled: bool, // Much easier to have an explicit bool for checkbox
#[serde(default = "DepthConfig::default_as_option")]
pub depth: Option<DepthConfig>,
#[serde(default = "StereoDepthConfig::default_as_option")]
pub depth: Option<StereoDepthConfig>,
pub ai_model: AiModel,
}

Expand All @@ -327,7 +331,7 @@ impl Default for DeviceConfig {
auto: false,
cameras: Vec::new(),
depth_enabled: true,
depth: Some(DepthConfig::default()),
depth: Some(StereoDepthConfig::default()),
ai_model: AiModel::default(),
}
}
Expand Down Expand Up @@ -359,7 +363,7 @@ impl From<&DeviceProperties> for DeviceConfig {
kind: *cam.supported_types.first().unwrap(),
})
.collect();
config.depth = Option::<DepthConfig>::from(props);
config.depth = Option::<StereoDepthConfig>::from(props);
config.ai_model = AiModel::from(props);
config
}
Expand Down Expand Up @@ -505,6 +509,7 @@ impl AiModel {
impl From<&DeviceProperties> for AiModel {
fn from(props: &DeviceProperties) -> Self {
let mut model = Self::default();

if let Some(cam) = props.cameras.iter().find(|cam| cam.is_color_camera()) {
model.camera = cam.board_socket;
} else if let Some(cam) = props.cameras.first() {
Expand Down Expand Up @@ -648,12 +653,10 @@ impl State {
old_config: &DeviceConfig,
new_config: &DeviceConfig,
) -> bool {
let any_runtime_conf_changed = old_config.depth.is_some()
&& new_config.depth.is_some()
&& old_config
.depth
.unwrap()
.only_runtime_configs_differ(&new_config.depth.unwrap()); // || others to be added
let any_runtime_conf_changed = match (&old_config.depth, &new_config.depth) {
(Some(old_depth), Some(new_depth)) => old_depth.only_runtime_configs_differ(new_depth),
_ => false,
};
any_runtime_conf_changed
&& old_config.cameras == new_config.cameras
&& old_config.ai_model == new_config.ai_model
Expand Down Expand Up @@ -762,8 +765,8 @@ impl State {
}
self.applied_device_config.config = Some(config.clone());
self.modified_device_config = config.clone();
let Some(applied_device_config) =
self.applied_device_config.config.as_mut() else {
let Some(applied_device_config) = self.applied_device_config.config.as_mut()
else {
self.reset();
self.applied_device_config.update_in_progress = false;
return;
Expand Down
Loading

0 comments on commit 1b044e8

Please sign in to comment.