# How can I show which actor(arrow) is above which actor on the screen.

**URL:** https://discourse.vtk.org/t/how-can-i-show-which-actor-arrow-is-above-which-actor-on-the-screen/13038
**Category:** Support
**Tags:** python, code
**Created:** [January 9, 2024, 1:06pm UTC](https://discourse.vtk.org/t/how-can-i-show-which-actor-arrow-is-above-which-actor-on-the-screen/13038 "2024-01-09T13:06:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![thecoderMCV](https://discourse.vtk.org/user_avatar/discourse.vtk.org/thecodermcv/32/8347_2.png) [@thecoderMCV](https://discourse.vtk.org/u/thecoderMCV)
#### Post date: [January 9, 2024, 1:06pm UTC](https://discourse.vtk.org/t/how-can-i-show-which-actor-arrow-is-above-which-actor-on-the-screen/13038/1 "2024-01-09T13:06:13Z")

</div>

Something like this:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/b/b8a332607033532cb97160707868862064bebde6.jpeg)

axis is standing on the actor here. But when I do it, it looks like below.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/3/32a80509fcd50f26ff22114b4b3ff45742ebb68e.jpeg)

So I don’t want it to be in it, I want it to be on it.

How can I do this in Python.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [January 9, 2024, 2:39pm UTC](https://discourse.vtk.org/t/how-can-i-show-which-actor-arrow-is-above-which-actor-on-the-screen/13038/2 "2024-01-09T14:39:31Z")

</div>

Hi @thecoderMCV

You want to use layered rendering. Place the arrow actor into another renderer and assign that renderer a layer ID such that 0 \< layerID \< numLayers.

Pseudocode:

```auto
vtkNew<vtkActor> axisActor;
vtkNew<vtkRenderer> axisRenderer;
axisRenderer->AddActor(axisActor);

vtkNew<vtkActor> lionActor;
vtkNew<vtkRenderer> mainRenderer;
mainRenderer->AddActor(lionActor);

vtkNew<vtkRenderWindow> window;
window->AddRenderer(axisRenderer);
window->AddRenderer(mainRenderer);

// Now, configure axisRenderer as an overlay.
// vtkRenderWindow uses the term 'layer' to mean a renderer
// in a collection of renderers stacked above one another.
// A layer with index 0 is the farthest from the screen and
// the index 'numLayers - 1' is at the front. Layers are always rendered
// from back to front.
window->SetNumberOfLayers(2); // as many as you need, just don't go beyond 100.
axisRenderer->SetLayer(1); // 0 is reserved for the base layer.
axisRenderer->EraseOff(); // so that the stuff behind the axis renderer is visible.

```

I’m not entirely sure interactor events would just work, let us know if it doesn’t.

You can learn more about layers from the C++ API docs for [vtkRenderWindow](https://vtk.org/doc/nightly/html/classvtkRenderWindow.html) and [vtkRenderer](https://vtk.org/doc/nightly/html/classvtkRenderer.html).

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 14, 2024, 3:18am UTC](https://discourse.vtk.org/t/how-can-i-show-which-actor-arrow-is-above-which-actor-on-the-screen/13038/3 "2024-01-14T03:18:25Z")

</div>

This example may also give you some ideas: [TransparentBackground](https://examples.vtk.org/site/Python/Rendering/TransparentBackground/) - here you can move the cone and cube independently of each other just by selecting the layer corresponding to the object. However the cone always stays in layer 1 and the cube always stays in layer 0. Note that any layer greater than 0 will have a transparent background.

In your case the axis actor could be substituted for the cone and the lion for the cube.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 14, 2024, 4:11am UTC](https://discourse.vtk.org/t/how-can-i-show-which-actor-arrow-is-above-which-actor-on-the-screen/13038/4 "2024-01-14T04:11:19Z")

</div>

Replace the cone actor with something like this:

```Python

from vtkmodules.vtkCommonTransforms import vtkTransform
from vtkmodules.vtkRenderingAnnotation import vtkAxesActor

...

    transform = vtkTransform()
    transform.Translate(0.0, 0.0, 0.0)

    axes = vtkAxesActor()
    # The axes are positioned with a user transform
    axes.SetUserTransform(transform)

```

The fun bit now will be setting up an interactor event so that if the axis actor is moved then the cube should also move.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 14, 2024, 5:26am UTC](https://discourse.vtk.org/t/how-can-i-show-which-actor-arrow-is-above-which-actor-on-the-screen/13038/5 "2024-01-14T05:26:34Z")

</div>

Ok here is my attempt, it assumes that layer 1 is the active layer:  
[LayeredActor.py](https://discourse.vtk.org/uploads/short-url/flaunfrF0pnp7qPA8nldGppXrQD.py) (5.3 KB)

I’ll probably add it to the VTK examples along with a C++ version.
