|
|
Technical hints for Java/Java3D programming and optimisation
In your eScience project reports, we ask you to record some "technical tips"
(or "hints") which can be useful for other students. Some of these are
summarised here; others are tips that Henry has picked up.
Before you start your programming, you should review
the tips you have been given on Java/Java3D optimisation in your
Computer Graphics course and elsewhere. A good book is "Java
Performance Tuning" by Shirazi. Also, if you have been given another
eScience student's software as a starting point then you should find
many hints by just reading it carefully.
Note: No responsibility is taken for the accuracy of these
hints. Please email Henry if they are wrong!
- Java memory size; Usually 64Meg; change using java -Xmx128M
- Flush buffers:
You need to flush the buffers when writing to sockets.
- Java3d optimisation for Wedge:
Different polling methods for the tracker can speed it up.
Use 600x800 resolution.
Garbage collector slows things down.
- JTable - table models saving data
The setValueAt method is called "when editing is finished" the table
says
that this is when
the entry has lost focus. If you wish to force a change then you need
to
force focus to change.
-
finding class files in packages
If you have a directory structure
. MainPogram
./domain1/*.java
./domain1/*.java
Then, in domain1 you have
package domain1;
import domain2.*;
This enables class files from domain2 to be linked to domain1.
BUT there is a problem in accessing class files in the parent directory
from classes in either of the subdirectories. Therefore, use the parent
directory for just a simple Main program.
- Optimisation tips:
Draw graphics into a buffer before painting onto a panel;
Have a pool of objects rather than instantiating them one at a time;
see also
http://www.glenmccl.com/jperf/index.htm
-
The students need to have it in their CLASSPATH on Linux
and Cygwin. For Cygwin, this involved editing the
C/cygwin/etc/profile
file to include c\henry\mm.mysql.jdbc-1.2c in the CLASSPATH path
(note that Java will read DOS strings; the entire CLASSPATH string is
"c;\jdk1.3;c:\henry\mm.mysql.jdbc-1.2c;." on my laptop).
You could also edit the AUTOEXEC.BAT file to include a statement equivalent to
SET CLASSPATH=c:\henry\mm.mysql.jdbc-1.2c;%CLASSPATH%
so that it will work in a DOS shell window as well as Cygwin.
---------- spheniscus (Linux)
[henry@spheniscus ~/java_dir]$ env | grep CLASSPATH
CLASSPATH=/data0/henry/java_dir/mm.mysql-2.0.4:.
setenv CLASSPATH /home/henry/java_dir/mm.mysql-2.0.4:.
setenv CLASSPATH /home/henry/teach/comp6442_2002/RodHarris/Comp6442:. (leave a space)
(env $CLASSPATH to view)
setenv CLASSPATH /home/henry/java_dir/mm.mysql-2.0.4:/home/henry/teach/comp6442_2002/RodHarris/Comp6442:.
echo $CLASSPATH
---------- ephebe
export CLASSPATH=/home/u8914398/comp6442/Comp6442:.
- Some Java3D tips:
error messages
java.lang.IllegalArgumentException: Texture: illegal image size
This might mean that the version of java3D is wrong.
check versions
cd c:
cd j2sdk1.4.1-02/demo/java3d/PackageInfo/
java PackageInfo .. says whether OpenGL/DirectX; version number
Also java QueryProperties .. query properties of graphics card etc.
- Some Java3D hints from 2001:
Problem:
After constructing my own Virtual Universe (not using a Simple Universe) the canvas was not being displayed on the screen.
Solution:
The order in which views, viewing platforms, locales, etc are attached on the view graph side of the scene graph is important. Start at the bottom of the graph and work your way up.
Problem:
The picking in Java 3D is really unreliable.
Solution:
Don't try to pick any sort of line, just try to pick objects with volume.
Problem:
Java Sound doesn't work in anything but the SimpleUniverse.
Solution:
Create a SimpleUniverse and get the AudioDevice from that then add it to your own VirtualUniverse.
Problem:
The head tracker and 6D mouse only seem to control the 2D mouse cursor.
Solution:
Turn the wedge computer off. Unplug the 2 serial cables from the back of it. Reboot the computer and log in, then reattach the serial cables.
Problem:
When run on the wedge the application couldn't use the head tracker driver application extension.
Solution:
Log in to the Wedge account on Monolith, Go under Start -> Settings -> ControlPanel. Then double click System, go under the Advanced tab, then click the Environment Variables button. In the dialog that opens there should be variables named CLASSPATH and PATH, make a copy of these and set your user account CLASSPATH and PATH variables to be the same as these. Also add a period (.) to both of these if one isn't already there.
Problem:
If I created a 3D object, added it to the scene graph, later removed it then tried to add it again I would get multiple parent exceptions, even though the previous parent was removed from the scene graph.
Solution:
Create a new 3D object with the same parameters as the first, add it to the scene graph and let the garbage collector take care of the original object.
Problem:
There is no way to find the length in time of a sound. There are 2 ways to play sounds with java, cached and streaming. When a sound is cached there is supposed to be a method which returns the (time) length of the sound, but this never worked, even when I explicitly told java to cache all sounds.
Solution:
Create a timer that every t milliseconds queries the sound to see if it is still playing. I used this in the 'sample sound' button of the 'Sound Foley' GUI to suspend the current thread until the sound stops playing.
Problem:
Serialized objects are really inconvenient to use. Implementing the Serializable interface allows the saving and loading of objects to be handled internally by java. At first this seems really good, but if you save an object then so much as change one character in the source code of its class then you can't reload this object, and this is a huge hassle when developing code.
Solution:
I wrote my own classes to load and save objects in my scene. The PathSaver object is used to save SoundPaths to disk in a text readable format. And can be used to load these paths again. When these paths are reloaded they are reloaded as DummyPaths, which carry all the data of SoundPaths but none of the behavior, so it is up to my SoundSceneFrame and WedgeSoundScene classes to take these DummyPaths and recreate SoundPaths from them.
Problem:
JComboBox content cannot be rendered over a Canvas3D. ie If you click the down arrow on a combo box, and it needs to be rendered over a canvas 3D, it will disappear behiend the canvas.
Solution:
Move the combo box to an east or west aligned panel, ensuring the box never overlaps the canvas.
- The cygwin command shell may have a timing overhead on
Windows. Experiment with using the Bash command shell.
- Try using the Profiler on Windows.
Last modified: Mon Jun 14 15:59:00 EST 2004
|