open3d无法显示点云的透明度,于是,这回使用pyvista。
这里面是一个函数,函数的输入是一个N*N*N的体素,numpy的array。
- import numpy as np
- import os
- import matplotlib.pyplot as plt
- from skimage.io import imread
- import pyvista as pv
- def Display(vols):
- if len(vols.shape)!=3:
- return
- nz,ny,nx=vols.shape
- points=[]
- alpha=[]
- for iz in range(nz):
- for iy in range(ny):
- for ix in range(nx):
- points.append([ix,iy,iz])
- alpha.append(vols[iz,iy,ix])
- points=np.array(points)
- alpha=np.array(alpha)
-
- cloud=pv.PolyData(points)
- cloud['alpha']=alpha
-
- plotter=pv.Plotter()
- plotter.add_mesh(cloud,scalars="alpha",cmap='coolwarm',opacity='linear')
- plotter.show()