o3d.io.read_point_cloud源代码
时间: 2023-12-06 22:41:30 浏览: 203
o3d.io.read_point_cloud函数是Open3D库中用于读取点云数据的函数。其源代码如下:
```python
def read_point_cloud(filename: str,
format: Optional[str] = None,
remove_nan_points: bool = True,
remove_infinite_points: bool = True,
print_progress: bool = False) -> 'open3d.geometry.PointCloud':
"""Function to read point cloud from file.
Args:
filename (str): path of the point cloud file.
format (str, optional): format of the file. If not provided, the
format will be inferred from the filename extension.
remove_nan_points (bool, optional): whether to remove NaN points.
remove_infinite_points (bool, optional): whether to remove infinite
points.
print_progress (bool, optional): whether to print progress information.
Returns:
open3d.geometry.PointCloud: an instance of the `open3d.geometry.PointCloud`
containing the point cloud data.
"""
if format is None:
format = utility._get_file_extension_lower(filename)
format = format.lower()
# Check if format is supported.
if format not in _READABLE_FORMATS:
raise ValueError(f"Unsupported file format '{format}'")
# Call the appropriate read function based on format.
if format == 'xyz':
return read_xyz(filename, remove_nan_points, remove_infinite_points,
print_progress)
elif format == 'xyzn':
return read_xyz_normal(filename, remove_nan_points,
remove_infinite_points, print_progress)
elif format == 'pts':
return read_pts(filename, remove_nan_points, remove_infinite_points,
print_progress)
elif format == 'ply':
return read_ply(filename, remove_nan_points, remove_infinite_points,
print_progress)
elif format == 'pcd':
return read_pcd(filename, remove_nan_points, remove_infinite_points,
print_progress)
elif format == 'fbx':
return read_fbx(filename, remove_nan_points, remove_infinite_points,
print_progress)
elif format == 'obj':
return read_triangle_mesh(filename).sample_points_poisson_disk(
number_of_points=0)
elif format == 'stl':
return read_triangle_mesh(filename).sample_points_poisson_disk(
number_of_points=0)
else:
raise ValueError(f"Unsupported file format '{format}'")
```
该函数首先判断文件格式是否支持,然后根据文件格式调用对应的读取函数,例如对于PLY格式的点云文件,会调用`read_ply`函数进行读取。最终返回一个`open3d.geometry.PointCloud`对象。
阅读全文