I want to create a cube with the certain vertices. For example, I have 8 points (vertices) with the following spatial coordinates in RAS.
Vertex
R
A
S
superiorUpRight
-731.523242270663
-74.7326192431123
-1012.2
superiorUpLeft
-531.523242270663
-421.142780756888
-1012.2
superiorDownRight
-818.125782649107
-124.732619243112
-1012.2
superiorDownLeft
-618.125782649107
-471.142780756888
-1012.2
inferiorUpRight
-731.523242270663
-74.7326192431123
-1412.2
inferiorUpLeft
-531.523242270663
-421.142780756888
-1412.2
inferiorDownRight
-818.125782649107
-124.732619243112
-1412.2
inferiorDownLeft
-618.125782649107
-471.142780756888
-1412.2
Min
-818.125782649107
-471.142780756888
-1412.2
Max
-531.523242270663
-74.7326192431123
-1012.2
How can I define one cube with these points?
I do not find the fuction about setting up vertices in vtk.vtkCubeSource(), then I used the function of vtk.vtkCubeSource().SetBounds (double xMin, double xMax, double yMin, double yMax, double zMin, double zMax) as following lines:
vtkCubeSource creates cube with non-rotated axes. I would recommend to create a cube with the right size, centered around the origin. Then position and orient the node by specifying a parent transform.
I really want to apologize. Unfortunately I did not find a simple example in moving a model (vtkMRMLModelNode) including as Translation + Rotation.
In the link you mentioned, Unfortunately, I did not see about the transformation of model node.
Using the file of procrustesAlignment.py in VTK, I enter the following commands:
I do not see any changes in the 3D window. Why?
I must mention that after creating the model, I can transfer it to any direction using Transforms module, but I would like to learn this from Python Interactor. Please guide me to do it from command line of Python.
No need to apply transform polydata filter manually. Instead, you can set a parent transform node for the model node and then call SetMatrixTransformToParent to set a transformation matrix.
You must leave the row 3 of the matrix as is: (0,0,0,1). Calling matrix.SetElement(3, 3, 0) makes the transform invalid.
vtkMatrix4x4 is already initialized to identity, so there is no need to set the orientation (top-left 3x3 matrix) to identity again, just leave it as is.
Translation part of the transform is in column 3, not column 2, so this is incorrect: matrix.SetElement(2, 2, -1212.200) (it would ruin your model by scaling it by a factor of 1000 and turning it inside out). Use matrix.SetElement(..., 3, ...) instead.
Delete this line. SetAndObserveTransformNodeID method requires a node ID, not a node name and you set the node ID correctly in the line below.
At now, I can define transform matrix, including as Translation and Rotation, with the following commands.
… #Define transformation matrix (Translation and Rotation)
transform = slicer.vtkMRMLTransformNode()
transform.SetName(‘Transformation’) #Add node Transormation to “Data” module
slicer.mrmlScene.AddNode(transform)
matrix = vtk.vtkMatrix4x4() #Translation #Shifting along the axis LR
matrix.SetElement(0, 3, translateLR) #Shifting along the axis PA
matrix.SetElement(1, 3, translatePA) #Shifting along the axis IS
matrix.SetElement(2, 3, translateIS) #Rotation #Rotation around IS (-60 degree)
matrix.SetElement(0, 0, math.cos(math.radians(300-360)))
matrix.SetElement(0, 1, -math.sin(math.radians(300-360)))
matrix.SetElement(1, 0, math.sin(math.radians(300-360)))
matrix.SetElement(1, 1, math.cos(math.radians(300-360)))
#Set IS parameter in “Transforms” module
transform.SetMatrixTransformToParent(matrix)
#Move “EPIDmodel” from “Transformable” to “Transormed” table in “Transforms” module and then apply to it.
modelNode = slicer.util.getNode(‘EPIDmodel’)
modelNode.SetAndObserveTransformNodeID(transform.GetID())
It is great to hear this. Note that you can compute transformation matrix by using translate and rotate methods of vtkTransform and retrieve the matrix by calling GetMatrix().