多边形Outline和 Feature Line 创建

根据上一文章中,我们成功创建了一个正方形在创建的VTK视图中。但是在未来的计划中,我们还要想体现更为复杂的模型。而模型是由不同的点,线,面组成的。相比较ABAQUS中的Mesh来说,这些点线面(Feature)其实就是node, face element, body element。

那么如何在VTK的视图中展示这些特征呢?下面我们以一个简单的例子来说明:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# vtk DataFile Version 1.0
Vibrational modes of plate
ASCII

DATASET POLYDATA
POINTS 12 float
0.0 0.0 0.0
1.0 0.0 0.0
1.0 1.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
1.0 0.0 1.0
1.0 1.0 1.0
0.0 1.0 1.0
2.0 0.0 0.0
2.0 1.0 0.0
2.0 1.0 1.0
2.0 0.0 1.0

POLYGONS 11 55
4 0 3 2 1
4 4 5 6 7
4 0 1 5 4
4 2 3 7 6
4 0 4 7 3
4 1 2 6 5
4 1 8 9 2
4 5 11 10 6
4 8 9 10 11
4 1 8 11 5
4 2 9 10 6

这个文件能够显示一个含有两个正方体的模型组成的长方体。如下图所示

显示模型边线

这里要使用vtkOutlineFilter()来实现这个功能:

1
2
3
4
5
6
7
8
9
10
# Outline
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(vtkReader.GetOutputPort())
outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())
outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
outline_actor.GetProperty().SetColor(1.0, 0.5, 1.0)
# outline_actor.VisibilityOff()
renderer.AddActor(outline_actor)

将上述代码添加到该系列文档中的第一个文章中的代码中。则可显示出模型的边线,如图,这里把模型本身隐藏了

这里我们可以看出来,这个功能并不能显示出内部面的框线。如果想要实现显示内部框线,那我们需要vtkFeatureEdges这个功能。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
featureEdges = vtk.vtkFeatureEdges()
featureEdges.SetInputConnection(vtkReader.GetOutputPort())
# featureEdges.BoundaryEdgesOff() # 打开
featureEdges.FeatureEdgesOff() # 打开
featureEdges.ManifoldEdgesOff()
# featureEdges.NonManifoldEdgesOff() # 打开
featureEdges.ColoringOn()
featureEdges.Update()
edgeMapper = vtk.vtkPolyDataMapper()
edgeMapper.SetInputConnection(featureEdges.GetOutputPort())
edgeActor = vtk.vtkActor()
edgeActor.SetMapper(edgeMapper)
renderer.AddActor(edgeActor)

选择打开FeatureEdgesOn()

可以看出来OutlineFeature Edges的显示是一样的。

我们再打开ManifoldEdgesOn,其中 Manifold edges 意思为交叠边,就是模型内部重复使用的边。

我们打开FeatureEdgesNonManifoldEdges,就可以得到类似ABAQUS中隐藏实体网格一样的网格边线了。