# How is vtkCursor2D supposed to be used?

**URL:** https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225
**Category:** Support
**Created:** [December 16, 2022, 7:21pm UTC](https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225 "2022-12-16T19:21:11Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [December 16, 2022, 7:21pm UTC](https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225/1 "2022-12-16T19:21:12Z")

</div>

Hello!!

I want to use a cross hair cursor with configurable “aperture” (pick radius) in my app. I found vtkCursor2D and the example, converted the example to Python and ran it. vtkCursor2D gives me the shape I want and I can control the size of the aperture, length of the cross hairs etc.

The vtkCursor2D generates a poly which I can then display just like any other geometry

So far, so good, but then I run out of ideas/info/examples.

How do I actually use the vtkCursor2D or it’s output as a cursor in a render window? I can’t see any obvious way of doing this?

How can I add a custom cursor to a render window?

Thanks,

Doug

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [December 20, 2022, 12:52pm UTC](https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225/2 "2022-12-20T12:52:31Z")

</div>

Hello,

You said the example worked as expected. So you need to give more details of what you want to achieve that is not present in the example. I mean, the example is supposed to have a render window.

best,

Paulo

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [December 20, 2022, 10:52pm UTC](https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225/3 "2022-12-20T22:52:31Z")

</div>

Paulo,

I thought I was quite clear about what I wanted to achieve…

“I want to use a cross hair cursor with configurable “aperture” (pick radius) in my app”

The current demo uses the vtkCursor2D class to generate a PolyData that is displayed on the render window via the usual mapper, actor, renderer just like any other geometry object.

Being able to create and control the shape of a cross hair cursor is good… but actually using that shape as a cursor in a render window would be GREAT. That’s where I’m stick - I can’t find any examples or docs on how to do this.

Edit : To be clear, I’d like to be able to replace the standard arrow “mouse” cursor with a cross hair “mouse” cursor

Thanks,

Doug

---

<div class="post-metadata">

### Author: ![manatee](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@manatee](https://discourse.vtk.org/u/manatee)
#### Post date: [December 21, 2022, 2:47pm UTC](https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225/4 "2022-12-21T14:47:36Z")

</div>

Doug,  
maybe you can create a callback on mouse movement, get the coordinates and change the position of your shape accordingly? You’d have to get rid of the arrow though - don’t know if that’s possible, let alone how to do it.

Best,  
Manatee

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [December 21, 2022, 4:39pm UTC](https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225/5 "2022-12-21T16:39:24Z")

</div>

@Manatee - Yes - I can do that. And add the code to keep the shape the same size and always front facing.  
But even then it’s not really a different mouse cursor - it’s just an object that looks like a mouse cursor that you can drag around…

I’m assuming there is a way to provide custom mouse cursors - I’ll keep digging until I find it. Next stop is to look at the source.

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [December 21, 2022, 4:42pm UTC](https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225/6 "2022-12-21T16:42:07Z")

</div>

By the way, it’s easy enough to use the output from the vtkCursor2D as the representation of a handle widget etc. - maybe that’s what vtkCursor2D is intended for and I’m barking up the wrong tree by trying to use it as a custom mouse cursor

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [December 21, 2022, 5:25pm UTC](https://discourse.vtk.org/t/how-is-vtkcursor2d-supposed-to-be-used/10225/7 "2022-12-21T17:25:10Z")

</div>

OK - I found a test called “TestCustomCursorShape.cxx” which includes the following snippet.  
I’m going to assume I can convert the polydata from vtkCursor2D to whatever format a mouse cursor is defined in and use this approach. Although I’m concerned about a pipeline that includes generating a file and then reading it in to change the cursor in in interactive session since I was planning on using a keyboard gesture to change the aperture and size of the axes on the cursor in a dynamic way - so writing/reading the file tens or hundreds of times in rapid succession may be common.

I’ll try it out and see what happens. If anyone knows a better way, please let me know.

```auto
  renWin->Render();
  renWin->SetCursorFileName(fileName);
  renWin->SetCurrentCursor(VTK_CURSOR_CUSTOM);
  renWin->Render();

```
