dvenkatsagar dvenkatsagar - 2 months ago 25
Javascript Question

centering the axis/pivot of a polydata model in python-vtk/three.js

I am creating a 3D model from a series of dicom images. The workflow that I am using is as follows:


  • Read the dicom series with
    vtkDICOMImageReader
    .

  • Get the Threshold image from the volume with
    vtkImageThreshold
    .

  • Generate a 3D model using the Discrete Marching Cubes algorithm.

  • Write the output as PLY file using the
    vtkPLYWriter
    .



When I look at the ply file using meshlab, it looks likes this (from the back).

The problem that Im facing is that, the axis/pivot are not at the center of the model. So is there a way to fix this?? I know that I need to use the
vtkTransformfilter
to do it (I think, I might be wrong), but I just dont know how.

I did look at the vtk examples given at their site, but it did not give enough information on what I wanted. I also searched the other questions in the SO, but most of them are using vtkActors and renderers, and didnt solve the problem that I have.

The dicom set that I am using is from here.

I would also like to know if its possible to do this in Three.js, like load the model and then center it?

Thank you

Answer

If it is ok to move the model, then you can define the center of the model, and transform it to the global origin, then save the transformed model as a PLY file.

First, you want to define the center of the model. A quick and dirty way could be to get the center of mass:

centerFilter = vtk.vtkCenterOfMass()
centerFilter.SetInputData(polydata)
centerFilter.SetUseScalarsAsWeights(False)
centerFilter.Update()
center = centerFilter.GetCenter()

Then you want to transform your model:

transform = vtk.vtkTransform()
transform.Translate(-center[0], -center[1], -center[2])
transformFilter = vtk.vtkTransformPolyDataFilter()
transformFilter.SetInputData(polydata)
transformFilter.SetTransform(transform)
transformFilter.Update()
centeredPolydata = transformFilter.GetOutput()

Then write the output PLY file with centeredPolydata.

Note: this will make it more difficult to relate the centered model to the image data.