我有几个vtk多边形数据对象,大小相等,我想沿着规范化方向向量中心对齐,如图A
所示。下面的矢量是基于三个3D点(图上的红点)使用SVD(符合最佳拟合意义)计算的。这三个点的平均值用于将3D vtk对象放置在彼此的顶部
reader = vtk.vtkPLYReader()
reader.SetFileName(filePath)
# Align the read poly data along the direction vector.
originPointMean = np.array([-13.7071, -160.8437, 1317.6533])
directionVector = np.array([-0.1134, -0.0695, 0.9911])
initAxis = [0, 0, 1] # old object's axis
crossVec = np.cross(initAxis, directionVector) # Calc axis of rotation
angle = np.arccos(np.dot(initAxis, directionVector)) # Calc rotation angle
transform = vtk.vtkTransform()
transform.RotateWXYZ(-90, 0, 0, 1) #An initial rotation around Z axis
transform.RotateWXYZ(np.rad2deg(angle), crossVec) # Rotate it along direction vector
transformFilter = vtk.vtkTransformPolyDataFilter()
transformFilter.SetTransform(transform)
transformFilter.SetInputConnection(reader.GetOutputPort())
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(transformFilter.GetOutputPort())
mapper.ScalarVisibilityOn()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(1.0)
actor.SetPosition(originPointMean [0], originPointMean [1], originPointMean [2] - 32) # Add some distance between objects in Z axis
renderer.AddActor(actor)
我的问题是:在使用vtkTransform()
沿方向向量旋转/对齐所有对象后,它们在x
方向上从下向上逐渐移动,因此不以向量为中心,如图B
所示。谢谢你们给我的任何有用的建议,我在这里错过了什么
我不确定,但在我看来,这“惊人”是意料之中的:
相关问题 更多 >
编程相关推荐