Merging Connected Components

Hi,

I’d like to create a button in my extension that merges all the segmentations in the image.

I found this: Slicer: vtkSegmentation Class Reference

Where I see that I can use GenerateMergedLabelmap() and GenerateMergedLabelmapForAllSegments(), but I’m unsure how to use it. Can anyone help?