I realized that after I had posted it.
I had tried a number of things to test different cases and left that line in by mistake. It didn't matter anyway because it blows up if you pass an empty collection in. My second post is working for me now though. Sorry to bother you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Does anyone have an example of traversing an vtk.vtkActorCollection in the .net wrappers?
I have tried using something like:
void RemoveCollectionFromRenderer(
vtk.vtkRenderer renderer,
vtk.vtkActorCollection actors)
{
while (actors.GetNextActor()!= null)
{
m_renderer.RemoveViewProp(actors.GetNextActor());
}
}
This code fails the first time that GetNextActor() returns null. Is there any other way to traverse a collection?
Thank you for your help.
The following seems to work.
void RemoveCollectionFromRenderer(
vtk.vtkRenderer renderer,
vtk.vtkActorCollection actors)
{
actors.InitTraversal();
for (int count = actors.GetNumberOfItems(); 0 < count; --count)
{
m_renderer.RemoveViewProp(actors.GetNextItem());
}
}
The problem is that one can never make the 'GetNextItem()' call if the next item will be null. In that case an exception is thrown.
Did you mean to call GetNextActor() twice per iteration? Each call increments the current actor, so the code skips over half of them. - Drew
I realized that after I had posted it.
I had tried a number of things to test different cases and left that line in by mistake. It didn't matter anyway because it blows up if you pass an empty collection in. My second post is working for me now though. Sorry to bother you.