Operating system: MacOS 15.3
Slicer version: 5.6.2
In my slicer extension, I am loading image and label (segmentation) volumes from a database. I have figured out how to load a custom terminology json file when the extension is loaded:
# Placed in extension's __init__ function
path = self.resourcePath("Terminologies/terminologyfilename.json")
tlogic = slicer.modules.terminologies.logic()
terminologyName = tlogic.LoadTerminologyFromFile(path)
I also created color table files to use when loading in segmentations:
color_table_name = "some name"
script_path = os.path.dirname(os.path.abspath(__file__)) # returns path to this file (volume.py)
color_file = os.path.join(script_path,"..","<module name>","Resources","Terminologies",f"{color_table_name}.txt")
color_table_node = slicer.util.loadColorTable(color_file)
ref_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
<load label data into ref_node>
ref_node.CreateDefaultDisplayNodes()
ref_node.GetDisplayNode().SetAndObserveColorNodeID(color_table_node.GetID())
seg_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(ref_node, seg_node)
seg_node.GetDisplayNode().SetAndObserveColorNodeID(color_table_node.GetID())
seg_node.SetReferenceImageGeometryParameterFromVolumeNode(ref_node)
slicer.mrmlScene.RemoveNode(ref_node)
I’m wondering if there is some way for me to set the default terminology name and category for seg_node in the above code so that when a user opens the Segment Editor for this segmentation node, adds a new segment, then double clicks on the Segment Color box (which brings up the Terminology selection window), my preferred Terminology, and Category are pre-selected, and all the user needs to do is pick the correct Property Type to assign to this segment?
Is there something like:
seg_node.SetDefaultTerminology()
seg_node.SetDefaultTerminologyCategory(<Category.CodeMeaning>)
?
It feels like I’m doing something wrong or inefficient by loading BOTH a custom terminology file AND custom colortables which essentially map the exact same IDs, Names, and RGB/opacity values to individual segments/labels in different ways… but from all I can read/find this is the way?