Convert numpy landmarks point coordinates to VTK.Polydata, and align them using the vtkProcrustesAlignmentFilter ()

Hello VTK Team, I am new to VTK, I want to use the vtkProcrustesAlignmentFilter () for aligning multiple landmark points. I use these codes to do it?

import numpy as np

import open3d as o3d

import pyvista as pv

import vtk

from vtk.util import numpy_support

land_ref = np.loadtxt(‘/media/josi/5CEAB0FEEAB0D58C/statistical_shape/final_folder/mark_L/case_00000_imaging_L_markCT.txt’)
land_point = np.loadtxt(‘/media/josi/5CEAB0FEEAB0D58C/statistical_shape/final_folder/mark_L/case_00001_imaging_L_markCT.txt’)
land_point1 = np.loadtxt(‘/media/josi/5CEAB0FEEAB0D58C/statistical_shape/final_folder/mark_L/case_00002_imaging_L_markCT.txt’)
point_cloud_ref = pv.PolyData(land_ref)
point_cloud_land = pv.PolyData(land_point)
point_cloud_land1 = pv.PolyData(land_point1)
group = vtk.vtkMultiBlockDataGroupFilter()
group.AddInputData(point_cloud_ref)
group.AddInputData(point_cloud_land)
group.AddInputData(point_cloud_land1)
procrustes = vtk.vtkProcrustesAlignmentFilter()
procrustes.SetInputConnection(group.GetOutputPort())
procrustes.GetLandmarkTransform().SetModeToRigidBody()
procrustes.Update()
procrustes.GetOutput().GetBlock(0)
map2a = vtk.vtkPolyDataMapper()
map2a.SetInputData(procrustes.GetOutput().GetBlock(0))
Actor2a = vtk.vtkActor()
Actor2a.SetMapper(map2a)
Actor2a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784)
map2b = vtk.vtkPolyDataMapper()
map2b.SetInputData(procrustes.GetOutput().GetBlock(1))
Actor2b = vtk.vtkActor()
Actor2b.SetMapper(map2b)
Actor2b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784)
map2c = vtk.vtkPolyDataMapper()
map2c.SetInputData(procrustes.GetOutput().GetBlock(2))
Actor2c = vtk.vtkActor()
Actor2c.SetMapper(map2c)
Actor2c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000)
ren1 = vtk.vtkRenderer()
ren2 = vtk.vtkRenderer()
ren3 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.AddRenderer(ren2)
renWin.AddRenderer(ren3)
renWin.SetSize(600,200)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren2.AddActor(Actor2a)
ren2.AddActor(Actor2b)
ren2.AddActor(Actor2c)
ren2.SetBackground(1,1,1)
ren2.SetViewport(0.25,0.0,0.5,1.0)
ren2.ResetCamera()
ren2.GetActiveCamera().SetPosition(1,-1,0)
ren2.ResetCamera()
renWin.Render()
iren.Initialize()
iren.Start()
I have the following question:

  • Am I doing it in right way?
  • How can I get the aligned points or the transformation matrix(rotation, translation and scale)?
  • By visualizing the output I get the window with nothing inside(no points)?
    Looking hearing from you. Thank you