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

python 复制代码
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来对幅值和透明度来显示点云。

python 复制代码
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()
相关推荐
默_笙5 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
qq_426003965 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫5 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技5 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读5 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时5 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
奇思妙想聪明勤奋的小羊5 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1235 天前
2026年第38周GitHub趋势周报
python·科技·github
IZero075 天前
Jev 与 Laya
python·语言模型