Set Orientation at vtkCylinderSource

Hello,

I would like to Set Orientation/Direction to a vtkCylinderSource that I create in Slicer in python.
From vtk documentation I realized that I have to set the orientation through vtkActor, but how can I display it on Slicer?

Here is a piece of code:

cyl = vtk.vtkCylinderSource()
cyl.SetRadius(50)
cyl.SetResolution(50)
cyl.SetHeight(100)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cyl.GetOutputPort())

actor = vtk.vtkActor()
actor.SetOrientation(0,0,90)
actor.SetMapper(mapper)

node = cyl.GetOutput()
n = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLModelNode’, ‘Cylinder’)
n.SetAndObservePolyData(node)
n.CreateDefaultDisplayNodes()
n.SetDisplayVisibility(True)
cyl.Update()

Thanks

If you need to dynamically set its position/rotation then you set a parent transform to it. If you need a fixed pose then to cylinder source output you can apply a vtkTransformPolyDataFilter on set the output of that into the model node.

1 Like

yes, I was wondering whether there is another option for dynamically setting the transformation except from SetMatrixTransformToParent. Thanks

In your module you can keep a reference to vtkTransformPolyDataFilter and update it whenever you need. However, in general it is more useful if you don’t keep transforms private but store in MRML nodes so that other nodes and modules can use it. For example, if you just store a transform privately then you cannot easily modify or inspect current values using GUI, use it to reslice a volume, combine with other transforms, save/load with the scene, etc.