[vtkusers] Java -how to remove an actor from a vtkpanel?

Henrik Westerberg henrik.westerberg at crg.es
Thu Aug 16 08:37:39 EDT 2007


Hello,

Hmmm I didn´t have any problems doing the following in my app:

renWin.GetRenderer().RemoveActor(aActor);
renWin.GetRenderer().ResetCamera();
renWin.GetRenderer().AddActor(aActor);
renWin.GetRenderer().ResetCamera();

but renWin is a vtkCanvas rather than a vtkPanel.

so try using ResetCamera rather than rePaint(). You could also
try an Update somewhere but for me going through java that 
would sometimes crash the jvm.

Also if you have 0 actors in the scene then no rendering is
done.

bye,

Henrik

-----Original Message-----
From: vtkusers-bounces+henrik.westerberg=crg.es at vtk.org on behalf of Stephen
Sent: Wed 8/15/2007 11:18 PM
Cc: vtkusers at vtk.org
Subject: [vtkusers] Java -how to remove an actor from a vtkpanel? 
 
Dear all.

Please see the code below. I am trying to add/remove actors to a 
vtkpanel. I find that although the number actors will 
increment/decrement, the view will not refresh unless I bring another 
window in front of it?

I feel I must be doing something silly, I hope someone can point me in 
the right direction, so far I have not found any resources to illustrate 
actor removal in Java.

many thanks

Stephen

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import vtk.*;


public class TestAddRemoveActor extends JPanel implements ActionListener {

     static JFrame frame;
     vtkPanel renWin;
     JButton removeActors;
     JButton addActors;

     vtkActor coneActor = new vtkActor();

     static {
         System.loadLibrary("vtkCommonJava");
         System.loadLibrary("vtkRenderingJava");
     }

   public TestAddRemoveActor() {
     setLayout(new BorderLayout());

       renWin = new vtkPanel();
       vtkConeSource cone = new vtkConeSource();
       cone.SetResolution(60);
       vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();
       coneMapper.SetInput(cone.GetOutput());

       coneActor.SetMapper(coneMapper);

       renWin.GetRenderer().AddActor(coneActor);

       removeActors = new JButton("Remove");
       removeActors.addActionListener(this);
    
       addActors    = new JButton("Add actor");
       addActors.addActionListener( this );

       add(renWin, BorderLayout.CENTER);
       add(removeActors, BorderLayout.NORTH);
       add(addActors, BorderLayout.SOUTH);
   }


     public void actionPerformed(ActionEvent e)
     {
         if (e.getSource().equals(addActors)){
             renWin.GetRenderer().Clear();
             vtkConeSource cone = new vtkConeSource();
             cone.SetResolution(60);
             vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();
             coneMapper.SetInput(cone.GetOutput());
             coneActor = new vtkActor();
             coneActor.SetMapper(coneMapper);
             renWin.repaint();
             renWin.GetRenderer().AddActor(coneActor);
             System.out.println( 
renWin.GetRenderer().GetActors().GetNumberOfItems() );
        }else{
             renWin.GetRenderer().RemoveActor( coneActor );
             renWin.repaint();                
             System.out.println( 
renWin.GetRenderer().GetActors().GetNumberOfItems() );
         }
     }
    

   public static void main(String s[])
   {
        TestAddRemoveActor panel = new TestAddRemoveActor();

        frame = new JFrame("TestMemoryLeak");
        frame.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
        frame.getContentPane().add("Center", panel);
        frame.pack();
        frame.setVisible(true);
    }
}

_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070816/ff830deb/attachment.htm>


More information about the vtkusers mailing list