I want to use a vtkAssembly in slicer. I am not clear there is any relationship between modelNode and vtkProp3D. How to use a model as vtkProp3D in slicer script.
Assembly.AddPart(NeedleModel)
Traceback (most recent call last): File “”, line 1, in TypeError: AddPart argument 1: method requires a vtkProp3D, a vtkMRMLModelNode was provided.
And another problem is how to rotate a model(or transform) setting a origin(x,y,z) myself.
Thank you very much.
Each model node is displayed using a prop in each view. You should not need assembly, as you can build your own model transform hierarchy using transform and model nodes.
Thank you Professor Lassoan.
I need add two parts into a Transform, and then I need set a Origin for this transform. Are there any example similar what I am doing.
Thanks.
You just need to create transform nodes and apply it to model and transform nodes below. SlicerIGT tutorials may help - see for example U-04.
Thank you for your quick reply.
I can do it through manu now. In order to run it through script, I found some code from here, but I could not distinguish the different between them.
First:
vTransform = vtk.vtkTransform()
vTransform.Translate(-0.88, 35.4, 5.65) # translate by -isocenter
vTransform.RotateZ(10) # The angle is in degrees
vTransform.Translate(0.88, -35.4, -5.65)
imageNode.ApplyTransform(vTransform)
Second:
transform = slicer.vtkMRMLLinearTransformNode()
scene = slicer.mrmlScene
scene.AddNode(transform)
imageNode.SetAndObserveTransformNodeID(transform.GetID())
vTransform = vtk.vtkTransform()
vTransform.Translate(-0.88, 35.4, 5.65) # translate by -isocenter
vTransform.RotateZ(10) # The angle is in degrees
vTransform.Translate(0.88, -35.4, -5.65)
transform.SetAndObserveMatrixTransformToParent(vTransform.GetMatrix())
#transform.SetMatrixTransformToParent(vTransform.GetMatrix())
First example changes the image position/orientation permanently.
Second example applies a transform to the image. You can remove the transform to get back the image to its original pose or harden the transform to change the image pose permanently.
Simplified and more up-to-date version of the second example:
transform = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLinearTransformNode')
imageNode.SetAndObserveTransformNodeID(transform.GetID())
vTransform = vtk.vtkTransform()
vTransform.Translate(-0.88, 35.4, 5.65) # translate by -isocenter
vTransform.RotateZ(10) # The angle is in degrees
vTransform.Translate(0.88, -35.4, -5.65)
transform.SetMatrixTransformToParent(vTransform.GetMatrix())