<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=004105903-18072003><FONT face=Arial color=#0000ff
size=2>Greg,</FONT></SPAN></DIV>
<DIV><SPAN
class=004105903-18072003>
<FONT face=Arial color=#0000ff size=2>Looks like you are doing GUI updates or
calling Render() in the construct() method of SwingWorker thread. This is a
possible cause of problem. save all this for finished() method of
SwingWorker</FONT></SPAN></DIV>
<DIV><SPAN class=004105903-18072003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=004105903-18072003> <FONT face=Arial
color=#0000ff size=2>Let me know if I am not clear</FONT></SPAN></DIV>
<DIV><SPAN class=004105903-18072003><FONT face=Arial color=#0000ff
size=2>--Shyam</FONT></SPAN></DIV>
<DIV><SPAN class=004105903-18072003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> vtkusers-admin@vtk.org
[mailto:vtkusers-admin@vtk.org]<B>On Behalf Of </B>Greg Scott<BR><B>Sent:</B>
Friday, July 18, 2003 3:26 AM<BR><B>To:</B>
vtkusers@vtk.org<BR><B>Subject:</B> [vtkusers] Getting Java threads and VTK to
work: how to avoid the event-handling thread?<BR><BR></FONT></DIV>
<DIV><FONT face=Arial size=2>Hi, I've found some 'interesting' behaviour
involving Java and C++ VTK usage.</FONT></DIV>
<DIV><FONT face=Arial size=2>My program performs the following
steps:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>1. In Java, create a vtkPanel with a particular
actor (a cube, say), then,</FONT></DIV>
<DIV><FONT face=Arial size=2>2. When the user clicks on a Swing button,
</FONT></DIV>
<DIV><FONT face=Arial size=2>3. The renderer and renderwindow belonging to the
vtkPanel are passed to some native C++ code, which</FONT></DIV>
<DIV><FONT face=Arial size=2>4. Does some C++ VTK processing involving the
renderer and window which would take too long in Java,</FONT></DIV>
<DIV><FONT face=Arial size=2>and using GetPixelData etc.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Now, the program works fine if the code required
for 3 and 4 occurs in the event-handling thread for 2., that is:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>JButton jMyButton = ....</FONT></DIV>
<DIV><FONT face=Arial size=2>jMyButton.addActionListener(new ActionListener()
{</FONT></DIV>
<DIV><FONT face=Arial size=2>
public void actionPerformed(...) {</FONT></DIV>
<DIV><FONT face=Arial size=2>
</FONT></DIV>
<DIV><FONT face=Arial size=2>
// Code for 3. here, which calls the C++
code to do step 4.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>
}});</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>HOWEVER, the big disadvantage in this is that the
whole GUI locks up since the processor-intensive C++ code executes in the
event-handling code, so the GUI is not redrawn; in effect it freezes until
stage 4. returns. It would be better to spawn a new thread to do 3 (and
4).</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>But, when start a new thread to execute 3
and 4 (i.e. a SwingWorker), I get lots of C++-side errors in a pop-up
window.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Please, does anyone know (a) why this is, and (b)
how to get around it?</FONT></DIV>
<DIV><FONT face=Arial size=2>Many thanks for any suggestions.</FONT></DIV>
<DIV><FONT face=Arial size=2>Greg</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BLOCKQUOTE></BODY></HTML>