# Is there a way to convert vtkOpenGLActor to vtkMrmlNode?

**URL:** <https://discourse.slicer.org/t/is-there-a-way-to-convert-vtkopenglactor-to-vtkmrmlnode/9239>\
**Category:** Development\
**Created:** [November 21, 2019, 6:40am UTC](https://discourse.slicer.org/t/is-there-a-way-to-convert-vtkopenglactor-to-vtkmrmlnode/9239 "2019-11-21T06:40:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaceYang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jaceyang/32/3686_2.png) [@JaceYang](https://discourse.slicer.org/u/JaceYang)\
**Post date:** [November 21, 2019, 6:40am UTC](https://discourse.slicer.org/t/is-there-a-way-to-convert-vtkopenglactor-to-vtkmrmlnode/9239/1 "2019-11-21T06:40:30Z")

</div>

```
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?

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/4/844b8d2aaa05e97c1c87777e02686023d5ea4257.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/4/445c1485fddefea5cbdb382df1cdd68440dfe46a.png)  
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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 21, 2019, 1:26pm UTC](https://discourse.slicer.org/t/is-there-a-way-to-convert-vtkopenglactor-to-vtkmrmlnode/9239/2 "2019-11-21T13:26:01Z")

</div>

`vtkMRMLNode` is not a `vtkActor`, so downcasting will not work. Instead, you can use the model [displayable manager’s GetIDByActor method](https://apidocs.slicer.org/master/classvtkMRMLModelDisplayableManager.html#adfed38f8e4568690d0856dc8a6a7d12a) to get model display node from a VTK actor (you can get access to the model displayable manager as shown [here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_displayable_manager_of_a_certain_type_for_a_certain_view)).

Note that the model displayable manager already has a [picker](https://apidocs.slicer.org/master/classvtkMRMLModelDisplayableManager.html#a29878f62c281afc9431cc9474f85533b) that you can use and get the ID of the picked display node directly.

---

<div class="post-metadata">

**Author:** ![JaceYang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jaceyang/32/3686_2.png) [@JaceYang](https://discourse.slicer.org/u/JaceYang)\
**Post date:** [November 22, 2019, 9:06am UTC](https://discourse.slicer.org/t/is-there-a-way-to-convert-vtkopenglactor-to-vtkmrmlnode/9239/4 "2019-11-22T09:06:35Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/f/df89eb5f818fa9c57d74ad4aed352dccfd9f74c6.png)  
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?

---

<div class="post-metadata">

**Author:** ![JaceYang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jaceyang/32/3686_2.png) [@JaceYang](https://discourse.slicer.org/u/JaceYang)\
**Post date:** [November 22, 2019, 9:07am UTC](https://discourse.slicer.org/t/is-there-a-way-to-convert-vtkopenglactor-to-vtkmrmlnode/9239/5 "2019-11-22T09:07:54Z")

</div>

thank you very much!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 22, 2019, 2:18pm UTC](https://discourse.slicer.org/t/is-there-a-way-to-convert-vtkopenglactor-to-vtkmrmlnode/9239/6 "2019-11-22T14:18:57Z")

</div>

You can use the segment editor widget’s setCurrentSegmentID method to select a segment as shown in [examples in script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script) (e.g., “mask a volume with segments and compute histogram for each region”). You can get picked segment ID from vtkMRMLSegmentationsDisplayableManager3D.

---

<div class="post-metadata">

**Author:** ![JaceYang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jaceyang/32/3686_2.png) [@JaceYang](https://discourse.slicer.org/u/JaceYang)\
**Post date:** [November 29, 2019, 1:45am UTC](https://discourse.slicer.org/t/is-there-a-way-to-convert-vtkopenglactor-to-vtkmrmlnode/9239/7 "2019-11-29T01:45:48Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/f/7f476e3f417daa6fbebd3e5ffbde73a6e2ddd0aa.png)
