1

I am trying to build a statistical shape model using vtk. Procrustes Alignment and Principal Component Analysis functions are already available in vtk, and there are python examples for them. However, I have difficulties to access the outcomes from the vtkPCAAnalysisFilter().

Specifically, I am trying to follow an example which I found on the vtk.org website. I have produced 3 text files which include coordinates of some points on the contour of a shape. Then I have converted those points into vtkPolyData and then performed ProcrustesAlignment and after that PCA:

#ProcrustesAlignment
group = vtk.vtkMultiBlockDataGroupFilter()
group.AddInputData(poly_1)
group.AddInputData(poly_2)
group.AddInputData(poly_3)
procrustes = vtk.vtkProcrustesAlignmentFilter()
procrustes.SetInputConnection(group.GetOutputPort())
procrustes.GetLandmarkTransform().SetModeToSimilarity()
procrustes.Update()

#PCA filter
pca = vtk.vtkPCAAnalysisFilter()
pca.SetInputConnection(procrustes.GetOutputPort())
pca.Update()

#displaying the most important eigenvalues 
EVNo = pca.GetModesRequiredFor(0.98)
for j in range (0,EVNo):
    print pca.GetEvals().GetValue(j)

However, I have not been able to access the eigenvectors resulted from the PCA. Also, how can I write the average model nodes in a file. And finally, how can I get the coefficients needed for a new "test" shape (I think I should use pca.GetShapeParameters(shapea, params, 2), but how to get the results to be written somewhere?). In the example I am using the following part has been implemented to be able to visualize the PCA results:

params = vtk.vtkFloatArray()
params.SetNumberOfComponents(1)
params.SetNumberOfTuples(1)
params.SetTuple1(0,0.0)
shapea = vtk.vtkPolyData()
shapea.DeepCopy(poly_1)
pca.GetParameterisedShape(params,shapea)
normalsa = vtk.vtkPolyDataNormals()
normalsa.SetInputData(shapea)
map3a = vtk.vtkPolyDataMapper()
map3a.SetInputConnection(normalsa.GetOutputPort())
Actor3a = vtk.vtkActor()
Actor3a.SetMapper(map3a)
Actor3a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784)
Actor3a.GetProperty().SetPointSize(5)

However, I am still confused about the defined "params" and "shapea".

Any help would be greatly appreciated.

Thanks,

lvl0l27
  • 47
  • 6

0 Answers0