[vtkusers] A minor question

N Smethurst nick.smethurst at free.fr
Wed Oct 29 14:27:02 EST 2003


Le Mercredi 29 Octobre 2003 19:46, Luke Hua a écrit :
> Say I am going to draw multiple actors( the number of actors is decided at
> run time), it seems I can't define an actors array. Can I use a for loop
> and after Addactor() call delete the old one and redefine a new one using
> the same name?

Remember that the pointer variable is a separate entity to the actual object. 
You can assign it to point at any other actor whenever you want (hence the 
potential for memory leaks!).

You could store the pointers in a vtkActorCollection.

vtkActorCollection * actorCollection = vtkActorCollection::New();
vtkActor * actor;
int m;
for (m=0; m<n; m++) {
    actor = vtkActor::New();
    actorCollection->addItem(actor);
    actor->Delete(); // Reduce ref count.
}

or if you add the actors to a renderer straight away, it has its own internal 
collection.

vtkRenderer  * renderer = vtkRenderer::New();
vtkActor * actor;
int m;
for (m=0; m<n; m++) {
    actor = vtkActor::New();
    renderer->addProp(actor);
    actor->Delete(); // Reduce ref count.

    // Connect actor to mapper..
}




More information about the vtkusers mailing list