按法线旋转 vtkDiskSource/vtkPolyDataMapper
Rotate vtkDiskSource/vtkPolyDataMapper by Normals
我需要在网格表面(表示为 vtkPolyDataMapper)上放置多个 vtkDiskSource,以便磁盘位于表面上。 vtkRegularPolygonSource 等对象具有 SetNormal 方法,可用于 "rotation"。还有 vtkTransform 但我不知道如何计算 X、Y、Z 值。有人可以帮我吗?
disk = vtk.vtkDiskSource()
disk.SetInnerRadius(1.0)
disk.SetOuterRadius(2.0)
<---- rotation
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(disk.GetOutputPort())
您可以使用 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
我需要在网格表面(表示为 vtkPolyDataMapper)上放置多个 vtkDiskSource,以便磁盘位于表面上。 vtkRegularPolygonSource 等对象具有 SetNormal 方法,可用于 "rotation"。还有 vtkTransform 但我不知道如何计算 X、Y、Z 值。有人可以帮我吗?
disk = vtk.vtkDiskSource()
disk.SetInnerRadius(1.0)
disk.SetOuterRadius(2.0)
<---- rotation
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(disk.GetOutputPort())
您可以使用 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