How does one find the translation and rotation measurements of one anatomy with respect to another?

I would like to find the Translation XYZ and Rotation XYZ of one anatomy with respect to another - say if I would like to consider center of the bone to be the origin and would like to find the above measurements of the center of a tumour with respect to the bone, how can I find such measurements?

First you need to specify coordinate system for each object. An easy way to do it is to place a plane in Markups module that is aligned with the origin and axis directions. You can right-click on a control point and enable Translation and Rotation interactions to make alignment easier.

You can then get the relative transform by copy-pasting this code snippet in the Python console:

planeA = getNode('P')
planeB = getNode('P_1')

# Compute PlaneA to PlaneB transformation matrix 
planeAToWorldMatrix = vtk.vtkMatrix4x4()
planeBToWorldMatrix = vtk.vtkMatrix4x4()
worldToPlaneBMatrix = vtk.vtkMatrix4x4()
vtk.vtkMatrix4x4.Invert(planeBToWorldMatrix, worldToPlaneBMatrix)
planeAToPlaneBMatrix = vtk.vtkMatrix4x4()
vtk.vtkMatrix4x4.Multiply4x4(worldToPlaneBMatrix, planeAToWorldMatrix, planeAToPlaneBMatrix)

# Save matrix into transformation node
planeAToPlaneBTransformNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTransformNode", "PlaneA to PlaneB transform")

You can then use Characterize transform matrix module (in Sandbox extension) to get some relative position and orientation information from that transformation.

Hello @lassoan Thank you for your response. I guess the above gives me relative positions to certain points that I choose which can change from dataset to dataset. May be I can rephrase my question.

If I have two STL files - one of the bone and second of tumour, is there a way I can find the center coordinate of bone (so I will consider it as my 0,0,0) and then find the coordinates of translation and rotation of the center of the tumour with respect to the center of the bone? This way I am reducing the dependency on point selection and relative coordinates.

The problem is that when I export the STL files and load it into another viewer (say something like viewstl), it brings all STLs to the center of the viewer and the spatial translations and rotations are lost (sometimes rotations are maintained, so just need translation values in such cases). May be this can help explain the reason I am looking for this solution.

You need more that a center point to determine a coordinate system in 3D. @lassoan 's suggestion is a simple way to define a coordinate system using a MarkupsPlane. Once you have defined the coordinate system based on the bone (origin at center, first coordinate axis along the long axis of the bone, second coordinate axis to the patient’s right (for example), third coordinate axis as the cross product of the first two axes (the normal to the plane defined by the first two axes)), only then can you describe the location of something else in this (e.g. a tumor center point) in that coordinate system.

You mention having two STL files. It is important to note that there is no solution to your problem unless coordinates of both STL files are already reported in a shared coordinate system. That is, if you load both of them into Slicer, do they appear in the proper 3D spatial relationship to each other? If for example, they are both centered or both have their coordinate origins at a corner of their bounding boxes, the information which would allow you to understand their spatial relationship to one another has already been lost.

It sounds like some of the software that you use cannot read or write meshes in STL files. If the meshes get centered after writing&reading then you can try to adjust settings when you read and write the file, use a different file format, or stop using that software.

Thanks @mikebind and @lassoan for your quick responses. I am not too good with running codes and hence I was looking for solutions to find the co-ordinates with the tools already provided in the interface. I am exporting the STLs from 3D Slicer itself so initially the co-ordinate system is maintained.

I think one solution might work and will need your help with that.

Is there a way to create a bounding box around the part, then create a plane though its exact midplane and get the origin center co-ordinates of that midplane?

I think it is unlikely that you will be able to extract the information you want using only existing GUI tools, however, the coding/analysis you need to do may be pretty minimal. Check out the Segment Statistics module. If you have your bone and your tumor as segments in a segmentation, the Segment Statistics module can help you gather the centroid coordinates for each, as well as principal axes and oriented bounding boxes. You could consider the centroid or the center of the bounding box as the origin point, and the principal axes of the bone bounding box as the coordinate axis directions. Then, in your own code (or even by hand if that’s better for you) you can take the centroid coordinates of the tumor and express them in your newly defined bone coordinate system (i.e. subtract the bone center and change the basis vectors). The result would be a description of the tumor location relative to the bone in a coordinate system centered on the bone and oriented by its principal axes. If the bone of interest is of reasonably consistent shape from subject to subject, this coordinate system may be reproducible enough to use to compare across subjects (which I am guessing is your ultimate goal?)

Instead of trying to fix data corruption by manually recording and later restoring some information that is lost; it would be better to prevent data corruption from happening.

Can you describe your data flow - list of what processing steps you do in what software, what inputs are used and outputs are generated in each step? We should be able to give you advice about what to change in your data flow to avoid data corruption.