Display and interact with a vtkMRMLAnnotationROINode() in the view

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 manage to get my solution to work.

I’m using slicer 4.11
I would like to create a vtkMRMLAnnotationROINode() and set it’s position size in the slice view as in the cropvolume module.

I’ve tried this script but the node it’s not showing in the 2D slice view but only in the 3D view

roi=slicer.vtkMRMLAnnotationROINode()
slicer.mrmlScene.AddNode(roi)
roi.Initialize(slicer.mrmlScene)
roi.SetDisplayVisibility(1)
roi.SetInteractiveMode(1)

If you have a solution please?

Thanks

We are working on the Markups module to replace the old Annotation module. I would recommend to use Markups ROI. You can create it like this:

roiNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLMarkupsROINode')
roiNode.SetCenter([20,30,40])
roiNode.SetSize([33,23,45])

Thanks you, unfortunately i’m using 4.11 of Slicer it seems the ‘vtkMRMLMarkupsROINode’ was not fully implemented yet.

Also i manage to emulate the good behavior i wanted by a trick: (after my image is loaded )

  cropVolumeWidget = slicer.modules.cropvolume.widgetRepresentation()
  cropVolumeWidget.setMRMLScene(slicer.mrmlScene)
  cropVolumeWidget.enter()
  inp = cropVolumeWidget.findChild(slicer.qMRMLNodeComboBox,"InputROIComboBox")
  inp.addNode()

This create the Roi node and showing it.
I would like to do the same but the good way. Do you have any idea how can i emulate the crop module by scripting : step 1 set a define input and output , step 2 create and edit by hand the roi node ?

Thanks