我编写了以下代码(为了更好的阅读而简化)以读取结构化网格并在我的卷中绘制切割平面。关于可视化的一切都很好:我得到了一个很好的等高线图,切割平面穿过它。但是,我未能提取切割平面中显示的数据。有没有办法提取与我的切割平面相关的坐标和数据(“强度” - 见下文)?
self._reader = vtk.vtkXMLStructuredGridReader()
self._reader.SetFileName(filename)
self._reader.Update()
self._reader.GetOutput().GetPointData().SetActiveScalars("Intensity")
self._isoContour = vtk.vtkContourFilter()
self._isoContour.SetInputConnection(self._reader.GetOutputPort())
self._isoContour.SetValue(0,100)
self.mapper = vtk.vtkPolyDataMapper()
self.mapper.SetInputConnection(self._reader.GetOutputPort())
self.mapper.ScalarVisibilityOn()
self.mapper.Update()
self._surface = vtk.vtkActor()
self._surface.SetMapper(self.mapper)
self._surface.GetProperty().SetRepresentationToWireframe()
plane = vtk.vtkPlane()
plane.SetOrigin(self._reader.GetOutput().GetCenter())
plane.SetNormal(0, 0, 1)
planeCut = vtk.vtkCutter()
planeCut.SetInput(self._reader.GetOutput())
planeCut.SetCutFunction(plane)
cutMapper = vtk.vtkPolyDataMapper()
cutMapper.SetInputConnection(planeCut.GetOutputPort())
cutMapper.SetLookupTable(table)
cutMapper.SetScalarRange(0,100)
cutActor = vtk.vtkActor()
cutActor.SetMapper(cutMapper)
self._renderer.AddActor(self._surface)
self._renderer.AddActor(cutActor)
self._iren.Render()
非常感谢你的帮助
埃里克
答案 0 :(得分:1)
这就是我要做的,写出数据:
self._reader.GetOutput().GetPointData().SetActiveScalars("Intensity")
planeCut = vtk.vtkCutter()
planeCut.SetInput(self._reader.GetOutput())
planeCut.SetCutFunction(plane)
planeCut.Update()
#DataSet of your cut:
planeCutPolyData=planeCut.GetOutput()
#Let write all the slice data:
w=vtk.vtkPolyDataWriter()
w.SetFileName('anyfilename.vtp')
w.SetInputConnection(placeCut.GetOutputPort())
w.Write()
vtk用户是寻找示例的好地方。这是一个从polyData中提取坐标的问题: http://vtk.1045678.n5.nabble.com/Polydata-get-point-coordinates-td3214274.html 与David的示例类似,请尝试:
#... insert code to generate planeCut
planeCut.Update()
for i in xrange(planeCut.GetOutput().GetNumberOfPoints()):
p=[0,0,0]
planeCut.GetOutput().GetPoint(i, p)
print p[0],p[1],p[2]
您还可以将数据传递给numpy,在vtk用户上,有以下示例: http://vtk.1045678.n5.nabble.com/Extract-Data-from-vtkImageReslice-to-numpy-array-td1246899.html#a1246902。与Eric的示例相同,您可以尝试:
import vtk.util.numpy_support as VN
#... insert code to generate planceCut
planeCut.Update()
pointData=planeCut.GetOutput().GetPointData()
intensityPointArray= VN.vtk_to_numpy(pointData.GetArray('Intensity'))
cellData=planeCut.GetOutput().GetCellData()
intensityCellArray= VN.vtk_to_numpy(pointData.GetArray('Intensity'))
vtk用户归档还有很多例子:)