# Relationship between SegmentEditorWidget and SegmentEditorNode?

**URL:** <https://discourse.slicer.org/t/relationship-between-segmenteditorwidget-and-segmenteditornode/5304>\
**Category:** Development\
**Created:** [January 7, 2019, 9:26pm UTC](https://discourse.slicer.org/t/relationship-between-segmenteditorwidget-and-segmenteditornode/5304 "2019-01-07T21:26:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [January 7, 2019, 9:26pm UTC](https://discourse.slicer.org/t/relationship-between-segmenteditorwidget-and-segmenteditornode/5304/1 "2019-01-07T21:26:39Z")

</div>

I am working on a set of custom extensions, and I have been able to muddle through to get several things working, but I am now running into problems and having trouble debugging. I think my problem may be related to not understanding the relationship between a segmentEditorWidget and a segmentEditorNode. For example, in my code I create a segmentEditorWidget and a segmentEditorNode, add them to the mrmlScene, and try to link them together:

```
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(newSegmentationNode) # This doesn't seem to link the widget to the new segmentation node, it still seems to link to an older, pre-existing segmentation node

segmentEditorWidget.setMRMLScene(slicer.mrmlScene) 
# Not sure if I should do this:
segmentEditorWidget.setMasterVolumeNode(volumeNode)
# or this:
segmentEditorNode.SetAndObserveMasterVolumeNode(volumeNode)

segmentEditorNode.SetAndObserveSegmentationNode(newSegmentationNode) # this line does seem to successfully link to the new segmentation node

```

I’m not sure how to properly understand the relationship between the widget and the node. If I change something in one of them, when is that reflected in the other, and when is it not? For my purposes, I want to start from an existing segmentation, make a copy of it, and then make several modifications to the new, copied segmentation. Can I get by without using a widget at all, since I never need to interact with it graphically? If so, how can I do the equivalent of segmentEditorWidget.setActiveEffectByName() and effect = segmentEditorWidget.activeEffect()? I am aware of the documentation at [apidocs.slicer.org](http://apidocs.slicer.org) and find it helpful sometimes, but it never contains anything like a readable explanation of the logical structure of things, just a few word notes (if I am lucky!).

For example, at [https://apidocs.slicer.org/master/classvtkMRMLSegmentEditorNode.html](https://apidocs.slicer.org/master/classvtkMRMLSegmentEditorNode.html), I see that there is a function SetActiveEffectName(), but it isn’t clear to me whether that function means I am assigning a name to an active effect or selecting a name. It allows me to use any string as an argument, even one which does not correspond to any of the set of possible active effects, which makes me worried that I am not selecting an effect but rather creating a name for an effect, but it could easily be that there just isn’t any error checking to make sure that the effect name I supply actually corresponds to an effect. I don’t see anything in the documentation which would help me figure out which of those is happening. I am a relatively novice python programmer and worse than novice C++ programmer, so when things get down to the C++ code, looking at the source code is only sometimes helpful and is entirely lacking in nuance for me.

Is there any reference which outlines the basic programming design for slicer and/or vtk? I mean something which might say something like “display nodes hold parameters related to the 2D and 3D display of segmentations. For a given segmentation node, it’s display node can be accessed through segmentationNode.GetDisplayNode()” or simple explanations like that. Thanks for any help you can provide.

---

<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:** [January 8, 2019, 4:03am UTC](https://discourse.slicer.org/t/relationship-between-segmenteditorwidget-and-segmenteditornode/5304/2 "2019-01-08T04:03:27Z")

</div>

_slicer.qMRMLSegmentEditorWidget_ is a GUI widget. _slicer.vtkMRMLSegmentEditorNode_ is a MRML node.

[These slides](https://github.com/PerkLab/PerkLabBootcamp/raw/master/Doc/day3_2_SlicerProgramming.pptx) should answer your questions.

> [@mikebind](#):
>
> there is a function SetActiveEffectName(), but it isn’t clear to me whether that function means I am assigning a name to an active effect or selecting a name

It activates an effect.

There are many examples (short code snippets and full segmentation workflows) available in the script repository: [Documentation/Nightly/ScriptRepository - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Segmentations)

Feel free to ask if you cannot find the answer to any of your questions.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [January 8, 2019, 9:18pm UTC](https://discourse.slicer.org/t/relationship-between-segmenteditorwidget-and-segmenteditornode/5304/3 "2019-01-08T21:18:08Z")

</div>

Thanks, those slides are very helpful and will help organize my thinking about how to properly structure and use modules.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 9, 2019, 12:54am UTC](https://discourse.slicer.org/t/relationship-between-segmenteditorwidget-and-segmenteditornode/5304/4 "2019-01-09T00:54:17Z")

</div>

Agreed. Why don’t we link them directly from here:

[https://www.slicer.org/wiki/Documentation/4.10/Training#Tutorials\_for\_software\_developers](https://www.slicer.org/wiki/Documentation/4.10/Training#Tutorials_for_software_developers)

---

<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:** [January 9, 2019, 1:07am UTC](https://discourse.slicer.org/t/relationship-between-segmenteditorwidget-and-segmenteditornode/5304/5 "2019-01-09T01:07:32Z")

</div>

It was already added to nightly version, but now I’ve added it to 4.10, too.
