python vtk 样条插值_用python中的vtk插值点

本文介绍如何使用VTK库进行三维数据点集的可视化处理,包括数据准备、网格生成、插值处理、表面重建及轮廓提取等步骤,并展示了最终的渲染效果。

import vtk

import numpy as np

src=np.random.rand(32,3)

vtkPoints=vtk.vtkPoints()

for i in range(0,src.shape[0]):

x=src[i,0]

y=src[i,1]

z=src[i,2]

p=[x,y,z]

vtkPoints.InsertNextPoint(p)

poly = vtk.vtkPolyData()

poly.SetPoints(vtkPoints)

#Triangulate the grid points.

#Create a grid of points to interpolate over

gridPoints =vtk.vtkPoints()

for x in range (0,src.shape[0]):

for y in range (0,src.shape[1]):

gridPoints.InsertNextPoint(x,y,0)

#Triangulate the grid points.

vtkDelaunay=vtk.vtkDelaunay2D()

vtkDelaunay.SetInputData(poly)

vtkDelaunay.Update()

#Create a dataset from the grid points

gridPolyData =vtk.vtkPolyData()

gridPolyData.SetPoints(gridPoints)

#Perform the interpolation

probeFilter =vtk.vtkProbeFilter()

probeFilter.SetSourceConnection(vtkDelaunay.GetOutputPort())

probeFilter.SetInputData(gridPolyData)

probeFilter.Update()

gridWarpScalar =vtk.vtkWarpScalar()

gridWarpScalar.SetInputConnection(probeFilter.GetOutputPort())

gridWarpScalar.Update()

#contour filter:

surf = vtk.vtkSurfaceReconstructionFilter()

surf.SetInputData(poly)

surf.GetOutput().GetPointData().SetScalars(weights)

surf.Update()

contourFilter = vtk.vtkContourFilter()

contourFilter.SetInputConnection(surf.GetOutputPort())

contourFilter.SetValue(0, 0.0)

contourFilter.Update()

# visualization

Mapper =vtk.vtkPolyDataMapper()

Mapper.SetInputConnection(contourFilter.GetOutputPort())

Mapper.ScalarVisibilityOff()

Actor=vtk.vtkActor()

Actor.SetMapper(Mapper)

Actor.GetProperty().SetColor(1.0, 0, 0)

Actor.GetProperty().SetPointSize(3)

gridMapper =vtk.vtkDataSetMapper()

gridMapper.SetInputConnection(vtkDelaunay.GetOutputPort())

gridMapper.ScalarVisibilityOff()

gridActor =vtk.vtkActor()

gridActor.SetMapper(gridMapper);

gridActor.GetProperty().SetColor(0, 0, 1.0)

gridActor.GetProperty().SetPointSize(3)

renderer =vtk.vtkRenderer()

renderWindow =vtk.vtkRenderWindow()

renderWindow.AddRenderer(renderer)

renderWindowInteractor =vtk.vtkRenderWindowInteractor()

renderWindowInteractor.SetRenderWindow(renderWindow)

style =vtk.vtkInteractorStyleTrackballCamera()

renderWindowInteractor.SetInteractorStyle(style)

renderer.AddActor(Actor)

renderer.AddActor(gridActor)

renderWindow.Render()

renderWindowInteractor.Start()

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值