I have several vtk poly data objects, equal in size that I want to align along a normalized direction vector centrically, shown on figure A
. The vector below is calculated based on the three 3D points (red dots on figures) using SVD (in line of best fit sense). The mean of that three points is used to place the 3D vtk objects top of each other.
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)
My problem is: after rotating/aligning all the objects along the direction vector using vtkTransform()
they are shifted in x
direction increasingly from bottom to top and therefore not centered on the vector as shown on figure B
. Thank you for the any helpful advice, what I am missing here.