parameters: (self)
docstring: Compute statistical measures for all (visible) segments
docstring_summary: Compute statistical measures for all (visible) segments
docstring_tokens: Compute statistical measures for all ( visible ) segments
function: def computeStatistics(self):
      """Compute statistical measures for all (visible) segments"""
      self.reset()
  
      segmentationNode = slicer.mrmlScene.GetNodeByID(self.getParameterNode().GetParameter("Segmentation"))
      transformedSegmentationNode = None
      try:
        if not segmentationNode.GetParentTransformNode() is None:
          # Create a temporary segmentation and harden the transform to ensure that the statistics are calculated
          # in world coordinates
          transformedSegmentationNode = slicer.vtkMRMLSegmentationNode()
          transformedSegmentationNode.Copy(segmentationNode)
          transformedSegmentationNode.HideFromEditorsOn()
          slicer.mrmlScene.AddNode(transformedSegmentationNode)
          transformedSegmentationNode.HardenTransform()
          self.getParameterNode().SetParameter("Segmentation", transformedSegmentationNode.GetID())
  
        # Get segment ID list
        visibleSegmentIds = vtk.vtkStringArray()
        if self.getParameterNode().GetParameter('visibleSegmentsOnly')=='True':
          segmentationNode.GetDisplayNode().GetVisibleSegmentIDs(visibleSegmentIds)
        else:
          segmentationNode.GetSegmentation().GetSegmentIDs(visibleSegmentIds)
        if visibleSegmentIds.GetNumberOfValues() == 0:
          logging.debug("computeStatistics will not return any results: there are no visible segments")
  
        # update statistics for all segment IDs
        for segmentIndex in range(visibleSegmentIds.GetNumberOfValues()):
          segmentID = visibleSegmentIds.GetValue(segmentIndex)
          self.updateStatisticsForSegment(segmentID)
      finally:
        if not transformedSegmentationNode is None:
          # We made a copy and hardened the segmentation transform
          self.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
          slicer.mrmlScene.RemoveNode(transformedSegmentationNode)
function_tokens: def computeStatistics ( self ) : self . reset ( ) segmentationNode = slicer . mrmlScene . GetNodeByID ( self . getParameterNode ( ) . GetParameter ( "Segmentation" ) ) transformedSegmentationNode = None try : if not segmentationNode . GetParentTransformNode ( ) is None : # Create a temporary segmentation and harden the transform to ensure that the statistics are calculated # in world coordinates transformedSegmentationNode = slicer . vtkMRMLSegmentationNode ( ) transformedSegmentationNode . Copy ( segmentationNode ) transformedSegmentationNode . HideFromEditorsOn ( ) slicer . mrmlScene . AddNode ( transformedSegmentationNode ) transformedSegmentationNode . HardenTransform ( ) self . getParameterNode ( ) . SetParameter ( "Segmentation" , transformedSegmentationNode . GetID ( ) ) # Get segment ID list visibleSegmentIds = vtk . vtkStringArray ( ) if self . getParameterNode ( ) . GetParameter ( 'visibleSegmentsOnly' ) == 'True' : segmentationNode . GetDisplayNode ( ) . GetVisibleSegmentIDs ( visibleSegmentIds ) else : segmentationNode . GetSegmentation ( ) . GetSegmentIDs ( visibleSegmentIds ) if visibleSegmentIds . GetNumberOfValues ( ) == 0 : logging . debug ( "computeStatistics will not return any results: there are no visible segments" ) # update statistics for all segment IDs for segmentIndex in range ( visibleSegmentIds . GetNumberOfValues ( ) ) : segmentID = visibleSegmentIds . GetValue ( segmentIndex ) self . updateStatisticsForSegment ( segmentID ) finally : if not transformedSegmentationNode is None : # We made a copy and hardened the segmentation transform self . getParameterNode ( ) . SetParameter ( "Segmentation" , segmentationNode . GetID ( ) ) slicer . mrmlScene . RemoveNode ( transformedSegmentationNode )