[vtkusers] Removing al actors from a Renderer (I get multipleXYPlots inone renderer)

Nico Vermaas vermaas at astron.nl
Mon Apr 7 02:31:06 EDT 2003


Rob,

Thanks for your reply, one more question about this.

I have my vtkLODActor declared as a member (vtkLODActor* myActor) and I
use AddActor(myActor) in a member function that is called many times
during execution (actually from the event loop).

I would expect actors building up like this, but my VisibleActorCount()
only gives one. But I'm not sure if the 'visible' actors realy represent
*all* the actors in the renderer, so..

Q: is there an actor added to the renderer every time I use AddActor,
or is it overwriting the previous actor when I use the same vtkLODActor
var?

Nico
 

>>>> Robert Belleman <robbel at science.uva.nl> 04/04/03 01:24pm >>>
>Nico,
>
>> I tried this... and I do get the right count that increases every
time
>> I add an actor. But the Removing part  does not work.
>>
>> vtkActorCollection *actors = vtkActorCollection::New();

>Later in your code, you obtain a pointer to the vtkActorCollection
>maintained by the renderer. I.e. do not create your own. Do:
>
> vtkActorCollection *actors = NULL;
>


>> int NumberOfActors = renderer->VisibleActorCount();

You mentioned you want to remove *2D* actors. The code
you have given removes *3D* actors. See the GetActors2D()
and RemoveActor2D() methods in vtkViewport.

> actors=this->renderer->GetActors();

Don't forget to initialize the traversal of the collection:

  actors->InitTraversal();

> for (int i=0; i<NumberOfActors; i++) {
>    this->renderer->RemoveActor(actors->GetNextActor());
> }

That's bascially correct.

> actors->Delete();

As this is not your vtkActorCollection, do not Delete() it.
Just remove that line.

> Q: How do I delete all actors from a renderer?

What you did came close, but removes 3D actors. If you want
to remove 2D actors, also look into the methods I mentioned
above.

-- Rob

--
[] Robert Belleman         X                                          
[]
[] robbel at science.uva.nl  |X| University of Amsterdam, the Netherlands
[]
[] tel: (+31) 20 525 7510  X  http://www.science.uva.nl/~robbel/      
[]






More information about the vtkusers mailing list