我需要在网格表面上放置多个vtkDiskSource (表示为vtkPolyDataMapper),以便磁盘位于表面上。像vtkRegularPolygonSource这样的对象有SetNormal方法,可以用于“旋转”。还有vtkTransform,但我不知道如何计算X,Y,Z值。有人能帮我吗?
disk = vtk.vtkDiskSource()
disk.SetInnerRadius(1.0)
disk.SetOuterRadius(2.0)
<---- rotation
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(disk.GetOutputPort())发布于 2018-11-29 09:12:45
您可以使用vtk.Transform将vtk.DiskSource放置在网格表面的正确方向上。
disk = vtk.vtkDiskSource()
disk.SetInnerRadius(1.0)
disk.SetOuterRadius(2.0)
disk.Update()
# Assume we have the normal of the mesh surface in normal
# and the position in coords
z_axis = [0., 0., 1.]
axis = np.cross(z_axis, normal)
angle = np.arccos(n.dot(z_axis, normal))
transform = vtk.vtkTransform()
# Put the disks a bit above the mesh, otherwise they might be partially burried
transform.Translate(*(coords + 0.1 * normal))
transform.RotateWXYZ(n.degrees(angle), *axis)
transform_filter = vtk.vtkTransformPolyDataFilter()
transform_filter.SetTransform(transform)
transform_filter.SetInputConnection(disk.GetOutputPort())
transform_filter.Update()
diskmapper = vtk.vtkPolyDataMapper()
diskmapper.SetInputConnection(transform_filter.GetOutputPort())
# Go on setting up actors https://stackoverflow.com/questions/53244072
复制相似问题