# vtk paintbrush (segmentation)

**URL:** https://discourse.vtk.org/t/vtk-paintbrush-segmentation/298
**Category:** Support
**Created:** [February 19, 2019, 5:11pm UTC](https://discourse.vtk.org/t/vtk-paintbrush-segmentation/298 "2019-02-19T17:11:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mikewho](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@mikewho](https://discourse.vtk.org/u/mikewho)
#### Post date: [February 19, 2019, 5:11pm UTC](https://discourse.vtk.org/t/vtk-paintbrush-segmentation/298/1 "2019-02-19T17:11:03Z")

</div>

At one point there was a vtkedge library that had some paintbrush functionality. Supposedly that has been absorbed by vtk, but I can’t seem to find any paintbrush options in vtk. Is there a recommended way to go about changing a vtkImageData using a circular brush? Thanks.

---

<div class="post-metadata">

### Author: ![Harry](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@Harry](https://discourse.vtk.org/u/Harry)
#### Post date: [February 19, 2019, 6:07pm UTC](https://discourse.vtk.org/t/vtk-paintbrush-segmentation/298/2 "2019-02-19T18:07:16Z")

</div>

I’m working on that now in the context of medical contouring/segmentation!  
Currently I create a custom InteractorStyle class inheriting from vtkInteractorStyleImage. I then override OnMouseMove(), OnLeftButtonDown() and OnLeftButtonUp(). I use a vtkCellPicker to get the world coordinates of the click, then vtkRegularPolygonSource to create a circle centered at the click coordinates. I boolean add these circles together as I’m drawing to get the final contour. I’m not sure if this is at all a good way to do it, but it’s been working for me!

---

<div class="post-metadata">

### Author: ![mikewho](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@mikewho](https://discourse.vtk.org/u/mikewho)
#### Post date: [February 19, 2019, 6:48pm UTC](https://discourse.vtk.org/t/vtk-paintbrush-segmentation/298/3 "2019-02-19T18:48:27Z")

</div>

Thanks, I’m doing something similar now, except modifying the vtkImageData pixels directly rather than creating a vtkRegularPolygonSource. It felt a bit clunky, but I guess this is the proper approach for the moment.

---

<div class="post-metadata">

### Author: ![Andrzej\_Marciniak](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrzej_marciniak/32/259_2.png) [@Andrzej\_Marciniak](https://discourse.vtk.org/u/Andrzej_Marciniak)
#### Post date: [April 1, 2019, 8:39pm UTC](https://discourse.vtk.org/t/vtk-paintbrush-segmentation/298/4 "2019-04-01T20:39:31Z")

</div>

Hi, I am using very similar solution (I just modify vtkImageData) but I have problem with interactions. How do you manage handling events for drawing. I would like to have drawing when left mouse button is pressed and mouse is moving. Is there a combination of mousemove and handleLeftButtonPress) I could use in?. What do you use?

I tried to use PantFilter and PaintWidget, but this was overwriting my all handlers.

---

<div class="post-metadata">

### Author: ![Harry](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@Harry](https://discourse.vtk.org/u/Harry)
#### Post date: [April 1, 2019, 9:00pm UTC](https://discourse.vtk.org/t/vtk-paintbrush-segmentation/298/5 "2019-04-01T21:00:54Z")

</div>

I set the interactor of my plane renderer class to my custom interactor, inheriting from vtkInteractorStyle.  
Within that interactor I override OnMouseMove(), OnLeftButtonDown() and OnLeftButtonUp().  
I do not use PaintWidget at all.

---

<div class="post-metadata">

### Author: ![Andrzej\_Marciniak](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrzej_marciniak/32/259_2.png) [@Andrzej\_Marciniak](https://discourse.vtk.org/u/Andrzej_Marciniak)
#### Post date: [April 1, 2019, 9:05pm UTC](https://discourse.vtk.org/t/vtk-paintbrush-segmentation/298/6 "2019-04-01T21:05:27Z")

</div>

Thanks, I will use the same.
