Translocating a structure to certain direction

Hi every body
i want to a structure translocates to certain direction that i define. how can i do that?
thanks a lot

A more specific description of the problem you are trying to solve would allow more help. In general, you can move things (for example image volumes, models, segmentations, markups, etc.) around in space in Slicer by using Transforms (Transforms — 3D Slicer documentation). Create a transform node and apply it to the object you want to move, and then you can use the sliders in the Transforms module to interactively apply translations and/or rotations. If you are trying to align objects or images, then you are better off using a registration method (there are several available in Slicer).

1 Like

thanks a lot

In fact, I have had problem with this module and I do not know how to make exact translocation.

In this picture I want to move the red model exactly on the skin and in the direction of the beam radiation. (Actually, moving in the direction of the center line of the beam radiation)
when I use ’ linear transform ’ the model is not in the right place and goes out of range of the beam radiation.

So, the transmission direction is incorrect and when I do the transitions in the PA and LR directions together, the result is not accurate… :frowning:

Could you please help me ?

Here is a function you could use to translate an object in a specified direction a specified distance.

def translateAlongVector(nodeToMove, directionVectorRAS, translationDistance):
  """ Moves nodeToMove by translationDistance the direction of directionVectorRAS.
  If nodeToMove already has a transform applied to it, this function updates that
  transform to translate the nodeToMove from it's current transformed location. If
  nodeToMove does not have an existing parent transform, then one is created for it.
  """
  # Create parent transform node if one does not exist
  transformNodeID = nodeToMove.GetTransformNodeID()
  if transformNodeID is None:
    # Need to create a new transform node
    transformNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLinearTransformNode', 'translationTransform')
    nodeToMove.SetAndObserveTransformNodeID(transformNode.GetID())
  else:
    # Get existing transform node
    transformNode =  slicer.mrmlScene.GetNodeByID(transformNodeID)
  # Determine translation vector
  import numpy as np
  unitDirectionVectorRAS = directionVectorRAS/np.linalg.norm(directionVectorRAS) # normalize
  translationVector = unitDirectionVectorRAS * translationDistance
  # Add translation to the 4x4 transformation matrix
  vtkTransformationMatrix = transformNode.GetMatrixTransformToParent()
  transformationMatrix = slicer.util.arrayFromVTKMatrix(vtkTransformationMatrix)
  transformationMatrix[:3,3] = transformationMatrix[:3,3] + translationVector
  transformNode.SetAndObserveMatrixTransformToParent( slicer.util.vtkMatrixFromArray(transformationMatrix) )

Example usage:

modelName = "myRedModel" # replace with the name of the object you want to move
modelNode = slicer.util.getNode(modelName)
beamDirection = [10, 20, 0] # a RAS (right, anterior, superior) vector describing the direction of the beam 
distanceToSkin = 30 # distance to move the model in mm
# apply the translation
translateAlongVector( modelNode, beamDirection, distanceToSkin)
1 Like