How to split one segment into three equal parts via script?

If you want to split to three equal volumes then you can use the new Segment cross-section area extension to compute cross-sections along slices. You can get the positions as a table and get physical position of 0, 1/3, 2/3, full volume like this:

crossSectionsTable = getNode('Segment cross-section area table')
positions = slicer.util.arrayFromTableColumn(crossSectionsTable, 'Position')
areas = slicer.util.arrayFromTableColumn(crossSectionsTable, 'Segment_1')

import numpy as np
volumeRatio = np.cumsum(areas)/np.sum(areas)
slicePositions = np.interp([0.0, 1.0/3.0, 2.0/3.0, 1.0], volumeRatio, positions[:,3])
print("Slice position along IS axis for zero, 1/3, 2/3, and full volumes: "+str(slicePositions))
2 Likes