Naming vtkActors

I suspect that this question / concern is addressed somewhere in an example (or reference page) that I haven’t found.

I have a number of actors in my program. I would like to be able to set a name or label for them when I create them so that I can distinguish them from each other when I loop over them in a vtkActorCollection (in order to change properties for some of them).

It’s possible I’m not thinking about this correctly. How can I accomplish my goal of knowing which actor is which?

IMO this is headed in the area of application logic. Typically I’ve used a map or hash to create a lookup between the actor’s address/pointer and additional metadata (such as name) that I’d like to associate with the actor. And of course you can create a two-way data structure so you can go from name to address etc.

In VTK 9.2, you can use SetObjectName()/GetObjectName() to label your actors.

If you’re using Python, you can add custom attributes to VTK objects:

a = vtk.vtkActor()
a.name = 'Kevin'

I use C++ and not Python. This is with Vtk 9.1

I see from the vtkActor reference page that vtkActor inherits from vtkObject. However, when I try to use SetObjectName, I receive a compile message that “class vtkActor has no member named SetObject Name”.

e.g.

vtkNew myActor;
myActor->SetObjectName(“AName”);

I have included both vtkObject.h and vtkActor.h in my header file.

Okay. I must be doing something stupid here. Any ideas as to why this fails for me?

As you said, you’re using VTK 9.1. The SetObjectName() method was added in VTK 9.2.

1 Like