尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

Rerun 组件详解:FillRatio 填充比 —— 控制深度图像点云投影中点的大小与间隙

Rerun 组件详解:FillRatio 填充比 —— 控制深度图像点云投影中点的大小与间隙 Rerun 组件详解FillRatio 填充比 —— 控制深度图像点云投影中点的大小与间隙【免费下载链接】rerunVisualize, query, and stream to train on multimodal robotics data.项目地址: https://gitcode.com/GitHub_Trending/re/rerun导读FillRatio填充比是 Rerun 可视化类型系统中的核心组件之一它描述“一个图元在多大程度上填满其可用空间”最常见的应用场景是控制由深度图像DepthImage反投影生成的三维点云中每个点的大小填充比为 1.0 时相邻点恰好中心相接、不留缝隙填充比为 0.5 时点仅与邻居边缘相触。读完本文你将掌握FillRatio的语义、取值范围、默认值、底层 Arrow 数据类型以及如何在 Rust / Python / C 三种 SDK 中通过DepthImage与EncodedDepthImage配置它并结合源码理解点云半径的计算原理。FillRatio 是什么一个组件在类型系统中的定位在 Rerun 的数据模型中一切可视化数据都由 Archetype原型组织每个 Archetype 由若干个 Component组件构成。FillRatio是一个组件component它的类型定义源头在 crates/build/re_type_definitions/rerun/components/fill_ratio.def.rs/// How much a primitive fills out the available space. /// /// Used for instance to scale the points of the point cloud created from [rerun::archetypes::DepthImage] projection in 3D views. /// Valid range is from 0 to max float although typically values above 1.0 are not useful. /// /// Defaults to 1.0. #[rerun::rerun_type] #[python(aliases float)] #[python(array_aliases float | npt.ArrayLike)] #[rust(derive(Copy, PartialEq, PartialOrd, bytemuck::Pod, bytemuck::Zeroable))] #[rust(repr transparent)] #[rerun(state stable)] pub struct FillRatio { pub value: rerun::encodings::Float32, }这段定义文件透露了几个关键信息该类型通过rerun_type宏标注属于稳定stable状态的类型其语义与序列化格式在 Rerun 的兼容性承诺范围内可放心用于长期存储的数据它在 Python 绑定中被声明了float别名意味着在 Python 中可以直接传入普通float或 NumPy 数组npt.ArrayLike它是一个透明包装#[repr(transparent)]的单个Float32值在 Rust 中可以实现零开销的转换与内存布局映射。FillRatio的文档字符串给出了三句关键定义这也是它在整个 Rerun 语义体系中的权威描述含义一个图元填充可用空间的程度典型用途缩放由深度图像投影生成的三维点云中点的尺寸默认值1.0。取值范围与默认值0 到 1.0 之间才真正有意义官方范围声明文档与类型定义一致声明合法范围0到浮点数最大值max float实用范围通常大于1.0的值不再有用默认值1.0。源码中的默认值实现默认值1.0不只是文档描述它在 Rust SDK 中被显式实现为Defaulttrait见 crates/store/re_sdk_types/src/components/fill_ratio_ext.rsuse super::FillRatio; impl Default for FillRatio { #[inline] fn default() - Self { 1.0.into() } }生成的组件类型位于 crates/store/re_sdk_types/src/components/fill_ratio.rs其结构为pub struct FillRatio(pub crate::encodings::Float32);并通过WrapperComponenttrait 关联其编码类型为Float32。从该文件可以看到组件类型名注册为rerun.components.FillRatio这正是日志数据在存储与传输中使用的稳定标识。数值语义1.0 意味着什么结合可视化器的实现见下文“底层原理”一节FillRatio的实际几何语义是fill_ratio 1.0默认点云中每个点的半径被设置为相邻像素投影点间距的一半——当相邻点处于相同深度时点与点之间中心相接、无缝隙fill_ratio 0.5点的大小缩小一半相邻点仅边缘相触介于两者之间时点的半径按比例缩放用于在“点之间有缝”与“点之间重叠”之间调节小于 1.0 会产生缝隙点变小大于 1.0 则点互相重叠视觉上可能形成更厚重的“填充”效果因此文档说超过 1.0 通常无意义。Rerun 编码与 Arrow 数据类型FillRatio的底层编码与序列化格式非常简洁项目值Rerun 编码encodingFloat3232 位 IEEE 浮点数Arrow 数据类型datatypeFloat32即该组件在 Arrow 内存格式中就是一个Float32标量列。对于一条深度图像数据point_fill_ratio对应一列单元素Float32由于 Arrow 支持向量化批量传输同一批数据中的多个填充比可以共享一个Float32数组列。从生成的 Rust 代码可以看到FillRatio与Float32之间通过FromT泛型转换打通implT: Intocrate::encodings::Float32 FromT for FillRatio因此FillRatio::from(0.5f32)、(0.5f32).into()等写法都合法这让 SDK 使用非常顺手。使用场景两个深度图像 Archetype 中的可选组件FillRatio目前被两个深度图像相关的 Archetype 引用DepthImage深度图像EncodedDepthImage编码深度图像。在 DepthImage 中在 crates/store/re_sdk_types/src/archetypes/depth_image.rs 中point_fill_ratio字段的定义为/// Scale the radii of the points in the point cloud generated from this image. /// /// A fill ratio of 1.0 (the default) means that each point is as big as to touch the center of its neighbor /// if it is at the same depth, leaving no gaps. /// A fill ratio of 0.5 means that each point touches the edge of its neighbor if it has the same depth. /// /// TODO(#6744): This applies only to 3D views! pub point_fill_ratio: OptionSerializedComponentBatch,其对应的组件描述符为descriptor_point_fill_ratio()关联组件类型为rerun.components.FillRatio。在DepthImage的 8 个组件中point_fill_ratio属于可选组件optional component——必需组件只有buffer与format两个其余 6 个meter、colormap、depth_range、point_fill_ratio、draw_order、magnification_filter均为可选。在 EncodedDepthImage 中编码深度图像支持 PNG / TIFF / RVL 等压缩格式同样携带point_fill_ratio定义见 crates/store/re_sdk_types/src/archetypes/encoded_depth_image.rs字段注释为 “Optional point fill ratio for point-cloud projection.”。在该 Archetype 中它同样属于可选组件。一个重要限制源码中的TODO(#6744)明确指出当前FillRatio仅对 3D 视图生效。在 2D 视图中深度图像以纹理矩形方式显示点云填充比不会影响渲染结果。要在 3D 视图中把深度图像显示为“深度点云depth cloud”需要实体上方存在 Pinhole 相机模型以完成反投影。SDK 使用方式Python / Rust / C 实战Python在 Python 中FillRatio被声明为float的别名因此可以直接传普通浮点数。通过DepthImage的point_fill_ratio参数配置import rerun as rr import numpy as np rr.init(depth_fill_ratio_demo) rr.spawn() # 构造一张 200x300 的 uint16 深度图 image np.full((200, 300), 65535, dtypenp.uint16) image[50:150, 50:150] 20000 rr.log( world/camera, rr.Pinhole( resolution[300, 200], focal_length[200.0, 200.0], ), ) rr.log( world/camera/depth, rr.DepthImage( image, meter10000.0, point_fill_ratio0.5, # 点半径减半相邻点仅边缘相触 ), )注意point_fill_ratio可以直接传float如0.5或 NumPy 数组npt.ArrayLike后者可用于批量设置多条记录。RustRust SDK 中通过with_point_fill_ratio链式方法设置该方法同样定义于 crates/store/re_sdk_types/src/archetypes/depth_image.rsuse ndarray::{Array, ShapeBuilder as _, s}; fn main() - Result(), Boxdyn std::error::Error { let rec rerun::RecordingStreamBuilder::new(rerun_example_depth_image_3d).spawn()?; let width 300; let height 200; let mut image Array::u16, _::from_elem((height, width).f(), 65535); image.slice_mut(s![50..150, 50..150]).fill(20000); image.slice_mut(s![130..180, 100..280]).fill(45000); let depth_image rerun::DepthImage::try_from(image)? .with_meter(10000.0) .with_colormap(rerun::components::Colormap::Viridis) .with_point_fill_ratio(0.5); // FillRatio 默认 1.0此处调小让点之间出现缝隙 // 在实体上方记录 Pinhole 相机模型深度图会自动反投影为 3D 点云 rec.log( world/camera, rerun::Pinhole::from_focal_length_and_resolution( [200.0, 200.0], [width as f32, height as f32], ), )?; rec.log(world/camera/depth, depth_image)?; Ok(()) }由于FillRatio实现了FromT: IntoFloat32与Defaultwith_point_fill_ratio(0.5_f32)、with_point_fill_ratio(rerun::components::FillRatio::default())等写法都合法。此外with_many_point_fill_ratio可一次传入多个值配合columns()/columns_of_unit_batches()实现按时间列columnar批量发送。CC SDK 对应组件为rerun::components::FillRatio同样通过DepthImage::with_point_fill_ratio配置#include rerun.hpp #include rerun/archetypes/depth_image.hpp namespace rr rerun; int main() { rr::RecordingStream rec(depth_fill_ratio_demo); rec.spawn().throw_on_failure(); std::vectoruint16_t data(300 * 200, 65535); // ... 填充深度数据 ... rec.log(world/camera, rr::archetypes::Pinhole::from_focal_length_and_resolution( {200.0f, 200.0f}, {300.0f, 200.0f})); rec.log(world/camera/depth, rr::archetypes::DepthImage(std::move(data), {300, 200}) .with_meter(10000.0f) .with_point_fill_ratio(0.5f)); rec.show(); }一个易错点FillRatio控制的是点的半径与DepthImage的meter深度单位到米的换算职责不同meter决定点云在 3D 空间中的位置反投影距离point_fill_ratio决定每个点占据多大面积。二者配合使用才能得到既定位正确又不互相遮挡的深度点云。底层原理可视化器如何消费 FillRatio3D 深度点云渲染路径FillRatio的实际消费方是 3D 空间视图的深度图可视化器。在 crates/views/re_view_spatial/src/visualizers/depth_images.rs 中可视化器首先从查询结果中读取fill_ratio字段第 45 行声明pub fill_ratio: OptionFillRatio判断实体所在的变换树中是否存在 Pinhole 相机根节点——只有在存在相机模型时才将深度图反投影为深度点云第 120-124 行若用户未设置则取fill_ratio.unwrap_or_default()即默认值1.0第 124 行将fill_ratio传入process_entity_view_as_depth_cloud(...)第 129-137 行由该函数按填充比计算每个点的半径并生成点云该路径同时支持FillRatio以批量batch形式出现代码中通过iter_optional(DepthImage::descriptor_point_fill_ratio().component)读取全部填充比再用slice::f32()取出f32数组第 284-304 行说明 Rerun 内部直接以 ArrowFloat32数组消费该组件。编码深度图像的可视化路径与此类似见 crates/views/re_view_spatial/src/visualizers/video/encoded_depth_image.rs其中同样按EncodedDepthImage::descriptor_point_fill_ratio()读取组件。从“组件描述符”到“点半径”整条链路可以概括为SDK 日志FillRatio f32 → Arrow Float32 数组序列化 → 存储层按 rerun.components.FillRatio 描述符索引 → 3D 视图可视化器 iter_optional 查询 → unwrap_or_default() 取默认 1.0 → process_entity_view_as_depth_cloud 按比例计算点半径 → GPU 渲染深度点云这也解释了为什么FillRatio是一个“小而通用”的组件它不关心自己属于哪个 Archetype只要数据列上带有rerun.components.FillRatio描述符深度图可视化器就能消费它反过来DepthImage与EncodedDepthImage两个 Archetype 都通过descriptor_point_fill_ratio()生成完全相同的组件描述符从而共享同一套点云缩放逻辑。与其他组件的协作关系FillRatio通常与以下组件协同工作均在DepthImageArchetype 中组件作用与 FillRatio 的关系DepthMetermeter深度原生单位到米的换算决定点云反投影的位置FillRatio 决定大小Colormap深度值到颜色的映射与点云外观正交互不影响ValueRangedepth_range颜色映射的取值范围越界值被 clamp不影响点云显示所有点仍会渲染DrawOrder2D 绘制顺序默认 -20.0仅 2D 视图生效FillRatio 仅 3D 生效二者互补其中与FillRatio语义最相关的是meter二者共同决定了深度点云“长什么样”——meter决定点在空间中的深度距离fill_ratio决定点的视觉大小与疏密程度。小结FillRatio是 Rerun 类型系统中一个稳定stable的Float32透明包装组件语义为“图元填充可用空间的程度”合法范围为0到max float实用范围为0到1.0之间默认值1.0由 crates/store/re_sdk_types/src/components/fill_ratio_ext.rs 中的Default实现保证底层编码与 Arrow 数据类型均为Float32类型名rerun.components.FillRatio被DepthImage与EncodedDepthImage两个 Archetype 作为可选组件point_fill_ratio引用仅对 3D 视图生效源码TODO(#6744)标注需配合 Pinhole 相机模型将深度图反投影为点云Python 中可直接传floatRust 中通过with_point_fill_ratio(...)链式构建C 中通过同名方法配置底层由 crates/views/re_view_spatial/src/visualizers/depth_images.rs 中的深度点云处理逻辑消费未设置时取默认值1.0按比例计算每个点的半径。延伸阅读继续阅读 DepthImage 组件文档 与 EncodedDepthImage 组件文档可进一步理解深度图像的完整组件体系类型定义源头见 crates/build/re_type_definitions/rerun/components/fill_ratio.def.rs生成的各语言绑定分别位于 crates/store/re_sdk_types/src/components/fill_ratio.rs 及 C / Python 对应生成目录。【免费下载链接】rerunVisualize, query, and stream to train on multimodal robotics data.项目地址: https://gitcode.com/GitHub_Trending/re/rerun创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表