在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()
相关推荐
ID_1800790547318 分钟前
超详细:Python 调用淘宝商品详情 API 完整教程
开发语言·python
平常心cyk37 分钟前
Python基础快速复习——函数的多种传参方式
python
lanboAI44 分钟前
基于卷积神经网络的舌苔诊断系统,resnet50,alexnet, shufflenet模型【pytorch框架+python源码】
pytorch·python·cnn
QWsin1 小时前
【Pydantic】Pydantic 是什么?
python
WeeJot嵌入式1 小时前
爬虫对抗:ZLibrary反爬机制实战分析
爬虫·python·网络安全·playwright·反爬机制
Bert.Cai1 小时前
Python input函数作用
开发语言·python
Fairy要carry1 小时前
项目03-手搓Agent之团队协作(发消息/分配任务)
linux·前端·python
柚子+1 小时前
Appium+python+雷电模拟器自动化测试入门
数据库·python·appium
rgb2gray2 小时前
论文详解:基于POI与出租车轨迹的城市多中心结构静态-动态多重分形特征
人工智能·python·算法·机器学习·数据分析·可解释
github_czy2 小时前
Python 函数式编程利器:Partial 与 ParamSpec 技术解析
python·fastapi