how to add a tag to an created actor

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 ?

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

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.

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:

#include <vtkObjectFactory.h>

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

   (...)

};

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

(...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 and https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.cpp.

regards,

Paulo