SetPosition of ellipsoid

Hi all,
I have write a little script to draw on slicer an ellipsoid.
However, I do not know how to set the position (center), could you please help me?
Thanks in advance.

The code

ellips = vtk.vtkParametricEllipsoid()
ellips.SetXRadius(40.0)
ellips.SetYRadius(10.0)
ellips.SetZRadius(15.0)
ellipsSource = vtk.vtkParametricFunctionSource()
ellipsSource.SetParametricFunction(ellips)
ellipsSource.Update()
modelsLogic = slicer.modules.models.logic()
model = modelsLogic.AddModel(ellipsSource.GetOutput())
model.SetName(โ€˜ellipse_1โ€™)
model.GetDisplayNode().SetSliceIntersectionVisibility(True)
model.GetDisplayNode().SetSliceIntersectionThickness(3)

from this code:

ellipsoid = vtk.vtkParametricEllipsoid()
ellipsoid.SetXRadius(1)
ellipsoid.SetYRadius(0.75)
ellipsoid.SetZRadius(0.5)
ellipsoidSource = vtk.vtkParametricFunctionSource()
ellipsoidSource.SetParametricFunction(ellipsoid)
ellipsoidSource.SetScalarModeToZ()
ellipsoidMapper = vtk.vtkPolyDataMapper()
ellipsoidMapper.SetInputConnection(ellipsoidSource.GetOutputPort())
ellipsoidMapper.SetScalarRange(-0.5, 0.5)
ellipsoidActor = vtk.vtkActor()
ellipsoidActor.SetMapper(ellipsoidMapper)
ellipsoidActor.SetPosition(8, -12, 0)
ellipsoidActor.SetScale(1.5, 1.5, 1.5)

You can add these lines to apply a transform to the model node:

transformNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTransformNode")
model.SetAndObserveTransformNodeID(transformNode.GetID())
transform = vtk.vtkTransform()
transform.Translate(8, -12, 0)
transform.Scale(1.5, 1.5, 1.5)
transformNode.SetMatrixTransformToParent(transform.GetMatrix())

Note that you can go to Transforms module and use the sliders to edit your transform.

2 Likes

Once again, thanks Andras.

1 Like