三维上测两个平面的角度方法

软件版本:Slicer 4.11.0-2019-11-19
问题描述:请问怎么才能在三维上测量自定义两个平面的角度,谢谢。

设置两个平面分别为"P"和“”P_1"
之后运行脚本

planeNodeNames = ['P', 'P_1']

# Print angles between slice nodes
def ShowAngle(unused1=None, unused2=None):
    planeNormalVectors = []
    for planeNodeName in planeNodeNames:
        planeNode = slicer.util.getFirstNodeByClassByName('vtkMRMLMarkupsPlaneNode', planeNodeName)
        planeNormalVector = [0.0, 0.0, 0.0]
        planeNode.GetNormalWorld(planeNormalVector)
        planeNormalVectors.append(planeNormalVector)
    angleRad = vtk.vtkMath.AngleBetweenVectors(planeNormalVectors[0], planeNormalVectors[1])
    angleDeg = vtk.vtkMath.DegreesFromRadians(angleRad)
    print('Angle between planes {0} and {1} = {2:0.3f}'.format(planeNodeNames[0], planeNodeNames[1], angleDeg))

# Observe plane node changes
for planeNodeName in planeNodeNames:
    planeNode = slicer.util.getFirstNodeByClassByName('vtkMRMLMarkupsPlaneNode', planeNodeName)
    planeNode.AddObserver(slicer.vtkMRMLMarkupsPlaneNode.PointModifiedEvent, ShowAngle)

# Print current angle
ShowAngle()