在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()

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

还有一种方式,就是用"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()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值