我使用的是VTK 8.0.1和python 3.5,我是VTK的新手。我正在尝试使用vtkPlotSurface导出曲面图。
通过引用TestSurfacePlot.cxx,我已经成功地创建了一个曲面图,并且能够在python中渲染它(尽管它看起来并不真的像一个曲面图)。
import vtk
import math as m
import numpy as np
## Set things up
chart = vtk.vtkChartXYZ()
view = vtk.vtkContextView()
view.GetRenderWindow().SetSize(800,800)
view.GetScene().AddItem(chart)
## Create a surface
table = vtk.vtkTable()
numPoints = 70;
inc = 9.424778 / (numPoints - 1);
for i in range(0,numPoints):
arr = vtk.vtkFloatArray()
table.AddColumn(arr)
table.SetNumberOfRows(numPoints)
for i in range(0,numPoints):
x = i * inc;
for j in range(0,numPoints):
y = j * inc;
table.SetValue(i, j, m.sin(m.sqrt(x*x + y*y)))
# Using table, create a surface plot
test = vtk.vtkPlotSurface()
test.SetXRange(0,9.424778)
test.SetYRange(0,9.424778)
test.SetInputData(table)
# Start visualizing the surface plot
chart.AddPlot(test)
view.GetRenderWindow().SetMultiSamples(0)
view.GetInteractor().Initialize()
view.GetRenderWindow().Render()
out = vtk.vtkOBJExporter()
out.SetFilePrefix("test")
out.SetInput(chart)
out.Write()
view.GetInteractor().Start()为了更好地可视化我所做的,我想尝试导出它,然后使用Paraview/ and进行可视化。然而,我正在努力寻找任何导出这种类型的vtk对象的具体示例……
我已经尝试添加了以下内容:
out = vtk.vtkOBJExporter()
out.SetFilePrefix("test")
out.SetInput(chart)
out.Write()但最终会出现以下类型错误:
TypeError: SetInput argument 1: method requires a vtkRenderWindow, a vtkContextView was provided.有人能提供帮助吗?提前谢谢。
发布于 2019-10-27 07:33:03
您可能会从使用PyVista中受益,因为它使创建这些类型的空间参考数据集和渲染更加用户友好。我会避免使用像你上面那样的vtkTable,而转向实际表示网格/曲面的VTK数据对象。
import pyvista as pv
import numpy as np
# Create a spatial reference
numPoints = 70
inc = 9.424778 / (numPoints - 1)
x = np.arange(0, numPoints) * inc
y = np.arange(0, numPoints) * inc
xx, yy, _ = np.meshgrid(x, y, [0])
zz = np.sin(np.sqrt(xx*xx + yy*yy))
# Make a PyVista/VTK mesh
surface = pv.StructuredGrid(xx, yy, zz)
# Plot it!
surface.plot(show_edges=True, show_grid=True, notebook=False)
# or save it out for opening in ParaView
surface.save("my_surface.vtk")

https://stackoverflow.com/questions/46162129
复制相似问题