在pyvista 中,显示带透明度的点云信息

import pyvista as pv
import numpy as np

# Number of points
num_points = 1000

# Generate random points on the surface of a sphere
phi = np.random.uniform(0, 2 * np.pi, num_points)
#theta = np.acos(1 - 2 * np.random.rand(num_points))
theta = np.arccos(1 - 2 * np.random.rand(num_points))
x = 10 * np.sin(theta) * np.cos(phi)
y = 10 * np.sin(theta) * np.sin(phi)
z = 10 * np.cos(theta)
points = np.column_stack((x, y, z))
colors = np.random.rand(num_points,4)
# Create a PyVista PolyData object
cloud = pv.PolyData(points)

# Assign random brightness to each point
#cloud.point_data["brightness"] = np.random.rand(num_points)
cloud.point_data["colors"]=colors
# Assign transparency based on z value
# Normalize z values to range [0, 1] for opacity
z_normalized = (z - z.min()) / (z.max() - z.min())
opacity = 1 - z_normalized  # Increase opacity with increasing z

# Plot the point cloud
plotter = pv.Plotter()
#plotter.add_points(cloud,opacity=opacity)
plotter.add_points(cloud,rgb=True)
plotter.set_background('black') 
plotter.show()

程序设计了一个含有一千个点的球面,每个点的颜色和透明度随机。

在pyvista 中,显示带透明度的点云信息_第1张图片

还有一种方式,就是用"brightness"和opacity=opacity来对幅值和透明度来显示点云。

points=np.column_stack((x, y, z))
alphas=np.random.rand(num_points)
point_cloud = pv.PolyData(points)    
plotter = pv.Plotter()
point_cloud.point_data["brightness"]=alphas
point_cloud['opacity']= alphas
plotter.add_points(point_cloud,scalars='brightness',opacity=opacity,point_size=5)
plotter.add_axes()
plotter.show()

在pyvista 中,显示带透明度的点云信息_第2张图片

你可能感兴趣的:(python,numpy,点云)