[vtkusers] A question
Wiebke Timm
wiebke.timm at uni-bielefeld.de
Tue Mar 9 04:31:14 EST 2004
Hi!
On 08.03.2004, at 21:19, Luke Hua wrote:
> Is there any way to retrieve actor by ID or properties? My renderer
> has various kind of actors and I need to delete and add them
> dynamically. It's very difficult to track the position of actors using
> Initialtraversal().
>
> There is no return values for addActor(). Could vtk make some changes
> so that the addActor() can return a ID for each actor therefore easier
> to retrieve actors?
>
> Or there is any other way to retrieve actors?
You can extend vtkActor to have an ID. Did that and it works
flawlessly. Just use the extended vtkActor instead of the original.
When your picker/renderer returns an actor you can get the ID easily.
If you don't want to set that ID yourself you can add a static variable
that "counts" actors, i.e. it has to be incremented inside the New()
method, then set the ID accordingly.
vtkMyActor.h looks like this:
#ifndef MYACT_H
#define MYACT_H
#include <vtkActor.h>
class vtkMyActor : public vtkActor {
public:
int GetID();
void SetID(int id);
static vtkMyActor* New();
void Delete();
private:
int id; // id of this glyph's actor
};
#endif
vtkMyActor.cc looks like this:
#include "vtkMyActor.h"
vtkMyActor* vtkMyActor::New() {
vtkActor::New();
}
void vtkMyActor::Delete() {
vtkActor::Delete();
}
int vtkMyActor::GetID() {
return this->id;
}
void vtkMyActor::SetID(int id) {
this->id = id;
}
Hope that helps...
Ciao!
Wiebke
More information about the vtkusers
mailing list