Open3d:从mesh中采样点云的两个函数
1.均匀采样:sample_points_uniformly
def sample_points_uniformly(self, number_of_points=100, use_triangle_normal=False): # real signature unknown; restored from __doc__"""sample_points_uniformly(self, number_of_points=100, use_triangle_normal=False)Function to uniformly sample points from the mesh.Args:number_of_points (int, optional, default=100): Number of points that should be uniformly sampled.use_triangle_normal (bool, optional, default=False): If True assigns the triangle normals instead of the interpolated vertex normals to the returned points. The triangle normals will be computed and added to the mesh if necessary.Returns:open3d.geometry.PointCloud"""pass
功能描述
该方法通过基于面积的均匀采样从网格表面生成点云,不考虑点间距约束。
参数说明
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
| int | 100 | 要采样的点数 |
| bool | False | 是否使用三角形面法线而非插值顶点法线 |
算法流程
-
三角形面积计算:
-
计算每个三角形的面积
-
计算总面积和每个三角形的采样权重
-
-
点分配:
-
按面积比例分配采样点到各三角形
-
n_points_for_triangle = round(area_triangle / total_area * number_of_points)
-
-
三角形内采样:
-
对每个三角形:
-
生成重心坐标随机点:
P = α·A + β·B + γ·C
-
其中
α + β + γ = 1
(随机生成)
-
-
法线处理:
-
同泊松圆盘采样
-
特点与注意
-
简单快速:计算复杂度低
-
面积加权:大三角形获得更多采样点
-
无间距约束:点可能聚集在小三角形区域
-
随机分布:每次采样结果不同
-
数量近似:实际点数可能略有偏差(四舍五入导致)
适用场景
-
快速网格简化
-
实时应用
-
机器学习数据准备
-
基础几何处理
2.泊松圆盘采样-sample_points_poisson_disk
def sample_points_poisson_disk(self, number_of_points, init_factor=5, pcl=None, use_triangle_normal=False): # real signature unknown; restored from __doc__"""sample_points_poisson_disk(self, number_of_points, init_factor=5, pcl=None, use_triangle_normal=False)Function to sample points from the mesh, where each point has approximately the same distance to the neighbouring points (blue noise). Method is based on Yuksel, "Sample Elimination for Generating Poisson Disk Sample Sets", EUROGRAPHICS, 2015.Args:number_of_points (int): Number of points that should be sampled.init_factor (float, optional, default=5): Factor for the initial uniformly sampled PointCloud. This init PointCloud is used for sample elimination.pcl (open3d.geometry.PointCloud, optional, default=None): Initial PointCloud that is used for sample elimination. If this parameter is provided the init_factor is ignored.use_triangle_normal (bool, optional, default=False): If True assigns the triangle normals instead of the interpolated vertex normals to the returned points. The triangle normals will be computed and added to the mesh if necessary.Returns:open3d.geometry.PointCloud"""pass
功能描述
该方法使用泊松圆盘采样算法从网格表面生成点云,确保采样点之间保持近似均匀的距离(蓝噪声分布)。其实现基于 Yuksel 2015 年的论文《Sample Elimination for Generating Poisson Disk Sample Sets》。
参数说明
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
number_of_points | int | 必填 | 最终要采样的目标点数 |
init_factor | float | 5 | 初始采样因子。初始采样点数为 init_factor × number_of_points |
pcl | PointCloud | None | 可选的初始点云(若提供则忽略 init_factor ) |
use_triangle_normal | bool | False | 是否使用三角形面法线而非插值顶点法线 |
算法流程
-
初始采样:
-
如果没有提供初始点云 (
pcl=None
) -
生成
init_factor × number_of_points
个均匀采样点
-
-
样本消除:
-
基于论文中的优化算法
-
逐步消除过于密集的点
-
保留
number_of_points
个满足最小距离约束的点
-
-
法线处理:
-
若
use_triangle_normal=True
:直接使用三角形面法线 -
否则:通过顶点法线插值得出采样点法线
-
特点与优势
-
蓝噪声特性:生成的点分布均匀,无聚集现象
-
距离约束:任意两点间保持最小距离
-
高质量采样:适用于需要均匀分布的视觉应用
-
效率优化:通过样本消除避免昂贵的直接计算
适用场景
-
3D打印表面准备
-
物理仿真输入
-
高质量渲染
-
表面重建的预处理
两种方法对比
特性 | 泊松圆盘采样 | 均匀采样 |
---|---|---|
点分布 | 均匀,蓝噪声 | 随机,面积加权 |
点间距 | 有最小距离约束 | 无约束 |
计算复杂度 | 较高 (O(n log n)) | 较低 (O(n)) |
采样质量 | 高质量,视觉愉悦 | 基础质量 |
参数控制 | 精细 (init_factor) | 简单 |
速度 | 较慢 | 很快 |
应用场景 | 高质量渲染/打印 | 快速处理/ML |
论文依据 | Yuksel 2015 | 经典方法 |
性能注意事项
-
泊松圆盘采样:
-
init_factor
显著影响性能(5-10 是合理范围) -
复杂网格建议使用预计算点云
-
-
均匀采样:
-
对超大数据集考虑分块处理
-
多次采样取平均可改善分布
-
高级使用技巧
泊松圆盘采样的优化
# 使用预计算点云加速
init_pcd = mesh.sample_points_uniformly(5000)
result_pcd = mesh.sample_points_poisson_disk(number_of_points=1000,pcl=init_pcd # 跳过初始采样阶段
)
法线处理建议
# 需要精确法线时
mesh.compute_vertex_normals() # 确保顶点法线存在
mesh.compute_triangle_normals() # 确保面法线存在# 根据需求选择法线类型
if need_precise_normals:pcd = mesh.sample_points_uniformly(1000, use_triangle_normal=True)
else:pcd = mesh.sample_points_uniformly(1000, use_triangle_normal=False)
参考资料:
1.Open3D 从mesh中采样点云【2025最新版】_mesh采样点云-CSDN博客
2.deepseek.ai