# How to Draw on the vtkImageViewer2?

**URL:** https://discourse.vtk.org/t/how-to-draw-on-the-vtkimageviewer2/4529
**Category:** Support
**Created:** [October 30, 2020, 9:00am UTC](https://discourse.vtk.org/t/how-to-draw-on-the-vtkimageviewer2/4529 "2020-10-30T09:00:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wulicheng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wulicheng/32/1990_2.png) [@wulicheng](https://discourse.vtk.org/u/wulicheng)
#### Post date: [October 30, 2020, 9:00am UTC](https://discourse.vtk.org/t/how-to-draw-on-the-vtkimageviewer2/4529/1 "2020-10-30T09:00:33Z")

</div>

I want to draw a polyon on the vtkImageViewer2 and colored it ?

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.vtk.org/u/flaviu2)
#### Post date: [November 3, 2020, 12:25pm UTC](https://discourse.vtk.org/t/how-to-draw-on-the-vtkimageviewer2/4529/2 "2020-11-03T12:25:51Z")

</div>

A good start to see how to draw a polygon can be found here: [https://github.com/Kitware/VTK/blob/8b08cf7a0523d88a5602a98c0456f7e397560698/Common/DataModel/Testing/Cxx/TestPolygon.cxx](https://github.com/Kitware/VTK/blob/8b08cf7a0523d88a5602a98c0456f7e397560698/Common/DataModel/Testing/Cxx/TestPolygon.cxx)

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [November 4, 2020, 7:05pm UTC](https://discourse.vtk.org/t/how-to-draw-on-the-vtkimageviewer2/4529/3 "2020-11-04T19:05:11Z")

</div>

I draw 2d wireframe overlays of 3d geometry in my own program on a slice viewer using vtkImageViewer2.

I do this by using vtkCutter to cut the polygon. If I want to fill it I then use vtkContourTriangulator. Then simply give it to a vtkPolyDataMapper and then to a vtkActor as normal. Lastly add the vtkActor to the renderer of vtkImageViewer2.

The only other trick here is that the polygon should be bumped slightly in front of the image slice plane so that the image doesn’t cover the polygon. I actually do this by just using a cutting plane slightly in front of the actual slice plane.

---

<div class="post-metadata">

### Author: ![wulicheng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wulicheng/32/1990_2.png) [@wulicheng](https://discourse.vtk.org/u/wulicheng)
#### Post date: [November 5, 2020, 11:03am UTC](https://discourse.vtk.org/t/how-to-draw-on-the-vtkimageviewer2/4529/5 "2020-11-05T11:03:18Z")

</div>

yes ,the trick is useful.
