Menu

InitTraversal

Help
aperture3
2006-12-15
2013-04-25
  • aperture3

    aperture3 - 2006-12-15

    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.

     
    • aperture3

      aperture3 - 2006-12-15

      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.

       
    • Andrew Dolgert

      Andrew Dolgert - 2006-12-15

      Did you mean to call GetNextActor() twice per iteration? Each call increments the current actor, so the code skips over half of them. - Drew

       
    • aperture3

      aperture3 - 2006-12-15

      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.

       

Log in to post a comment.