VTK着色管过滤器,具有连接信息

时间:2016-11-08 08:55:30

标签: python data-visualization vtk

我想要用球体和管子连接它们来表示我想要的分子。我想根据连接信息给管子上色。这意味着我有各种断开连接的区域或断开连接的组件我希望每个区域的颜色不同。到目前为止,我有这个,在python中,它的工作原理。我已经评论过我试图做到这一点。可变data是一个PolyData数组,包含带有连接信息的点,标量和单元格。

tube = vtk.vtkTubeFilter()
tube.SetInput(data)
tube.SetNumberOfSides(5);
#tube.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
tube.SetVaryRadiusToVaryRadiusOff()
tube.SetRadius(0.1)

"""appendFilter = vtk.vtkAppendPolyData()
appendFilter.AddInputConnection(tube.GetOutputPort())
appendFilter.Update()

connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
connectivityFilter.SetInputConnection(appendFilter.GetOutput())
connectivityFilter.ScalarConnectivityOn()
connectivityFilter.FullScalarConnectivityOn()
connectivityFilter.SetExtractionModeToAllRegions()
connectivityFilter.ColorRegionsOn()
connectivityFilter.Update()
"""
#print (connectivityFilter.GetNumberOfExtractedRegions())

tubeMapper = vtk.vtkPolyDataMapper()
tubeMapper.SetInputConnection(tube.GetOutputPort())
tubeMapper.Update()

这就是它到目前为止的样子 enter image description here

1 个答案:

答案 0 :(得分:0)

我实际上有一些工作,但我不确定连接定义是否存在问题。我只是忘记getOutputPort中的“端口”一词。无论如何,这里是答案(我省略原子和管半径和其他无关的选项)

tube = vtk.vtkTubeFilter()
tube.SetInput(data)
tube.SetVaryRadiusToVaryRadiusOff()
tube.SetRadius(tuberad)

appendFilter = vtk.vtkAppendPolyData()
appendFilter.AddInputConnection(tube.GetOutputPort())
appendFilter.Update()

connectivityFilter = vtk.vtkPolyDataConnectivityFilter()
connectivityFilter.SetInputConnection(appendFilter.GetOutputPort())
connectivityFilter.SetExtractionModeToAllRegions()
connectivityFilter.ColorRegionsOn()
connectivityFilter.Update()

tubeMapper = vtk.vtkPolyDataMapper()
tubeMapper.SetInputConnection(connectivityFilter.GetOutputPort())
tubeMapper.SetScalarRange(connectivityFilter.GetOutput().GetPointData().GetArray("RegionId").GetRange())
tubeMapper.Update()

它看起来很好看,但你可能会注意到一些明显连接的组件仍然有不同的颜色,我仍然想知道为什么。

enter image description here