<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>RE: [vtkusers] Java -how to remove an actor from a vtkpanel? </TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>
<P><FONT SIZE=2>Hello,<BR>
<BR>
Hmmm I didnīt have any problems doing the following in my app:<BR>
<BR>
renWin.GetRenderer().RemoveActor(aActor);<BR>
renWin.GetRenderer().ResetCamera();<BR>
renWin.GetRenderer().AddActor(aActor);<BR>
renWin.GetRenderer().ResetCamera();<BR>
<BR>
but renWin is a vtkCanvas rather than a vtkPanel.<BR>
<BR>
so try using ResetCamera rather than rePaint(). You could also<BR>
try an Update somewhere but for me going through java that<BR>
would sometimes crash the jvm.<BR>
<BR>
Also if you have 0 actors in the scene then no rendering is<BR>
done.<BR>
<BR>
bye,<BR>
<BR>
Henrik<BR>
<BR>
-----Original Message-----<BR>
From: vtkusers-bounces+henrik.westerberg=crg.es@vtk.org on behalf of Stephen<BR>
Sent: Wed 8/15/2007 11:18 PM<BR>
Cc: vtkusers@vtk.org<BR>
Subject: [vtkusers] Java -how to remove an actor from a vtkpanel?<BR>
<BR>
Dear all.<BR>
<BR>
Please see the code below. I am trying to add/remove actors to a<BR>
vtkpanel. I find that although the number actors will<BR>
increment/decrement, the view will not refresh unless I bring another<BR>
window in front of it?<BR>
<BR>
I feel I must be doing something silly, I hope someone can point me in<BR>
the right direction, so far I have not found any resources to illustrate<BR>
actor removal in Java.<BR>
<BR>
many thanks<BR>
<BR>
Stephen<BR>
<BR>
import java.awt.*;<BR>
import java.awt.event.*;<BR>
import javax.swing.*;<BR>
import vtk.*;<BR>
<BR>
<BR>
public class TestAddRemoveActor extends JPanel implements ActionListener {<BR>
<BR>
static JFrame frame;<BR>
vtkPanel renWin;<BR>
JButton removeActors;<BR>
JButton addActors;<BR>
<BR>
vtkActor coneActor = new vtkActor();<BR>
<BR>
static {<BR>
System.loadLibrary("vtkCommonJava");<BR>
System.loadLibrary("vtkRenderingJava");<BR>
}<BR>
<BR>
public TestAddRemoveActor() {<BR>
setLayout(new BorderLayout());<BR>
<BR>
renWin = new vtkPanel();<BR>
vtkConeSource cone = new vtkConeSource();<BR>
cone.SetResolution(60);<BR>
vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();<BR>
coneMapper.SetInput(cone.GetOutput());<BR>
<BR>
coneActor.SetMapper(coneMapper);<BR>
<BR>
renWin.GetRenderer().AddActor(coneActor);<BR>
<BR>
removeActors = new JButton("Remove");<BR>
removeActors.addActionListener(this);<BR>
<BR>
addActors = new JButton("Add actor");<BR>
addActors.addActionListener( this );<BR>
<BR>
add(renWin, BorderLayout.CENTER);<BR>
add(removeActors, BorderLayout.NORTH);<BR>
add(addActors, BorderLayout.SOUTH);<BR>
}<BR>
<BR>
<BR>
public void actionPerformed(ActionEvent e)<BR>
{<BR>
if (e.getSource().equals(addActors)){<BR>
renWin.GetRenderer().Clear();<BR>
vtkConeSource cone = new vtkConeSource();<BR>
cone.SetResolution(60);<BR>
vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();<BR>
coneMapper.SetInput(cone.GetOutput());<BR>
coneActor = new vtkActor();<BR>
coneActor.SetMapper(coneMapper);<BR>
renWin.repaint();<BR>
renWin.GetRenderer().AddActor(coneActor);<BR>
System.out.println(<BR>
renWin.GetRenderer().GetActors().GetNumberOfItems() );<BR>
}else{<BR>
renWin.GetRenderer().RemoveActor( coneActor );<BR>
renWin.repaint(); <BR>
System.out.println(<BR>
renWin.GetRenderer().GetActors().GetNumberOfItems() );<BR>
}<BR>
}<BR>
<BR>
<BR>
public static void main(String s[])<BR>
{<BR>
TestAddRemoveActor panel = new TestAddRemoveActor();<BR>
<BR>
frame = new JFrame("TestMemoryLeak");<BR>
frame.addWindowListener(new WindowAdapter()<BR>
{<BR>
public void windowClosing(WindowEvent e) {System.exit(0);}<BR>
});<BR>
frame.getContentPane().add("Center", panel);<BR>
frame.pack();<BR>
frame.setVisible(true);<BR>
}<BR>
}<BR>
<BR>
_______________________________________________<BR>
This is the private VTK discussion list.<BR>
Please keep messages on-topic. Check the FAQ at: <A HREF="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</A><BR>
Follow this link to subscribe/unsubscribe:<BR>
<A HREF="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</A><BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>