Skip to content

Commit

Permalink
cleanin up
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Mar 2, 2023
1 parent cb9d705 commit 7cf4fd0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 42 deletions.
2 changes: 1 addition & 1 deletion crates/re_data_store/src/entity_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Default for EntityProperties {
visible_history: ExtraQueryHistory::default(),
interactive: true,
pinhole_image_plane_distance: EditableAutoValue::default(),
backproject_depth: true,
backproject_depth: false,
backproject_pinhole_ent_path: None,
backproject_scale: EditableAutoValue::default(),
backproject_radius_scale: EditableAutoValue::default(),
Expand Down
7 changes: 2 additions & 5 deletions crates/re_renderer/examples/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ impl RenderDepthClouds {
let (points, colors, radii): (Vec<_>, Vec<_>, Vec<_>) = (0..depth.dimensions.y)
.flat_map(|y| (0..depth.dimensions.x).map(move |x| glam::UVec2::new(x, y)))
.map(|texcoords| {
let linear_depth = depth.get_linear(
depth.dimensions.x - texcoords.x - 1,
depth.dimensions.y - texcoords.y - 1,
);
let linear_depth = depth.get_linear(texcoords.x, texcoords.y);
let pos_in_world = ((texcoords.as_vec2() - offset) * linear_depth
/ focal_length)
.extend(linear_depth);
Expand Down Expand Up @@ -176,7 +173,7 @@ impl RenderDepthClouds {
let depth_cloud_draw_data = DepthCloudDrawData::new(
re_ctx,
&[DepthCloud {
world_from_obj,
depth_camera_extrinsics: world_from_obj,
depth_camera_intrinsics: *intrinsics,
radius_scale: *radius_scale,
depth_dimensions: depth.dimensions,
Expand Down
5 changes: 3 additions & 2 deletions crates/re_renderer/shader/depth_cloud.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn compute_point_data(quad_idx: i32) -> PointData {
norm_linear_depth,
);

let pos_in_world = depth_cloud_info.world_from_obj * Vec4(pos_in_obj, 1.0);
let pos_in_world = depth_cloud_info.extrinsincs * Vec4(pos_in_obj, 1.0);

var data: PointData;
data.pos_in_world = pos_in_world.xyz;
Expand All @@ -52,7 +52,8 @@ fn compute_point_data(quad_idx: i32) -> PointData {
// ---

struct DepthCloudInfo {
world_from_obj: Mat4,
/// The extrinsincs of the camera used for the projection.
extrinsincs: Mat4,

/// The intrinsics of the camera used for the projection.
///
Expand Down
10 changes: 5 additions & 5 deletions crates/re_renderer/src/renderer/depth_cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod gpu_data {
#[repr(C, align(256))]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub struct DepthCloudInfoUBO {
pub world_from_obj: crate::wgpu_buffer_types::Mat4,
pub depth_camera_extrinsics: crate::wgpu_buffer_types::Mat4,
pub depth_camera_intrinsics: crate::wgpu_buffer_types::Mat3,
pub radius_scale: crate::wgpu_buffer_types::F32RowPadded,

Expand All @@ -65,8 +65,8 @@ pub enum DepthCloudDepthData {
}

pub struct DepthCloud {
// TODO: just call it extrinsics at this point
pub world_from_obj: glam::Mat4,
/// The extrinsics of the camera used for the projection.
pub depth_camera_extrinsics: glam::Mat4,

/// The intrinsics of the camera used for the projection.
///
Expand All @@ -88,7 +88,7 @@ pub struct DepthCloud {
impl Default for DepthCloud {
fn default() -> Self {
Self {
world_from_obj: glam::Mat4::IDENTITY,
depth_camera_extrinsics: glam::Mat4::IDENTITY,
depth_camera_intrinsics: glam::Mat3::IDENTITY,
radius_scale: 1.0,
depth_dimensions: glam::UVec2::ZERO,
Expand Down Expand Up @@ -135,7 +135,7 @@ impl DepthCloudDrawData {
ctx,
"depth_cloud_ubos".into(),
depth_clouds.iter().map(|info| gpu_data::DepthCloudInfoUBO {
world_from_obj: info.world_from_obj.into(),
depth_camera_extrinsics: info.depth_camera_extrinsics.into(),
depth_camera_intrinsics: info.depth_camera_intrinsics.into(),
radius_scale: info.radius_scale.into(),
end_padding: Default::default(),
Expand Down
43 changes: 32 additions & 11 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use egui::NumExt as _;
use re_data_store::{query_latest_single, EditableAutoValue, EntityPath, EntityProperties};
use re_log_types::{
component_types::{Tensor, TensorDataMeaning},
component_types::{Tensor, TensorData, TensorDataMeaning},
TimeType, Transform,
};

Expand Down Expand Up @@ -473,7 +473,9 @@ fn depth_props_ui(
entity_props.backproject_pinhole_ent_path = Some(pinhole_ent_path.clone());

let tensor = query_latest_single::<Tensor>(&ctx.log_db.entity_db, entity_path, &query);
if tensor.map(|t| t.meaning) == Some(TensorDataMeaning::Depth) {
if tensor.as_ref().map(|t| t.meaning) == Some(TensorDataMeaning::Depth) {
let tensor = tensor.as_ref().unwrap();

ui.checkbox(&mut entity_props.backproject_depth, "Backproject Depth")
.on_hover_text(
"If enabled, the depth texture will be backprojected into a point cloud rather \
Expand All @@ -482,8 +484,35 @@ fn depth_props_ui(
ui.end_row();

if entity_props.backproject_depth {
ui.label("Pinhole");
ctx.entity_path_button(ui, None, &pinhole_ent_path)
.on_hover_text(
"The entity path of the pinhole transform being used to do the backprojection.",
);
ui.end_row();

// Compute Auto scale values
let mut scale = *entity_props
.backproject_scale
.or(&re_data_store::EditableAutoValue::Auto(
tensor.meter.map_or_else(
|| match &tensor.data {
TensorData::U16(_) => 1.0 / u16::MAX as f32,
_ => 1.0,
},
|meter| match &tensor.data {
TensorData::U16(_) => 1.0 / meter * u16::MAX as f32,
_ => meter,
},
),
))
.get();
let mut radius_scale = *entity_props
.backproject_radius_scale
.or(&re_data_store::EditableAutoValue::Auto(0.02))
.get();

ui.label("Backproject scale");
let mut scale = *entity_props.backproject_scale.get();
let speed = (scale * 0.05).at_least(0.01);
if ui
.add(
Expand All @@ -499,7 +528,6 @@ fn depth_props_ui(
ui.end_row();

ui.label("Backproject radius scale");
let mut radius_scale = *entity_props.backproject_radius_scale.get();
let speed = (radius_scale * 0.05).at_least(0.01);
if ui
.add(
Expand All @@ -513,13 +541,6 @@ fn depth_props_ui(
entity_props.backproject_radius_scale = EditableAutoValue::UserEdited(radius_scale);
}
ui.end_row();

ui.label("Pinhole");
ctx.entity_path_button(ui, None, &pinhole_ent_path)
.on_hover_text(
"The entity path of the pinhole transform being used to do the backprojection.",
);
ui.end_row();
}
}
}
48 changes: 30 additions & 18 deletions crates/re_viewer/src/ui/view_spatial/scene/scene_part/images.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use egui::NumExt;
use glam::{Vec3, Vec4Swizzles};
use glam::Vec3;
use itertools::Itertools;

use re_data_store::{query_latest_single, EntityPath, EntityProperties, InstancePathHash};
Expand Down Expand Up @@ -154,15 +154,15 @@ impl ImagesPart {
if tensor.meaning == TensorDataMeaning::Depth {
if let Some(pinhole_ent_path) = properties.backproject_pinhole_ent_path.as_ref()
{
// NOTE: we don't pass `world_from_obj` because this corresponds to the
// NOTE: we don't pass in `world_from_obj` because this corresponds to the
// transform of the projection plane, which is of no use to us here.
// What we want are the extrinsics from the depth camera!
// What we want are the extrinsics of the depth camera!
Self::process_entity_view_as_depth_cloud(
scene,
ctx,
transforms,
properties,
tensor,
&tensor,
pinhole_ent_path,
);
return Ok(());
Expand Down Expand Up @@ -263,7 +263,7 @@ impl ImagesPart {
ctx: &mut ViewerContext<'_>,
transforms: &TransformCache,
properties: &EntityProperties,
tensor: Tensor,
tensor: &Tensor,
pinhole_ent_path: &EntityPath,
) {
crate::profile_function!();
Expand All @@ -285,15 +285,8 @@ impl ImagesPart {
return;
};

// TODO: that's where we derive it if Auto
let scale = *properties.backproject_scale.get();
let radius_scale = *properties.backproject_radius_scale.get();

let (h, w) = (tensor.shape()[0].size, tensor.shape()[1].size);
let dimensions = glam::UVec2::new(w as _, h as _);

// TODO(cmc): automagically convert as needed for non-native datatypes?
let data = match tensor.data {
// TODO(cmc): automagically convert as needed for non-natively supported datatypes?
let data = match &tensor.data {
TensorData::U16(data) => DepthCloudDepthData::U16(data.to_vec()),
TensorData::F32(data) => DepthCloudDepthData::F32(data.to_vec()),
_ => {
Expand All @@ -305,13 +298,32 @@ impl ImagesPart {
}
};

let world_from_obj = extrinsics * glam::Mat4::from_scale(glam::Vec3::splat(scale));
// TODO(cmc): we need access to mutable entity properties from here, because that's where
// we need to compute the actual Auto value... but right now we have no way to write it
// back :(

let scale = *properties
.backproject_scale
.or(&re_data_store::EditableAutoValue::Auto(
tensor.meter.map_or(1.0, |meter| match &data {
DepthCloudDepthData::U16(_) => 1.0 / meter * u16::MAX as f32,
DepthCloudDepthData::F32(_) => meter,
}),
))
.get();
let radius_scale = *properties
.backproject_radius_scale
.or(&re_data_store::EditableAutoValue::Auto(0.02))
.get();

let xxx: glam::Mat3 = intrinsics.image_from_cam.into();
let (h, w) = (tensor.shape()[0].size, tensor.shape()[1].size);
let dimensions = glam::UVec2::new(w as _, h as _);

let world_from_obj = extrinsics * glam::Mat4::from_scale(glam::Vec3::splat(scale));

scene.primitives.depth_clouds.push(DepthCloud {
world_from_obj,
depth_camera_intrinsics: xxx,
depth_camera_extrinsics: world_from_obj,
depth_camera_intrinsics: intrinsics.image_from_cam.into(),
radius_scale,
depth_dimensions: dimensions,
depth_data: data,
Expand Down

0 comments on commit 7cf4fd0

Please sign in to comment.