<!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.2800.1141" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<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></BODY></HTML>