# Adding medical tools in segment editor and perform erase effect!

**URL:** <https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [May 5, 2021, 3:37pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474 "2021-05-05T15:37:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raj\_Kumar\_Ranabhat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raj_kumar_ranabhat/32/9857_2.png) [@Raj\_Kumar\_Ranabhat](https://discourse.slicer.org/u/Raj_Kumar_Ranabhat)\
**Post date:** [May 5, 2021, 3:37pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/1 "2021-05-05T15:37:00Z")

</div>

Hi Experts,

In our project, instead of sphere brush (default), we would like to import our own medical tools (obj) file and make an erase effect on 3D model from that medical tool. What will be the fastest and convenient way to do so.

Please provide some guidance .

Thank you.

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar\_Ranabhat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raj_kumar_ranabhat/32/9857_2.png) [@Raj\_Kumar\_Ranabhat](https://discourse.slicer.org/u/Raj_Kumar_Ranabhat)\
**Post date:** [May 10, 2021, 1:44pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/2 "2021-05-10T13:44:24Z")

</div>

@lassoan, By the way, we already have Virtual Reality version for this simulator, we would like to implement it also in the PC version. My current plan is to load the obj file (medical tool) and transform it to the sphere tool of the segment editor.

Secondly,  
Is the link primary source code which is controlling paint and erase effect of 3D Slicer ?

> <https://github.com/Slicer/Slicer/blob/0daa3b92680706c1e98b6585a676545f41c0b8a2/Modules/Scripted/EditorLib/PaintEffect.py>

Please feel free to write.

Thank you,

Sincerely  
Raj

---

<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:** [May 11, 2021, 5:25am UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/3 "2021-05-11T05:25:51Z")

</div>

Segment Editor is not ideal for real-time simulation of drilling. For real-time volume removal, you are probably better off using volume rendering for 3D display and blanking out parts of the volume by combining your tool volume (rasterized volume of the tool model) with the displayed volume. This should be all doable in Python and since you can do everything with numpy array operations, it should be very fast.

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar\_Ranabhat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raj_kumar_ranabhat/32/9857_2.png) [@Raj\_Kumar\_Ranabhat](https://discourse.slicer.org/u/Raj_Kumar_Ranabhat)\
**Post date:** [May 11, 2021, 3:00pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/4 "2021-05-11T15:00:54Z")

</div>

Hi @lassoan , thank you for reply. Actually our spine models are built/resected with uploading patient specific MR/CT scans and using Segment Editor module.

Yes for our Virtual Reality system there is huge latency during the resection and we tried to use volume rendering technique instead of using closed surface representation. The study is still going on.

In addition with VR simulation, we do have regular PC version simulation, right now we are just using 3D sphere or scissor effect for resection. Though it doesn’t look real time but is acceptable for training purpose.

**Our plan is instead of using 3d sphere or brush for erase effect, we planned to import medical tools like burr/ Kerrison as obj file and make a erase effect.**

([Slicer/PaintEffect.py at 0daa3b92680706c1e98b6585a676545f41c0b8a2 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/blob/0daa3b92680706c1e98b6585a676545f41c0b8a2/Modules/Scripted/EditorLib/PaintEffect.py))

I was trying modify and use the painteffect.py code from github but it seems there is no any effects of this code in the paint/erase in 3d slicer.

Please suggest for our approach.

Thank you !!!

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar\_Ranabhat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raj_kumar_ranabhat/32/9857_2.png) [@Raj\_Kumar\_Ranabhat](https://discourse.slicer.org/u/Raj_Kumar_Ranabhat)\
**Post date:** [May 19, 2021, 2:30pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/5 "2021-05-19T14:30:46Z")

</div>

Hi @lassoan , @pieper , @muratmaga ,

Any suggestions, How can I use 3D obj file model as a brush in erase effect instead of 3D sphere.

Thank you !!

Sincerely,  
Raj

---

<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:** [May 19, 2021, 2:35pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/6 "2021-05-19T14:35:54Z")

</div>

You can apply a transform to your 3D model, import it into the segmentation, and erase from another segment using Logical operators effect. You can find examples for each of these steps in the [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#segmentations).

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar\_Ranabhat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raj_kumar_ranabhat/32/9857_2.png) [@Raj\_Kumar\_Ranabhat](https://discourse.slicer.org/u/Raj_Kumar_Ranabhat)\
**Post date:** [May 19, 2021, 2:46pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/7 "2021-05-19T14:46:34Z")

</div>

Hi @lassoan

Thank you for the suggestions. Only one thing, I got stuck is how to get the node of the 3D sphere being used in paint/erase effect before apply transform to imported 3D model.

Thank you

---

<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:** [May 19, 2021, 3:23pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/8 "2021-05-19T15:23:13Z")

</div>

See this example for importing a loading a 3D model and importing it into segmentation: [https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#rasterize-a-model-and-save-it-to-a-series-of-image-files](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#rasterize-a-model-and-save-it-to-a-series-of-image-files)

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar\_Ranabhat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raj_kumar_ranabhat/32/9857_2.png) [@Raj\_Kumar\_Ranabhat](https://discourse.slicer.org/u/Raj_Kumar_Ranabhat)\
**Post date:** [May 19, 2021, 4:47pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/9 "2021-05-19T16:47:37Z")

</div>

Hi @lassoan , Thank you for the scripts.

Last question, I am still struggling . In segment Editor 3D sphere brush is used for paint/erase effect. How can I access that 3D sphere Brush node so that I can transform my loaded obj to that model node.

Thank you

---

<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:** [May 19, 2021, 4:57pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/10 "2021-05-19T16:57:02Z")

</div>

You can use Logical operators effect to modify (paint or erase) another segment using your imported segment.

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar\_Ranabhat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raj_kumar_ranabhat/32/9857_2.png) [@Raj\_Kumar\_Ranabhat](https://discourse.slicer.org/u/Raj_Kumar_Ranabhat)\
**Post date:** [May 19, 2021, 5:10pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/11 "2021-05-19T17:10:05Z")

</div>

Thank you @lassoan ,

But there should be user-interactions with mouse to the imported model during erase as available in current paint effect .

---

<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:** [May 19, 2021, 5:21pm UTC](https://discourse.slicer.org/t/adding-medical-tools-in-segment-editor-and-perform-erase-effect/17474/12 "2021-05-19T17:21:10Z")

</div>

You can implement custom user interactions in your module (add observers to mouse events, etc. or create custom effect, using qSlicerSegmentEditorPaintEffect as base class and customizing the updateBrushModel method). I would not recommend doing this, though. Displaying the bone using volume rendering and blanking out regions that are being removed results in much higher quality rendering and a magnitude higher frame rate.
