2

我编写了以下代码(为了更好地阅读而进行了简化)来读取结构化网格并在我的体积中绘制一个剖切面。关于可视化,一切都很好:我得到了一个很好的等高线图,剖切面穿过它。但是,我未能提取切割平面中显示的数据。有没有办法提取与我的切割平面相关的坐标和数据(“强度” - 见下文)?

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()

非常感谢你的帮助

埃里克

4

1 回答 1

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 users 是寻找示例的好地方。这是一个关于从 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 用户存档还有更多示例 :)

于 2014-05-10T13:47:08.737 回答