How to find the volume of a segmentation node whose master representation is closed surface representation

Hello,

I want to find the volume of a segmentation node with closed surface representation. How can I do that using segment statistics module? I have found an example in script repository but I think it is only applicable for binary lablemap representation. Here is the code I found.

segmentationNode = getNode("Segmentation")

# Compute segment statistics
import SegmentStatistics
segStatLogic = SegmentStatistics.SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.computeStatistics()
stats = segStatLogic.getStatistics()

# Display volume of each segment
for segmentId in stats["SegmentIDs"]:
  volume_cm3 = stats[segmentId,"LabelmapSegmentStatisticsPlugin.volume_cm3"]
  segmentName = segmentationNode.GetSegmentation().GetSegment(segmentId).GetName()
  print(f"{segmentName} volume = {volume_cm3} cm3")

Thanks for your help in advance.

You can use metrics provided by ClosedSurfaceSegmentStatisticsPlugin.