# How to create and manipulate stuff in vtkContext2D

**URL:** https://discourse.vtk.org/t/how-to-create-and-manipulate-stuff-in-vtkcontext2d/4037
**Category:** Support
**Created:** [August 21, 2020, 9:23am UTC](https://discourse.vtk.org/t/how-to-create-and-manipulate-stuff-in-vtkcontext2d/4037 "2020-08-21T09:23:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![alejandronespereira](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@alejandronespereira](https://discourse.vtk.org/u/alejandronespereira)
#### Post date: [August 21, 2020, 9:23am UTC](https://discourse.vtk.org/t/how-to-create-and-manipulate-stuff-in-vtkcontext2d/4037/1 "2020-08-21T09:23:24Z")

</div>

I am drawing a 3D scene and some 2D slices of the scene on separate windows. If I try to render the full scene into a vectorized image with vtkExporterGL2PS, the output comes with invalid utf-8 characters that break the xml of the .svg files. The 2D slices, however, are properly rendered, but I am using VTK 6.3 and I’ve read that porting 3D things won’t be available in future versions, requiring a vtkcontext2D. To do the trick.

I’ve been unable to find any guide or example on the vtkDocumentation about how to use it, and I have some questions.

I guess that porting a 3D scene into a 2D context is out of the question, but how can I draw simple shapes in a context2D ?

---

<div class="post-metadata">

### Author: ![scottwittenburg](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scottwittenburg/32/5654_2.png) [@scottwittenburg](https://discourse.vtk.org/u/scottwittenburg)
#### Post date: [August 21, 2020, 3:56pm UTC](https://discourse.vtk.org/t/how-to-create-and-manipulate-stuff-in-vtkcontext2d/4037/2 "2020-08-21T15:56:05Z")

</div>

Hi Alejandro,

I also had a hard time figuring out how to make use of this part of VTK api. One place to get started is to look through the tests in Rendering/Context2D/Testing/, where you’ll find some Python and C++ tests exercising some of the api. To draw simple shapes, I think the best (maybe only?) approach is to define a new subclass of vtkContextItem and override the Paint method, which receives as argument a pointer to a vtkContext2D object you can use to draw all kinds of primitives, see the documentation of the vtkContext2D class here [1]. See Rendering/Context2D/Testing/Cxx/TestContext2D.cxx for a simple example of that approach.

Hope this helps.

Cheers,  
Scott

[1] [https://vtk.org/doc/nightly/html/classvtkContext2D.html](https://vtk.org/doc/nightly/html/classvtkContext2D.html)

---

<div class="post-metadata">

### Author: ![alejandronespereira](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@alejandronespereira](https://discourse.vtk.org/u/alejandronespereira)
#### Post date: [August 21, 2020, 3:59pm UTC](https://discourse.vtk.org/t/how-to-create-and-manipulate-stuff-in-vtkcontext2d/4037/3 "2020-08-21T15:59:04Z")

</div>

Thanks! I’ll look into those
