# how to add a tag to an created actor

**URL:** https://discourse.vtk.org/t/how-to-add-a-tag-to-an-created-actor/2998
**Category:** Support
**Created:** [April 9, 2020, 10:08am UTC](https://discourse.vtk.org/t/how-to-add-a-tag-to-an-created-actor/2998 "2020-04-09T10:08:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![xuexl](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/3ec8ea/32.png) [@xuexl](https://discourse.vtk.org/u/xuexl)
#### Post date: [April 9, 2020, 10:08am UTC](https://discourse.vtk.org/t/how-to-add-a-tag-to-an-created-actor/2998/1 "2020-04-09T10:08:33Z")

</div>

using “vtkSphereSource”, I have added some spheres, and i want to delete some of them that clicked.  
so, how to distinguish them from others.  
using “vtkCellPicker”, i can get the actor that clicked, but i need a check that the actor is created by me.  
can i add a tag on the actor when creating it ?  
does anyone have the same needs ?

---

<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: [April 9, 2020, 11:52am UTC](https://discourse.vtk.org/t/how-to-add-a-tag-to-an-created-actor/2998/2 "2020-04-09T11:52:43Z")

</div>

Hi, friend,

You can disable picking on the actors created by the program by calling `PickableOff()` on them.

But if you need to keep them pickable, you can add them, for example, to a `std::map<>` for fast retrieval and query the map in the pick handling code to tell which actors are user-created.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![xuexl](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/x/3ec8ea/32.png) [@xuexl](https://discourse.vtk.org/u/xuexl)
#### Post date: [April 10, 2020, 2:39am UTC](https://discourse.vtk.org/t/how-to-add-a-tag-to-an-created-actor/2998/3 "2020-04-10T02:39:39Z")

</div>

Thanks for your reply.

Usually, adding some little models on the other existing model is needed.  
When i encounter it at first in the vtk of c++, Just like you said, I add them to a map, and it throws some questions, It is my misuse of the “vtkSmartPointer” and the pointer of c++, maybe.

At last, I get the actor, then get the mapper, then get the producer, then check the className, the code like this “_picker-\>GetActor()-\>GetMapper()-\>GetInputConnection(0,0)-\>GetProducer()-\>IsA(“vtkSphereSource”)_” , As a stopgap measure.

I have another idea in the beginning that create myself class from vtkActor when i can add a tag on the class. but it failed.

Now, I develop a web program using vtk of js, I encounter the same question.  
I decide to try the method you said.

---

<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: [April 10, 2020, 11:49am UTC](https://discourse.vtk.org/t/how-to-add-a-tag-to-an-created-actor/2998/4 "2020-04-10T11:49:54Z")

</div>

Ah… subclassing `vtkActor` is a nice idea. But to implement a VTK class you have to comply with VTK bureaucracy:

In the `.h` of your class, you do:

```cpp
#include <vtkObjectFactory.h>

class myActor : public vtkActor
{
public:
    static myActor* New();
    vtkTypeMacro(myActor, vtkActor)

   (...)

};

```

And, in the class’ `.cpp`, you do:

```cpp
(...includes...)

vtkStandardNewMacro(myActor);

(...methods...)

```

By doing this, your custom class is expected to be compatible with VTK framework.

Example of a VTK custom class here: [https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.h](https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.h) and [https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.cpp](https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.cpp).

regards,

Paulo
