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

Something like this:

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

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

How can I do this in Python.

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:

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 and vtkRenderer.

2 Likes

This example may also give you some ideas: 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.

1 Like

Replace the cone actor with something like this:


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.

1 Like

Ok here is my attempt, it assumes that layer 1 is the active layer:
LayeredActor.py (5.3 KB)

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

2 Likes