[vtkusers] Using Java Threads in VTK

Jarek Sacha jarek at ieee.org
Mon Dec 8 23:14:30 EST 2003


Sunayana Saha wrote:

> I am trying to create a 3D animation tool using VTK in Java. I 
> basically want to iterate through different set of 3D points 
> continuously, until the user decides to stop. If I do this using an 
> infinite 'while' loop, then I lose control over the program and the 
> user can no longer stop the animation unless he totally terminates the 
> program.
>  
> I am thus trying to use a Java Thread to implement the above 
> functionality. I change the points in the 'run()' method of the Thread 
> and then try to render the VTK window. As soon as I do this, I get 
> lots of C++-side errors in a pop-up window. I read a previous post in 
> VTK's mailing list and that says that using Render in the Thread 
> construct method causes this problem. When I comment out the Render 
> statement, I do not get the C++ side errors, but the window is no 
> longer updated to reflect the new set of points.

Not sure what you problem is. You can compare you code to an animation 
the LabeledMesh example translated into Java
http://cvs.sourceforge.net/viewcvs.py/ij-plugins/VTK-Examples/Examples/Annotation/Java/LabeledMesh.java?rev=1.9&view=auto

Pay attention the the very end of the constructor where 
WindowSetObserver is created and the call to 
SwingUtilities.invokeLater() is made.

WindowSetObserver is set to ensure that animation code is executed when 
the VTK window is initialized (displayed for the first time). The 
SwingUtilities.invokeLater() is used to ensure that the animation is 
executed in the AWT dispatch thread.

This and other Java VTK examples are available, as usual, at 
http://ij-plugins.sourceforge.net/vtk-examples/. Coincidently, I just 
posted a new version of the examples, a moment ago :)

Jarek




More information about the vtkusers mailing list