I extract vessel centerline by vmtk with type vtkMRMLModelNode.
Then i want get ijk coord for centerline projection after rigistration.
line = [] #line projection
centerlineNode = slicer.util.getNode('Centerlinemodel')
mesh = centerlineNode.GetMesh()
points = mesh.GetPoints()
for id in range(points.GetNumberOfPoints()):
point_Ras = points.GetPoint(id)
point_ijk = self.ras2ijk(point_Ras, vessel_src_Node)
point_kji = [point_ijk[2],point_ijk[1],point_ijk[0]]
print('index:',point_kji) # image coordinate position
...
def ras2ijk(self, point_Ras, volumeNode):
transformRasToVolumeRas = vtk.vtkGeneralTransform(
slicer.vtkMRMLTransformNode.GetTransformBetweenNodes( volumeNode.GetParentTransformNode(),None,
transformRasToVolumeRas)
point_VolumeRas = transformRasToVolumeRas.TransformPoint(point_Ras)
volumeRasToIjk = vtk.vtkMatrix4x4()
volumeNode.GetRASToIJKMatrix(volumeRasToIjk)
point_ijk = [0, 0, 0, 1]
volumeRasToIjk.MultiplyPoint(np.append(point_VolumeRas, 1.0), point_ijk)
point_ijk = [int(round(c)) for c in point_ijk[0:3]]
return point_ijk
Is that conversion right? point_kji get some invalid value such as minus value or value out of range.