Hi Slicer Community,
I apologize in advance if the answer to my question is out there. I’ve seen related threads, but I haven’t been able to piece it together to get my solution working.
Basically, I would like to instantiate a vtkMRMLAnnotationROINode
before having the user switch Interaction Modes (to Place mode) in order to change certain properties of the AnnotationROINode, such as the Name etc. so that the user doesn’t see the default names (like R, R_1, R_2), etc.
Basically, I have created a button addBoundingBoxButton
which is connected to a function onAddBoundingBox
, which I would like to do the following:
def onAddBoundingBox(self):
boundingBoxName = 'Finding {}'.format(self.findingCounter) #internal counter for number of findings identified
#add vtkMRMLAnnotationROINode and change name
annotationROINode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLAnnotationROINode',boundingBoxName)
slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton").SetReferenceActivePlaceNodeClassName("vtkMRMLAnnotationROINode")
slicer.mrmlScene.GetNodeByID("vtkMRMLInteractionNodeSingleton").SetCurrentInteractionMode(1)
The problem is that the annotationROINode
object is not the one modified when the InteractionNode is changed to Place mode, and when the vtkMRMLAnnotationROINode
is placed, a new object is created with a default name. Weirdly, when I do this same approach with vtkMRMLMarkupsLineNode
, I get the desired behavior (i.e., I can create the vtkMRMLMarkupsLineNode
beforehand and the InteractionNode lets me place the line that I have already created in my script). Perhaps this behavior is because of some inherent differences in the Annotations vs the Markups modules? Is there a way to link the annotationROINode
object I’ve created to the one that will be created in Place mode?
Another method I was thinking of was creating the vtkMRMLAnnotationROINode
and then using two fiducial points to let the user choose the center and radius of the bounding box (I suspect this is how it is done in practice, but I couldn’t find a clear procedure for this in the source code, and I would like to take advantage of this being implemented in Place mode through the Interaction Node). I have looked at other threads like this one and this one, but it’s not clear to me how to create a button with a connecting function that (1) lets me place two fiducial points, (2) waits for the user to place them, (3) then extracts the Control Points, and (4) creates/modifies the vtkMRMLAnnotationROINode
with the desired properties. It seems that when I put all of these functions in a connector function, it runs to the very end of the function without waiting for the fiducial points to be placed, so obviously this produces errors downstream.
One last thing I will say is that I am aware that the AnotationROI nodes will be moved to the Markups module sometime in the near future, but I unfortunately can’t wait that long (although, I’m excited for it!).
Thanks for any guidance or help,
Eric