Is there a way to convert vtkOpenGLActor to vtkMrmlNode?

I want to use the mouse to pick 3D object in the 3D view.So I use the vtkPropPicker and get a vtkOpenGLActor.Then I can modify the property(like color) of this vtkActor.
But when I convert this vtkActor to vtkMRMLNode using SafeDownCast,the program crashes.
The father class of vtkActor and vtkMRMLNode are both vtkObject.Is there a way to convert vtkOpenGLActor to vtkMRMLNode?



The properties of the vtkOpenGLActor can be modified. But the properties of the segments are not changed with the vtkOpenGLActor.So how to build the connection between the vtkOpenGLActor and the vtkMRMLSegmentationNode?

vtkMRMLNode is not a vtkActor, so downcasting will not work. Instead, you can use the model displayable manager’s GetIDByActor method to get model display node from a VTK actor (you can get access to the model displayable manager as shown here).

Note that the model displayable manager already has a picker that you can use and get the ID of the picked display node directly.

2 Likes

image
when I click this,the function qSlicerSegmentationsModuleWidget::onSegmentSelectionChanged is called.

when I click in 3D view the function vtkThreeDViewInteractorStyle::OnLeftButtonDown() is called.
Is there a way when I click in 3D view the function qSlicerSegmentationsModuleWidget::onSegmentSelectionChanged will be called?

thank you very much!

You can use the segment editor widget’s setCurrentSegmentID method to select a segment as shown in examples in script repository (e.g., “mask a volume with segments and compute histogram for each region”). You can get picked segment ID from vtkMRMLSegmentationsDisplayableManager3D.

Actually we want a function that when I click in the 3D render view, the segment I click will be selected.
image